Skip to content

Commit 6789a5e

Browse files
committed
Merge branch 'master' into feature/webpack-options-compile-errors-warning
2 parents a228dae + 949890a commit 6789a5e

File tree

262 files changed

+3806
-2487
lines changed

Some content is hidden

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

262 files changed

+3806
-2487
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ root = true
22

33
[*]
44
indent_style = tab
5-
indent_size = 4
5+
indent_size = 2
66
charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
9-
max_line_length = 233
9+
max_line_length = 80
1010

1111
[.prettierrc]
1212
indent_style = space

.prettierignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Ignore all paths.
2+
**/*.*
3+
4+
# Enable prettier for the following paths.
5+
!setup/**/*.js
6+
!lib/**/*.js
7+
!bin/*.js
8+
!hot/*.js
9+
!buildin/*.js
10+
!test/*.js
11+
!test/**/webpack.config.js
12+
!examples/**/webpack.config.js
13+
!schemas/**/*.js
14+
!declarations.d.ts

declarations.d.ts

Lines changed: 49 additions & 13 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> {
@@ -52,32 +53,60 @@ declare module "@webassemblyjs/ast" {
5253
module: string;
5354
descr: {
5455
type: string;
55-
valtype: string;
56-
id: string;
56+
valtype?: string;
57+
id?: Identifier;
58+
signature?: Signature;
5759
};
5860
name: string;
5961
}
6062
export class ModuleExport extends Node {
6163
name: string;
64+
descr: {
65+
type: string;
66+
exportType: string;
67+
id?: Identifier;
68+
};
6269
}
70+
export class ModuleExportDescr extends Node {}
6371
export class IndexLiteral extends Node {}
64-
export class NumberLiteral extends Node {}
65-
export class Global extends Node {}
66-
export class FuncParam extends Node {}
67-
export class Instruction extends Node {}
72+
export class NumberLiteral extends Node {
73+
value: number;
74+
raw: string;
75+
}
76+
export class FloatLiteral 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+
}
84+
export class FuncParam extends Node {
85+
valtype: string;
86+
}
87+
export class Instruction extends Node {
88+
id: string;
89+
args: NumberLiteral[];
90+
}
6891
export class CallInstruction extends Instruction {}
6992
export class ObjectInstruction extends Instruction {}
7093
export class Func extends Node {
7194
signature: Signature;
7295
}
7396
export class Signature {
74-
params: any;
75-
result: any;
97+
params: FuncParam[];
98+
results: string[];
7699
}
77-
export class TypeInstructionFunc extends Node {}
100+
export class TypeInstruction extends Node {}
78101
export class IndexInFuncSection extends Node {}
79102
export function indexLiteral(index: number): IndexLiteral;
80-
export function numberLiteral(num: number): NumberLiteral;
103+
export function numberLiteralFromRaw(num: number): NumberLiteral;
104+
export function floatLiteral(
105+
value: number,
106+
nan?: boolean,
107+
inf?: boolean,
108+
raw?: string
109+
): FloatLiteral;
81110
export function global(globalType: string, nodes: Node[]): Global;
82111
export function identifier(indentifier: string): Identifier;
83112
export function funcParam(valType: string, id: Identifier): FuncParam;
@@ -88,13 +117,20 @@ declare module "@webassemblyjs/ast" {
88117
type: string,
89118
init: Node[]
90119
): ObjectInstruction;
91-
export function func(initFuncId, funcParams, funcResults, funcBody): Func;
92-
export function typeInstructionFunc(params, result): TypeInstructionFunc;
120+
export function signature(params: FuncParam[], results: string[]): Signature;
121+
export function func(initFuncId, Signature, funcBody): Func;
122+
export function typeInstruction(
123+
id: Identifier,
124+
functype: Signature
125+
): TypeInstruction;
93126
export function indexInFuncSection(index: IndexLiteral): IndexInFuncSection;
94127
export function moduleExport(
95128
identifier: string,
129+
descr: ModuleExportDescr
130+
): ModuleExport;
131+
export function moduleExportDescr(
96132
type: string,
97-
index: IndexLiteral
133+
index: ModuleExportDescr
98134
): ModuleExport;
99135

100136
export function getSectionMetadata(ast: any, section: string);

