Skip to content

Commit

Permalink
Add test to verify comments aren't duplicated when replacing the root…
Browse files Browse the repository at this point in the history
… node
  • Loading branch information
BenBaryoPX committed Oct 16, 2024
1 parent f3305ff commit 0ee0655
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/arborist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,25 @@ describe('Arborist tests', () => {
arborist.applyChanges();
assert.equal(arborist.script, code, 'Invalid changes were applied.');
});
it(`Verify comments aren't duplicated when replacing the root node`, () => {
const code = `//comment1\nconst a = 1, b = 2;`;
const expected = `//comment1\nconst a = 1;\nconst b = 2;`;
const arb = new Arborist(code);
const decls = [];
arb.ast.forEach(n => {
if (n.type === 'VariableDeclarator') {
decls.push({
type: 'VariableDeclaration',
kind: 'const',
declarations: [n],
});
}
});
arb.markNode(arb.ast[0], {
...arb.ast[0],
body: decls,
});
arb.applyChanges();
assert.equal(arb.script, expected);
});
});

0 comments on commit 0ee0655

Please sign in to comment.