Skip to content

Commit ce6ac00

Browse files
committed
Merge branch 'master' of git://github.com/webpack/webpack into type-sortable-set
2 parents 1d39cce + 02a955b commit ce6ac00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+896
-401
lines changed

declarations.d.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,6 @@ declare namespace NodeJS {
77
}
88
}
99

10-
// There are no typings for chrome-trace-event
11-
declare module "chrome-trace-event" {
12-
interface Event {
13-
name: string;
14-
id?: number;
15-
cat: string[];
16-
args?: Object;
17-
}
18-
19-
export class Tracer {
20-
constructor(options: { noStream: boolean });
21-
pipe(stream: NodeJS.WritableStream): void;
22-
instantEvent(event: Event): void;
23-
counter: number;
24-
trace: {
25-
begin(event: Event): void;
26-
end(event: Event): void;
27-
};
28-
}
29-
}
30-
3110
// There are no typings for @webassemblyjs/ast
3211
declare module "@webassemblyjs/ast" {
3312
export function traverse(
@@ -139,6 +118,12 @@ declare module "@webassemblyjs/ast" {
139118
args: string[];
140119
result: string[];
141120
}
121+
122+
// Node matcher
123+
export function isGlobalType(n: Node): boolean;
124+
export function isTable(n: Node): boolean;
125+
export function isMemory(n: Node): boolean;
126+
export function isFuncImportDescr(n: Node): boolean;
142127
}
143128

144129
/**

examples/dll-app-and-vendor/0-vendor/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This is the vendor build part.
22

3-
It's built separately from the app part. The vendors dll is only built when vendors has changed and not while the normal development cycle.
3+
It's built separately from the app part. The vendors dll is only built when the array of vendors has changed and not during the normal development cycle.
44

55
The DllPlugin in combination with the `output.library` option exposes the internal require function as global variable in the target environment.
66

examples/dll-app-and-vendor/0-vendor/template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This is the vendor build part.
22

3-
It's built separately from the app part. The vendors dll is only built when vendors has changed and not while the normal development cycle.
3+
It's built separately from the app part. The vendors dll is only built when the array of vendors has changed and not during the normal development cycle.
44

55
The DllPlugin in combination with the `output.library` option exposes the internal require function as global variable in the target environment.
66

lib/CaseSensitiveModulesWarning.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const WebpackError = require("./WebpackError");
1414
*/
1515
const sortModules = modules => {
1616
return modules.slice().sort((a, b) => {
17-
a = a.identifier();
18-
b = b.identifier();
17+
const aIdent = a.identifier();
18+
const bIdent = b.identifier();
1919
/* istanbul ignore next */
20-
if (a < b) return -1;
20+
if (aIdent < bIdent) return -1;
2121
/* istanbul ignore next */
22-
if (a > b) return 1;
22+
if (aIdent > bIdent) return 1;
2323
/* istanbul ignore next */
2424
return 0;
2525
});

lib/HotModuleReplacement.runtime.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ module.exports = function() {
5555
for (var name in $require$) {
5656
if (
5757
Object.prototype.hasOwnProperty.call($require$, name) &&
58-
name !== "e"
58+
name !== "e" &&
59+
name !== "t"
5960
) {
6061
Object.defineProperty(fn, name, ObjectFactory(name));
6162
}
@@ -80,6 +81,10 @@ module.exports = function() {
8081
}
8182
}
8283
};
84+
fn.t = function(value, mode) {
85+
if (mode & 1) value = fn(value);
86+
return $require$.t(value, mode & ~1);
87+
};
8388
return fn;
8489
}
8590

lib/Module.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,12 @@ Object.defineProperty(Module.prototype, "meta", {
370370
}, "Module.meta was renamed to Module.buildMeta")
371371
});
372372

373+
/** @type {function(): string} */
373374
Module.prototype.identifier = null;
375+
376+
/** @type {function(RequestShortener): string} */
374377
Module.prototype.readableIdentifier = null;
378+
375379
Module.prototype.build = null;
376380
Module.prototype.source = null;
377381
Module.prototype.size = null;

lib/ModuleBuildError.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ const WebpackError = require("./WebpackError");
88
const { cutOffLoaderExecution } = require("./ErrorHelpers");
99

