Skip to content

Commit 9fbe914

Browse files
committed
Merge branch 'master' into feature/module-build-error-with-loader-name
# Conflicts: # lib/ModuleBuildError.js # lib/ModuleError.js # lib/ModuleWarning.js
2 parents e68d83e + 19389b7 commit 9fbe914

File tree

84 files changed

+1194
-487
lines changed

Some content is hidden

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

84 files changed

+1194
-487
lines changed

declarations.d.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ declare module "@webassemblyjs/ast" {
3636
ModuleImport?: (p: NodePath<ModuleImport>) => void;
3737
ModuleExport?: (p: NodePath<ModuleExport>) => void;
3838
Start?: (p: NodePath<Start>) => void;
39+
Global?: (p: NodePath<Global>) => void;
3940
}
4041
);
4142
export class NodePath<T> {
@@ -60,28 +61,46 @@ declare module "@webassemblyjs/ast" {
6061
}
6162
export class ModuleExport extends Node {
6263
name: string;
64+
descr: ModuleExportDescr;
65+
}
66+
type Index = Identifier | NumberLiteral;
67+
export class ModuleExportDescr extends Node {
68+
type: string;
69+
exportType: string;
70+
id: Index;
71+
}
72+
export class NumberLiteral extends Node {
73+
value: number;
74+
raw: string;
6375
}
64-
export class ModuleExportDescr extends Node {}
65-
export class IndexLiteral extends Node {}
66-
export class NumberLiteral extends Node {}
6776
export class FloatLiteral extends Node {}
68-
export class Global extends Node {}
77+
export class GlobalType extends Node {
78+
valtype: string;
79+
}
80+
export class Global extends Node {
81+
init: Instruction[];
82+
globalType: GlobalType;
83+
}
6984
export class FuncParam extends Node {
7085
valtype: string;
7186
}
72-
export class Instruction extends Node {}
87+
export class Instruction extends Node {
88+
id: string;
89+
args: NumberLiteral[];
90+
}
7391
export class CallInstruction extends Instruction {}
7492
export class ObjectInstruction extends Instruction {}
7593
export class Func extends Node {
7694
signature: Signature;
7795
}
7896
export class Signature {
97+
type: "Signature";
7998
params: FuncParam[];
8099
results: string[];
81100
}
82101
export class TypeInstruction extends Node {}
83102
export class IndexInFuncSection extends Node {}
84-
export function indexLiteral(index: number): IndexLiteral;
103+
export function indexLiteral(index: number): Index;
85104
export function numberLiteralFromRaw(num: number): NumberLiteral;
86105
export function floatLiteral(
87106
value: number,
@@ -93,29 +112,33 @@ declare module "@webassemblyjs/ast" {
93112
export function identifier(indentifier: string): Identifier;
94113
export function funcParam(valType: string, id: Identifier): FuncParam;
95114
export function instruction(inst: string, args: Node[]): Instruction;
96-
export function callInstruction(funcIndex: IndexLiteral): CallInstruction;
115+
export function callInstruction(funcIndex: Index): CallInstruction;
97116
export function objectInstruction(
98117
kind: string,
99118
type: string,
100119
init: Node[]
101120
): ObjectInstruction;
102121
export function signature(params: FuncParam[], results: string[]): Signature;
103-
export function func(initFuncId, Signature, funcBody): Func;
122+
export function func(initFuncId, signature: Signature, funcBody): Func;
104123
export function typeInstruction(
105124
id: Identifier,
106125
functype: Signature
107126
): TypeInstruction;
108-
export function indexInFuncSection(index: IndexLiteral): IndexInFuncSection;
127+
export function indexInFuncSection(index: Index): IndexInFuncSection;
109128
export function moduleExport(
110129
identifier: string,
111130
descr: ModuleExportDescr
112131
): ModuleExport;
113132
export function moduleExportDescr(
114133
type: string,
115-
index: ModuleExportDescr
116-
): ModuleExport;
134+
index: Index
135+
): ModuleExportDescr;
117136

118137
export function getSectionMetadata(ast: any, section: string);
138+
export class FuncSignature {
139+
args: string[];
140+
result: string[];
141+
}
119142
}
120143

121144
/**

lib/AsyncDependencyToInitialChunkError.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class AsyncDependencyToInitialChunkError extends WebpackError {
1616
* @param {TODO} loc location of dependency
1717
*/
1818
constructor(chunkName, module, loc) {
19-
super();
19+
super(
20+
`It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`
21+
);
2022

2123
this.name = "AsyncDependencyToInitialChunkError";
22-
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`;
2324
this.module = module;
24-
this.origin = module;
25-
this.originLoc = loc;
25+
this.loc = loc;
2626

2727
Error.captureStackTrace(this, this.constructor);
2828
}

lib/CaseSensitiveModulesWarning.js

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,60 @@ const WebpackError = require("./WebpackError");
88

99
/** @typedef {import("./Module")} Module */
1010

11+
/**
12+
* @param {Module[]} modules the modules to be sorted
13+
* @returns {Module[]} sorted version of original modules
14+
*/
15+
const sortModules = modules => {
16+
return modules.slice().sort((a, b) => {
17+
a = a.identifier();
18+
b = b.identifier();
19+
/* istanbul ignore next */
20+
if (a < b) return -1;
21+
/* istanbul ignore next */
22+
if (a > b) return 1;
23+
/* istanbul ignore next */
24+
return 0;
25+
});
26+
};
27+
28+
/**
29+
* @param {Module[]} modules each module from throw
30+
* @returns {string} each message from provided moduels
31+
*/
32+
const createModulesListMessage = modules => {
33+
return modules
34+
.map(m => {
35+
let message = `* ${m.identifier()}`;
36+
const validReasons = m.reasons.filter(reason => reason.module);
37+
38+
if (validReasons.length > 0) {
39+
message += `\n Used by ${validReasons.length} module(s), i. e.`;
40+
message += `\n ${validReasons[0].module.identifier()}`;
41+
}
42+
return message;
43+
})
44+
.join("\n");
45+
};
46+
1147
class CaseSensitiveModulesWarning extends WebpackError {
1248
/**
1349
* Creates an instance of CaseSensitiveModulesWarning.
1450
* @param {Module[]} modules modules that were detected
1551
*/
1652
constructor(modules) {
17-
super();
18-
19-
this.name = "CaseSensitiveModulesWarning";
20-
const sortedModules = this._sort(modules);
21-
const modulesList = this._moduleMessages(sortedModules);
22-
this.message = `There are multiple modules with names that only differ in casing.
53+
const sortedModules = sortModules(modules);
54+
const modulesList = createModulesListMessage(sortedModules);
55+
super(`There are multiple modules with names that only differ in casing.
2356
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
2457
Use equal casing. Compare these module identifiers:
25-
${modulesList}`;
58+
${modulesList}`);
2659

60+
this.name = "CaseSensitiveModulesWarning";
2761
this.origin = this.module = sortedModules[0];
2862

2963
Error.captureStackTrace(this, this.constructor);
3064
}
31-
32-
/**
33-
* @private
34-
* @param {Module[]} modules the modules to be sorted
35-
* @returns {Module[]} sorted version of original modules
36-
*/
37-
_sort(modules) {
38-
return modules.slice().sort((a, b) => {
39-
a = a.identifier();
40-
b = b.identifier();
41-
/* istanbul ignore next */
42-
if (a < b) return -1;
43-
/* istanbul ignore next */
44-
if (a > b) return 1;
45-
/* istanbul ignore next */
46-
return 0;
47-
});
48-
}
49-
50-
/**
51-
* @private
52-
* @param {Module[]} modules each module from throw
53-
* @returns {string} each message from provided moduels
54-
*/
55-
_moduleMessages(modules) {
56-
return modules
57-
.map(m => {
58-
let message = `* ${m.identifier()}`;
59-
const validReasons = m.reasons.filter(reason => reason.module);
60-
61-
if (validReasons.length > 0) {
62-
message += `\n Used by ${validReasons.length} module(s), i. e.`;
63-
message += `\n ${validReasons[0].module.identifier()}`;
64-
}
65-
return message;
66-
})
67-
.join("\n");
68-
}
6965
}
7066

7167
module.exports = CaseSensitiveModulesWarning;

lib/Chunk.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,10 @@ class Chunk {
607607
return result;
608608
}
609609

610-
getChildIdsByOrdersMap() {
610+
getChildIdsByOrdersMap(includeDirectChildren) {
611611
const chunkMaps = Object.create(null);
612612

613-
for (const chunk of this.getAllAsyncChunks()) {
613+
const addChildIdsByOrdersToMap = chunk => {
614614
const data = chunk.getChildIdsByOrders();
615615
for (const key of Object.keys(data)) {
616616
let chunkMap = chunkMaps[key];
@@ -619,7 +619,16 @@ class Chunk {
619619
}
620620
chunkMap[chunk.id] = data[key];
621621
}
622+
};
623+
624+
if (includeDirectChildren) {
625+
addChildIdsByOrdersToMap(this);
622626
}
627+
628+
for (const chunk of this.getAllAsyncChunks()) {
629+
addChildIdsByOrdersToMap(chunk);
630+
}
631+
623632
return chunkMaps;
624633
}
625634

lib/CommentCompilationWarning.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
"use strict";
6+
7+
const WebpackError = require("./WebpackError");
8+
9+
class CommentCompilationWarning extends WebpackError {
10+
constructor(message, module, loc) {
11+
super(message);
12+
13+
this.name = "CommentCompilationWarning";
14+
15+
this.module = module;
16+
this.loc = loc;
17+
18+
Error.captureStackTrace(this, this.constructor);
19+
}
20+
}
21+
22+
module.exports = CommentCompilationWarning;

lib/Compilation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ class Compilation extends Tapable {
487487

488488
const errorAndCallback = err => {
489489
err.origin = module;
490+
err.dependencies = dependencies;
490491
this.errors.push(err);
491492
if (bail) {
492493
callback(err);
@@ -531,7 +532,7 @@ class Compilation extends Tapable {
531532
if (err) {
532533
semaphore.release();
533534
return errorOrWarningAndCallback(
534-
new ModuleNotFoundError(module, err, dependencies)
535+
new ModuleNotFoundError(module, err)
535536
);
536537
}
537538
if (!dependentModule) {

lib/EntryModuleNotFoundError.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ const WebpackError = require("./WebpackError");
88

99
class EntryModuleNotFoundError extends WebpackError {
1010
constructor(err) {
11-
super();
11+
super("Entry module not found: " + err);
1212

1313
this.name = "EntryModuleNotFoundError";
14-
this.message = "Entry module not found: " + err;
1514
this.details = err.details;
1615
this.error = err;
1716

lib/HarmonyLinkingError.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ const WebpackError = require("./WebpackError");
88
module.exports = class HarmonyLinkingError extends WebpackError {
99
/** @param {string} message Error message */
1010
constructor(message) {
11-
super();
11+
super(message);
1212
this.name = "HarmonyLinkingError";
13-
this.message = message;
1413
this.hideStack = true;
1514

1615
Error.captureStackTrace(this, this.constructor);

lib/ModuleBuildError.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,38 @@ const { cutOffLoaderExecution } = require("./ErrorHelpers");
99

1010
class ModuleBuildError extends WebpackError {
1111
constructor(module, err, { from = null } = {}) {
12-
super();
13-
14-
this.name = "ModuleBuildError";
15-
this.message = "Module build failed";
12+
let message = "Module build failed";
13+
let details = undefined;
1614
if (from) {
17-
this.message += ` (from ${from})`;
15+
message += ` (from ${from})`;
1816
}
19-
20-
let message;
17+
message += ": ";
2118
if (err !== null && typeof err === "object") {
2219
if (typeof err.stack === "string" && err.stack) {
2320
const stack = cutOffLoaderExecution(err.stack);
2421
if (!err.hideStack) {
25-
message = stack;
22+
message += stack;
2623
} else {
27-
this.details = stack;
24+
details = stack;
2825
if (typeof err.message === "string" && err.message) {
29-
message = err.message;
26+
message += err.message;
3027
} else {
31-
message = err;
28+
message += err;
3229
}
3330
}
3431
} else if (typeof err.message === "string" && err.message) {
35-
message = err.message;
32+
message += err.message;
3633
} else {
37-
message = err;
34+
message += err;
3835
}
3936
} else {
4037
message = err;
4138
}
4239

43-
if (message !== "") {
44-
this.message += `:\n${message}`;
45-
}
40+
super(message);
4641

42+
this.name = "ModuleBuildError";
43+
this.details = details;
4744
this.module = module;
4845
this.error = err;
4946

0 commit comments

Comments
 (0)