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 hook nodes by id in plugins and walk the tree … · webpack/webpack@e4eec2d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .changeset
    • 084-javascript-walk-syntax-tree.md
  • lib
    • define
      • DefinePlugin.js
    • dependencies
      • amd
        • AMDRequireDependenciesBlockParserPlugin.js
      • commonjs
        • CommonJsExportsParserPlugin.js
        • CommonJsImportsParserPlugin.js
      • core
        • ImportPhase.js
      • esm
        • CreateRequireParserPlugin.js
        • ESMDetectionParserPlugin.js
        • ESMExportDependencyParserPlugin.js
        • ESMImportDependencyParserPlugin.js
        • ESMLiveExportParserPlugin.js
        • ESMTopLevelThisParserPlugin.js
      • import-meta
        • ImportMetaPlugin.js
      • import
        • ImportParserPlugin.js
      • worker
        • WorkerAndWorkletPlugin.js
    • javascript
      • APIPlugin.js
      • CompatibilityPlugin.js
      • ConstPlugin.js
      • JavascriptMetaInfoPlugin.js
      • JavascriptParser.js
      • JavascriptParserHelpers.js
      • UseStrictPlugin.js
    • optimize
      • ConstExportsPlugin.js
      • InnerGraphPlugin.js
      • SideEffectsFlagPlugin.js
    • performance
      • PureAnnotationsPlugin.js
      • TopLevelThisPlugin.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.changeset/084-javascript-walk-syntax-tree.md‎

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Walk JavaScript modules on the syntax tree, holding less memory while parsing.
Collapse file

‎lib/define/DefinePlugin.js‎

Copy file name to clipboardExpand all lines: lib/define/DefinePlugin.js
+11-7Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ class DefinePlugin {
11721172
const mainValue =
11731173
/** @type {ValueCacheVersion} */
11741174
(compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
1175-
parser.hooks.program.tap(PLUGIN_NAME, () => {
1175+
parser.hooks.program.tap({ name: PLUGIN_NAME, path: true }, () => {
11761176
const buildInfo = parser.state.module.buildInfo;
11771177
if (!buildInfo.valueDependencies) {
11781178
buildInfo.valueDependencies = new Map();
@@ -1264,9 +1264,11 @@ class DefinePlugin {
12641264
// only detect the same nested key once
12651265
hooked.add(nested);
12661266
parser.hooks.collectDestructuringAssignmentProperties.tap(
1267-
PLUGIN_NAME,
1268-
(expr) => {
1269-
const nameInfo = parser.getNameForExpression(expr);
1267+
{ name: PLUGIN_NAME, path: true },
1268+
(path, node) => {
1269+
const nameInfo = parser.getNameForExpression(
1270+
parser.nodeOfPath(path, node)
1271+
);
12701272
if (nameInfo && nameInfo.name === nested) return true;
12711273
}
12721274
);
@@ -1493,9 +1495,11 @@ class DefinePlugin {
14931495
withValueDependency(key, evaluateToString("object"))
14941496
);
14951497
parser.hooks.collectDestructuringAssignmentProperties.tap(
1496-
PLUGIN_NAME,
1497-
(expr) => {
1498-
const nameInfo = parser.getNameForExpression(expr);
1498+
{ name: PLUGIN_NAME, path: true },
1499+
(path, node) => {
1500+
const nameInfo = parser.getNameForExpression(
1501+
parser.nodeOfPath(path, node)
1502+
);
14991503
if (nameInfo && nameInfo.name === key) return true;
15001504
}
15011505
);
Collapse file

‎lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js‎

Copy file name to clipboardExpand all lines: lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"use strict";
77

8+
const { Field } = require("../../javascript/syntax-parser");
89
const RuntimeGlobals = require("../../runtime/RuntimeGlobals");
910
const memoize = require("../../util/memoize");
1011

@@ -88,7 +89,9 @@ const hasOwnAwaitOrYield = (argument) => {
8889
const fields = /** @type {NodeFields} */ (
8990
/** @type {Node | NodeFields} */ (node)
9091
);
91-
for (const key of Object.keys(fields)) {
92+
// for…in, not Object.keys: a lazy node of the syntax tree keeps its
93+
// children on the prototype until they are read
94+
for (const key in fields) {
9295
const value = fields[key];
9396
if (Array.isArray(value)) {
9497
for (const child of value) {
@@ -154,9 +157,24 @@ class AMDRequireDependenciesBlockParserPlugin {
154157
* @returns {void}
155158
*/
156159
apply(parser) {
160+
// every CommonJS `require(…)` reaches this tap too, so it reads ids: with
161+
// one argument only an array is an AMD require
157162
parser.hooks.call
158163
.for("require")
159-
.tap(PLUGIN_NAME, this.processCallRequire.bind(this, parser));
164+
.tap({ name: PLUGIN_NAME, path: true }, (path, node) => {
165+
const argumentCount = path.fieldCount(Field.arguments, node);
166+
if (argumentCount === 0 || argumentCount > 3) return;
167+
if (argumentCount === 1) {
168+
const param = parser.evaluateExpression(
169+
parser.nodeOfPath(path, path.field(0, Field.arguments, node))
170+
);
171+
if (!param.isArray() && !param.isConstArray()) return;
172+
}
173+
return this.processCallRequire(
174+
parser,
175+
/** @type {CallExpression} */ (path.object(node))
176+
);
177+
});
160178
}
161179

162180
/**

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.