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 — perf(javascript): read every parser hook node by id, so a build makes no ESTree object by alexander-akait · Pull Request #23256 · webpack/webpack

perf(javascript): read every parser hook node by id, so a build makes no ESTree object #23256

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 16 commits into main from perf/javascript-plugins-path-taps-rest
Nov 11, 2026

Uh oh!

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

Merged

perf(javascript): read every parser hook node by id, so a build makes no ESTree object #23256

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b0ee24b
perf(javascript): add path forms of the parser tap helpers
alexander-akait Nov 10, 2026
aa9cf2b
perf(javascript): read CommonJS and createRequire hook nodes by id
alexander-akait Nov 10, 2026
233cbf6
perf(javascript): read ESM, worker, URL and context hook nodes by id
alexander-akait Nov 10, 2026
d70a9a7
perf(javascript): read AMD, System, Node, HMR and provide hook nodes …
alexander-akait Nov 10, 2026
b1f8a08
perf(javascript): read define, import.meta and parser-own hook nodes …
alexander-akait Nov 10, 2026
ffababf
perf(javascript): read CommonJS export and context nodes by id
alexander-akait Nov 10, 2026
2c03787
perf(javascript): read import, URL and namespace check nodes by id
alexander-akait Nov 10, 2026
dfd3d0b
perf(javascript): walk patterns, labels, updates and dead branches by id
alexander-akait Nov 10, 2026
eb1b3cc
perf(javascript): read AMD, require.ensure and HMR accept nodes by id
alexander-akait Nov 10, 2026
56376f1
perf(javascript): read ESM, live export, import, context and worker n…
alexander-akait Nov 10, 2026
b1b3579
perf(javascript): read import guards, import().then and System.import…
alexander-akait Nov 10, 2026
560297a
perf(javascript): load getFunctionNode on first use
alexander-akait Nov 11, 2026
14d8951
refactor(javascript): type an import option key name instead of unknown
alexander-akait Nov 11, 2026
1e97fd1
fix(javascript): pick an AMD factory's mode detection by its reader
alexander-akait Nov 11, 2026
057ad05
test: cover the object-form parser APIs and drop dead ConstPlugin code
alexander-akait Nov 11, 2026
00c21ca
test: widen the burn gap in hotspots-ranked
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
perf(javascript): add path forms of the parser tap helpers
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 10, 2026
commit b0ee24bbebb7b7b487eded8759de9c2f9fe67922

There are no files selected for viewing

89 changes: 48 additions & 41 deletions 89 lib/dependencies/amd/AMDPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

const {
approve,
evaluateToIdentifier,
evaluateToString,
toConstantDependency
evaluateToIdentifierByPath,
evaluateToStringByPath,
toConstantDependencyByPath
} = require("../../javascript/JavascriptParserHelpers");
const {
JAVASCRIPT_MODULE_TYPE_AUTO,
Expand Down Expand Up @@ -39,7 +39,7 @@ const UnsupportedDependency = require("./UnsupportedDependency");
* } from "../../../declarations/WebpackOptions"
*/
/** @import Compiler from "../../Compiler" */
/** @import Parser, { Range } from "../../javascript/JavascriptParser" */
/** @import Parser from "../../javascript/JavascriptParser" */
/** @import { GetMembers } from "../../javascript/BasicEvaluatedExpression" */

