GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(javascript): write a node acorn shares between two fields once pe… · webpack/webpack@208adba

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/javascript
    • syntax-parser.js
  • test/unitCases/javascript
    • parser.unittest.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/javascript/syntax-parser.js‎

Copy file name to clipboardExpand all lines: lib/javascript/syntax-parser.js
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20402,7 +20402,9 @@ class SyntaxTree {
2040220402
}
2040320403
}
2040420404
}
20405-
/** @type {Map<EstreeSource, number>} */
20405+
// One id per field holding a node, as acorn shares an object between two
20406+
// (an import's `imported` and `local`): each field takes the next one written.
20407+
/** @type {Map<EstreeSource, number[]>} */
2040620408
const ids = new Map();
2040720409
/**
2040820410
* @param {EstreeSourceItem | undefined} item a child, its id or none
@@ -20412,7 +20414,9 @@ class SyntaxTree {
2041220414
typeof item === "number"
2041320415
? item
2041420416
: item
20415-
? /** @type {number} */ (ids.get(item))
20417+
? /** @type {number} */ (
20418+
/** @type {number[]} */ (ids.get(item)).shift()
20419+
)
2041620420
: 0;
2041720421
let node = 0;
2041820422
for (let v = visited.length - 1; v >= 0; v--) {
@@ -20421,7 +20425,9 @@ class SyntaxTree {
2042120425
object.type
2042220426
];
2042320427
node = this.add(type, object.start, object.end);
20424-
ids.set(object, node);
20428+
const written = ids.get(object);
20429+
if (written === undefined) ids.set(object, [node]);
20430+
else written.push(node);
2042520431
const base = this._bases[node];
2042620432
for (const field of /** @type {TreeNodeType} */ (types[type]).fields) {
2042720433
const value = object[field.name];
Collapse file

‎test/unitCases/javascript/parser.unittest.js‎

Copy file name to clipboardExpand all lines: test/unitCases/javascript/parser.unittest.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5846,6 +5846,26 @@ describe("WebpackParser writing a SyntaxTree", () => {
58465846
expect(later).toEqual([]);
58475847
});
58485848

5849+
it("writes a node acorn shares between two fields once per field", () => {
5850+
const { Field } = require("../../../lib/javascript/syntax-parser");
5851+
const { tree } = parseIntoTree('import { x } from "m"; let y; export { y };');
5852+
/** @type {Map<number, number>} */
5853+
const parents = new Map();
5854+
/** @type {string[]} */
5855+
const shared = [];
5856+
for (let node = 1; node <= tree._count; node++) {
5857+
for (const field of Object.values(Field)) {
5858+
for (let i = 0, n = tree.fieldCount(field, node); i < n; i++) {
5859+
const child = tree.field(i, field, node);
5860+
if (child === 0) continue;
5861+
if (parents.has(child)) shared.push(`${child} in ${node}`);
5862+
parents.set(child, node);
5863+
}
5864+
}
5865+
}
5866+
expect(shared).toEqual([]);
5867+
});
5868+
58495869
it("writes an import or export a loop runs, where they are allowed everywhere", () => {
58505870
for (const source of [
58515871
'for (;;) import a from "b";',

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.