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: generated code around semicolons, await, replacements and file names by alexander-akait · Pull Request #23149 · webpack/webpack

fix: generated code around semicolons, await, replacements and file names #23149

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 26 commits into main from fix/codegen-correctness
Nov 5, 2026

Uh oh!

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

Merged

fix: generated code around semicolons, await, replacements and file names #23149

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dcc67de
fix(esm): keep the ASI semicolon where an erased export or "use stric…
alexander-akait Nov 5, 2026
bb59607
fix(async-modules): keep parentheses balanced when lowering top-level…
alexander-akait Nov 5, 2026
de4d955
fix(javascript): do not treat await in require.ensure and AMD callbac…
alexander-akait Nov 5, 2026
2928f92
fix(commonjs): walk the test of a conditional require() and require.r…
alexander-akait Nov 5, 2026
d0632fe
fix(amd): do not move an await or yield of the caller into the AMD re…
alexander-akait Nov 5, 2026
60faa58
fix(url): keep parentheses balanced when replacing new URL() arguments
alexander-akait Nov 5, 2026
9921835
fix(dependencies): walk require.ensure arguments once when the depend…
alexander-akait Nov 5, 2026
246ef46
fix(javascript): keep replaced import and asset expressions apart fro…
alexander-akait Nov 5, 2026
38732b7
fix(dependencies): keep walked expressions in place when a dead impor…
alexander-akait Nov 5, 2026
f40074f
fix(dependencies): escape template literal text when rewriting contex…
alexander-akait Nov 5, 2026
47e3e6a
fix(externals): quote string import names of ESM module externals
alexander-akait Nov 5, 2026
609a121
fix(javascript): read import() attributes from a quoted or non-first …
alexander-akait Nov 5, 2026
8226cea
fix(graph): reject a worker named like an initial entry it is not par…
alexander-akait Nov 5, 2026
18f3250
fix(graph): fill in worker entry options only from the module that cr…
alexander-akait Nov 5, 2026
4b2f9eb
fix(html): emit an authored page with the html options of the entry t…
alexander-akait Nov 5, 2026
fed0806
fix(css): concatenate a stylesheet's @import and composes only when t…
alexander-akait Nov 5, 2026
af524a0
fix: accept only file-name-safe inline hash digests
alexander-akait Nov 5, 2026
853fac2
fix: always sanitize [runtime] and module ids in path templates
alexander-akait Nov 5, 2026
fb076a6
fix: recognize data URIs with an uppercase scheme in path templates
alexander-akait Nov 5, 2026
6db1333
fix: treat file names in context directories as literal names
alexander-akait Nov 5, 2026
86d1737
test: keep the context file-name case cacheable across builds
alexander-akait Nov 5, 2026
d068a62
refactor(amd): type the walk that looks for an await or yield of the …
alexander-akait Nov 5, 2026
45d3593
test: update snapshots for the moved ASI semicolon and keep the lower…
alexander-akait Nov 5, 2026
867707a
fix(css): require an @import target that a concatenation root stands …
alexander-akait Nov 5, 2026
a905efa
fix(externals): keep Unicode identifier import names bare
alexander-akait Nov 5, 2026
4fe3455
fix(esm): keep a lowered await's operand when a line break follows await
alexander-akait Nov 5, 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
Prev Previous commit
Next Next commit
fix(dependencies): keep walked expressions in place when a dead impor…
…t(), require.ensure chunk name or destructuring key is replaced
  • Loading branch information

Uh oh!

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

@alexander-akait
alexander-akait committed Nov 5, 2026
commit 38732b7135dd34923898de240e95478281d32afb

There are no files selected for viewing

4 changes: 3 additions & 1 deletion 4 lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
parser.walkExpression(errorExpression.fn.body);
}
parser.scope.topLevelScope = wasTopLevel;
} else if (errorExpressionArg) {
} else if (errorExpressionArg && errorCallbackExists) {
// A chunk name in this slot is dropped from the output, so
// replacements nested in it would have no source around them.
parser.walkExpression(errorExpressionArg);
}
return true;
Expand Down
19 changes: 16 additions & 3 deletions 19 lib/dependencies/esm/ESMImportSpecifierDependency.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ ESMImportSpecifierDependency.Template = class ESMImportSpecifierDependencyTempla
}
}

