webpack 4.11.1 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,12 +14,12 @@ const WebpackError = require("./WebpackError");
14
14
  */
15
15
  const sortModules = modules => {
16
16
  return modules.slice().sort((a, b) => {
17
- a = a.identifier();
18
- b = b.identifier();
17
+ const aIdent = a.identifier();
18
+ const bIdent = b.identifier();
19
19
  /* istanbul ignore next */
20
- if (a < b) return -1;
20
+ if (aIdent < bIdent) return -1;
21
21
  /* istanbul ignore next */
22
- if (a > b) return 1;
22
+ if (aIdent > bIdent) return 1;
23
23
  /* istanbul ignore next */
24
24
  return 0;
25
25
  });
@@ -55,7 +55,8 @@ module.exports = function() {
55
55
  for (var name in $require$) {
56
56
  if (
57
57
  Object.prototype.hasOwnProperty.call($require$, name) &&
58
- name !== "e"
58
+ name !== "e" &&
59
+ name !== "t"
59
60
  ) {
60
61
  Object.defineProperty(fn, name, ObjectFactory(name));
61
62
  }
@@ -80,6 +81,10 @@ module.exports = function() {
80
81
  }
81
82
  }
82
83
  };
84
+ fn.t = function(value, mode) {
85
+ if (mode & 1) value = fn(value);
86
+ return $require$.t(value, mode & ~1);
87
+ };
83
88
  return fn;
84
89
  }
85
90
 
package/lib/Module.js CHANGED
@@ -370,8 +370,12 @@ Object.defineProperty(Module.prototype, "meta", {
370
370
  }, "Module.meta was renamed to Module.buildMeta")
371
371
  });
372
372
 
373
+ /** @type {function(): string} */
373
374
  Module.prototype.identifier = null;
375
+
376
+ /** @type {function(RequestShortener): string} */
374
377
  Module.prototype.readableIdentifier = null;
378
+
375
379
  Module.prototype.build = null;
376
380
  Module.prototype.source = null;
377
381
  Module.prototype.size = null;
@@ -8,12 +8,17 @@ const WebpackError = require("./WebpackError");
8
8
  const { cutOffLoaderExecution } = require("./ErrorHelpers");
9
9
 
10
10
  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";
13
13
  let details = undefined;
14
+ if (from) {
15
+ message += ` (from ${from}):\n`;
16
+ } else {
17
+ message += ": ";
18
+ }
14
19
  if (err !== null && typeof err === "object") {
15
20
  if (typeof err.stack === "string" && err.stack) {
16
- var stack = cutOffLoaderExecution(err.stack);
21
+ const stack = cutOffLoaderExecution(err.stack);
17
22
  if (!err.hideStack) {
18
23
  message += stack;
19
24
  } else {
@@ -29,6 +34,8 @@ class ModuleBuildError extends WebpackError {
29
34
  } else {
30
35
  message += err;
31
36
  }
37
+ } else {
38
+ message = err;
32
39
  }
33
40
 
34
41
  super(message);
@@ -8,9 +8,19 @@ const WebpackError = require("./WebpackError");
8
8
  const { cleanUp } = require("./ErrorHelpers");
9
9
 
10
10
  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);
14
24
  this.name = "ModuleError";
15
25
  this.module = module;
16
26
  this.error = err;
@@ -8,13 +8,19 @@ const WebpackError = require("./WebpackError");
8
8
  const { cleanUp } = require("./ErrorHelpers");
9
9
 
10
10
  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);
18
24
  this.name = "ModuleWarning";
19
25
  this.module = module;
20
26
  this.warning = warning;
@@ -166,19 +166,30 @@ class NormalModule extends Module {
166
166
  }
167
167
 
168
168
  createLoaderContext(resolver, options, compilation, fs) {
169
+ const requestShortener = compilation.runtimeTemplate.requestShortener;
169
170
  const loaderContext = {
170
171
  version: 2,
171
172
  emitWarning: warning => {
172
173
  if (!(warning instanceof Error)) {
173
174
  warning = new NonErrorEmittedError(warning);
174
175
  }
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
+ );
176
182
  },
177
183
  emitError: error => {
178
184
  if (!(error instanceof Error)) {
179
185
  error = new NonErrorEmittedError(error);
180
186
  }
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
+ );
182
193
  },
