Skip to content

Commit ff224a7

Browse files
committed
Merge branch 'master' into master
2 parents f28bb4e + ebe90f4 commit ff224a7

File tree

294 files changed

+4874
-2782
lines changed

Some content is hidden

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

294 files changed

+4874
-2782
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

declarations.d.ts

Lines changed: 65 additions & 18 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,52 +53,98 @@ 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: 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;
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[];
6290
}
63-
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 {}
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+
type: "Signature";
98+
params: FuncParam[];
99+
results: string[];
76100
}
77-
export class TypeInstructionFunc extends Node {}
101+
export class TypeInstruction extends Node {}
78102
export class IndexInFuncSection extends Node {}
79-
export function indexLiteral(index: number): IndexLiteral;
80-
export function numberLiteral(num: number): NumberLiteral;
103+
export function indexLiteral(index: number): Index;
104+
export function numberLiteralFromRaw(num: number): NumberLiteral;
105+
export function floatLiteral(
106+
value: number,
107+
nan?: boolean,
108+
inf?: boolean,
109+
raw?: string
110+
): FloatLiteral;
81111
export function global(globalType: string, nodes: Node[]): Global;
82112
export function identifier(indentifier: string): Identifier;
83113
export function funcParam(valType: string, id: Identifier): FuncParam;
84114
export function instruction(inst: string, args: Node[]): Instruction;
85-
export function callInstruction(funcIndex: IndexLiteral): CallInstruction;
115+
export function callInstruction(funcIndex: Index): CallInstruction;
86116
export function objectInstruction(
87117
kind: string,
88118
type: string,
89119
init: Node[]
90120
): ObjectInstruction;
91-
export function func(initFuncId, funcParams, funcResults, funcBody): Func;
92-
export function typeInstructionFunc(params, result): TypeInstructionFunc;
93-
export function indexInFuncSection(index: IndexLiteral): IndexInFuncSection;
121+
export function signature(params: FuncParam[], results: string[]): Signature;
122+
export function func(initFuncId, signature: Signature, funcBody): Func;
123+
export function typeInstruction(
124+
id: Identifier,
125+
functype: Signature
126+
): TypeInstruction;
127+
export function indexInFuncSection(index: Index): IndexInFuncSection;
94128
export function moduleExport(
95129
identifier: string,
96-
type: string,
97-
index: IndexLiteral
130+
descr: ModuleExportDescr
98131
): ModuleExport;
132+
export function moduleExportDescr(
133+
type: string,
134+
index: Index
135+
): ModuleExportDescr;
99136

100137
export function getSectionMetadata(ast: any, section: string);
138+
export class FuncSignature {
139+
args: string[];
140+
result: string[];
141+
}
142+
143+
// Node matcher
144+
export function isGlobalType(n: Node): boolean;
145+
export function isTable(n: Node): boolean;
146+
export function isMemory(n: Node): boolean;
147+
export function isFuncImportDescr(n: Node): boolean;
101148
}
102149

103150
/**

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/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: 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/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: 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+
const aIdent = a.identifier();
18+
const bIdent = b.identifier();
19+
/* istanbul ignore next */
20+
if (aIdent < bIdent) return -1;
21+
/* istanbul ignore next */
22+
if (aIdent > bIdent) 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;

0 commit comments

Comments
 (0)