/** @type {{ ids: Ids, range: Range, shorthand: boolean | string }[]} */
/** @type {{ ids: Ids, range: Range, shorthand: boolean | string, computed: boolean | undefined }[]} */
const replacementsInDestructuring = [];
traverseDestructuringAssignmentProperties(
dep.referencedPropertiesInDestructuring,
Expand All @@ -612,15 +612,21 @@ ESMImportSpecifierDependency.Template = class ESMImportSpecifierDependencyTempla
replacementsInDestructuring.push({
ids: stack.map((p) => p.id),
range: property.range,
shorthand: property.shorthand
shorthand: property.shorthand,
computed: property.computed
});
}
);
// loop-invariant: resolve the imported module's exports info once
const destructuredExportsInfo = moduleGraph.getExportsInfo(
/** @type {Module} */ (moduleGraph.getModule(dep))
);
for (const { ids, shorthand, range } of replacementsInDestructuring) {
for (const {
ids,
shorthand,
range,
computed
} of replacementsInDestructuring) {
/** @type {Ids} */
const concatedIds = [...prefixedIds, ...ids];
const used = destructuredExportsInfo.getUsedName(concatedIds, runtime);
Expand All @@ -640,6 +646,13 @@ ESMImportSpecifierDependency.Template = class ESMImportSpecifierDependencyTempla

const comment = `${Template.toNormalComment(name)} `;
const key = comment + JSON.stringify(newName);
if (computed) {
// The parser walked the key expression, so keep it evaluated in
// place for the replacements nested in it.
source.insert(range[0], "(");
source.insert(range[1], `, ${key})`);
continue;
}
source.replace(
range[0],
range[1] - 1,
Expand Down
11 changes: 11 additions & 0 deletions 11 lib/dependencies/import/ImportDependency.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
const connection = moduleGraph.getConnection(dep);
// Dead branch: module is excluded and has no id; code is never executed.
if (connection && !connection.isTargetActive(runtime)) {
// The parser walked non-static options, so the replacements nested in
// them need their source kept around them, as on the live path.
if (dep.optionsRange) {
source.replace(
dep.range[0],
dep.optionsRange[0] - 1,
"Promise.resolve(/* dead branch */void ("
);
source.replace(dep.optionsRange[1], dep.range[1] - 1, "))");
return;
}
source.replace(
dep.range[0],
dep.range[1] - 1,
Expand Down
4 changes: 3 additions & 1 deletion 4 lib/javascript/JavascriptParser.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ const SCOPE_INFO_TERMINATED_THROW = 2;
* @property {Range} range
* @property {Set<DestructuringAssignmentProperty> | undefined=} pattern
* @property {boolean | string} shorthand
* @property {boolean=} computed whether the key is a computed `[expression]` other than a literal
*/

/**
Expand Down Expand Up @@ -4276,7 +4277,8 @@ class JavascriptParser extends Parser {
id: str,
range: /** @type {Range} */ (key.range),
pattern,
shorthand: this.scope.inShorthand
shorthand: this.scope.inShorthand,
computed: property.computed && key.type !== "Literal"
});
} else {
// could not evaluate key
Expand Down
1 change: 1 addition & 0 deletions 1 test/configCases/inline-exports/dead-branch-import-options/dead.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const V = "DEAD_VALUE";
1 change: 1 addition & 0 deletions 1 test/configCases/inline-exports/dead-branch-import-options/dir/a.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "json";
1 change: 1 addition & 0 deletions 1 test/configCases/inline-exports/dead-branch-import-options/env.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isDEV = false;
13 changes: 13 additions & 0 deletions 13 test/configCases/inline-exports/dead-branch-import-options/index.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { isDEV } from "./env.js";

var makeOptions = function (value) {
return { with: { type: value } };
};

it("should keep a dead-branch import() balanced when its options are computed", async () => {
var name = "a";
const ns = await (isDEV
? import("./dead.js", makeOptions(require(`./dir/${name}.js`)))
: import("./live.js"));
expect(ns.V).toBe("LIVE_VALUE");
});
1 change: 1 addition & 0 deletions 1 test/configCases/inline-exports/dead-branch-import-options/live.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const V = "LIVE_VALUE";
13 changes: 13 additions & 0 deletions 13 test/configCases/inline-exports/dead-branch-import-options/webpack.config.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
mode: "production",
optimization: { inlineExports: true, minimize: false }
},
{
mode: "production",
optimization: { inlineExports: true }
}
];
1 change: 1 addition & 0 deletions 1 test/configCases/mangle/destructuring-computed-key-expression/dir/a.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "a";
7 changes: 7 additions & 0 deletions 7 test/configCases/mangle/destructuring-computed-key-expression/index.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as ns from "./module.js";

it("should keep a computed destructuring key with nested requires intact", () => {
var name = "a";
const { ["someLongExportName" || require(`./dir/${name}.js`)]: value } = ns;
expect(value).toBe("value");
});
2 changes: 2 additions & 0 deletions 2 test/configCases/mangle/destructuring-computed-key-expression/module.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const someLongExportName = "value";
export const otherLongExportName = "other";
17 changes: 17 additions & 0 deletions 17 test/configCases/mangle/destructuring-computed-key-expression/webpack.config.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
mode: "production",
optimization: {
mangleExports: "size",
concatenateModules: false,
minimize: false
}
},
{
mode: "production",
optimization: { mangleExports: "size" }
}
];
1 change: 1 addition & 0 deletions 1 test/configCases/parsing/require-ensure-chunk-name-expression/dir/a.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "a";
11 changes: 11 additions & 0 deletions 11 test/configCases/parsing/require-ensure-chunk-name-expression/index.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
it("should drop a computed require.ensure chunk name without leaking its replacements", (done) => {
var name = "a";
require.ensure(
[],
function (require) {
expect(require("./dir/a.js")).toBe("a");
done();
},
"named" || require(`./dir/${name}.js`)
);
});
12 changes: 12 additions & 0 deletions 12 test/configCases/parsing/require-ensure-chunk-name-expression/webpack.config.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
mode: "development",
devtool: false
},
{
mode: "production"
}
];
5 changes: 5 additions & 0 deletions 5 types.d.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8330,6 +8330,11 @@ declare interface DestructuringAssignmentProperty {
range: [number, number];
pattern?: Set<DestructuringAssignmentProperty>;
shorthand: string | boolean;

/**
* whether the key is a computed `[expression]` other than a literal
*/
computed?: boolean;
}

/**
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.