183
194
  exec: (code, filename) => {
184
195
  // @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'.
@@ -219,6 +230,19 @@ class NormalModule extends Module {
219
230
  return loaderContext;
220
231
  }
221
232
 
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
+
222
246
  createSource(source, resourceBuffer, sourceMap) {
223
247
  // if there is no identifier return raw source
224
248
  if (!this.identifier) {
@@ -272,7 +296,17 @@ class NormalModule extends Module {
272
296
  }
273
297
 
274
298
  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
+ });
276
310
  return callback(error);
277
311
  }
278
312
 
@@ -282,10 +316,17 @@ class NormalModule extends Module {
282
316
  const extraInfo = result.result.length >= 2 ? result.result[2] : null;
283
317
 
284
318
  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`
288
328
  );
329
+ const error = new ModuleBuildError(this, err);
289
330
  return callback(error);
290
331
  }
291
332
 
package/lib/Parser.js CHANGED
@@ -23,7 +23,7 @@ const joinRanges = (startRange, endRange) => {
23
23
  const defaultParserOptions = {
24
24
  ranges: true,
25
25
  locations: true,
26
- ecmaVersion: 2018,
26
+ ecmaVersion: 2019,
27
27
  sourceType: "module",
28
28
  onComment: null,
29
29
  plugins: {
@@ -34,6 +34,8 @@ const defaultParserOptions = {
34
34
  // regexp to match at lease one "magic comment"
35
35
  const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);
36
36
 
37
+ const EMPTY_ARRAY = [];
38
+
37
39
  const EMPTY_COMMENT_OPTIONS = {
38
40
  options: null,
39
41
  errors: null
@@ -1356,7 +1358,11 @@ class Parser extends Tapable {
1356
1358
  }
1357
1359
 
1358
1360
  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, () => {
1360
1366
  this.prewalkStatement(catchClause.body);
1361
1367
  this.walkStatement(catchClause.body);
1362
1368
  });
@@ -6,16 +6,53 @@
6
6
 
7
7
  const identifierUtils = require("./util/identifier");
8
8
 
9
+ /** @typedef {import("./Compiler")} Compiler */
10
+ /** @typedef {import("./Chunk")} Chunk */
11
+ /** @typedef {import("./Module")} Module */
12
+
13
+ /**
14
+ * @typedef {Object} RecordsChunks
15
+ * @property {Record<string, number>=} byName
16
+ * @property {Record<string, number>=} bySource
17
+ * @property {number[]=} usedIds
18
+ */
19
+
20
+ /**
21
+ * @typedef {Object} RecordsModules
22
+ * @property {Record<string, number>=} byIdentifier
23
+ * @property {Record<string, number>=} bySource
24
+ * @property {Record<number, number>=} usedIds
25
+ */
26
+
27
+ /**
28
+ * @typedef {Object} Records
29
+ * @property {RecordsChunks=} chunks
30
+ * @property {RecordsModules=} modules
31
+ */
32
+
9
33
  class RecordIdsPlugin {
34
+ /**
35
+ * @param {Object} options Options object
36
+ * @param {boolean=} options.portableIds true, when ids need to be portable
37
+ */
10
38
  constructor(options) {
11
39
  this.options = options || {};
12
40
  }
13
41
 
42
+ /**
43
+ * @param {Compiler} compiler the Compiler
44
+ * @returns {void}
45
+ */
14
46
  apply(compiler) {
15
47
  const portableIds = this.options.portableIds;
16
48
  compiler.hooks.compilation.tap("RecordIdsPlugin", compilation => {
17
49
  compilation.hooks.recordModules.tap(
18
50
  "RecordIdsPlugin",
51
+ /**
52
+ * @param {Module[]} modules the modules array
53
+ * @param {Records} records the records object
54
+ * @returns {void}
55
+ */
19
56
  (modules, records) => {
20
57
  if (!records.modules) records.modules = {};
21
58
  if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
@@ -36,9 +73,15 @@ class RecordIdsPlugin {
36
73
  );
37
74
  compilation.hooks.reviveModules.tap(
38
75
  "RecordIdsPlugin",
76
+ /**
77
+ * @param {Module[]} modules the modules array
78
+ * @param {Records} records the records object
79
+ * @returns {void}
80
+ */
39
81
  (modules, records) => {
40
82
  if (!records.modules) return;
41
83
  if (records.modules.byIdentifier) {
84
+ /** @type {Set<number>} */
42
85
  const usedIds = new Set();
43
86
  for (const module of modules) {
44
87
  if (module.id !== null) continue;
@@ -62,6 +105,10 @@ class RecordIdsPlugin {
62
105
  }
63
106
  );
64
107
 
108
+ /**
109
+ * @param {Module} module the module
110
+ * @returns {string} the (portable) identifier
111
+ */
65
112
  const getModuleIdentifier = module => {
66
113
  if (portableIds) {
67
114
  return identifierUtils.makePathsRelative(
@@ -73,7 +120,12 @@ class RecordIdsPlugin {
73
120
  return module.identifier();
74
121
  };
75
122
 
123
+ /**
124
+ * @param {Chunk} chunk the chunk
125
+ * @returns {string[]} sources of the chunk
126
+ */
76
127
  const getChunkSources = chunk => {
128
+ /** @type {string[]} */
77
129
  const sources = [];
78
130
  for (const chunkGroup of chunk.groupsIterable) {
79
131
  const index = chunkGroup.chunks.indexOf(chunk);
@@ -108,10 +160,16 @@ class RecordIdsPlugin {
108
160
 
109
161
  compilation.hooks.recordChunks.tap(
110
162
  "RecordIdsPlugin",
163
+ /**
164
+ * @param {Chunk[]} chunks the chunks array
165
+ * @param {Records} records the records object
166
+ * @returns {void}
167
+ */
111
168
  (chunks, records) => {
112
169
  if (!records.chunks) records.chunks = {};
113
170
  if (!records.chunks.byName) records.chunks.byName = {};
114
171
  if (!records.chunks.bySource) records.chunks.bySource = {};
172
+ /** @type {Set<number>} */
115
173
  const usedIds = new Set();
116
174
  for (const chunk of chunks) {
117
175
  if (typeof chunk.id !== "number") continue;
@@ -128,8 +186,14 @@ class RecordIdsPlugin {
128
186
  );
129
187
  compilation.hooks.reviveChunks.tap(
130
188
  "RecordIdsPlugin",
189
+ /**
190
+ * @param {Chunk[]} chunks the chunks array
191
+ * @param {Records} records the records object
192
+ * @returns {void}
193
+ */
131
194
  (chunks, records) => {
132
195
  if (!records.chunks) return;
196
+ /** @type {Set<number>} */
133
197
  const usedIds = new Set();
134
198
  if (records.chunks.byName) {
135
199
  for (const chunk of chunks) {
@@ -148,8 +212,8 @@ class RecordIdsPlugin {
148
212
  for (const source of sources) {
149
213
  const id = records.chunks.bySource[source];
150
214
  if (id === undefined) continue;
151
- if (usedIds[id]) continue;
152
- usedIds[id] = true;
215
+ if (usedIds.has(id)) continue;
216
+ usedIds.add(id);
153
217
  chunk.id = id;
154
218
  break;
155
219
  }
@@ -201,7 +201,7 @@ class WebpackOptionsApply extends OptionsApply {
201
201
  }
202
202
 
203
203
  if (options.output.library || options.output.libraryTarget !== "var") {
204
- let LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
204
+ const LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
205
205
  new LibraryTemplatePlugin(
206
206
  options.output.library,
207
207
  options.output.libraryTarget,
@@ -245,7 +245,7 @@ class WebpackOptionsApply extends OptionsApply {
245
245
  : modern
246
246
  ? "\n//# source" + "MappingURL=[url]"
247
247
  : null;
248
- let Plugin = evalWrapped
248
+ const Plugin = evalWrapped
249
249
  ? EvalSourceMapDevToolPlugin
250
250
  : SourceMapDevToolPlugin;
251
251
  new Plugin({
@@ -381,7 +381,7 @@ class WebpackOptionsApply extends OptionsApply {
381
381
  new WarnCaseSensitiveModulesPlugin().apply(compiler);
382
382
 
383
383
  if (options.cache) {
384
- let CachePlugin = require("./CachePlugin");
384
+ const CachePlugin = require("./CachePlugin");
385
385
  new CachePlugin(
386
386
  typeof options.cache === "object" ? options.cache : null
387
387
  ).apply(compiler);
@@ -71,9 +71,18 @@ class Profiler {
71
71
  }
72
72
  }
73
73
 
74
+ /**
75
+ * @typedef {Object} Trace
76
+ * @description an object that wraps Tracer and Profiler with a counter
77
+ * @property {Tracer} trace instance of Tracer
78
+ * @property {number} counter Counter
79
+ * @property {Profiler} profiler instance of Profiler
80
+ * @property {Function} end the end function
81
+ */
82
+
74
83
  /**
75
84
  * @param {string} outputPath The location where to write the log.
76
- * @returns {{trace: ?, counter: number, profiler: Profiler, end: Function}} The trace object
85
+ * @returns {Trace} The trace object
77
86
  */
78
87
  function createTrace(outputPath) {
79
88
  const trace = new Tracer({
@@ -325,7 +334,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
325
334
 
326
335
  /**
327
336
  * @param {string} hookName Name of the hook to profile.
328
- * @param {Tracer} tracer Instance of tracer.
337
+ * @param {Trace} tracer The trace object.
329
338
  * @param {object} options Options for the profiled fn.
330
339
  * @param {string} options.name Plugin name
331
340
  * @param {string} options.type Plugin type (sync | async | promise)
@@ -13,6 +13,9 @@ const { shrinkPaddedLEB128 } = require("@webassemblyjs/wasm-opt");
13
13
  const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit");
14
14
  const { decode } = require("@webassemblyjs/wasm-parser");
15
15
  const t = require("@webassemblyjs/ast");
16
+ const {
17
+ moduleContextFromModuleAST
18
+ } = require("@webassemblyjs/helper-module-context");
16
19
 
17
20
  const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency");
18
21
 
@@ -45,20 +48,6 @@ function compose(...fns) {
45
48
  }, value => value);
46
49
  }
47
50
 
48
- // Utility functions
49
-
50
- /**
51
- * @param {t.ModuleImport} n the import
52
- * @returns {boolean} true, if a global was imported
53
- */
54
- const isGlobalImport = n => n.descr.type === "GlobalType";
55
-
56
- /**
57
- * @param {t.ModuleImport} n the import
58
- * @returns {boolean} true, if a func was imported
59
- */
60
- const isFuncImport = n => n.descr.type === "FuncImportDescr";
61
-
62
51
  // TODO replace with @callback
63
52
 
64
53
  /**
@@ -75,24 +64,6 @@ const removeStartFunc = state => bin => {
75
64
  });
76
65
  };
77
66
 
78
- /**
79
- * Retrieve the start function
80
- *
81
- * @param {Object} ast - Module's AST
82
- * @returns {t.Identifier | undefined} - node if any
83
- */
84
- function getStartFuncIndex(ast) {
85
- let startAtFuncIndex;
86
-
87
- t.traverse(ast, {
88
- Start({ node }) {
89
- startAtFuncIndex = node.index;
90
- }
91
- });
92
-
93
- return startAtFuncIndex;
94
- }
95
-
96
67
  /**
97
68
  * Get imported globals
98
69
  *
@@ -104,7 +75,7 @@ function getImportedGlobals(ast) {
104
75
 
105
76
  t.traverse(ast, {
106
77
  ModuleImport({ node }) {
107
- if (isGlobalImport(node) === true) {
78
+ if (t.isGlobalType(node.descr) === true) {
108
79
  importedGlobals.push(node);
109
80
  }
110
81
  }
@@ -118,7 +89,7 @@ function getCountImportedFunc(ast) {
118
89
 
119
90
  t.traverse(ast, {
120
91
  ModuleImport({ node }) {
121
- if (isFuncImport(node) === true) {
92
+ if (t.isFuncImportDescr(node.descr) === true) {
122
93
  count++;
123
94
  }
124
95
  }
@@ -206,7 +177,7 @@ const rewriteImportedGlobals = state => bin => {
206
177
 
207
178
  bin = editWithAST(state.ast, bin, {
208
179
  ModuleImport(path) {
209
- if (isGlobalImport(path.node) === true) {
180
+ if (t.isGlobalType(path.node.descr) === true) {
210
181
  const globalType = path.node.descr;
211
182
 
212
183
  globalType.mutability = "var";
@@ -309,7 +280,7 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => {
309
280
  * @param {Object} state transformation state
310
281
  * @param {Object} state.ast - Module's ast
311
282
  * @param {t.Identifier} state.initFuncId identifier of the init function
312
- * @param {t.Index} state.startAtFuncIndex index of the start function
283
+ * @param {t.Index} state.startAtFuncOffset index of the start function
313
284
  * @param {t.ModuleImport[]} state.importedGlobals list of imported globals
314
285
  * @param {t.Instruction[]} state.additionalInitCode list of addition instructions for the init function
315
286
  * @param {t.Index} state.nextFuncIndex index of the next function
@@ -319,7 +290,7 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => {
319
290
  const addInitFunction = ({
320
291
  ast,
321
292
  initFuncId,
322
- startAtFuncIndex,
293
+ startAtFuncOffset,
323
294
  importedGlobals,
324
295
  additionalInitCode,
325
296
  nextFuncIndex,
@@ -342,8 +313,8 @@ const addInitFunction = ({
342
313
  return [...acc, ...body];
343
314
  }, []);
344
315
 
345
- if (typeof startAtFuncIndex !== "undefined") {
346
- funcBody.push(t.callInstruction(startAtFuncIndex));
316
+ if (typeof startAtFuncOffset === "number") {
317
+ funcBody.push(t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset)));
347
318
  }
348
319
 
349
320
  for (const instr of additionalInitCode) {
@@ -405,15 +376,18 @@ class WebAssemblyGenerator extends Generator {
405
376
  : "__webpack_init__"
406
377
  );
407
378
 
379
+ // parse it
408
380
  const ast = decode(bin, {
409
381
  ignoreDataSection: true,
410
382
  ignoreCodeSection: true,
411
383
  ignoreCustomNameSection: true
412
384
  });
413
385
 
386
+ const moduleContext = moduleContextFromModuleAST(ast.body[0]);
387
+
414
388
  const importedGlobals = getImportedGlobals(ast);
415
389
  const countImportedFunc = getCountImportedFunc(ast);
416
- const startAtFuncIndex = getStartFuncIndex(ast);
390
+ const startAtFuncOffset = moduleContext.getStart();
417
391
  const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
418
392
  const nextTypeIndex = getNextTypeIndex(ast);
419
393
 
@@ -451,7 +425,7 @@ class WebAssemblyGenerator extends Generator {
451
425
  initFuncId,
452
426
  importedGlobals,
453
427
  additionalInitCode,
454
- startAtFuncIndex,
428
+ startAtFuncOffset,
455
429
  nextFuncIndex,
456
430
  nextTypeIndex
457
431
  })
@@ -16,30 +16,6 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
16
16
 
17
17
  /** @typedef {import("../Module")} Module */
18
18
 
19
- /**
20
- * @param {t.ModuleImport} n the import
21
- * @returns {boolean} true, if a memory was imported
22
- */
23
- const isMemoryImport = n => n.descr.type === "Memory";
24
-
25
- /**
26
- * @param {t.ModuleImport} n the import
27
- * @returns {boolean} true, if a table was imported
28
- */
29
- const isTableImport = n => n.descr.type === "Table";
30
-
31
- /**
32
- * @param {t.ModuleImport} n the import
33
- * @returns {boolean} true, if a func was imported
34
- */
35
- const isFuncImport = n => n.descr.type === "FuncImportDescr";
36
-
37
- /**
38
- * @param {t.ModuleImport} n the import
39
- * @returns {boolean} true, if a global was imported
40
- */
41
- const isGlobalImport = n => n.descr.type === "GlobalType";
42
-
43
19
  const JS_COMPAT_TYPES = new Set(["i32", "f32", "f64"]);
44
20
 
45
21
  /**
@@ -160,16 +136,16 @@ class WebAssemblyParser extends Tapable {
160
136
  /** @type {false | string} */
161
137
  let onlyDirectImport = false;
162
138
 
163
- if (isMemoryImport(node) === true) {
139
+ if (t.isMemory(node.descr) === true) {
164
140
  onlyDirectImport = "Memory";
165
- } else if (isTableImport(node) === true) {
141
+ } else if (t.isTable(node.descr) === true) {
166
142
  onlyDirectImport = "Table";
167
- } else if (isFuncImport(node) === true) {
143
+ } else if (t.isFuncImportDescr(node.descr) === true) {
168
144
  const incompatibleType = getJsIncompatibleType(node.descr.signature);
169
145
  if (incompatibleType) {
170
146
  onlyDirectImport = `Non-JS-compatible Func Sigurature (${incompatibleType})`;
171
147
  }
172
- } else if (isGlobalImport(node) === true) {
148
+ } else if (t.isGlobalType(node.descr) === true) {
173
149
  const type = node.descr.valtype;
174
150
  if (!JS_COMPAT_TYPES.has(type)) {
175
151
  onlyDirectImport = `Non-JS-compatible Global Type (${type})`;
@@ -185,7 +161,7 @@ class WebAssemblyParser extends Tapable {
185
161
 
186
162
  state.module.addDependency(dep);
187
163
 
188
- if (isGlobalImport(node)) {
164
+ if (t.isGlobalType(node.descr)) {
189
165
  importedGlobals.push(node);
190
166
  }
191
167
  }
@@ -32,28 +32,17 @@ class JsonpMainTemplatePlugin {
32
32
  const allPrefetchChunks = chunk.getChildIdsByOrdersMap(true).prefetch;
33
33
  return allPrefetchChunks && Object.keys(allPrefetchChunks).length;
34
34
  };
35
- // TODO refactor this
36
- if (!mainTemplate.hooks.jsonpScript) {
37
- mainTemplate.hooks.jsonpScript = new SyncWaterfallHook([
38
- "source",
39
- "chunk",
40
- "hash"
41
- ]);
42
- }
43
- if (!mainTemplate.hooks.linkPreload) {
44
- mainTemplate.hooks.linkPreload = new SyncWaterfallHook([
45
- "source",
46
- "chunk",
47
- "hash"
48
- ]);
49
- }
50
- if (!mainTemplate.hooks.linkPrefetch) {
51
- mainTemplate.hooks.linkPrefetch = new SyncWaterfallHook([
52
- "source",
53
- "chunk",
54
- "hash"
55
- ]);
56
- }
35
+
36
+ // TODO webpack 5, no adding to .hooks, use WeakMap and static methods
37
+ ["jsonpScript", "linkPreload", "linkPrefetch"].forEach(hook => {
38
+ if (!mainTemplate.hooks[hook]) {
39
+ mainTemplate.hooks[hook] = new SyncWaterfallHook([
40
+ "source",
41
+ "chunk",
42
+ "hash"
43
+ ]);
44
+ }
45
+ });
57
46
 
58
47
  const getScriptSrcPath = (hash, chunk, chunkIdExpression) => {
59
48
  const chunkFilename = mainTemplate.outputOptions.chunkFilename;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.11.1",
3
+ "version": "4.12.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@webassemblyjs/ast": "1.5.10",
9
- "@webassemblyjs/helper-module-context": "1.5.10",
10
- "@webassemblyjs/wasm-edit": "1.5.10",
11
- "@webassemblyjs/wasm-opt": "1.5.10",
12
- "@webassemblyjs/wasm-parser": "1.5.10",
13
- "acorn": "^5.0.0",
8
+ "@webassemblyjs/ast": "1.5.12",
9
+ "@webassemblyjs/helper-module-context": "1.5.12",
10
+ "@webassemblyjs/wasm-edit": "1.5.12",
11
+ "@webassemblyjs/wasm-opt": "1.5.12",
12
+ "@webassemblyjs/wasm-parser": "1.5.12",
13
+ "acorn": "^5.6.2",
14
14
  "acorn-dynamic-import": "^3.0.0",
15
15
  "ajv": "^6.1.0",
16
16
  "ajv-keywords": "^3.1.0",
17
- "chrome-trace-event": "^0.1.1",
17
+ "chrome-trace-event": "^1.0.0",
18
18
  "enhanced-resolve": "^4.0.0",
19
19
  "eslint-scope": "^3.7.1",
20
20
  "json-parse-better-errors": "^1.0.2",