examples/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@
120120
If you think an example is missing, please report it as issue. :)
121121

122122
# Building an Example
123-
1. Run `npm install` in the root of the project.
124-
2. Run `npm link webpack` in the root of the project.
125-
3. Run `node build.js` in the specific example directory. (Ex: `cd examples/commonjs && node build.js`)
123+
1. Run `yarn` in the root of the project.
124+
2. Run `yarn link webpack` in the root of the project.
125+
3. Run `yarn add --dev webpack-cli` in the root of the project.
126+
4. Run `node build.js` in the specific example directory. (Ex: `cd examples/commonjs && node build.js`)
126127

127128
Note: To build all examples run `npm run build:examples`

lib/AmdMainTemplatePlugin.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
const { ConcatSource } = require("webpack-sources");
99
const Template = require("./Template");
1010

11+
/** @typedef {import("./Compilation")} Compilation */
12+
1113
class AmdMainTemplatePlugin {
14+
/**
15+
* @param {string} name the library name
16+
*/
1217
constructor(name) {
18+
/** @type {string} */
1319
this.name = name;
1420
}
1521

22+
/**
23+
* @param {Compilation} compilation the compilation instance
24+
* @returns {void}
25+
*/
1626
apply(compilation) {
1727
const { mainTemplate, chunkTemplate } = compilation;
1828

@@ -61,7 +71,9 @@ class AmdMainTemplatePlugin {
6171
}
6272

6373
mainTemplate.hooks.globalHashPaths.tap("AmdMainTemplatePlugin", paths => {
64-
if (this.name) paths.push(this.name);
74+
if (this.name) {
75+
paths.push(this.name);
76+
}
6577
return paths;
6678
});
6779

lib/AsyncDependencyToInitialChunkError.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@
66

77
const WebpackError = require("./WebpackError");
88

9-
module.exports = class AsyncDependencyToInitialChunkError extends WebpackError {
9+
/** @typedef {import("./Module")} Module */
10+
11+
class AsyncDependencyToInitialChunkError extends WebpackError {
12+
/**
13+
* Creates an instance of AsyncDependencyToInitialChunkError.
14+
* @param {string} chunkName Name of Chunk
15+
* @param {Module} module module tied to dependency
16+
* @param {TODO} loc location of dependency
17+
*/
1018
constructor(chunkName, module, loc) {
11-
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+
);
1222

1323
this.name = "AsyncDependencyToInitialChunkError";
14-
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`;
1524
this.module = module;
16-
this.origin = module;
17-
this.originLoc = loc;
25+
this.loc = loc;
1826

1927
Error.captureStackTrace(this, this.constructor);
2028
}
21-
};
29+
}
30+
31+
module.exports = AsyncDependencyToInitialChunkError;

lib/BannerPlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const validateOptions = require("schema-utils");
1313
const schema = require("../schemas/plugins/BannerPlugin.json");
1414

1515
const wrapComment = str => {
16-
if (!str.includes("\n")) return Template.toComment(str);
16+
if (!str.includes("\n")) {
17+
return Template.toComment(str);
18+
}
1719
return `/*!\n * ${str
1820
.replace(/\*\//g, "* /")
1921
.split("\n")

lib/BasicEvaluatedExpression.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,21 @@ class BasicEvaluatedExpression {
9090

9191
asBool() {
9292
if (this.truthy) return true;
93-
else if (this.falsy) return false;
94-
else if (this.isBoolean()) return this.bool;
95-
else if (this.isNull()) return false;
96-
else if (this.isString()) return this.string !== "";
97-
else if (this.isNumber()) return this.number !== 0;
98-
else if (this.isRegExp()) return true;
99-
else if (this.isArray()) return true;
100-
else if (this.isConstArray()) return true;
101-
else if (this.isWrapped())
93+
if (this.falsy) return false;
94+
if (this.isBoolean()) return this.bool;
95+
if (this.isNull()) return false;
96+
if (this.isString()) return this.string !== "";
97+
if (this.isNumber()) return this.number !== 0;
98+
if (this.isRegExp()) return true;
99+
if (this.isArray()) return true;
100+
if (this.isConstArray()) return true;
101+
if (this.isWrapped()) {
102102
return (this.prefix && this.prefix.asBool()) ||
103103
(this.postfix && this.postfix.asBool())
104104
? true
105105
: undefined;
106-
else if (this.isTemplateString()) {
106+
}
107+
if (this.isTemplateString()) {
107108
for (const quasi of this.quasis) {
108109
if (quasi.asBool()) return true;
109110
}
@@ -165,7 +166,9 @@ class BasicEvaluatedExpression {
165166
this.type = TypeConditional;
166167
this.options = [];
167168
}
168-
for (const item of options) this.options.push(item);
169+
for (const item of options) {
170+
this.options.push(item);
171+
}
169172
return this;
170173
}
171174

lib/CachePlugin.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ class CachePlugin {
2626
(childCompiler, compilerName, compilerIndex) => {
2727
if (cache) {
2828
let childCache;
29-
if (!cache.children) cache.children = {};
30-
if (!cache.children[compilerName])
29+
if (!cache.children) {
30+
cache.children = {};
31+
}
32+
if (!cache.children[compilerName]) {
3133
cache.children[compilerName] = [];
32-
if (cache.children[compilerName][compilerIndex])
34+
}
35+
if (cache.children[compilerName][compilerIndex]) {
3336
childCache = cache.children[compilerName][compilerIndex];
34-
else cache.children[compilerName].push((childCache = {}));
37+
} else {
38+
cache.children[compilerName].push((childCache = {}));
39+
}
3540
registerCacheToCompiler(childCompiler, childCache);
3641
}
3742
}
@@ -43,7 +48,9 @@ class CachePlugin {
4348
this.watching = true;
4449
});
4550
compiler.hooks.run.tapAsync("CachePlugin", (compiler, callback) => {
46-
if (!compiler._lastCompilationFileDependencies) return callback();
51+
if (!compiler._lastCompilationFileDependencies) {
52+
return callback();
53+
}
4754
const fs = compiler.inputFileSystem;
4855
const fileTs = (compiler.fileTimestamps = new Map());
4956
asyncLib.forEach(

lib/CaseSensitiveModulesWarning.js

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,62 @@
66

77
const WebpackError = require("./WebpackError");
88

9-
module.exports = class CaseSensitiveModulesWarning extends WebpackError {
10-
constructor(modules) {
11-
super();
9+
/** @typedef {import("./Module")} Module */
1210

13-
this.name = "CaseSensitiveModulesWarning";
14-
const sortedModules = this._sort(modules);
15-
const modulesList = this._moduleMessages(sortedModules);
16-
this.message = `There are multiple modules with names that only differ in casing.
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+
47+
class CaseSensitiveModulesWarning extends WebpackError {
48+
/**
49+
* Creates an instance of CaseSensitiveModulesWarning.
50+
* @param {Module[]} modules modules that were detected
51+
*/
52+
constructor(modules) {
53+
const sortedModules = sortModules(modules);
54+
const modulesList = createModulesListMessage(sortedModules);
55+
super(`There are multiple modules with names that only differ in casing.
1756
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
1857
Use equal casing. Compare these module identifiers:
19-
${modulesList}`;
58+
${modulesList}`);
2059

60+
this.name = "CaseSensitiveModulesWarning";
2161
this.origin = this.module = sortedModules[0];
2262

2363
Error.captureStackTrace(this, this.constructor);
2464
}
65+
}
2566

26-
_sort(modules) {
27-
return modules.slice().sort((a, b) => {
28-
a = a.identifier();
29-
b = b.identifier();
30-
/* istanbul ignore next */
31-
if (a < b) return -1;
32-
/* istanbul ignore next */
33-
if (a > b) return 1;
34-
/* istanbul ignore next */
35-
return 0;
36-
});
37-
}
38-
39-
_moduleMessages(modules) {
40-
return modules
41-
.map(m => {
42-
let message = `* ${m.identifier()}`;
43-
const validReasons = m.reasons.filter(reason => reason.module);
44-
45-
if (validReasons.length > 0) {
46-
message += `\n Used by ${validReasons.length} module(s), i. e.`;
47-
message += `\n ${validReasons[0].module.identifier()}`;
48-
}
49-
return message;
50-
})
51-
.join("\n");
52-
}
53-
};
67+
module.exports = CaseSensitiveModulesWarning;

0 commit comments

Comments
 (0)