File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,6 @@ import * as line from '../util/diff/line';
44import { structHash } from '../json-hash' ;
55import type { Operation } from '../json-patch/codec/json/types' ;
66
7- export class DiffError extends Error {
8- constructor ( message : string = 'DIFF' ) {
9- super ( message ) ;
10- }
11- }
12-
137export class Diff {
148 protected patch : Operation [ ] = [ ] ;
159
@@ -83,8 +77,8 @@ export class Diff {
8377 public diffAny ( path : string , src : unknown , dst : unknown ) : void {
8478 switch ( typeof src ) {
8579 case 'string' : {
86- if ( typeof dst ! == 'string' ) throw new DiffError ( ) ;
87- this . diffStr ( path , src , dst ) ;
80+ if ( typeof dst == 'string' ) this . diffStr ( path , src , dst ) ;
81+ else this . diffVal ( path , src , dst ) ;
8882 break ;
8983 }
9084 case 'number' :
Original file line number Diff line number Diff line change @@ -53,6 +53,11 @@ describe('obj', () => {
5353 assertDiff ( src , dst ) ;
5454 } ) ;
5555
56+ test ( 'string key type change' , ( ) => {
57+ assertDiff ( { foo : 'asdf' } , { foo : 123 } ) ;
58+ assertDiff ( { foo : 123 } , { foo : 'asdf' } ) ;
59+ } ) ;
60+
5661 test ( 'can insert new key' , ( ) => {
5762 const src = { } ;
5863 const dst = { foo : 'hello!' } ;
@@ -103,6 +108,11 @@ describe('obj', () => {
103108} ) ;
104109
105110describe ( 'arr' , ( ) => {
111+ test ( 'string element type change' , ( ) => {
112+ assertDiff ( [ 'asdf' ] , [ 123 ] ) ;
113+ assertDiff ( [ 123 ] , [ 'asdf' ] ) ;
114+ } ) ;
115+
106116 test ( 'can add element to an empty array' , ( ) => {
107117 const src : unknown [ ] = [ ] ;
108118 const dst : unknown [ ] = [ 1 ] ;
You can’t perform that action at this time.
0 commit comments