1010
class ModuleBuildError extends WebpackError {
11-
constructor(module, err) {
12-
let message = "Module build failed: ";
11+
constructor(module, err, { from = null } = {}) {
12+
let message = "Module build failed";
1313
let details = undefined;
14+
if (from) {
15+
message += ` (from ${from}):\n`;
16+
} else {
17+
message += ": ";
18+
}
1419
if (err !== null && typeof err === "object") {
1520
if (typeof err.stack === "string" && err.stack) {
16-
var stack = cutOffLoaderExecution(err.stack);
21+
const stack = cutOffLoaderExecution(err.stack);
1722
if (!err.hideStack) {
1823
message += stack;
1924
} else {
@@ -29,6 +34,8 @@ class ModuleBuildError extends WebpackError {
2934
} else {
3035
message += err;
3136
}
37+
} else {
38+
message = err;
3239
}
3340

3441
super(message);

lib/ModuleError.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ const WebpackError = require("./WebpackError");
88
const { cleanUp } = require("./ErrorHelpers");
99

1010
class ModuleError extends WebpackError {
11-
constructor(module, err) {
12-
super(err && typeof err === "object" && err.message ? err.message : err);
13-
11+
constructor(module, err, { from = null } = {}) {
12+
let message = "Module Error";
13+
if (from) {
14+
message += ` (from ${from}):\n`;
15+
} else {
16+
message += ": ";
17+
}
18+
if (err && typeof err === "object" && err.message) {
19+
message += err.message;
20+
} else if (err) {
21+
message += err;
22+
}
23+
super(message);
1424
this.name = "ModuleError";
1525
this.module = module;
1626
this.error = err;

lib/ModuleWarning.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ const WebpackError = require("./WebpackError");
88
const { cleanUp } = require("./ErrorHelpers");
99

1010
class ModuleWarning extends WebpackError {
11-
constructor(module, warning) {
12-
super(
13-
warning && typeof warning === "object" && warning.message
14-
? warning.message
15-
: warning
16-
);
17-
11+
constructor(module, warning, { from = null } = {}) {
12+
let message = "Module Warning";
13+
if (from) {
14+
message += ` (from ${from}):\n`;
15+
} else {
16+
message += ": ";
17+
}
18+
if (warning && typeof warning === "object" && warning.message) {
19+
message += warning.message;
20+
} else if (warning) {
21+
message += warning;
22+
}
23+
super(message);
1824
this.name = "ModuleWarning";
1925
this.module = module;
2026
this.warning = warning;

lib/NormalModule.js

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,30 @@ class NormalModule extends Module {
166166
}
167167

168168
createLoaderContext(resolver, options, compilation, fs) {
169+
const requestShortener = compilation.runtimeTemplate.requestShortener;
169170
const loaderContext = {
170171
version: 2,
171172
emitWarning: warning => {
172173
if (!(warning instanceof Error)) {
173174
warning = new NonErrorEmittedError(warning);
174175
}
175-
this.warnings.push(new ModuleWarning(this, warning));
176+
const currentLoader = this.getCurrentLoader(loaderContext);
177+
this.warnings.push(
178+
new ModuleWarning(this, warning, {
179+
from: requestShortener.shorten(currentLoader.loader)
180+
})
181+
);
176182
},
177183
emitError: error => {
178184
if (!(error instanceof Error)) {
179185
error = new NonErrorEmittedError(error);
180186
}
181-
this.errors.push(new ModuleError(this, error));
187+
const currentLoader = this.getCurrentLoader(loaderContext);
188+
this.errors.push(
189+
new ModuleError(this, error, {
190+
from: requestShortener.shorten(currentLoader.loader)
191+
})
192+
);
182193
},
183194
exec: (code, filename) => {
184195
// @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'.
@@ -219,6 +230,19 @@ class NormalModule extends Module {
219230
return loaderContext;
220231
}
221232

233+
getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
234+
if (
235+
this.loaders &&
236+
this.loaders.length &&
237+
index < this.loaders.length &&
238+
index >= 0 &&
239+
this.loaders[index]
240+
) {
241+
return this.loaders[index];
242+
}
243+
return null;
244+
}
245+
222246
createSource(source, resourceBuffer, sourceMap) {
223247
// if there is no identifier return raw source
224248
if (!this.identifier) {
@@ -272,7 +296,17 @@ class NormalModule extends Module {
272296
}
273297

274298
if (err) {
275-
const error = new ModuleBuildError(this, err);
299+
if (!(err instanceof Error)) {
300+
err = new NonErrorEmittedError(err);
301+
}
302+
const currentLoader = this.getCurrentLoader(loaderContext);
303+
const error = new ModuleBuildError(this, err, {
304+
from:
305+
currentLoader &&
306+
compilation.runtimeTemplate.requestShortener.shorten(
307+
currentLoader.loader
308+
)
309+
});
276310
return callback(error);
277311
}
278312

@@ -282,10 +316,17 @@ class NormalModule extends Module {
282316
const extraInfo = result.result.length >= 2 ? result.result[2] : null;
283317

284318
if (!Buffer.isBuffer(source) && typeof source !== "string") {
285-
const error = new ModuleBuildError(
286-
this,
287-
new Error("Final loader didn't return a Buffer or String")
319+
const currentLoader = this.getCurrentLoader(loaderContext, 0);
320+
const err = new Error(
321+
`Final loader (${
322+
currentLoader
323+
? compilation.runtimeTemplate.requestShortener.shorten(
324+
currentLoader.loader
325+
)
326+
: "unknown"
327+
}) didn't return a Buffer or String`
288328
);
329+
const error = new ModuleBuildError(this, err);
289330
return callback(error);
290331
}
291332

lib/Parser.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const joinRanges = (startRange, endRange) => {
2323
const defaultParserOptions = {
2424
ranges: true,
2525
locations: true,
26-
ecmaVersion: 2018,
26+
ecmaVersion: 2019,
2727
sourceType: "module",
2828
onComment: null,
2929
plugins: {
@@ -34,6 +34,8 @@ const defaultParserOptions = {
3434
// regexp to match at lease one "magic comment"
3535
const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
3636

37+
const EMPTY_ARRAY = [];
38+
3739
const EMPTY_COMMENT_OPTIONS = {
3840
options: null,
3941
errors: null
@@ -1356,7 +1358,11 @@ class Parser extends Tapable {
13561358
}
13571359

13581360
walkCatchClause(catchClause) {
1359-
this.inScope([catchClause.param], () => {
1361+
// Error binding is optional in catch clause since ECMAScript 2019
1362+
const errorBinding =
1363+
catchClause.param === null ? EMPTY_ARRAY : [catchClause.param];
1364+
1365+
this.inScope(errorBinding, () => {
13601366
this.prewalkStatement(catchClause.body);
13611367
this.walkStatement(catchClause.body);
13621368
});

0 commit comments

Comments
 (0)