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 — feat(javascript): let program taps read the program through the path by alexander-akait · Pull Request #23234 · webpack/webpack

feat(javascript): let program taps read the program through the path #23234

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 4 commits into main from feat/javascript-program-path-taps
Nov 9, 2026

Uh oh!

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

Merged

feat(javascript): let program taps read the program through the path #23234

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
b8b901a
feat(javascript): let program taps read the program through the path
alexander-akait Nov 9, 2026
cd8f9b1
perf(javascript): keep the program view's cleanup out of parse
alexander-akait Nov 9, 2026
b35ceed
refactor(javascript): cast a path tap's function without unknown
alexander-akait Nov 9, 2026
36a02bf
perf(javascript): keep built-in program taps on objects until the tre…
alexander-akait Nov 9, 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
feat(javascript): let program taps read the program through the path
A `{ name, path: true }` tap on `program` gets the path, the program's node
and the comments. It replaces the experimental `walkIds` option and
`programTree` hook, which never shipped.

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 9, 2026
commit b8b901a90b07ab13b87526e572dc8b5576fd6a8b

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 .changeset/046-javascript-program-path-taps.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack": minor
---

Let a `program` parser tap read the program through the path with `path: true`.
5 changes: 0 additions & 5 deletions 5 .changeset/046-javascript-program-tree-hook.md
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

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

2 changes: 1 addition & 1 deletion 2 docs/syntax.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Conventions every language keeps, and a new member follows:

## JavaScript

