File tree 2 files changed +21
-0
lines changed 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,23 @@ class BaseNode {
51
51
}
52
52
return true ;
53
53
}
54
+
55
+ clone ( ) {
56
+ function visit ( value ) {
57
+ if ( value instanceof BaseNode ) {
58
+ return value . clone ( ) ;
59
+ }
60
+ if ( Array . isArray ( value ) ) {
61
+ return value . map ( visit ) ;
62
+ }
63
+ return value ;
64
+ }
65
+ const clone = Object . create ( this ) ;
66
+ for ( const prop of Object . keys ( this ) ) {
67
+ clone [ prop ] = visit ( this [ prop ] ) ;
68
+ }
69
+ return clone ;
70
+ }
54
71
}
55
72
56
73
function scalars_equal ( thisVal , otherVal , ignoredFields ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ suite("BaseNode.equals", function() {
13
13
const thisNode = new AST . Identifier ( "name" ) ;
14
14
const otherNode = new AST . Identifier ( "name" ) ;
15
15
assert . strictEqual ( thisNode . equals ( otherNode ) , true ) ;
16
+ assert . strictEqual ( thisNode . equals ( thisNode . clone ( ) ) , true ) ;
17
+ assert . notStrictEqual ( thisNode , thisNode . clone ( ) ) ;
16
18
} ) ;
17
19
test ( "Node.type" , function ( ) {
18
20
const thisNode = new AST . Identifier ( "name" ) ;
@@ -54,6 +56,8 @@ suite("BaseNode.equals", function() {
54
56
assert . strictEqual ( thisNode . equals ( otherNode , [ 'span' , 'comment' ] ) , true ) ;
55
57
assert . strictEqual ( thisNode . value . equals ( otherNode . value ) , true ) ;
56
58
assert . strictEqual ( thisNode . value . equals ( otherNode . value , [ ] ) , false ) ;
59
+ assert . strictEqual ( thisRes . equals ( thisRes . clone ( ) , [ ] ) , true ) ;
60
+ assert . notStrictEqual ( thisRes , thisRes . clone ( ) ) ;
57
61
} ) ;
58
62
test ( "Attributes without order" , function ( ) {
59
63
const thisRes = this . parser . parse ( ftl `
You can’t perform that action at this time.
0 commit comments