const PLUGIN_NAME = "AMDPlugin";
Expand Down Expand Up @@ -154,29 +154,28 @@ class AMDPlugin {
parser.hooks.expression
.for(optionExpr)
.tap(
PLUGIN_NAME,
toConstantDependency(parser, RuntimeGlobals.amdOptions, [
{ name: PLUGIN_NAME, path: true },
toConstantDependencyByPath(parser, RuntimeGlobals.amdOptions, [
RuntimeGlobals.amdOptions
])
);
parser.hooks.evaluateIdentifier
.for(optionExpr)
.tap(PLUGIN_NAME, (expr) =>
evaluateToIdentifier(
optionExpr,
rootName,
getMembers,
true
)(expr)
.tap(
{ name: PLUGIN_NAME, path: true },
evaluateToIdentifierByPath(optionExpr, rootName, getMembers, true)
);
parser.hooks.evaluateTypeof
.for(optionExpr)
.tap(PLUGIN_NAME, evaluateToString("object"));
.tap(
{ name: PLUGIN_NAME, path: true },
evaluateToStringByPath("object")
);
parser.hooks.typeof
.for(optionExpr)
.tap(
PLUGIN_NAME,
toConstantDependency(parser, JSON.stringify("object"))
{ name: PLUGIN_NAME, path: true },
toConstantDependencyByPath(parser, JSON.stringify("object"))
);
};

Expand All @@ -193,45 +192,53 @@ class AMDPlugin {
() => []
);

parser.hooks.expression.for("define").tap(PLUGIN_NAME, (expr) => {
const dep = new ConstDependency(
RuntimeGlobals.amdDefine,
/** @type {Range} */ (expr.range),
[RuntimeGlobals.amdDefine]
parser.hooks.expression
.for("define")
.tap(
{ name: PLUGIN_NAME, path: true },
toConstantDependencyByPath(parser, RuntimeGlobals.amdDefine, [
RuntimeGlobals.amdDefine
])
);
dep.loc = parser.getLocation(expr);
parser.state.module.addPresentationalDependency(dep);
return true;
});
parser.hooks.typeof
.for("define")
.tap(
PLUGIN_NAME,
toConstantDependency(parser, JSON.stringify("function"))
{ name: PLUGIN_NAME, path: true },
toConstantDependencyByPath(parser, JSON.stringify("function"))
);
parser.hooks.evaluateTypeof
.for("define")
.tap(PLUGIN_NAME, evaluateToString("function"));
parser.hooks.canRename.for("define").tap(PLUGIN_NAME, approve);
parser.hooks.rename.for("define").tap(PLUGIN_NAME, (expr) => {
const dep = new ConstDependency(
RuntimeGlobals.amdDefine,
/** @type {Range} */ (expr.range),
[RuntimeGlobals.amdDefine]
.tap(
{ name: PLUGIN_NAME, path: true },
evaluateToStringByPath("function")
);
dep.loc = parser.getLocation(expr);
parser.state.module.addPresentationalDependency(dep);
return false;
});
parser.hooks.canRename
.for("define")
.tap({ name: PLUGIN_NAME, path: true }, approve);
parser.hooks.rename
.for("define")
.tap({ name: PLUGIN_NAME, path: true }, (path, node) => {
const dep = new ConstDependency(
RuntimeGlobals.amdDefine,
path.range(node),
[RuntimeGlobals.amdDefine]
);
dep.loc = parser.getLocation(parser.nodeOfPath(path, node));
parser.state.module.addPresentationalDependency(dep);
return false;
});
parser.hooks.typeof
.for("require")
.tap(
PLUGIN_NAME,
toConstantDependency(parser, JSON.stringify("function"))
{ name: PLUGIN_NAME, path: true },
toConstantDependencyByPath(parser, JSON.stringify("function"))
);
parser.hooks.evaluateTypeof
.for("require")
.tap(PLUGIN_NAME, evaluateToString("function"));
.tap(
{ name: PLUGIN_NAME, path: true },
evaluateToStringByPath("function")
);
};

normalModuleFactory.hooks.parser
Expand Down
13 changes: 8 additions & 5 deletions 13 lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const WebpackError = require("../../errors/WebpackError");
const {
evaluateToIdentifier
evaluateToIdentifierByPath
} = require("../../javascript/JavascriptParserHelpers");
const ImportMetaContextDependency = require("./ImportMetaContextDependency");

Expand Down Expand Up @@ -69,17 +69,20 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
apply(parser) {
parser.hooks.evaluateIdentifier
.for("import.meta.webpackContext")
.tap(PLUGIN_NAME, (expr) =>
evaluateToIdentifier(
.tap(
{ name: PLUGIN_NAME, path: true },
evaluateToIdentifierByPath(
"import.meta.webpackContext",
"import.meta",
() => ["webpackContext"],
true
)(expr)
)
);
parser.hooks.call
.for("import.meta.webpackContext")
.tap(PLUGIN_NAME, (expr) => {
.tap({ name: PLUGIN_NAME, path: true }, (path, node) => {
// the call's options are read whole, only where it is written
const expr = /** @type {CallExpression} */ (path.object(node));
if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
const [directoryNode, optionsNode] = expr.arguments;
if (optionsNode && optionsNode.type !== "ObjectExpression") return;
Expand Down
18 changes: 12 additions & 6 deletions 18 lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"use strict";

const {
evaluateToIdentifier
evaluateToIdentifierByPath
} = require("../../javascript/JavascriptParserHelpers");
const ImportMetaGlobDependency = require("./ImportMetaGlobDependency");
const { parseImportMetaGlobCall } = require("./ImportMetaGlobHelpers");

/** @import { CallExpression } from "estree" */
/** @import JavascriptParser from "../../javascript/JavascriptParser" */

const PLUGIN_NAME = "ImportMetaGlobDependencyParserPlugin";
Expand All @@ -24,15 +25,20 @@ module.exports = class ImportMetaGlobDependencyParserPlugin {
apply(parser) {
parser.hooks.evaluateIdentifier
.for("import.meta.glob")
.tap(PLUGIN_NAME, (expr) =>
evaluateToIdentifier(
.tap(
{ name: PLUGIN_NAME, path: true },
evaluateToIdentifierByPath(
"import.meta.glob",
"import.meta",
() => ["glob"],
true
)(expr)
)
);
parser.hooks.call.for("import.meta.glob").tap(PLUGIN_NAME, (expr) => {
parser.hooks.call
.for("import.meta.glob")
.tap({ name: PLUGIN_NAME, path: true }, (path, node) => {
// the call's arguments are read whole, only where it is written
const expr = /** @type {CallExpression} */ (path.object(node));
const {
options: globOptions,
errors,
Expand Down Expand Up @@ -69,6 +75,6 @@ module.exports = class ImportMetaGlobDependencyParserPlugin {
dep.optional = Boolean(parser.scope.inTry);
parser.state.current.addDependency(dep);
return true;
});
});
}
};
7 changes: 6 additions & 1 deletion 7 lib/dependencies/context/RequireContextDependencyParserPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const RequireContextDependency = require("./RequireContextDependency");

/** @import { CallExpression } from "estree" */
/** @import { ContextMode } from "../../context/ContextModule" */
/** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */

Expand All @@ -19,7 +20,11 @@ module.exports = class RequireContextDependencyParserPlugin {
* @returns {void}
*/
apply(parser) {
parser.hooks.call.for("require.context").tap(PLUGIN_NAME, (expr) => {
parser.hooks.call
.for("require.context")
.tap({ name: PLUGIN_NAME, path: true }, (path, node) => {
// the call's arguments are read whole, only where it is written
const expr = /** @type {CallExpression} */ (path.object(node));
let regExp = /^\.\/.*$/;
let recursive = true;
/** @type {ContextMode} */
Expand Down
113 changes: 113 additions & 0 deletions 113 lib/javascript/JavascriptParserHelpers.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getUnsupportedFeatureWarning = memoize(() =>

/** @import { CallExpression, Expression, NewExpression } from "estree" */
/** @import JavascriptParser, { JavascriptNodeReader, Range } from "./JavascriptParser" */
/** @typedef {(path: JavascriptNodeReader, node: number) => BasicEvaluatedExpression} EvaluateByPath */
/** @import { GetMembers } from "./BasicEvaluatedExpression" */

module.exports.approve = () => true;
Expand Down Expand Up @@ -182,3 +183,115 @@ module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
parser.state.module.addPresentationalDependency(dep);
return true;
};

/**
* `evaluateToBoolean` for a `{ path: true }` tap, reading the node by id.
* @param {boolean} value the boolean value
* @returns {EvaluateByPath} plugin function
*/
module.exports.evaluateToBooleanByPath = (value) =>
function booleanExpression(path, node) {
return new BasicEvaluatedExpression()
.setBoolean(value)
.setRange(path.range(node));
};

/**
* `evaluateToIdentifier` for a `{ path: true }` tap, reading the node by id.
* @param {string} identifier identifier
* @param {string} rootInfo rootInfo
* @param {GetMembers} getMembers getMembers
* @param {boolean | null=} truthy is truthy, null if nullish
* @returns {EvaluateByPath} plugin function
*/
module.exports.evaluateToIdentifierByPath = (
identifier,
rootInfo,
getMembers,
truthy
) =>
function identifierExpression(path, node) {
const evaluatedExpression = new BasicEvaluatedExpression()
.setIdentifier(identifier, rootInfo, getMembers)
.setSideEffects(false)
.setRange(path.range(node));
switch (truthy) {
case true:
evaluatedExpression.setTruthy();
break;
case null:
evaluatedExpression.setNullish(true);
break;
case false:
evaluatedExpression.setFalsy();
break;
}

return evaluatedExpression;
};

/**
* `evaluateToNumber` for a `{ path: true }` tap, reading the node by id.
* @param {number} value the number value
* @returns {EvaluateByPath} plugin function
*/
module.exports.evaluateToNumberByPath = (value) =>
function numberExpression(path, node) {
return new BasicEvaluatedExpression()
.setNumber(value)
.setRange(path.range(node));
};

/**
* `evaluateToString` for a `{ path: true }` tap, reading the node by id.
* @param {string} value the string value
* @returns {EvaluateByPath} plugin function
*/
module.exports.evaluateToStringByPath = (value) =>
function stringExpression(path, node) {
return new BasicEvaluatedExpression()
.setString(value)
.setRange(path.range(node));
};

/**
* `expressionIsUnsupported` for a `{ path: true }` tap, reading the node by id.
* @param {JavascriptParser} parser the parser
* @param {string} message the message
* @returns {(path: JavascriptNodeReader, node: number) => boolean | undefined} callback to handle unsupported expression
*/
module.exports.expressionIsUnsupportedByPath = (parser, message) =>
function unsupportedExpression(path, node) {
const loc = parser.getLocation(parser.nodeOfPath(path, node));
const dep = new ConstDependency("(void 0)", path.range(node), null);
dep.loc = loc;
parser.state.module.addPresentationalDependency(dep);
if (!parser.state.module) return;
parser.state.module.addWarning(
new (getUnsupportedFeatureWarning())(message, loc)
);
return true;
};

/**
* `toConstantDependency` for a `{ path: true }` tap, reading the node by id.
* @param {JavascriptParser} parser the parser
* @param {string} value the const value
* @param {(string[] | null)=} runtimeRequirements runtime requirements
* @returns {(path: JavascriptNodeReader, node: number) => true} plugin function
*/
module.exports.toConstantDependencyByPath = (
parser,
value,
runtimeRequirements
) =>
function constDependency(path, node) {
const dep = new ConstDependency(
value,
path.range(node),
runtimeRequirements
);
dep.loc = parser.getLocation(parser.nodeOfPath(path, node));
parser.state.module.addPresentationalDependency(dep);
return true;
};
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.