- `syntax.js` reaches `parser` and `printer` through getters: parsing never loads the printer, and the printer loads the parser to read an asset into a `SyntaxTree`. It is the only parser: a source it refuses is refused, and terser's parse options for what is not a program (`parse.expression`, `parse.strict`, `parse.experimental_typescript`) are refused too. `toEstreeObject(node, fields?)` builds the ESTree object of a node of the last parse (`SyntaxTree#estree` of any tree), each call returning the same object: every field, or only those listed and the rest on a later call; a whole program asked for first is built in one pass in id order. It bridges hooks and plugins while the parser moves to that struct-of-arrays tree. A reader the next parse must not disturb, as `JavascriptParser` is for its `programTree` hook, takes the tree with `takeParsedTree()` and releases it once read. The tree already reads as [the node path](#the-node-path) does, a node passed last: `type`, `start`, `end`, `range`, `name`, `value`, `field`, `fieldCount`, `flag` and `textOf` with the `NodeType`, `Field`, `Flag` and `Part` that `syntax.parser` exports. `SourceProcessor` walks the tree a parse writes as the CSS and HTML ones walk theirs, each visitor handed that path and the children taken in source order (a template's quasis and expressions in turn). Asked for `mode: "minify"`, the same walk prints: `syntax-printer.js`'s `printer` returns each node's text from its children's, as `minify` prints a source it neither compresses nor mangles, comments left out and terser's format options read from `format`. A minify walks the tree its own parse wrote (`walkSyntaxTree`) with the comments it keeps, a name printed inside its parent's text where none of its own is read: each is taken as terser's printer reaches it, by the node holding its token, and printed once the text before it is, which a text opening with it leaves to the node printing that text. What terser's stream reads off the text before a node — `has_parens` before a function or object starting a statement, `!--`, `</script` — it reads off the tree instead, the one `parsedTree()` returns while the walk runs, and through the one member only the JavaScript path has, `ancestor(level)`, a node enclosing the current one; and each child's text is read once (`PrintContext#consume`), so a long one is made flat and its pieces let go as it is printed.
- `syntax.js` reaches `parser` and `printer` through getters: parsing never loads the printer, and the printer loads the parser to read an asset into a `SyntaxTree`. It is the only parser: a source it refuses is refused, and terser's parse options for what is not a program (`parse.expression`, `parse.strict`, `parse.experimental_typescript`) are refused too. `toEstreeObject(node, fields?)` builds the ESTree object of a node of the last parse (`SyntaxTree#estree` of any tree), each call returning the same object: every field, or only those listed and the rest on a later call; a whole program asked for first is built in one pass in id order. It bridges hooks and plugins while the parser moves to that struct-of-arrays tree. A reader the next parse must not disturb takes the tree with `takeParsedTree()` and releases it once read. The tree already reads as [the node path](#the-node-path) does, a node passed last: `type`, `start`, `end`, `range`, `name`, `value`, `field`, `fieldCount`, `flag` and `textOf` with the `NodeType`, `Field`, `Flag` and `Part` that `syntax.parser` exports. `SourceProcessor` walks the tree a parse writes as the CSS and HTML ones walk theirs, each visitor handed that path and the children taken in source order (a template's quasis and expressions in turn). Asked for `mode: "minify"`, the same walk prints: `syntax-printer.js`'s `printer` returns each node's text from its children's, as `minify` prints a source it neither compresses nor mangles, comments left out and terser's format options read from `format`. A minify walks the tree its own parse wrote (`walkSyntaxTree`) with the comments it keeps, a name printed inside its parent's text where none of its own is read: each is taken as terser's printer reaches it, by the node holding its token, and printed once the text before it is, which a text opening with it leaves to the node printing that text. What terser's stream reads off the text before a node — `has_parens` before a function or object starting a statement, `!--`, `</script` — it reads off the tree instead, the one `parsedTree()` returns while the walk runs, and through the one member only the JavaScript path has, `ancestor(level)`, a node enclosing the current one; and each child's text is read once (`PrintContext#consume`), so a long one is made flat and its pieces let go as it is printed.
- `syntax-parser.js` — tokenizer, acorn-derived core and every production in one file (any parse reaches the productions). `parseProgram(input, pos, options)` is the one entry, a build's included: it writes a new `SyntaxTree`, read through `A`, and returns the program's node, unless `estree: true` asks for ESTree objects, the program returned, as `JavascriptParser` and `WebManifestParser` do (rebuilding a whole program with `toEstreeObject` costs 30–55% more). Beside `sourceType` (and `auto`, a module turning into a script at a top-level `return`), `ecmaVersion` and `parseError`, it takes acorn's grammar and token options, `comments` (an array to collect into) and `importPhases`. `JavascriptParser`, the concatenation, the minifier, the `SourceProcessor` and the tooling all parse through it; only a custom `parse` function replaces it. The tree path writes each node into the tree, or the one a caller passes as `syntaxTree`, as it finishes, children before their parent, an id in the tree's columns rather than an object; the few the parser reads back by name (a key, a module name, an exported declaration, a function before its body ends) stay objects until their parent is written, and an expression read as a pattern after all is retyped in place. Every edition takes a tree, each owned production checking the edition where acorn does; parser plugins do not, since acorn's own productions read their nodes back. A parse into ESTree objects keeps acorn's productions for an older edition, whose objects lack the newer fields. `regexp.js` (pattern validator) is the one on-demand piece, reached only for a pattern the host engine rejected — never `require` it from a build path.
- **`sourceType` names which production a source is**, for `parseProgram`, `process` and the printer's `minify` alike: `"module"` (the default), `"script"`, or a `FunctionBody` read as acorn's `commonjs` goal reads one (`return` and `new.target` at its top, no `import`, `export` or `import.meta`): `"commonjs"`, a CommonJS module in the function Node wraps it in, or `"event-handler"`, an event handler attribute's value in the one HTML compiles it into, which a `#!` line cannot open. HTML offers only `"event-handler"` for an attribute, never `"module"`. `minify` compresses a function's body inside a function built around its tree, so every rule a function's body reads by applies and a name it reads undeclared stays global (for a handler, the element's, form's or document's); it prints the body without that function, mapped where it was read, its `#!` line and comments kept, and a handler without the last semicolon the closing brace would leave off. `parseProgram` and `process` read import phases (`import defer`, `import source`) too.
- `syntax-printer.js` — webpack's JavaScript minifier, printing, mangling and compressing in one pass; `jsMinify.js` is the `minify` the default minimizer dispatches JS to under `experiments.futureDefaults`, and goes through it alone; without that flag the minimizer dispatches to `terserMinify` as `minimizer-webpack-plugin` publishes it, running the user's own terser since webpack lists it only as a devDependency. Neither needs an option to say which, and the printer itself never loads terser. `createModules` builds what the one pass reads: the parser's tables (`createParseTables`), the mangler's names (`createFrequency`), the output stream (`MinifiedOutput`, which the node printer's stream extends), the parse into a `SyntaxTree` (`parse.parseTree`), its mangling (`mangleTree`, `mangleTreeProperties`, `mangleManglingScopes`) and the `improvements` switches the node printer reads. `prepareMinify` reads and mangles the one source a `SourceProcessor` run minifies, and `createNodePrinter`'s printer compresses it as it prints. `test/specCases/minify-corpora.spectest.js` minifies each source of each corpus in its `CORPORA` list (add a new one there) under the option sets in `OPTION_SETS` with the one `SourceProcessor` pass `jsMinify` runs and with terser, and runs each output whose test states what its input prints (terser's `expect_stdout`, swc's `expected.stdout` and `exec.rs`) in terser's sandbox: it must print that, unless `INHERITED` lists it as misprinting by an option's own contract. webpack must refuse a source where terser does and only there: where the reference refuses a source the spec allows, the parse error it answers with is listed in `REFUSED_BY_REFERENCE` with what makes the source legal, and where webpack refuses a source the reference reads, the source is listed in `REFUSED_BY_WEBPACK` with the rule it breaks (a test262 test expecting a parse error needs no entry). Summed over each corpus, webpack's outputs must gzip no bigger than terser's. An entry that stops matching fails until retired. Each output is also sized against swc's recorded one, a fixture's `output.js` or, for one of terser's cases, what swc's port of it records (gzip decides, raw breaks a tie): one bigger fails unless `test/helpers/swcSmaller.js` lists it under what swc does that webpack does not yet, and a listed one no longer bigger fails until retired. Under the default minimizer's options each source of every corpus but test262 is also minified by `oxc-minify`, held the same way to `test/helpers/oxcSmaller.js`; `test/helpers/rivalSmallerByDesign.js` adds to both lists the sources no minifier change closes (deflate's header, or swc running a transform the case's own options turn off); an oxc output that misprints is no lead. `JS_MINIFY_REPORT=<file>` tallies where webpack's is worse, the same and better. terser's corpus submodule is pinned to the `terser` devDependency — bump both together, and regenerate `data.js`.
Expand Down
53 changes: 13 additions & 40 deletions 53 lib/dependencies/esm/ESMDetectionParserPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"use strict";

const {
hasTopLevelUsingDeclaration,
hasTopLevelUsingDeclarationInTree
hasTopLevelUsingDeclaration
} = require("../../javascript/JavascriptParserHelpers");
const {
JAVASCRIPT_MODULE_TYPE_ESM
Expand Down Expand Up @@ -81,44 +80,18 @@ module.exports = class ESMDetectionParserPlugin {
enableHarmony(isStrictHarmony);
}
};
if (parser.options.walkIds) {
const { Field, NodeType } = require("../../javascript/syntax-parser");

parser.hooks.programTree.tap(PLUGIN_NAME, (tree, program) => {
topLevelUsingDeclaration = hasTopLevelUsingDeclarationInTree(
tree,
program
);
detectHarmony(() => {
const count = tree.fieldCount(Field.body, program);
for (let i = 0; i < count; i++) {
const type = tree.type(tree.field(i, Field.body, program));
if (
type === NodeType.ImportDeclaration ||
type === NodeType.ExportDefaultDeclaration ||
type === NodeType.ExportNamedDeclaration ||
type === NodeType.ExportAllDeclaration
) {
return true;
}
}
return false;
});
});
} else {
parser.hooks.program.tap(PLUGIN_NAME, (ast) => {
topLevelUsingDeclaration = hasTopLevelUsingDeclaration(ast);
detectHarmony(() =>
ast.body.some(
(statement) =>
statement.type === "ImportDeclaration" ||
statement.type === "ExportDefaultDeclaration" ||
statement.type === "ExportNamedDeclaration" ||
statement.type === "ExportAllDeclaration"
)
);
});
}
parser.hooks.program.tap(PLUGIN_NAME, (ast) => {
topLevelUsingDeclaration = hasTopLevelUsingDeclaration(ast);
detectHarmony(() =>
ast.body.some(
(statement) =>
statement.type === "ImportDeclaration" ||
statement.type === "ExportDefaultDeclaration" ||
statement.type === "ExportNamedDeclaration" ||
statement.type === "ExportAllDeclaration"
)
);
});

parser.hooks.topLevelAwait.tap(PLUGIN_NAME, (node) => {
const module = parser.state.module;
Expand Down
23 changes: 6 additions & 17 deletions 23 lib/javascript/JavascriptMetaInfoPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const {
const { getInnerGraphUtils } = require("../optimize/InnerGraph");
const { recordOptimizationBailout } = require("../util/buildDiagnostics");

const {
hasTopLevelUsingDeclaration,
hasTopLevelUsingDeclarationInTree
} = require("./JavascriptParserHelpers");
const { hasTopLevelUsingDeclaration } = require("./JavascriptParserHelpers");

/** @import Compiler from "../Compiler" */
/** @import JavascriptParser from "../javascript/JavascriptParser" */
Expand Down Expand Up @@ -50,19 +47,11 @@ class JavascriptMetaInfoPlugin {
parser.state.module.buildInfo.moduleConcatenationBailout =
"a top-level using declaration";
};
if (parser.options.walkIds) {
parser.hooks.programTree.tap(PLUGIN_NAME, (tree, program) => {
if (hasTopLevelUsingDeclarationInTree(tree, program)) {
recordTopLevelUsing();
}
});
} else {
parser.hooks.program.tap(PLUGIN_NAME, (ast) => {
if (hasTopLevelUsingDeclaration(ast)) {
recordTopLevelUsing();
}
});
}
parser.hooks.program.tap(PLUGIN_NAME, (ast) => {
if (hasTopLevelUsingDeclaration(ast)) {
recordTopLevelUsing();
}
});
parser.hooks.call.for("eval").tap(PLUGIN_NAME, () => {
const buildInfo = parser.state.module.buildInfo;
buildInfo.moduleConcatenationBailout = "eval()";
Expand Down
Loading
Oops, something went wrong.

Uh oh!

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

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 01402809 — 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.