diff --git a/libs/remix-astwalker/src/astWalker.ts b/libs/remix-astwalker/src/astWalker.ts index 24229a298a..5ee9e46e71 100644 --- a/libs/remix-astwalker/src/astWalker.ts +++ b/libs/remix-astwalker/src/astWalker.ts @@ -100,6 +100,9 @@ export class AstWalker extends EventEmitter { tempArr.push(nodes) nodes = tempArr } + + // To break object referencing + nodes = [...nodes] if(ast.nodes && ast.baseContracts?.length) { // for ContractDefinition nodes.push(...ast.baseContracts) diff --git a/libs/remix-astwalker/tests/newTests.ts b/libs/remix-astwalker/tests/newTests.ts index cb30b5f36a..d739cd09e8 100644 --- a/libs/remix-astwalker/tests/newTests.ts +++ b/libs/remix-astwalker/tests/newTests.ts @@ -57,7 +57,7 @@ tape("New ASTWalker", (t: tape.Test) => { t.test("ASTWalker.getASTNodeChildren", (st: tape.Test) => { const latestAST = JSON.parse(JSON.stringify(latestASTNode)) - st.plan(14); + st.plan(26); st.equal(latestAST.nodeType, 'SourceUnit') let subNodes1 = astWalker.getASTNodeChildren(latestAST) @@ -81,11 +81,35 @@ tape("New ASTWalker", (t: tape.Test) => { st.equal(subNodes2[3].nodeType, 'InheritanceSpecifier') let subNodes3 = astWalker.getASTNodeChildren(subNodes2[0]) - st.equal(subNodes3.length, 1) st.equal(subNodes3[0].nodeType, 'ElementaryTypeName') + let subNodes4 = astWalker.getASTNodeChildren(subNodes3[0]) + st.equal(subNodes4.length, 0) + subNodes3 = astWalker.getASTNodeChildren(subNodes2[1]) + st.equal(subNodes3.length, 1) + st.equal(subNodes3[0].nodeType, 'Block') + + subNodes4 = astWalker.getASTNodeChildren(subNodes3[0]) + st.equal(subNodes4.length, 1) + st.equal(subNodes4[0].nodeType, 'ExpressionStatement') + + let subNodes5 = astWalker.getASTNodeChildren(subNodes4[0]) + st.equal(subNodes5.length, 1) + st.equal(subNodes5[0].nodeType, 'Assignment') + + let subNodes6 = astWalker.getASTNodeChildren(subNodes5[0]) + + st.equal(subNodes6.length, 2) + st.equal(subNodes6[0].nodeType, 'Identifier') + st.equal(subNodes6[1].nodeType, 'Identifier') + + let subNodes7 = astWalker.getASTNodeChildren(subNodes6[0]) + st.equal(subNodes7.length, 0) + + subNodes7 = astWalker.getASTNodeChildren(subNodes6[1]) + st.equal(subNodes7.length, 0) st.end(); });