mirror of https://github.com/webpack/webpack.git
fix: ASI in concatenated module only when necessary
This commit is contained in:
parent
09543e7d8e
commit
362935e340
|
@ -146,6 +146,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
||||||
* @property {string | undefined} interopNamespaceObject2Name
|
* @property {string | undefined} interopNamespaceObject2Name
|
||||||
* @property {boolean} interopDefaultAccessUsed
|
* @property {boolean} interopDefaultAccessUsed
|
||||||
* @property {string | undefined} interopDefaultAccessName
|
* @property {string | undefined} interopDefaultAccessName
|
||||||
|
* @property {boolean} prefixAsi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,6 +173,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
||||||
|
|
||||||
/** @typedef {Set<string>} UsedNames */
|
/** @typedef {Set<string>} UsedNames */
|
||||||
|
|
||||||
|
const CHARS_REQUIRING_SEMICOLON = ["[", "(", "+", "-", "/"];
|
||||||
const RESERVED_NAMES = new Set(
|
const RESERVED_NAMES = new Set(
|
||||||
[
|
[
|
||||||
// internal names (should always be renamed)
|
// internal names (should always be renamed)
|
||||||
|
@ -1467,6 +1469,12 @@ class ConcatenatedModule extends Module {
|
||||||
);
|
);
|
||||||
const r = /** @type {Range} */ (reference.identifier.range);
|
const r = /** @type {Range} */ (reference.identifier.range);
|
||||||
const source = info.source;
|
const source = info.source;
|
||||||
|
|
||||||
|
// in case finalName starts with a character that requires a semicolon
|
||||||
|
if (CHARS_REQUIRING_SEMICOLON.includes(finalName[0])) {
|
||||||
|
info.prefixAsi = true;
|
||||||
|
}
|
||||||
|
|
||||||
// range is extended by 2 chars to cover the appended "._"
|
// range is extended by 2 chars to cover the appended "._"
|
||||||
source.replace(r[0], r[1] + 1, finalName);
|
source.replace(r[0], r[1] + 1, finalName);
|
||||||
}
|
}
|
||||||
|
@ -1660,10 +1668,13 @@ ${defineGetters}`
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case "concatenated": {
|
case "concatenated": {
|
||||||
result.add(
|
result.add(
|
||||||
`\n;// CONCATENATED MODULE: ${info.module.readableIdentifier(
|
`\n// CONCATENATED MODULE: ${info.module.readableIdentifier(
|
||||||
requestShortener
|
requestShortener
|
||||||
)}\n`
|
)}\n`
|
||||||
);
|
);
|
||||||
|
if (/** @type {ConcatenatedModuleInfo} */ (rawInfo).prefixAsi) {
|
||||||
|
result.add(";");
|
||||||
|
}
|
||||||
result.add(info.source);
|
result.add(info.source);
|
||||||
if (info.chunkInitFragments) {
|
if (info.chunkInitFragments) {
|
||||||
for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
|
for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
|
||||||
|
@ -1825,6 +1836,7 @@ ${defineGetters}`
|
||||||
info.chunkInitFragments = chunkInitFragments;
|
info.chunkInitFragments = chunkInitFragments;
|
||||||
info.globalScope = globalScope;
|
info.globalScope = globalScope;
|
||||||
info.moduleScope = moduleScope;
|
info.moduleScope = moduleScope;
|
||||||
|
info.prefixAsi = CHARS_REQUIRING_SEMICOLON.includes(code[0]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
/** @type {Error} */
|
/** @type {Error} */
|
||||||
(err).message +=
|
(err).message +=
|
||||||
|
@ -1873,7 +1885,8 @@ ${defineGetters}`
|
||||||
interopNamespaceObject2Used: false,
|
interopNamespaceObject2Used: false,
|
||||||
interopNamespaceObject2Name: undefined,
|
interopNamespaceObject2Name: undefined,
|
||||||
interopDefaultAccessUsed: false,
|
interopDefaultAccessUsed: false,
|
||||||
interopDefaultAccessName: undefined
|
interopDefaultAccessName: undefined,
|
||||||
|
prefixAsi: false
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case "external":
|
case "external":
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
/** @type {import("../../../../").Configuration} */
|
||||||
|
module.exports = {
|
||||||
|
optimization: {
|
||||||
|
concatenateModules: true
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue