commit
6db94536ad
|
@ -0,0 +1 @@
|
|||
[Code of Conduct](https://js.foundation/community/code-of-conduct)
|
|
@ -59,7 +59,7 @@ declare module "neo-async" {
|
|||
}
|
||||
|
||||
export type AsyncAutoTasks<R extends Dictionary<any>, E> = {
|
||||
[K in keyof R]: AsyncAutoTask<R[K], R, E>
|
||||
[K in keyof R]: AsyncAutoTask<R[K], R, E>;
|
||||
};
|
||||
export type AsyncAutoTask<R1, R extends Dictionary<any>, E> =
|
||||
| AsyncAutoTaskFunctionWithoutDependencies<R1, E>
|
||||
|
|
|
@ -40,10 +40,10 @@ if (module.hot) {
|
|||
"warning",
|
||||
"[HMR] Cannot apply update. Need to do a full reload!"
|
||||
);
|
||||
log("warning", "[HMR] " + (err.stack || err.message));
|
||||
log("warning", "[HMR] " + log.formatError(err));
|
||||
window.location.reload();
|
||||
} else {
|
||||
log("warning", "[HMR] Update failed: " + (err.stack || err.message));
|
||||
log("warning", "[HMR] Update failed: " + log.formatError(err));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
12
hot/log.js
12
hot/log.js
|
@ -45,3 +45,15 @@ module.exports.groupEnd = logGroup(groupEnd);
|
|||
module.exports.setLogLevel = function(level) {
|
||||
logLevel = level;
|
||||
};
|
||||
|
||||
module.exports.formatError = function(err) {
|
||||
var message = err.message;
|
||||
var stack = err.stack;
|
||||
if (!stack) {
|
||||
return message;
|
||||
} else if (stack.indexOf(message) < 0) {
|
||||
return message + "\n" + stack;
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -72,12 +72,9 @@ if (module.hot) {
|
|||
"warning",
|
||||
"[HMR] Cannot check for update. Need to do a full reload!"
|
||||
);
|
||||
log("warning", "[HMR] " + (err.stack || err.message));
|
||||
log("warning", "[HMR] " + log.formatError(err));
|
||||
} else {
|
||||
log(
|
||||
"warning",
|
||||
"[HMR] Update check failed: " + (err.stack || err.message)
|
||||
);
|
||||
log("warning", "[HMR] Update check failed: " + log.formatError(err));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -23,13 +23,10 @@ if (module.hot) {
|
|||
var status = module.hot.status();
|
||||
if (["abort", "fail"].indexOf(status) >= 0) {
|
||||
log("warning", "[HMR] Cannot apply update.");
|
||||
log("warning", "[HMR] " + (err.stack || err.message));
|
||||
log("warning", "[HMR] " + log.formatError(err));
|
||||
log("warning", "[HMR] You need to restart the application!");
|
||||
} else {
|
||||
log(
|
||||
"warning",
|
||||
"[HMR] Update failed: " + (err.stack || err.message)
|
||||
);
|
||||
log("warning", "[HMR] Update failed: " + log.formatError(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ if (module.hot) {
|
|||
var status = module.hot.status();
|
||||
if (["abort", "fail"].indexOf(status) >= 0) {
|
||||
log("warning", "[HMR] Cannot apply update.");
|
||||
log("warning", "[HMR] " + (err.stack || err.message));
|
||||
log("warning", "[HMR] " + log.formatError(err));
|
||||
log("warning", "[HMR] You need to restart the application!");
|
||||
} else {
|
||||
log("warning", "[HMR] Update failed: " + (err.stack || err.message));
|
||||
|
|
|
@ -527,18 +527,14 @@ class ChunkGroup {
|
|||
for (const child of chunk._children) {
|
||||
if (!child._parents.has(chunk)) {
|
||||
throw new Error(
|
||||
`checkConstraints: child missing parent ${chunk.debugId} -> ${
|
||||
child.debugId
|
||||
}`
|
||||
`checkConstraints: child missing parent ${chunk.debugId} -> ${child.debugId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const parentChunk of chunk._parents) {
|
||||
if (!parentChunk._children.has(chunk)) {
|
||||
throw new Error(
|
||||
`checkConstraints: parent missing child ${parentChunk.debugId} <- ${
|
||||
chunk.debugId
|
||||
}`
|
||||
`checkConstraints: parent missing child ${parentChunk.debugId} <- ${chunk.debugId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,9 +86,7 @@ class CommonJsStuffPlugin {
|
|||
"CommonJsStuffPlugin",
|
||||
toConstantDependency(
|
||||
parser,
|
||||
`${RuntimeGlobals.moduleCache}[${
|
||||
RuntimeGlobals.entryModuleId
|
||||
}]`,
|
||||
`${RuntimeGlobals.moduleCache}[${RuntimeGlobals.entryModuleId}]`,
|
||||
[RuntimeGlobals.moduleCache, RuntimeGlobals.entryModuleId]
|
||||
)
|
||||
);
|
||||
|
|
|
@ -770,9 +770,7 @@ class Compilation {
|
|||
const factory = this.dependencyFactories.get(dep.constructor);
|
||||
if (factory === undefined) {
|
||||
throw new Error(
|
||||
`No module factory available for dependency type: ${
|
||||
dep.constructor.name
|
||||
}`
|
||||
`No module factory available for dependency type: ${dep.constructor.name}`
|
||||
);
|
||||
}
|
||||
let innerMap = dependencies.get(factory);
|
||||
|
@ -1059,9 +1057,7 @@ class Compilation {
|
|||
if (!moduleFactory) {
|
||||
return callback(
|
||||
new WebpackError(
|
||||
`No dependency factory available for this dependency type: ${
|
||||
dependency.constructor.name
|
||||
}`
|
||||
`No dependency factory available for this dependency type: ${dependency.constructor.name}`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -465,9 +465,7 @@ class ContextModule extends Module {
|
|||
if (typeof fakeMap === "number") {
|
||||
return `return ${this.getReturn(fakeMap)};`;
|
||||
}
|
||||
return `return ${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(id, ${fakeMapDataExpression})`;
|
||||
return `return ${RuntimeGlobals.createFakeNamespaceObject}(id, ${fakeMapDataExpression})`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -741,9 +739,7 @@ module.exports = webpackAsyncContext;`;
|
|||
const requestPrefix = hasNoChunk
|
||||
? "Promise.resolve()"
|
||||
: hasMultipleOrNoChunks
|
||||
? `Promise.all(ids.slice(${chunksStartPosition}).map(${
|
||||
RuntimeGlobals.ensureChunk
|
||||
}))`
|
||||
? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
|
||||
: `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
|
||||
const returnModuleObject = this.getReturnModuleObjectSource(
|
||||
fakeMap,
|
||||
|
|
|
@ -10,7 +10,6 @@ const { SyncBailHook, HookMap } = require("tapable");
|
|||
const vm = require("vm");
|
||||
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||
const StackedSetMap = require("./util/StackedSetMap");
|
||||
const TrackingSet = require("./util/TrackingSet");
|
||||
|
||||
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
||||
|
||||
|
@ -37,8 +36,6 @@ const defaultParserOptions = {
|
|||
// regexp to match at lease one "magic comment"
|
||||
const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
|
||||
|
||||
const EMPTY_ARRAY = [];
|
||||
|
||||
const EMPTY_COMMENT_OPTIONS = {
|
||||
options: null,
|
||||
errors: null
|
||||
|
@ -855,6 +852,14 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
// Block-Prewalking iterates the scope for block variable declarations
|
||||
blockPrewalkStatements(statements) {
|
||||
for (let index = 0, len = statements.length; index < len; index++) {
|
||||
const statement = statements[index];
|
||||
this.blockPrewalkStatement(statement);
|
||||
}
|
||||
}
|
||||
|
||||
// Walking iterates the statements and expressions and processes them
|
||||
walkStatements(statements) {
|
||||
for (let index = 0, len = statements.length; index < len; index++) {
|
||||
|
@ -868,9 +873,6 @@ class JavascriptParser {
|
|||
case "BlockStatement":
|
||||
this.prewalkBlockStatement(statement);
|
||||
break;
|
||||
case "ClassDeclaration":
|
||||
this.prewalkClassDeclaration(statement);
|
||||
break;
|
||||
case "DoWhileStatement":
|
||||
this.prewalkDoWhileStatement(statement);
|
||||
break;
|
||||
|
@ -922,6 +924,23 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
blockPrewalkStatement(statement) {
|
||||
switch (statement.type) {
|
||||
case "VariableDeclaration":
|
||||
this.blockPrewalkVariableDeclaration(statement);
|
||||
break;
|
||||
case "ExportDefaultDeclaration":
|
||||
this.blockPrewalkExportDefaultDeclaration(statement);
|
||||
break;
|
||||
case "ExportNamedDeclaration":
|
||||
this.blockPrewalkExportNamedDeclaration(statement);
|
||||
break;
|
||||
case "ClassDeclaration":
|
||||
this.blockPrewalkClassDeclaration(statement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
walkStatement(statement) {
|
||||
if (this.hooks.statement.call(statement) !== undefined) return;
|
||||
switch (statement.type) {
|
||||
|
@ -991,7 +1010,11 @@ class JavascriptParser {
|
|||
}
|
||||
|
||||
walkBlockStatement(statement) {
|
||||
this.walkStatements(statement.body);
|
||||
this.inBlockScope(() => {
|
||||
const body = statement.body;
|
||||
this.blockPrewalkStatements(body);
|
||||
this.walkStatements(body);
|
||||
});
|
||||
}
|
||||
|
||||
walkExpressionStatement(statement) {
|
||||
|
@ -1109,20 +1132,30 @@ class JavascriptParser {
|
|||
}
|
||||
|
||||
walkForStatement(statement) {
|
||||
if (statement.init) {
|
||||
if (statement.init.type === "VariableDeclaration") {
|
||||
this.walkStatement(statement.init);
|
||||
} else {
|
||||
this.walkExpression(statement.init);
|
||||
this.inBlockScope(() => {
|
||||
if (statement.init) {
|
||||
if (statement.init.type === "VariableDeclaration") {
|
||||
this.blockPrewalkVariableDeclaration(statement.init);
|
||||
this.walkStatement(statement.init);
|
||||
} else {
|
||||
this.walkExpression(statement.init);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (statement.test) {
|
||||
this.walkExpression(statement.test);
|
||||
}
|
||||
if (statement.update) {
|
||||
this.walkExpression(statement.update);
|
||||
}
|
||||
this.walkStatement(statement.body);
|
||||
if (statement.test) {
|
||||
this.walkExpression(statement.test);
|
||||
}
|
||||
if (statement.update) {
|
||||
this.walkExpression(statement.update);
|
||||
}
|
||||
const body = statement.body;
|
||||
if (body.type === "BlockStatement") {
|
||||
// no need to add additional scope
|
||||
this.blockPrewalkStatements(body.body);
|
||||
this.walkStatements(body.body);
|
||||
} else {
|
||||
this.walkStatement(body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
prewalkForInStatement(statement) {
|
||||
|
@ -1133,13 +1166,23 @@ class JavascriptParser {
|
|||
}
|
||||
|
||||
walkForInStatement(statement) {
|
||||
if (statement.left.type === "VariableDeclaration") {
|
||||
this.walkVariableDeclaration(statement.left);
|
||||
} else {
|
||||
this.walkPattern(statement.left);
|
||||
}
|
||||
this.walkExpression(statement.right);
|
||||
this.walkStatement(statement.body);
|
||||
this.inBlockScope(() => {
|
||||
if (statement.left.type === "VariableDeclaration") {
|
||||
this.blockPrewalkVariableDeclaration(statement.left);
|
||||
this.walkVariableDeclaration(statement.left);
|
||||
} else {
|
||||
this.walkPattern(statement.left);
|
||||
}
|
||||
this.walkExpression(statement.right);
|
||||
const body = statement.body;
|
||||
if (body.type === "BlockStatement") {
|
||||
// no need to add additional scope
|
||||
this.blockPrewalkStatements(body.body);
|
||||
this.walkStatements(body.body);
|
||||
} else {
|
||||
this.walkStatement(body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
prewalkForOfStatement(statement) {
|
||||
|
@ -1153,13 +1196,23 @@ class JavascriptParser {
|
|||
}
|
||||
|
||||
walkForOfStatement(statement) {
|
||||
if (statement.left.type === "VariableDeclaration") {
|
||||
this.walkVariableDeclaration(statement.left);
|
||||
} else {
|
||||
this.walkPattern(statement.left);
|
||||
}
|
||||
this.walkExpression(statement.right);
|
||||
this.walkStatement(statement.body);
|
||||
this.inBlockScope(() => {
|
||||
if (statement.left.type === "VariableDeclaration") {
|
||||
this.blockPrewalkVariableDeclaration(statement.left);
|
||||
this.walkVariableDeclaration(statement.left);
|
||||
} else {
|
||||
this.walkPattern(statement.left);
|
||||
}
|
||||
this.walkExpression(statement.right);
|
||||
const body = statement.body;
|
||||
if (body.type === "BlockStatement") {
|
||||
// no need to add additional scope
|
||||
this.blockPrewalkStatements(body.body);
|
||||
this.walkStatements(body.body);
|
||||
} else {
|
||||
this.walkStatement(body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Declarations
|
||||
|
@ -1173,7 +1226,7 @@ class JavascriptParser {
|
|||
walkFunctionDeclaration(statement) {
|
||||
const wasTopLevel = this.scope.topLevelScope;
|
||||
this.scope.topLevelScope = false;
|
||||
this.inScope(statement.params, () => {
|
||||
this.inFunctionScope(true, statement.params, () => {
|
||||
for (const param of statement.params) {
|
||||
this.walkPattern(param);
|
||||
}
|
||||
|
@ -1214,6 +1267,33 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
enterDeclaration(declaration, onIdent) {
|
||||
switch (declaration.type) {
|
||||
case "VariableDeclaration":
|
||||
for (const declarator of declaration.declarations) {
|
||||
switch (declarator.type) {
|
||||
case "VariableDeclarator": {
|
||||
this.enterPattern(declarator.id, onIdent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "FunctionDeclaration":
|
||||
this.enterPattern(declaration.id, onIdent);
|
||||
break;
|
||||
case "ClassDeclaration":
|
||||
this.enterPattern(declaration.id, onIdent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
blockPrewalkExportNamedDeclaration(statement) {
|
||||
if (statement.declaration) {
|
||||
this.blockPrewalkStatement(statement.declaration);
|
||||
}
|
||||
}
|
||||
|
||||
prewalkExportNamedDeclaration(statement) {
|
||||
let source;
|
||||
if (statement.source) {
|
||||
|
@ -1226,16 +1306,11 @@ class JavascriptParser {
|
|||
if (
|
||||
!this.hooks.exportDeclaration.call(statement, statement.declaration)
|
||||
) {
|
||||
const originalDefinitions = this.scope.definitions;
|
||||
const tracker = new TrackingSet(this.scope.definitions);
|
||||
this.scope.definitions = tracker;
|
||||
this.prewalkStatement(statement.declaration);
|
||||
const newDefs = Array.from(tracker.getAddedItems());
|
||||
this.scope.definitions = originalDefinitions;
|
||||
for (let index = newDefs.length - 1; index >= 0; index--) {
|
||||
const def = newDefs[index];
|
||||
this.hooks.exportSpecifier.call(statement, def, def, index);
|
||||
}
|
||||
let index = 0;
|
||||
this.enterDeclaration(statement.declaration, def => {
|
||||
this.hooks.exportSpecifier.call(statement, def, def, index++);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (statement.specifiers) {
|
||||
|
@ -1277,18 +1352,24 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
blockPrewalkExportDefaultDeclaration(statement) {
|
||||
if (statement.declaration.type === "ClassDeclaration") {
|
||||
this.blockPrewalkClassDeclaration(statement.declaration);
|
||||
}
|
||||
}
|
||||
|
||||
prewalkExportDefaultDeclaration(statement) {
|
||||
if (statement.declaration.id) {
|
||||
const originalDefinitions = this.scope.definitions;
|
||||
const tracker = new TrackingSet(this.scope.definitions);
|
||||
this.scope.definitions = tracker;
|
||||
this.prewalkStatement(statement.declaration);
|
||||
const newDefs = Array.from(tracker.getAddedItems());
|
||||
this.scope.definitions = originalDefinitions;
|
||||
for (let index = 0, len = newDefs.length; index < len; index++) {
|
||||
const def = newDefs[index];
|
||||
this.hooks.exportSpecifier.call(statement, def, "default");
|
||||
}
|
||||
this.prewalkStatement(statement.declaration);
|
||||
if (
|
||||
statement.declaration.id &&
|
||||
statement.declaration.type !== "FunctionExpression" &&
|
||||
statement.declaration.type !== "ClassExpression"
|
||||
) {
|
||||
this.hooks.exportSpecifier.call(
|
||||
statement,
|
||||
statement.declaration.id.name,
|
||||
"default"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1332,12 +1413,20 @@ class JavascriptParser {
|
|||
}
|
||||
|
||||
prewalkVariableDeclaration(statement) {
|
||||
if (statement.kind !== "var") return;
|
||||
this._prewalkVariableDeclaration(statement, this.hooks.varDeclarationVar);
|
||||
}
|
||||
|
||||
blockPrewalkVariableDeclaration(statement) {
|
||||
if (statement.kind === "var") return;
|
||||
const hookMap =
|
||||
statement.kind === "const"
|
||||
? this.hooks.varDeclarationConst
|
||||
: statement.kind === "let"
|
||||
? this.hooks.varDeclarationLet
|
||||
: this.hooks.varDeclarationVar;
|
||||
: this.hooks.varDeclarationLet;
|
||||
this._prewalkVariableDeclaration(statement, hookMap);
|
||||
}
|
||||
|
||||
_prewalkVariableDeclaration(statement, hookMap) {
|
||||
for (const declarator of statement.declarations) {
|
||||
switch (declarator.type) {
|
||||
case "VariableDeclarator": {
|
||||
|
@ -1386,7 +1475,7 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
prewalkClassDeclaration(statement) {
|
||||
blockPrewalkClassDeclaration(statement) {
|
||||
if (statement.id) {
|
||||
this.scope.renames.set(statement.id.name, null);
|
||||
this.scope.definitions.add(statement.id.name);
|
||||
|
@ -1416,11 +1505,15 @@ class JavascriptParser {
|
|||
}
|
||||
|
||||
walkCatchClause(catchClause) {
|
||||
// Error binding is optional in catch clause since ECMAScript 2019
|
||||
const errorBinding =
|
||||
catchClause.param === null ? EMPTY_ARRAY : [catchClause.param];
|
||||
|
||||
this.inScope(errorBinding, () => {
|
||||
this.inBlockScope(() => {
|
||||
// Error binding is optional in catch clause since ECMAScript 2019
|
||||
if (catchClause.param !== null) {
|
||||
this.enterPattern(catchClause.param, ident => {
|
||||
this.scope.renames.set(ident, null);
|
||||
this.scope.definitions.add(ident);
|
||||
});
|
||||
this.walkPattern(catchClause.param);
|
||||
}
|
||||
this.prewalkStatement(catchClause.body);
|
||||
this.walkStatement(catchClause.body);
|
||||
});
|
||||
|
@ -1603,7 +1696,7 @@ class JavascriptParser {
|
|||
scopeParams.push(expression.id.name);
|
||||
}
|
||||
|
||||
this.inScope(scopeParams, () => {
|
||||
this.inFunctionScope(true, scopeParams, () => {
|
||||
for (const param of expression.params) {
|
||||
this.walkPattern(param);
|
||||
}
|
||||
|
@ -1621,7 +1714,7 @@ class JavascriptParser {
|
|||
walkArrowFunctionExpression(expression) {
|
||||
const wasTopLevel = this.scope.topLevelScope;
|
||||
this.scope.topLevelScope = wasTopLevel ? "arrow" : false;
|
||||
this.inScope(expression.params, () => {
|
||||
this.inFunctionScope(false, expression.params, () => {
|
||||
for (const param of expression.params) {
|
||||
this.walkPattern(param);
|
||||
}
|
||||
|
@ -1797,7 +1890,7 @@ class JavascriptParser {
|
|||
scopeParams.push(functionExpression.id.name);
|
||||
}
|
||||
|
||||
this.inScope(scopeParams, () => {
|
||||
this.inFunctionScope(true, scopeParams, () => {
|
||||
if (renameThis) {
|
||||
this.scope.renames.set("this", renameThis);
|
||||
}
|
||||
|
@ -1912,6 +2005,12 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param {any} params scope params
|
||||
* @param {function(): void} fn inner function
|
||||
* @returns {void}
|
||||
*/
|
||||
inScope(params, fn) {
|
||||
const oldScope = this.scope;
|
||||
this.scope = {
|
||||
|
@ -1925,22 +2024,60 @@ class JavascriptParser {
|
|||
|
||||
this.scope.renames.set("this", null);
|
||||
|
||||
for (const param of params) {
|
||||
if (typeof param !== "string") {
|
||||
this.enterPattern(param, (param, pattern) => {
|
||||
const hook = this.hooks.pattern.get(param);
|
||||
if (!hook || hook.call(pattern) !== true) {
|
||||
this.scope.renames.set(param, null);
|
||||
this.scope.definitions.add(param);
|
||||
}
|
||||
});
|
||||
} else if (param) {
|
||||
this.scope.renames.set(param, null);
|
||||
this.scope.definitions.add(param);
|
||||
this.enterPatterns(params, (ident, pattern) => {
|
||||
const hook = pattern && this.hooks.pattern.get(ident);
|
||||
if (!hook || hook.call(pattern) !== true) {
|
||||
this.scope.renames.set(ident, null);
|
||||
this.scope.definitions.add(ident);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fn();
|
||||
|
||||
this.scope = oldScope;
|
||||
}
|
||||
|
||||
inFunctionScope(hasThis, params, fn) {
|
||||
const oldScope = this.scope;
|
||||
this.scope = {
|
||||
topLevelScope: oldScope.topLevelScope,
|
||||
inTry: false,
|
||||
inShorthand: false,
|
||||
isStrict: oldScope.isStrict,
|
||||
definitions: oldScope.definitions.createChild(),
|
||||
renames: oldScope.renames.createChild()
|
||||
};
|
||||
|
||||
if (hasThis) {
|
||||
this.scope.renames.set("this", null);
|
||||
}
|
||||
|
||||
this.enterPatterns(params, (ident, pattern) => {
|
||||
const hook = pattern && this.hooks.pattern.get(ident);
|
||||
if (!hook || hook.call(pattern) !== true) {
|
||||
this.scope.renames.set(ident, null);
|
||||
this.scope.definitions.add(ident);
|
||||
}
|
||||
});
|
||||
|
||||
fn();
|
||||
|
||||
this.scope = oldScope;
|
||||
}
|
||||
|
||||
inBlockScope(fn) {
|
||||
const oldScope = this.scope;
|
||||
this.scope = {
|
||||
topLevelScope: oldScope.topLevelScope,
|
||||
inTry: oldScope.inTry,
|
||||
inShorthand: false,
|
||||
isStrict: oldScope.isStrict,
|
||||
definitions: oldScope.definitions.createChild(),
|
||||
renames: oldScope.renames.createChild()
|
||||
};
|
||||
|
||||
fn();
|
||||
|
||||
this.scope = oldScope;
|
||||
}
|
||||
|
||||
|
@ -1955,6 +2092,16 @@ class JavascriptParser {
|
|||
}
|
||||
}
|
||||
|
||||
enterPatterns(patterns, onIdent) {
|
||||
for (const pattern of patterns) {
|
||||
if (typeof pattern !== "string") {
|
||||
this.enterPattern(pattern, onIdent);
|
||||
} else if (pattern) {
|
||||
onIdent(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enterPattern(pattern, onIdent) {
|
||||
if (!pattern) return;
|
||||
switch (pattern.type) {
|
||||
|
@ -2156,6 +2303,7 @@ class JavascriptParser {
|
|||
if (this.hooks.program.call(ast, comments) === undefined) {
|
||||
this.detectStrictMode(ast.body);
|
||||
this.prewalkStatements(ast.body);
|
||||
this.blockPrewalkStatements(ast.body);
|
||||
this.walkStatements(ast.body);
|
||||
}
|
||||
this.scope = oldScope;
|
||||
|
|
|
@ -136,9 +136,7 @@ module.exports = class MainTemplate {
|
|||
const moduleId = chunkGraph.getModuleId(entryModule);
|
||||
let moduleIdExpr = JSON.stringify(moduleId);
|
||||
if (runtimeRequirements.has(RuntimeGlobals.entryModuleId)) {
|
||||
moduleIdExpr = `${
|
||||
RuntimeGlobals.entryModuleId
|
||||
} = ${moduleIdExpr}`;
|
||||
moduleIdExpr = `${RuntimeGlobals.entryModuleId} = ${moduleIdExpr}`;
|
||||
}
|
||||
buf.push(`${mayReturn}__webpack_require__(${moduleIdExpr});`);
|
||||
}
|
||||
|
@ -230,9 +228,7 @@ module.exports = class MainTemplate {
|
|||
)
|
||||
? Template.asString([
|
||||
"var execOptions = { id: moduleId, module: module, factory: modules[moduleId], require: __webpack_require__ };",
|
||||
`${
|
||||
RuntimeGlobals.interceptModuleExecution
|
||||
}.forEach(function(handler) { handler(execOptions); });`,
|
||||
`${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`,
|
||||
"module = execOptions.module;",
|
||||
"execOptions.factory.call(module.exports, module, module.exports, execOptions.require);"
|
||||
])
|
||||
|
|
|
@ -464,9 +464,7 @@ class ExportInfo {
|
|||
}
|
||||
}
|
||||
throw new Error(
|
||||
`Unexpected flags for canMangle ${this.canMangleProvide} ${
|
||||
this.canMangleUse
|
||||
}`
|
||||
`Unexpected flags for canMangle ${this.canMangleProvide} ${this.canMangleUse}`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -541,9 +539,7 @@ class ExportInfo {
|
|||
break;
|
||||
}
|
||||
throw new Error(
|
||||
`Unexpected flags for getRenameInfo ${this.canMangleProvide} ${
|
||||
this.canMangleUse
|
||||
}`
|
||||
`Unexpected flags for getRenameInfo ${this.canMangleProvide} ${this.canMangleUse}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,22 @@ class ModuleParseError extends WebpackError {
|
|||
/**
|
||||
* @param {string} source source code
|
||||
* @param {Error&any} err the parse error
|
||||
* @param {string[]} loaders the loaders used
|
||||
*/
|
||||
constructor(source, err) {
|
||||
constructor(source, err, loaders) {
|
||||
let message = "Module parse failed: " + (err && err.message);
|
||||
let loc = undefined;
|
||||
|
||||
message += "\nYou may need an appropriate loader to handle this file type.";
|
||||
if (loaders.length >= 1) {
|
||||
message += `\nFile was processed with these loaders:${loaders
|
||||
.map(loader => `\n * ${loader}`)
|
||||
.join("")}`;
|
||||
message +=
|
||||
"\nYou may need an additional loader to handle the result of these loaders.";
|
||||
} else {
|
||||
message +=
|
||||
"\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders";
|
||||
}
|
||||
|
||||
if (
|
||||
err &&
|
||||
|
@ -31,7 +41,7 @@ class ModuleParseError extends WebpackError {
|
|||
// binary file
|
||||
message += "\n(Source code omitted for this binary file)";
|
||||
} else {
|
||||
const sourceLines = source.split("\n");
|
||||
const sourceLines = source.split(/\r?\n/);
|
||||
const start = Math.max(0, lineNumber - 3);
|
||||
const linesBefore = sourceLines.slice(start, lineNumber - 1);
|
||||
const theLine = sourceLines[lineNumber - 1];
|
||||
|
|
|
@ -469,7 +469,6 @@ class NormalModule extends Module {
|
|||
markModuleAsErrored(error) {
|
||||
// Restore build meta from successful build to keep importing state
|
||||
this.buildMeta = Object.assign({}, this._lastSuccessfulBuildMeta);
|
||||
|
||||
this.error = error;
|
||||
this.errors.push(error);
|
||||
}
|
||||
|
@ -576,7 +575,10 @@ class NormalModule extends Module {
|
|||
|
||||
const handleParseError = e => {
|
||||
const source = /** @type {string} */ (this._source.source());
|
||||
const error = new ModuleParseError(source, e);
|
||||
const loaders = this.loaders.map(item =>
|
||||
contextify(options.context, item.loader)
|
||||
);
|
||||
const error = new ModuleParseError(source, e, loaders);
|
||||
this.markModuleAsErrored(error);
|
||||
this._initBuildHash(compilation);
|
||||
return callback();
|
||||
|
|
|
@ -578,9 +578,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
err.message +
|
||||
"\n" +
|
||||
"BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
|
||||
` You need to specify '${
|
||||
item.loader
|
||||
}-loader' instead of '${item.loader}',\n` +
|
||||
` You need to specify '${item.loader}-loader' instead of '${item.loader}',\n` +
|
||||
" see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed";
|
||||
}
|
||||
callback(err);
|
||||
|
|
|
@ -399,35 +399,23 @@ class RuntimeTemplate {
|
|||
} else if (exportsType === "named") {
|
||||
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
||||
if (header) {
|
||||
getModuleFunction = `function() { ${header}return ${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${moduleIdExpr}, 3); }`;
|
||||
getModuleFunction = `function() { ${header}return ${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 3); }`;
|
||||
} else {
|
||||
getModuleFunction = `${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}.bind(__webpack_require__, ${comment}${idExpr}, 3)`;
|
||||
getModuleFunction = `${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, 3)`;
|
||||
}
|
||||
} else if (strict) {
|
||||
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
||||
if (header) {
|
||||
getModuleFunction = `function() { ${header}return ${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${moduleIdExpr}, 1); }`;
|
||||
getModuleFunction = `function() { ${header}return ${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 1); }`;
|
||||
} else {
|
||||
getModuleFunction = `${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}.bind(__webpack_require__, ${comment}${idExpr}, 1)`;
|
||||
getModuleFunction = `${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, 1)`;
|
||||
}
|
||||
} else {
|
||||
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
||||
if (header) {
|
||||
getModuleFunction = `function() { ${header}return ${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${moduleIdExpr}, 7); }`;
|
||||
getModuleFunction = `function() { ${header}return ${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 7); }`;
|
||||
} else {
|
||||
getModuleFunction = `${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}.bind(__webpack_require__, ${comment}${idExpr}, 7)`;
|
||||
getModuleFunction = `${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, 7)`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,20 +479,14 @@ class RuntimeTemplate {
|
|||
|
||||
if (!exportsType && !originModule.buildMeta.strictHarmonyModule) {
|
||||
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
||||
content += `/* harmony import */ ${optDeclaration}${importVar}_default = /*#__PURE__*/${
|
||||
RuntimeGlobals.compatGetDefaultExport
|
||||
}(${importVar});\n`;
|
||||
content += `/* harmony import */ ${optDeclaration}${importVar}_default = /*#__PURE__*/${RuntimeGlobals.compatGetDefaultExport}(${importVar});\n`;
|
||||
}
|
||||
if (exportsType === "named") {
|
||||
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
||||
if (Array.isArray(chunkGraph.moduleGraph.getProvidedExports(module))) {
|
||||
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${moduleId}, 1);\n`;
|
||||
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${moduleId}, 1);\n`;
|
||||
} else {
|
||||
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${moduleId});\n`;
|
||||
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${moduleId});\n`;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
|
@ -567,9 +549,7 @@ class RuntimeTemplate {
|
|||
);
|
||||
} else {
|
||||
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
||||
return `/*#__PURE__*/${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${importVar})`;
|
||||
return `/*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${importVar})`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,9 +97,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends NullD
|
|||
// has function range but no array range
|
||||
if (dep.functionRange && !dep.arrayRange) {
|
||||
const startBlock = `${promise}.then((`;
|
||||
const endBlock = `).bind(exports, __webpack_require__, exports, module)).catch(${
|
||||
RuntimeGlobals.uncaughtErrorHandler
|
||||
})`;
|
||||
const endBlock = `).bind(exports, __webpack_require__, exports, module)).catch(${RuntimeGlobals.uncaughtErrorHandler})`;
|
||||
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
||||
|
||||
source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
|
||||
|
|
|
@ -835,9 +835,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|||
initFragments.push(
|
||||
new InitFragment(
|
||||
content +
|
||||
`${
|
||||
RuntimeGlobals.definePropertyGetter
|
||||
}(${exportsName}, __WEBPACK_IMPORT_KEY__, function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__));\n`,
|
||||
`${RuntimeGlobals.definePropertyGetter}(${exportsName}, __WEBPACK_IMPORT_KEY__, function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__));\n`,
|
||||
InitFragment.STAGE_HARMONY_IMPORTS,
|
||||
dep.sourceOrder
|
||||
)
|
||||
|
|
|
@ -107,16 +107,16 @@ class HarmonyImportDependency extends ModuleDependency {
|
|||
// It's not an harmony module
|
||||
if (
|
||||
moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule &&
|
||||
(ids.length === 0 || ids[0] !== "default")
|
||||
(ids.length > 0 && ids[0] !== "default")
|
||||
) {
|
||||
// In strict harmony modules we only support the default export
|
||||
const exportName =
|
||||
ids.length > 0
|
||||
? `the named export ${ids.map(id => `'${id}'`).join(".")}`
|
||||
: "the namespace object";
|
||||
return [
|
||||
new HarmonyLinkingError(
|
||||
`Can't import ${exportName} ${additionalMessage} from non EcmaScript module (only default export is available)`
|
||||
`Can't import the named export ${ids
|
||||
.map(id => `'${id}'`)
|
||||
.join(
|
||||
"."
|
||||
)} ${additionalMessage} from non EcmaScript module (only default export is available)`
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -45,9 +45,7 @@ class ImportParserPlugin {
|
|||
const { comment } = e;
|
||||
parser.state.module.warnings.push(
|
||||
new CommentCompilationWarning(
|
||||
`Compilation error while processing magic comment(-s): /*${
|
||||
comment.value
|
||||
}*/: ${e.message}`,
|
||||
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
||||
comment.loc
|
||||
)
|
||||
);
|
||||
|
@ -59,9 +57,7 @@ class ImportParserPlugin {
|
|||
if (typeof importOptions.webpackIgnore !== "boolean") {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackIgnore\` expected a boolean, but received: ${
|
||||
importOptions.webpackIgnore
|
||||
}.`,
|
||||
`\`webpackIgnore\` expected a boolean, but received: ${importOptions.webpackIgnore}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
@ -76,9 +72,7 @@ class ImportParserPlugin {
|
|||
if (typeof importOptions.webpackChunkName !== "string") {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackChunkName\` expected a string, but received: ${
|
||||
importOptions.webpackChunkName
|
||||
}.`,
|
||||
`\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
@ -90,9 +84,7 @@ class ImportParserPlugin {
|
|||
if (typeof importOptions.webpackMode !== "string") {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackMode\` expected a string, but received: ${
|
||||
importOptions.webpackMode
|
||||
}.`,
|
||||
`\`webpackMode\` expected a string, but received: ${importOptions.webpackMode}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
@ -108,9 +100,7 @@ class ImportParserPlugin {
|
|||
} else {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackPrefetch\` expected true or a number, but received: ${
|
||||
importOptions.webpackPrefetch
|
||||
}.`,
|
||||
`\`webpackPrefetch\` expected true or a number, but received: ${importOptions.webpackPrefetch}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
@ -124,9 +114,7 @@ class ImportParserPlugin {
|
|||
} else {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackPreload\` expected true or a number, but received: ${
|
||||
importOptions.webpackPreload
|
||||
}.`,
|
||||
`\`webpackPreload\` expected true or a number, but received: ${importOptions.webpackPreload}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
@ -139,9 +127,7 @@ class ImportParserPlugin {
|
|||
) {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackInclude\` expected a regular expression, but received: ${
|
||||
importOptions.webpackInclude
|
||||
}.`,
|
||||
`\`webpackInclude\` expected a regular expression, but received: ${importOptions.webpackInclude}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
@ -156,9 +142,7 @@ class ImportParserPlugin {
|
|||
) {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
`\`webpackExclude\` expected a regular expression, but received: ${
|
||||
importOptions.webpackExclude
|
||||
}.`,
|
||||
`\`webpackExclude\` expected a regular expression, but received: ${importOptions.webpackExclude}.`,
|
||||
expr.loc
|
||||
)
|
||||
);
|
||||
|
|
|
@ -51,9 +51,7 @@ class LoaderPlugin {
|
|||
if (factory === undefined) {
|
||||
return callback(
|
||||
new Error(
|
||||
`No module factory available for dependency type: ${
|
||||
dep.constructor.name
|
||||
}`
|
||||
`No module factory available for dependency type: ${dep.constructor.name}`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -80,9 +80,7 @@ ModuleDecoratorDependency.Template = class ModuleDecoratorDependencyTemplate ext
|
|||
runtimeRequirements.add(dep.decorator);
|
||||
initFragments.push(
|
||||
new InitFragment(
|
||||
`/* module decorator */ ${module.moduleArgument} = ${dep.decorator}(${
|
||||
module.moduleArgument
|
||||
});\n`,
|
||||
`/* module decorator */ ${module.moduleArgument} = ${dep.decorator}(${module.moduleArgument});\n`,
|
||||
InitFragment.STAGE_PROVIDES,
|
||||
0,
|
||||
`module decorator ${chunkGraph.getModuleId(module)}`
|
||||
|
|
|
@ -90,9 +90,7 @@ RequireEnsureDependency.Template = class RequireEnsureDependencyTemplate extends
|
|||
source.replace(
|
||||
contentRange[1],
|
||||
range[1] - 1,
|
||||
`).bind(null, __webpack_require__)).catch(${
|
||||
RuntimeGlobals.uncaughtErrorHandler
|
||||
})`
|
||||
`).bind(null, __webpack_require__)).catch(${RuntimeGlobals.uncaughtErrorHandler})`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,9 +63,7 @@ class WebAssemblyImportDependency extends ModuleDependency {
|
|||
) {
|
||||
return [
|
||||
new UnsupportedWebAssemblyFeatureError(
|
||||
`Import "${this.name}" from "${this.request}" with ${
|
||||
this.onlyDirectImport
|
||||
} can only be used for direct wasm to wasm dependencies`
|
||||
`Import "${this.name}" from "${this.request}" with ${this.onlyDirectImport} can only be used for direct wasm to wasm dependencies`
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -34,9 +34,7 @@ class ChunkModuleIdRangePlugin {
|
|||
);
|
||||
if (!chunk) {
|
||||
throw new Error(
|
||||
`ChunkModuleIdRangePlugin: Chunk with name '${
|
||||
options.name
|
||||
}"' was not found`
|
||||
`ChunkModuleIdRangePlugin: Chunk with name '${options.name}"' was not found`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,9 +68,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
"var promise = new Promise(function(resolve, reject) {",
|
||||
Template.indent([
|
||||
"installedChunkData = installedChunks[chunkId] = [resolve, reject];",
|
||||
`var filename = require('path').join(__dirname, ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId));`,
|
||||
`var filename = require('path').join(__dirname, ${RuntimeGlobals.getChunkScriptFilename}(chunkId));`,
|
||||
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
|
||||
Template.indent([
|
||||
"if(err) return reject(err);",
|
||||
|
@ -82,9 +80,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
||||
Template.indent([
|
||||
`${
|
||||
RuntimeGlobals.moduleFactories
|
||||
}[moduleId] = moreModules[moduleId];`
|
||||
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
|
@ -142,9 +138,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"return new Promise(function(resolve, reject) {",
|
||||
Template.indent([
|
||||
`var filename = require('path').join(__dirname, ${
|
||||
RuntimeGlobals.getChunkUpdateScriptFilename
|
||||
}(chunkId));`,
|
||||
`var filename = require('path').join(__dirname, ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
|
||||
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
|
||||
Template.indent([
|
||||
"if(err) return reject(err);",
|
||||
|
@ -172,9 +166,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
]),
|
||||
"}",
|
||||
"",
|
||||
`${
|
||||
RuntimeGlobals.hmrDownloadUpdateHandlers
|
||||
}.readFileVm = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
`${RuntimeGlobals.hmrDownloadUpdateHandlers}.readFileVm = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
Template.indent([
|
||||
"applyHandlers.push(function(options) {",
|
||||
Template.indent([
|
||||
|
@ -223,9 +215,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"return new Promise(function(resolve, reject) {",
|
||||
Template.indent([
|
||||
`var filename = require('path').join(__dirname, ${
|
||||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}());`,
|
||||
`var filename = require('path').join(__dirname, ${RuntimeGlobals.getUpdateManifestFilename}());`,
|
||||
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
|
||||
Template.indent([
|
||||
"if(err) {",
|
||||
|
|
|
@ -59,17 +59,13 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
? "if(true) { // all chunks have JS"
|
||||
: `if(${hasJsMatcher("chunkId")}) {`,
|
||||
Template.indent([
|
||||
`var chunk = require("./" + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId));`,
|
||||
`var chunk = require("./" + ${RuntimeGlobals.getChunkScriptFilename}(chunkId));`,
|
||||
"var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;",
|
||||
"for(var moduleId in moreModules) {",
|
||||
Template.indent([
|
||||
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
||||
Template.indent([
|
||||
`${
|
||||
RuntimeGlobals.moduleFactories
|
||||
}[moduleId] = moreModules[moduleId];`
|
||||
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
|
@ -107,9 +103,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
"var currentUpdateRuntime;",
|
||||
"function loadUpdateChunk(chunkId, updatedModulesList) {",
|
||||
Template.indent([
|
||||
`var update = require("./" + ${
|
||||
RuntimeGlobals.getChunkUpdateScriptFilename
|
||||
}(chunkId));`,
|
||||
`var update = require("./" + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
|
||||
"var updatedModules = update.modules;",
|
||||
"var runtime = update.runtime;",
|
||||
"for(var moduleId in updatedModules) {",
|
||||
|
@ -126,9 +120,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
]),
|
||||
"}",
|
||||
"",
|
||||
`${
|
||||
RuntimeGlobals.hmrDownloadUpdateHandlers
|
||||
}.require = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
`${RuntimeGlobals.hmrDownloadUpdateHandlers}.require = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
Template.indent([
|
||||
"applyHandlers.push(function(options) {",
|
||||
Template.indent([
|
||||
|
@ -177,9 +169,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"return Promise.resolve().then(function() {",
|
||||
Template.indent([
|
||||
`return require("./" + ${
|
||||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}());`
|
||||
`return require("./" + ${RuntimeGlobals.getUpdateManifestFilename}());`
|
||||
]),
|
||||
'}).catch(function(err) { if(err.code !== "MODULE_NOT_FOUND") throw err; });'
|
||||
]),
|
||||
|
|
|
@ -946,23 +946,17 @@ class ConcatenatedModule extends Module {
|
|||
if (info.interopNamespaceObjectUsed) {
|
||||
if (info.module.buildMeta.exportsType === "named") {
|
||||
result.add(
|
||||
`var ${info.interopNamespaceObjectName} = /*#__PURE__*/${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${info.name}, 2);\n`
|
||||
`var ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${info.name}, 2);\n`
|
||||
);
|
||||
} else if (!info.module.buildMeta.exportsType) {
|
||||
result.add(
|
||||
`var ${info.interopNamespaceObjectName} = /*#__PURE__*/${
|
||||
RuntimeGlobals.createFakeNamespaceObject
|
||||
}(${info.name});\n`
|
||||
`var ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${info.name});\n`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (info.interopDefaultAccessUsed) {
|
||||
result.add(
|
||||
`var ${info.interopDefaultAccessName} = /*#__PURE__*/${
|
||||
RuntimeGlobals.compatGetDefaultExport
|
||||
}(${info.name});\n`
|
||||
`var ${info.interopDefaultAccessName} = /*#__PURE__*/${RuntimeGlobals.compatGetDefaultExport}(${info.name});\n`
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
@ -1328,9 +1322,7 @@ class HarmonyImportSpecifierDependencyConcatenatedTemplate extends DependencyTem
|
|||
const exportData = Buffer.from(JSON.stringify(ids), "utf-8").toString(
|
||||
"hex"
|
||||
);
|
||||
content = `__WEBPACK_MODULE_REFERENCE__${
|
||||
info.index
|
||||
}_${exportData}${callFlag}${strictFlag}__`;
|
||||
content = `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${strictFlag}__`;
|
||||
}
|
||||
if (dep.shorthand) {
|
||||
content = dep.name + ": " + content;
|
||||
|
@ -1527,23 +1519,17 @@ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate extends Depen
|
|||
? "_strict"
|
||||
: "";
|
||||
if (def.ids.length === 0) {
|
||||
finalName = `__WEBPACK_MODULE_REFERENCE__${
|
||||
info.index
|
||||
}_ns${strictFlag}__`;
|
||||
finalName = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
|
||||
} else {
|
||||
const exportData = Buffer.from(
|
||||
JSON.stringify(def.ids),
|
||||
"utf-8"
|
||||
).toString("hex");
|
||||
finalName = `__WEBPACK_MODULE_REFERENCE__${
|
||||
info.index
|
||||
}_${exportData}${strictFlag}__`;
|
||||
finalName = `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${strictFlag}__`;
|
||||
}
|
||||
const exportsName = this.rootModule.exportsArgument;
|
||||
const content =
|
||||
`/* concated harmony reexport */ ${
|
||||
RuntimeGlobals.definePropertyGetter
|
||||
}(` +
|
||||
`/* concated harmony reexport */ ${RuntimeGlobals.definePropertyGetter}(` +
|
||||
`${exportsName}, ${JSON.stringify(used)}, ` +
|
||||
`function() { return ${finalName}; });\n`;
|
||||
initFragments.push(
|
||||
|
|
|
@ -682,9 +682,7 @@ module.exports = class SplitChunksPlugin {
|
|||
compilation.errors.push(
|
||||
new WebpackError(
|
||||
"SplitChunksPlugin\n" +
|
||||
`Cache group "${
|
||||
cacheGroup.key
|
||||
}" conflicts with existing chunk.\n` +
|
||||
`Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
|
||||
`Both have the same name "${name}".\n` +
|
||||
"Use a different name for the cache group.\n" +
|
||||
'HINT: You can omit "name" to automatically create a name.\n' +
|
||||
|
|
|
@ -159,9 +159,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|||
|
||||
if (serializers.has(Constructor)) {
|
||||
throw new Error(
|
||||
`ObjectMiddleware.register: serializer for ${
|
||||
Constructor.name
|
||||
} is already registered`
|
||||
`ObjectMiddleware.register: serializer for ${Constructor.name} is already registered`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -187,9 +185,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|||
static registerNotSerializable(Constructor) {
|
||||
if (serializers.has(Constructor)) {
|
||||
throw new Error(
|
||||
`ObjectMiddleware.registerNotSerializable: serializer for ${
|
||||
Constructor.name
|
||||
} is already registered`
|
||||
`ObjectMiddleware.registerNotSerializable: serializer for ${Constructor.name} is already registered`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ const DEFAULTS = {
|
|||
publicPath: OFF_FOR_TO_STRING,
|
||||
excludeModules: () => [],
|
||||
excludeAssets: () => [],
|
||||
maxModules: (o, { forToString }) => (forToString ? 15 : Infinity),
|
||||
maxModules: (o, { forToString }) => ((forToString ? 15 : Infinity)),
|
||||
modulesSort: () => "id",
|
||||
chunksSort: () => "id",
|
||||
assetsSort: () => "name",
|
||||
|
|
|
@ -135,7 +135,7 @@ const SIMPLE_PRINTERS = {
|
|||
"asset.size": (
|
||||
size,
|
||||
{ asset: { isOverSizeLimit }, yellow, green, formatSize }
|
||||
) => (isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size)),
|
||||
) => ((isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size))),
|
||||
"asset.emitted": (emitted, { green, formatFlag }) =>
|
||||
emitted ? green(formatFlag("emitted")) : undefined,
|
||||
"asset.isOverSizeLimit": (isOverSizeLimit, { yellow, formatFlag }) =>
|
||||
|
@ -317,7 +317,8 @@ const SIMPLE_PRINTERS = {
|
|||
rendered ? green(formatFlag("rendered")) : undefined,
|
||||
"chunk.recorded": (recorded, { formatFlag, green }) =>
|
||||
recorded ? green(formatFlag("recorded")) : undefined,
|
||||
"chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined),
|
||||
"chunk.reason": (reason, { yellow }) =>
|
||||
(reason ? yellow(reason) : undefined),
|
||||
"chunk.rootModules": (modules, context) => {
|
||||
let maxModuleId = 0;
|
||||
for (const module of modules) {
|
||||
|
@ -707,7 +708,7 @@ const SIMPLE_ELEMENT_JOINERS = {
|
|||
if (maxModuleId >= 10) prefix += " ";
|
||||
}
|
||||
return (
|
||||
prefix +
|
||||
(prefix +
|
||||
joinExplicitNewLine(
|
||||
items.filter(item => {
|
||||
switch (item.element) {
|
||||
|
@ -726,13 +727,13 @@ const SIMPLE_ELEMENT_JOINERS = {
|
|||
return true;
|
||||
}),
|
||||
indenter
|
||||
)
|
||||
))
|
||||
);
|
||||
},
|
||||
chunk: items => {
|
||||
let hasEntry = false;
|
||||
return (
|
||||
"chunk " +
|
||||
("chunk " +
|
||||
joinExplicitNewLine(
|
||||
items.filter(item => {
|
||||
switch (item.element) {
|
||||
|
@ -746,7 +747,7 @@ const SIMPLE_ELEMENT_JOINERS = {
|
|||
return true;
|
||||
}),
|
||||
" "
|
||||
)
|
||||
))
|
||||
);
|
||||
},
|
||||
"chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
|
||||
|
@ -766,8 +767,8 @@ const SIMPLE_ELEMENT_JOINERS = {
|
|||
break;
|
||||
case "resolvedModule":
|
||||
return (
|
||||
moduleReason.module !== moduleReason.resolvedModule &&
|
||||
item.content
|
||||
(moduleReason.module !== moduleReason.resolvedModule &&
|
||||
item.content)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -50,9 +50,7 @@ class ClassSerializer {
|
|||
const hash = context.read();
|
||||
if (this.hash !== hash)
|
||||
throw new Error(
|
||||
`Version mismatch for ${this.Constructor.name}: ${hash} !== ${
|
||||
this.hash
|
||||
}`
|
||||
`Version mismatch for ${this.Constructor.name}: ${hash} !== ${this.hash}`
|
||||
);
|
||||
if (typeof this.Constructor.deserialize === "function") {
|
||||
return this.Constructor.deserialize(context);
|
||||
|
|
|
@ -30,7 +30,7 @@ register(
|
|||
CachedSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/CachedSource",
|
||||
new class CachedSourceSerializer {
|
||||
new (class CachedSourceSerializer {
|
||||
/**
|
||||
* @param {CachedSource} source the cached source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -56,14 +56,14 @@ register(
|
|||
source._cachedMaps = read();
|
||||
return source;
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
RawSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/RawSource",
|
||||
new class RawSourceSerializer {
|
||||
new (class RawSourceSerializer {
|
||||
/**
|
||||
* @param {RawSource} source the raw source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -82,14 +82,14 @@ register(
|
|||
const source = read();
|
||||
return new RawSource(source);
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
ConcatSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/ConcatSource",
|
||||
new class ConcatSourceSerializer {
|
||||
new (class ConcatSourceSerializer {
|
||||
/**
|
||||
* @param {ConcatSource} source the concat source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -109,14 +109,14 @@ register(
|
|||
source.children = children;
|
||||
return source;
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
PrefixSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/PrefixSource",
|
||||
new class PrefixSourceSerializer {
|
||||
new (class PrefixSourceSerializer {
|
||||
/**
|
||||
* @param {PrefixSource} source the prefix source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -134,14 +134,14 @@ register(
|
|||
deserialize({ read }) {
|
||||
return new PrefixSource(read(), read());
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
ReplaceSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/ReplaceSource",
|
||||
new class ReplaceSourceSerializer {
|
||||
new (class ReplaceSourceSerializer {
|
||||
/**
|
||||
* @param {ReplaceSource} source the replace source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -175,14 +175,14 @@ register(
|
|||
}
|
||||
return source;
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
OriginalSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/OriginalSource",
|
||||
new class OriginalSourceSerializer {
|
||||
new (class OriginalSourceSerializer {
|
||||
/**
|
||||
* @param {OriginalSource} source the original source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -200,14 +200,14 @@ register(
|
|||
deserialize({ read }) {
|
||||
return new OriginalSource(read(), read());
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
SourceLocation,
|
||||
CURRENT_MODULE,
|
||||
"acorn/SourceLocation",
|
||||
new class SourceLocationSerializer {
|
||||
new (class SourceLocationSerializer {
|
||||
/**
|
||||
* @param {SourceLocation} loc the location to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -236,14 +236,14 @@ register(
|
|||
}
|
||||
};
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
Position,
|
||||
CURRENT_MODULE,
|
||||
"acorn/Position",
|
||||
new class PositionSerializer {
|
||||
new (class PositionSerializer {
|
||||
/**
|
||||
* @param {Position} pos the position to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -264,14 +264,14 @@ register(
|
|||
column: read()
|
||||
};
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
||||
register(
|
||||
SourceMapSource,
|
||||
CURRENT_MODULE,
|
||||
"webpack-sources/SourceMapSource",
|
||||
new class SourceMapSourceSerializer {
|
||||
new (class SourceMapSourceSerializer {
|
||||
/**
|
||||
* @param {SourceMapSource} source the source map source to be serialized
|
||||
* @param {ObjectSerializerContext} context context
|
||||
|
@ -292,5 +292,5 @@ register(
|
|||
const map = read();
|
||||
return new SourceMapSource(source, "unknown", map);
|
||||
}
|
||||
}()
|
||||
})()
|
||||
);
|
||||
|
|
|
@ -134,9 +134,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|||
: undefined;
|
||||
|
||||
const instantiateCall =
|
||||
`${RuntimeGlobals.instantiateWasm}(${module.exportsArgument}, ${
|
||||
module.moduleArgument
|
||||
}.i` + (importsObj ? `, ${importsObj})` : `)`);
|
||||
`${RuntimeGlobals.instantiateWasm}(${module.exportsArgument}, ${module.moduleArgument}.i` +
|
||||
(importsObj ? `, ${importsObj})` : `)`);
|
||||
|
||||
return new RawSource(
|
||||
Template.asString([
|
||||
|
|
|
@ -335,9 +335,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
"}",
|
||||
"promises.push(installedWasmModules[wasmModuleId] = promise.then(function(res) {",
|
||||
Template.indent([
|
||||
`return ${
|
||||
RuntimeGlobals.wasmInstances
|
||||
}[wasmModuleId] = (res.instance || res).exports;`
|
||||
`return ${RuntimeGlobals.wasmInstances}[wasmModuleId] = (res.instance || res).exports;`
|
||||
]),
|
||||
"}));"
|
||||
]),
|
||||
|
|
|
@ -60,9 +60,7 @@ class WasmFinalizeExportsPlugin {
|
|||
// 4. error
|
||||
/** @type {TODO} */
|
||||
const error = new UnsupportedWebAssemblyFeatureError(
|
||||
`Export "${name}" with ${
|
||||
jsIncompatibleExports[name]
|
||||
} can only be used for direct wasm to wasm dependencies\n` +
|
||||
`Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` +
|
||||
`It's used from ${connection.originModule.readableIdentifier(
|
||||
compilation.requestShortener
|
||||
)} at ${formatLocation(connection.dependency.loc)}.`
|
||||
|
|
|
@ -168,9 +168,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|||
[
|
||||
'"use strict";',
|
||||
"// Instantiate WebAssembly module",
|
||||
`var wasmExports = ${RuntimeGlobals.wasmInstances}[${
|
||||
module.moduleArgument
|
||||
}.i];`,
|
||||
`var wasmExports = ${RuntimeGlobals.wasmInstances}[${module.moduleArgument}.i];`,
|
||||
|
||||
exportsInfo.otherExportsInfo.used !== UsageState.Unused
|
||||
? `${RuntimeGlobals.makeNamespaceObject}(${module.exportsArgument});`
|
||||
|
|
|
@ -153,9 +153,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
"promises.push(installedChunkData[2] = promise);",
|
||||
"",
|
||||
"// start chunk loading",
|
||||
`var url = ${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId);`,
|
||||
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
|
||||
"var loadingEnded = function() { if(installedChunks[chunkId]) return installedChunks[chunkId][1]; if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined; };",
|
||||
jsonpScript.call("", chunk),
|
||||
"document.head.appendChild(script);"
|
||||
|
@ -232,9 +230,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"waitingUpdateResolves[chunkId] = resolve;",
|
||||
"// start update chunk loading",
|
||||
`var url = ${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getChunkUpdateScriptFilename
|
||||
}(chunkId);`,
|
||||
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId);`,
|
||||
"var loadingEnded = function() {",
|
||||
Template.indent([
|
||||
"if(waitingUpdateResolves[chunkId]) {",
|
||||
|
@ -276,9 +272,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
]),
|
||||
"};",
|
||||
"",
|
||||
`${
|
||||
RuntimeGlobals.hmrDownloadUpdateHandlers
|
||||
}.jsonp = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
`${RuntimeGlobals.hmrDownloadUpdateHandlers}.jsonp = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
Template.indent([
|
||||
"applyHandlers.push(function(options) {",
|
||||
Template.indent([
|
||||
|
@ -325,9 +319,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
`${RuntimeGlobals.hmrDownloadManifest} = function() {`,
|
||||
Template.indent([
|
||||
'if (typeof fetch === "undefined") throw new Error("No browser support: need fetch API");',
|
||||
`return fetch(${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}()).then(function(response) {`,
|
||||
`return fetch(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getUpdateManifestFilename}()).then(function(response) {`,
|
||||
Template.indent([
|
||||
"if(response.status === 404) return; // no update available",
|
||||
'if(!response.ok) throw new Error("Failed to fetch update manifest " + response.statusText);',
|
||||
|
@ -427,9 +419,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
||||
Template.indent(
|
||||
`${
|
||||
RuntimeGlobals.moduleFactories
|
||||
}[moduleId] = moreModules[moduleId];`
|
||||
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
|
||||
),
|
||||
"}"
|
||||
]),
|
||||
|
|
|
@ -121,6 +121,7 @@ class JsonpTemplatePlugin {
|
|||
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
|
||||
"var realSrc = event && event.target && event.target.src;",
|
||||
"error.message = 'Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
|
||||
"error.name = 'ChunkLoadError';",
|
||||
"error.type = errorType;",
|
||||
"error.request = realSrc;",
|
||||
"reportError(error);"
|
||||
|
@ -154,9 +155,7 @@ class JsonpTemplatePlugin {
|
|||
"}",
|
||||
'link.rel = "preload";',
|
||||
'link.as = "script";',
|
||||
`link.href = ${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId);`,
|
||||
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
|
||||
crossOriginLoading
|
||||
? Template.asString([
|
||||
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
|
||||
|
@ -184,9 +183,7 @@ class JsonpTemplatePlugin {
|
|||
"}",
|
||||
'link.rel = "prefetch";',
|
||||
'link.as = "script";',
|
||||
`link.href = ${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId);`
|
||||
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
|
@ -57,9 +57,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
||||
Template.indent(
|
||||
`${
|
||||
RuntimeGlobals.moduleFactories
|
||||
}[moduleId] = moreModules[moduleId];`
|
||||
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
|
||||
),
|
||||
"}"
|
||||
]),
|
||||
|
@ -69,9 +67,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent("installedChunks[chunkIds.pop()] = 1;")
|
||||
]),
|
||||
"};",
|
||||
`importScripts(${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId));`,
|
||||
`importScripts(${RuntimeGlobals.getChunkScriptFilename}(chunkId));`,
|
||||
"",
|
||||
withHmr
|
||||
? "if(currentUpdateChunks && currentUpdateChunks[chunkId]) loadUpdateChunk(chunkId);"
|
||||
|
@ -110,16 +106,12 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
]),
|
||||
"};",
|
||||
"// start update chunk loading",
|
||||
`importScripts(${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getChunkUpdateScriptFilename
|
||||
}(chunkId));`,
|
||||
`importScripts(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
|
||||
'if(!success) throw new Error("Loading update chunk failed for unknown reason");'
|
||||
]),
|
||||
"}",
|
||||
"",
|
||||
`${
|
||||
RuntimeGlobals.hmrDownloadUpdateHandlers
|
||||
}.jsonp = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
`${RuntimeGlobals.hmrDownloadUpdateHandlers}.jsonp = function(chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {`,
|
||||
Template.indent([
|
||||
"applyHandlers.push(function(options) {",
|
||||
Template.indent([
|
||||
|
@ -167,9 +159,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
`${RuntimeGlobals.hmrDownloadManifest} = function() {`,
|
||||
Template.indent([
|
||||
'if (typeof fetch === "undefined") throw new Error("No browser support: need fetch API");',
|
||||
`return fetch(${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}()).then(function(response) {`,
|
||||
`return fetch(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getUpdateManifestFilename}()).then(function(response) {`,
|
||||
Template.indent([
|
||||
"if(response.status === 404) return; // no update available",
|
||||
'if(!response.ok) throw new Error("Failed to fetch update manifest " + response.statusText);',
|
||||
|
|
|
@ -279,9 +279,7 @@ describe("BenchmarkTestCases", function() {
|
|||
describe(`${testName} create benchmarks`, function() {
|
||||
baselines.forEach(baseline => {
|
||||
let baselineStats = null;
|
||||
it(`should benchmark ${baseline.name} (${
|
||||
baseline.rev
|
||||
})`, function(done) {
|
||||
it(`should benchmark ${baseline.name} (${baseline.rev})`, function(done) {
|
||||
const outputDirectory = path.join(
|
||||
__dirname,
|
||||
"js",
|
||||
|
@ -332,14 +330,10 @@ describe("BenchmarkTestCases", function() {
|
|||
}, 180000);
|
||||
|
||||
if (baseline.name !== "HEAD") {
|
||||
it(`HEAD should not be slower than ${baseline.name} (${
|
||||
baseline.rev
|
||||
})`, function() {
|
||||
it(`HEAD should not be slower than ${baseline.name} (${baseline.rev})`, function() {
|
||||
if (baselineStats.maxConfidence < headStats.minConfidence) {
|
||||
throw new Error(
|
||||
`HEAD (${headStats.text}) is slower than ${baseline.name} (${
|
||||
baselineStats.text
|
||||
}) (90% confidence)`
|
||||
`HEAD (${headStats.text}) is slower than ${baseline.name} (${baselineStats.text}) (90% confidence)`
|
||||
);
|
||||
} else if (
|
||||
baselineStats.minConfidence > headStats.maxConfidence
|
||||
|
|
|
@ -332,7 +332,7 @@ Object {
|
|||
"errors": Array [
|
||||
Object {
|
||||
"loc": "2:12",
|
||||
"message": "Module parse failed: Unexpected token (2:12)\\nYou may need an appropriate loader to handle this file type.\\n| window.foo = {\\n> bar: true,;\\n| };\\n| ",
|
||||
"message": "Module parse failed: Unexpected token (2:12)\\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\\n| window.foo = {\\n> bar: true,;\\n| };\\n| ",
|
||||
"moduleId": 0,
|
||||
"moduleIdentifier": "<cwd>/test/fixtures/errors/has-syntax-error.js",
|
||||
"moduleName": "./has-syntax-error.js",
|
||||
|
@ -682,6 +682,155 @@ Object {
|
|||
],
|
||||
"warnings": Array [],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
const identityLoader = path.resolve(
|
||||
__dirname,
|
||||
"fixtures/errors/identity-loader.js"
|
||||
);
|
||||
const addCommentLoader = path.resolve(
|
||||
__dirname,
|
||||
"fixtures/errors/add-comment-loader.js"
|
||||
);
|
||||
|
||||
it("should show loader used if it is present when module parsing fails", async () => {
|
||||
await expect(
|
||||
compile({
|
||||
mode: "development",
|
||||
entry: "./abc.html",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.html$/,
|
||||
use: [{ loader: identityLoader }]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"loc": "1:0",
|
||||
"message": "Module parse failed: Unexpected token (1:0)\\nFile was processed with these loaders:\\n * ./identity-loader.js\\nYou may need an additional loader to handle the result of these loaders.\\n> <!DOCTYPE html>\\n| <html>\\n| <body>",
|
||||
"moduleId": "./abc.html",
|
||||
"moduleIdentifier": "<cwd>/test/fixtures/errors/identity-loader.js!<cwd>/test/fixtures/errors/abc.html",
|
||||
"moduleName": "./abc.html",
|
||||
"moduleTrace": Array [],
|
||||
},
|
||||
],
|
||||
"warnings": Array [],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("should show all loaders used if they are in config when module parsing fails", async () => {
|
||||
await expect(
|
||||
compile({
|
||||
mode: "development",
|
||||
entry: "./abc.html",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.html$/,
|
||||
use: [{ loader: identityLoader }, { loader: addCommentLoader }]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"loc": "1:0",
|
||||
"message": "Module parse failed: Unexpected token (1:0)\\nFile was processed with these loaders:\\n * ./identity-loader.js\\n * ./add-comment-loader.js\\nYou may need an additional loader to handle the result of these loaders.\\n> <!DOCTYPE html>\\n| <html>\\n| <body>",
|
||||
"moduleId": "./abc.html",
|
||||
"moduleIdentifier": "<cwd>/test/fixtures/errors/identity-loader.js!<cwd>/test/fixtures/errors/add-comment-loader.js!<cwd>/test/fixtures/errors/abc.html",
|
||||
"moduleName": "./abc.html",
|
||||
"moduleTrace": Array [],
|
||||
},
|
||||
],
|
||||
"warnings": Array [],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("should show all loaders used if use is a string", async () => {
|
||||
await expect(
|
||||
compile({
|
||||
mode: "development",
|
||||
entry: "./abc.html",
|
||||
module: {
|
||||
rules: [
|
||||
{ test: /\.html$/, use: identityLoader },
|
||||
{ test: /\.html$/, use: addCommentLoader }
|
||||
]
|
||||
}
|
||||
})
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"loc": "1:0",
|
||||
"message": "Module parse failed: Unexpected token (1:0)\\nFile was processed with these loaders:\\n * ./identity-loader.js\\n * ./add-comment-loader.js\\nYou may need an additional loader to handle the result of these loaders.\\n> <!DOCTYPE html>\\n| <html>\\n| <body>",
|
||||
"moduleId": "./abc.html",
|
||||
"moduleIdentifier": "<cwd>/test/fixtures/errors/identity-loader.js!<cwd>/test/fixtures/errors/add-comment-loader.js!<cwd>/test/fixtures/errors/abc.html",
|
||||
"moduleName": "./abc.html",
|
||||
"moduleTrace": Array [],
|
||||
},
|
||||
],
|
||||
"warnings": Array [],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("should show 'no loaders are configured to process this file' if loaders are not included in config when module parsing fails", async () => {
|
||||
await expect(
|
||||
compile({
|
||||
mode: "development",
|
||||
entry: "./abc.html",
|
||||
module: {}
|
||||
})
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"loc": "1:0",
|
||||
"message": "Module parse failed: Unexpected token (1:0)\\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\\n> <!DOCTYPE html>\\n| <html>\\n| <body>",
|
||||
"moduleId": "./abc.html",
|
||||
"moduleIdentifier": "<cwd>/test/fixtures/errors/abc.html",
|
||||
"moduleName": "./abc.html",
|
||||
"moduleTrace": Array [],
|
||||
},
|
||||
],
|
||||
"warnings": Array [],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("should show 'source code omitted for this binary file' when module parsing fails for binary files", async () => {
|
||||
const folder = path.join(__dirname, "/fixtures");
|
||||
await expect(
|
||||
compile({
|
||||
mode: "development",
|
||||
entry: path.resolve(folder, "./font.ttf"),
|
||||
module: {}
|
||||
})
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"loc": "1:0",
|
||||
"message": "Module parse failed: Unexpected character ' |