Skip to content

Commit 637dae8

Browse files
test(js): cover the lazy parser's defensive ranges copy
1 parent e990319 commit 637dae8

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎test/JavascriptParser.unittest.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,5 +1555,25 @@ describe("JavascriptParser", () => {
15551555
block.range = [1, 2];
15561556
expect(block.range).toEqual([1, 2]);
15571557
});
1558+
1559+
it("serves a direct caller's `ranges` lazily, leaving its options alone", () => {
1560+
const options = { ecmaVersion: 2022, lazyNodes: true, ranges: true };
1561+
const program = /** @type {EXPECTED_ANY} */ (
1562+
WebpackParser.parse(
1563+
"var x = 1;",
1564+
/** @type {import("acorn").Options} */ (
1565+
/** @type {unknown} */ (options)
1566+
)
1567+
)
1568+
);
1569+
expect(options.ranges).toBe(true);
1570+
const declaration = program.body[0];
1571+
// lazy: `range` comes from the prototype getter, not from acorn
1572+
expect(
1573+
Object.getOwnPropertyDescriptor(declaration, "range")
1574+
).toBeUndefined();
1575+
expect(declaration.range).toEqual([0, 10]);
1576+
expect(declaration.range).toBe(declaration.range);
1577+
});
15581578
});
15591579
});

0 commit comments

Comments
 (0)