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 — test(javascript): cover the object-form parser paths the ESTree walk reached by alexander-akait · Pull Request #23261 · webpack/webpack

test(javascript): cover the object-form parser paths the ESTree walk reached #23261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
alexander-akait merged 2 commits into main from test/javascript-parser-object-paths
Nov 11, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

test(javascript): cover the object-form parser paths the ESTree walk reached #23261

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
f0fb342
refactor(javascript): drop the object-form walk helpers nothing calls
alexander-akait Nov 11, 2026
a51fb79
test: cover the object-form parser paths the ESTree walk reached
alexander-akait Nov 11, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
refactor(javascript): drop the object-form walk helpers nothing calls
The hoisted-declaration collectors, the object import().then() callback
walk and isLeftToEvaluator's unary and binary branch served the removed
ESTree walk; every hook now reads the parser's own tree.

Claude-Session: https://claude.ai/code/session_013FhutRENJSfqFqSYN8hkt3
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait committed Nov 11, 2026
commit f0fb34287d7eba752ff98c50ca0e34ec17faaba6

There are no files selected for viewing

107 changes: 7 additions & 100 deletions 107 lib/dependencies/import/ImportParserPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ const getCommentCompilationWarning = memoize(() =>
require("../../errors/CommentCompilationWarning")
);

/**
* @import {
* ArrowFunctionExpression,
* FunctionExpression,
* Identifier,
* ObjectPattern
* } from "estree"
*/
/**
* @import {
* JavascriptParserOptions
Expand Down Expand Up @@ -115,78 +107,6 @@ function tagDynamicImportReferenced(parser, path, importCall, variableName) {
);
}

/**
* Walk import then fulfilled callback.
* @param {JavascriptParser} parser javascript parser
* @param {JavascriptNodeReader} path the reader of the import expression
* @param {number} importCallNode the import expression
* @param {ArrowFunctionExpression | FunctionExpression} fulfilledCallback the fulfilled callback
* @param {Identifier | ObjectPattern} namespaceObjArg the argument of namespace object=
*/
function walkImportThenFulfilledCallback(
parser,
path,
importCallNode,
fulfilledCallback,
namespaceObjArg
) {
const importCall = /** @type {ImportExpression} */ (
path.object(importCallNode)
);
const arrow = fulfilledCallback.type === "ArrowFunctionExpression";
const wasTopLevel = parser.scope.topLevelScope;
parser.scope.topLevelScope = arrow ? (wasTopLevel ? "arrow" : false) : false;
const scopeParams = [...fulfilledCallback.params];

// Add function name in scope for recursive calls
if (!arrow && fulfilledCallback.id) {
scopeParams.push(fulfilledCallback.id);
}

parser.inFunctionScope(!arrow, scopeParams, () => {
if (namespaceObjArg.type === "Identifier") {
tagDynamicImportReferenced(
parser,
path,
importCallNode,
namespaceObjArg.name
);
} else {
parser.enterDestructuringAssignment(namespaceObjArg, importCall);
const referencedPropertiesInDestructuring =
parser.destructuringAssignmentPropertiesFor(importCall);
if (referencedPropertiesInDestructuring) {
const state = getState(parser, path);
const references = /** @type {ReferencedSpecifiers} */ (
state.get(importCallNode)
);
/** @type {ReferencedSpecifiers} */
const refsInDestructuring = [];
traverseDestructuringAssignmentProperties(
referencedPropertiesInDestructuring,
(stack) => refsInDestructuring.push(stack.map((p) => p.id))
);
for (const ids of refsInDestructuring) {
references.push(ids);
}
}
}
for (const param of fulfilledCallback.params) {
parser.walkPattern(param);
}
if (fulfilledCallback.body.type === "BlockStatement") {
parser.detectMode(fulfilledCallback.body.body);
const prev = parser.prevStatement;
parser.preWalkStatement(fulfilledCallback.body);
parser.prevStatement = prev;
parser.walkStatement(fulfilledCallback.body);
} else {
parser.walkExpression(fulfilledCallback.body);
}
});
parser.scope.topLevelScope = wasTopLevel;
}

/**
* The namespace parameter of an `import().then()` call's fulfilled callback.
* @param {JavascriptNodeReader} path the reader of the call
Expand Down Expand Up @@ -913,26 +833,13 @@ class ImportParserPlugin {
if (fulfilledNamespaceObj !== 0) {
first = 1;
const callback = path.field(0, Field.arguments, importThenNode);
if (path === parser._tree) {
walkImportThenFulfilledCallbackNode(
parser,
path,
node,
callback,
fulfilledNamespaceObj
);
} else {
// a preparsed AST or a synthetic node: the reader holds objects
walkImportThenFulfilledCallback(
parser,
path,
node,
/** @type {ArrowFunctionExpression | FunctionExpression} */
(path.object(callback)),
/** @type {Identifier | ObjectPattern} */
(path.object(fulfilledNamespaceObj))
);
}
walkImportThenFulfilledCallbackNode(
parser,
path,
node,
callback,
fulfilledNamespaceObj
);
}
const count = path.fieldCount(Field.arguments, importThenNode);
for (let i = first; i < count; i++) {
Expand Down
130 changes: 13 additions & 117 deletions 130 lib/javascript/JavascriptParser.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ const {
/** @typedef {(ident: string) => void} OnIdentString */
/** @typedef {(ident: string, identifier: Identifier) => void} OnIdent */
/** @typedef {StatementPathItem[]} StatementPath */
/** @typedef {(Statement | ModuleDeclaration)[]} HoistedDeclarations the declarations one scope hoists, in source order */
/** @typedef {(ModuleDeclaration | Statement | undefined)[]} ModuleDeclarations the program's import and re-export declarations in source order, each followed by the statement written before it */
/** @typedef {number | number[]} BlockDeclarations which statements of one list declare into its block scope: a mask of their indices, or the indices themselves once one is too large to mask */

Expand All @@ -179,8 +178,6 @@ const {

/** @type {string[]} */
const EMPTY_ARRAY = [];
/** @type {HoistedDeclarations} */
const EMPTY_HOISTED_DECLARATIONS = [];
// what the module pass reports; `export default` is the block pass's
// what the parser records per scope, and so what the hoisting pass reaches
const RECORDED_STATEMENT_TYPES = new Set([
Expand Down Expand Up @@ -269,28 +266,18 @@ const isLeftToEvaluatorOperator = (type, operator) =>

/**
* Whether the evaluator, rather than the rules, judges a node the side-effect
* rules leave undecided.
* @param {Node | undefined} node the node, read for a unary or binary operator
* rules leave undecided; a unary or binary node goes by its operator instead.
* @param {number} type its `NodeType`
* @returns {boolean} whether the evaluator judges it
*/
const isLeftToEvaluator = (node, type) => {
switch (type) {
case NodeType.UnaryExpression:
case NodeType.BinaryExpression:
return isLeftToEvaluatorOperator(
type,
/** @type {UnaryExpression | BinaryExpression} */ (node).operator
);
default:
if (ruledPurityNodeTypes === undefined) {
ruledPurityNodeTypes = new Uint8Array(256);
for (const name of RULED_PURITY_TYPES) {
ruledPurityNodeTypes[NodeType[name]] = 1;
}
}
return ruledPurityNodeTypes[type] !== 1;
const isLeftToEvaluator = (type) => {
if (ruledPurityNodeTypes === undefined) {
ruledPurityNodeTypes = new Uint8Array(256);
for (const name of RULED_PURITY_TYPES) {
ruledPurityNodeTypes[NodeType[name]] = 1;
}
}
return ruledPurityNodeTypes[type] !== 1;
};

/**
Expand Down Expand Up @@ -1160,99 +1147,6 @@ const evaluateAstCaches = new WeakMap();
// The inner map is strong while the compilation lives, so cap it
const EVALUATE_AST_CACHE_LIMIT = 4096;

/**
* Add one declaration, starting the list at the first — most scopes declare
* nothing, and the shared empty list spares them an array.
* @param {HoistedDeclarations} hoisted the list so far
* @param {Statement | ModuleDeclaration} declaration what to add
* @returns {HoistedDeclarations} the list holding it
*/
const addHoistedDeclaration = (hoisted, declaration) => {
if (hoisted === EMPTY_HOISTED_DECLARATIONS) return [declaration];
hoisted.push(declaration);
return hoisted;
};

/**
* Collect the declarations that hoist to one scope, for an AST that did not
* come from webpack's parser and so carries no record of its own.
* @param {(Statement | ModuleDeclaration)[]} statements the scope's statements
* @param {HoistedDeclarations} hoisted the list so far
* @returns {HoistedDeclarations} the list holding what they declare
*/
const collectHoistedDeclarations = (statements, hoisted) => {
for (let index = 0, len = statements.length; index < len; index++) {
hoisted = collectHoistedDeclaration(statements[index], hoisted);
}
return hoisted;
};

/**
* Collect from one statement, descending exactly as far as a `var` reaches:
* through blocks and loop bodies, never into another function.
* @param {Statement | ModuleDeclaration} statement the statement
* @param {HoistedDeclarations} hoisted the list so far
* @returns {HoistedDeclarations} the list holding what it declares
*/
const collectHoistedDeclaration = (statement, hoisted) => {
switch (statement.type) {
case "VariableDeclaration":
if (statement.kind === "var") {
hoisted = addHoistedDeclaration(hoisted, statement);
}
break;
case "FunctionDeclaration":
case "ClassDeclaration":
hoisted = addHoistedDeclaration(hoisted, statement);
break;
case "BlockStatement":
hoisted = collectHoistedDeclarations(statement.body, hoisted);
break;
case "IfStatement":
hoisted = collectHoistedDeclaration(statement.consequent, hoisted);
if (statement.alternate) {
hoisted = collectHoistedDeclaration(statement.alternate, hoisted);
}
break;
case "ForStatement":
if (statement.init && statement.init.type === "VariableDeclaration") {
hoisted = collectHoistedDeclaration(statement.init, hoisted);
}
hoisted = collectHoistedDeclaration(statement.body, hoisted);
break;
case "ForInStatement":
case "ForOfStatement":
if (statement.left.type === "VariableDeclaration") {
hoisted = collectHoistedDeclaration(statement.left, hoisted);
}
hoisted = collectHoistedDeclaration(statement.body, hoisted);
break;
case "WhileStatement":
case "DoWhileStatement":
case "LabeledStatement":
case "WithStatement":
hoisted = collectHoistedDeclaration(statement.body, hoisted);
break;
case "TryStatement":
hoisted = collectHoistedDeclaration(statement.block, hoisted);
if (statement.handler) {
hoisted = collectHoistedDeclaration(statement.handler.body, hoisted);
}
if (statement.finalizer) {
hoisted = collectHoistedDeclaration(statement.finalizer, hoisted);
}
break;
case "SwitchStatement": {
const cases = statement.cases;
for (let index = 0, len = cases.length; index < len; index++) {
hoisted = collectHoistedDeclarations(cases[index].consequent, hoisted);
}
break;
}
}
return hoisted;
};

/**
* Parses as the goal asks, an `auto` source as a module and then, where that
* fails, as a script, reporting the module parse's error when both fail.
Expand All @@ -1275,7 +1169,8 @@ const parseInGoal = (type, parseAs) => {
};

/**
* `collectHoistedDeclarations` for a list of statements of the tree, by id.
* Collects the declarations a list of statements of the tree hoists to its
* scope, by id.
* @param {SyntaxTree} tree the tree
* @param {number} owner the node holding the list
* @param {number} field the `Field` holding the statements
Expand All @@ -1294,7 +1189,8 @@ const collectHoistedDeclarationsNode = (tree, owner, field, hoisted) => {
};

/**
* `collectHoistedDeclaration` for a statement of the tree, by id.
* Collects what one statement of the tree hoists, descending as far as a
* `var` reaches: through blocks and loop bodies, never into a function.
* @param {SyntaxTree} tree the tree
* @param {number} id the statement, or `0` for none
* @param {number[]} hoisted the declarations found so far, added to
Expand Down Expand Up @@ -8794,7 +8690,7 @@ class JavascriptParser extends Parser {
if (
type === NodeType.UnaryExpression || type === NodeType.BinaryExpression
? isLeftToEvaluatorOperator(type, this._operatorOf(node))
: isLeftToEvaluator(undefined, type)
: isLeftToEvaluator(type)
) {
return this.evaluateExpression(asNode(node)).couldHaveSideEffects();
}
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.