webpack 5.44.0 → 5.45.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

package/bin/webpack.js CHANGED
File without changes
@@ -855,10 +855,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
855
855
  logger: this.getLogger("webpack.FileSystemInfo")
856
856
  });
857
857
  if (compiler.fileTimestamps) {
858
- this.fileSystemInfo.addFileTimestamps(compiler.fileTimestamps);
858
+ this.fileSystemInfo.addFileTimestamps(compiler.fileTimestamps, true);
859
859
  }
860
860
  if (compiler.contextTimestamps) {
861
- this.fileSystemInfo.addContextTimestamps(compiler.contextTimestamps);
861
+ this.fileSystemInfo.addContextTimestamps(
862
+ compiler.contextTimestamps,
863
+ true
864
+ );
862
865
  }
863
866
  /** @type {Map<string, string | Set<string>>} */
864
867
  this.valueCacheVersions = new Map();
package/lib/Compiler.js CHANGED
@@ -222,13 +222,13 @@ class Compiler {
222
222
  /** @type {Set<string>} */
223
223
  this.immutablePaths = new Set();
224
224
 
225
- /** @type {Set<string>} */
225
+ /** @type {ReadonlySet<string>} */
226
226
  this.modifiedFiles = undefined;
227
- /** @type {Set<string>} */
227
+ /** @type {ReadonlySet<string>} */
228
228
  this.removedFiles = undefined;
229
- /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
229
+ /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
230
230
  this.fileTimestamps = undefined;
231
- /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
231
+ /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
232
232
  this.contextTimestamps = undefined;
233
233
  /** @type {number} */
234
234
  this.fsStartTime = undefined;
@@ -8,6 +8,7 @@
8
8
  const { create: createResolver } = require("enhanced-resolve");
9
9
  const asyncLib = require("neo-async");
10
10
  const AsyncQueue = require("./util/AsyncQueue");
11
+ const StackedCacheMap = require("./util/StackedCacheMap");
11
12
  const createHash = require("./util/createHash");
12
13
  const { join, dirname, relative } = require("./util/fs");
13
14
  const makeSerializable = require("./util/makeSerializable");
@@ -365,7 +366,7 @@ class Snapshot {
365
366
  }
366
367
 
367
368
  /**
368
- * @param {function(Snapshot): (Map<string, any> | Set<string>)[]} getMaps first
369
+ * @param {function(Snapshot): (ReadonlyMap<string, any> | ReadonlySet<string>)[]} getMaps first
369
370
  * @returns {Iterable<string>} iterable
370
371
  */
371
372
  _createIterable(getMaps) {
@@ -853,14 +854,14 @@ class FileSystemInfo {
853
854
  (s, v) => s.setManagedMissing(v),
854
855
  true
855
856
  );
856
- /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
857
- this._fileTimestamps = new Map();
857
+ /** @type {StackedCacheMap<string, FileSystemInfoEntry | "ignore" | null>} */
858
+ this._fileTimestamps = new StackedCacheMap();
858
859
  /** @type {Map<string, string>} */
859
860
  this._fileHashes = new Map();
860
861
  /** @type {Map<string, TimestampAndHash | string>} */
861
862
  this._fileTshs = new Map();
862
- /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
863
- this._contextTimestamps = new Map();
863
+ /** @type {StackedCacheMap<string, FileSystemInfoEntry | "ignore" | null>} */
864
+ this._contextTimestamps = new StackedCacheMap();
864
865
  /** @type {Map<string, string>} */
865
866
  this._contextHashes = new Map();
866
867
  /** @type {Map<string, TimestampAndHash | string>} */
@@ -1060,24 +1061,22 @@ class FileSystemInfo {
1060
1061
  }
1061
1062
 
1062
1063
  /**
1063
- * @param {Map<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
1064
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
1065
+ * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1064
1066
  * @returns {void}
1065
1067
  */
1066
- addFileTimestamps(map) {
1067
- for (const [path, ts] of map) {
1068
- this._fileTimestamps.set(path, ts);
1069
- }
1068
+ addFileTimestamps(map, immutable) {
1069
+ this._fileTimestamps.addAll(map, immutable);
1070
1070
  this._cachedDeprecatedFileTimestamps = undefined;
1071
1071
  }
1072
1072
 
1073
1073
  /**
1074
- * @param {Map<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
1074
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
1075
+ * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1075
1076
  * @returns {void}
1076
1077
  */
1077
- addContextTimestamps(map) {
1078
- for (const [path, ts] of map) {
1079
- this._contextTimestamps.set(path, ts);
1080
- }
1078
+ addContextTimestamps(map, immutable) {
1079
+ this._contextTimestamps.addAll(map, immutable);
1081
1080
  this._cachedDeprecatedContextTimestamps = undefined;
1082
1081
  }
1083
1082
 
@@ -313,12 +313,12 @@ module.exports = class MultiCompiler {
313
313
  /**
314
314
  * @template SetupResult
315
315
  * @param {function(Compiler, number, Callback<Stats>, function(): boolean, function(): void, function(): void): SetupResult} setup setup a single compiler
316
- * @param {function(Compiler, Callback<Stats>): void} run run/continue a single compiler
316
+ * @param {function(Compiler, SetupResult, Callback<Stats>): void} run run/continue a single compiler
317
317
  * @param {Callback<MultiStats>} callback callback when all compilers are done, result includes Stats of all changed compilers
318
318
  * @returns {SetupResult[]} result of setup
319
319
  */
320
320
  _runGraph(setup, run, callback) {
321
- /** @typedef {{ compiler: Compiler, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
321
+ /** @typedef {{ compiler: Compiler, setupResult: SetupResult, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
322
322
 
323
323
  // State transitions for nodes:
324
324
  // -> blocked (initial)
@@ -335,6 +335,7 @@ module.exports = class MultiCompiler {
335
335
  /** @type {Node[]} */
336
336
  const nodes = this.compilers.map(compiler => ({
337
337
  compiler,
338
+ setupResult: undefined,
338
339
  result: undefined,
339
340
  state: "blocked",
340
341
  children: [],
@@ -444,14 +445,14 @@ module.exports = class MultiCompiler {
444
445
  const setupResults = [];
445
446
  nodes.forEach((node, i) => {
446
447
  setupResults.push(
447
- setup(
448
+ (node.setupResult = setup(
448
449
  node.compiler,
449
450
  i,
450
451
  nodeDone.bind(null, node),
451
452
  () => node.state !== "starting" && node.state !== "running",
452
453
  () => nodeChange(node),
453
454
  () => nodeInvalid(node)
454
- )
455
+ ))
455
456
  );
456
457
  });
457
458
  let processing = true;
@@ -470,7 +471,7 @@ module.exports = class MultiCompiler {
470
471
  ) {
471
472
  running++;
472
473
  node.state = "starting";
473
- run(node.compiler, nodeDone.bind(null, node));
474
+ run(node.compiler, node.setupResult, nodeDone.bind(null, node));
474
475
  node.state = "running";
475
476
  }
476
477
  }
@@ -522,8 +523,9 @@ module.exports = class MultiCompiler {
522
523
  }
523
524
  return watching;
524
525
  },
525
- (compiler, initial, callback) => {
526
- if (!compiler.watching.running) compiler.watching.invalidate();
526
+ (compiler, watching, callback) => {
527
+ if (compiler.watching !== watching) return;
528
+ if (!watching.running) watching.invalidate();
527
529
  },
528
530
  handler
529
531
  );
@@ -546,7 +548,7 @@ module.exports = class MultiCompiler {
546
548
  if (this.validateDependencies(callback)) {
547
549
  this._runGraph(
548
550
  () => {},
549
- (compiler, callback) => compiler.run(callback),
551
+ (compiler, setupResult, callback) => compiler.run(callback),
550
552
  (err, stats) => {
551
553
  this.running = false;
552
554
 
@@ -293,9 +293,13 @@ class NormalModule extends Module {
293
293
  */
294
294
  identifier() {
295
295
  if (this.layer === null) {
296
- return this.request;
296
+ if (this.type === "javascript/auto") {
297
+ return this.request;
298
+ } else {
299
+ return `${this.type}|${this.request}`;
300
+ }
297
301
  } else {
298
- return `${this.request}|${this.layer}`;
302
+ return `${this.type}|${this.request}|${this.layer}`;
299
303
  }
300
304
  }
301
305
 
@@ -20,7 +20,7 @@ const ModuleGraph = require("./ModuleGraph");
20
20
  const NormalModule = require("./NormalModule");
21
21
  const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin");
22
22
  const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
23
- const DescriptionDataMatcherRulePlugin = require("./rules/DescriptionDataMatcherRulePlugin");
23
+ const ObjectMatcherRulePlugin = require("./rules/ObjectMatcherRulePlugin");
24
24
  const RuleSetCompiler = require("./rules/RuleSetCompiler");
25
25
  const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
26
26
  const LazySet = require("./util/LazySet");
@@ -44,6 +44,7 @@ const { parseResource } = require("./util/identifier");
44
44
  * @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
45
45
  * @property {string} context
46
46
  * @property {string} request
47
+ * @property {Record<string, any> | undefined} assertions
47
48
  * @property {ModuleDependency[]} dependencies
48
49
  * @property {Object} createData
49
50
  * @property {LazySet<string>} fileDependencies
@@ -182,7 +183,8 @@ const ruleSetCompiler = new RuleSetCompiler([
182
183
  new BasicMatcherRulePlugin("issuer"),
183
184
  new BasicMatcherRulePlugin("compiler"),
184
185
  new BasicMatcherRulePlugin("issuerLayer"),
185
- new DescriptionDataMatcherRulePlugin(),
186
+ new ObjectMatcherRulePlugin("assert", "assertions"),
187
+ new ObjectMatcherRulePlugin("descriptionData"),
186
188
  new BasicEffectRulePlugin("type"),
187
189
  new BasicEffectRulePlugin("sideEffects"),
188
190
  new BasicEffectRulePlugin("parser"),
@@ -339,6 +341,7 @@ class NormalModuleFactory extends ModuleFactory {
339
341
  context,
340
342
  dependencies,
341
343
  request,
344
+ assertions,
342
345
  resolveOptions,
343
346
  fileDependencies,
344
347
  missingDependencies,
@@ -447,6 +450,7 @@ class NormalModuleFactory extends ModuleFactory {
447
450
  resourceQuery: resourceDataForRules.query,
448
451
  resourceFragment: resourceDataForRules.fragment,
449
452
  scheme,
453
+ assertions,
450
454
  mimetype: matchResourceData ? "" : resourceData.data.mimetype || "",
451
455
  dependency: dependencyType,
452
456
  descriptionData: matchResourceData
@@ -694,6 +698,7 @@ class NormalModuleFactory extends ModuleFactory {
694
698
  const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
695
699
  const dependency = dependencies[0];
696
700
  const request = dependency.request;
701
+ const assertions = dependency.assertions;
697
702
  const contextInfo = data.contextInfo;
698
703
  const fileDependencies = new LazySet();
699
704
  const missingDependencies = new LazySet();
@@ -704,6 +709,7 @@ class NormalModuleFactory extends ModuleFactory {
704
709
  resolveOptions,
705
710
  context,
706
711
  request,
712
+ assertions,
707
713
  dependencies,
708
714
  fileDependencies,
709
715
  missingDependencies,
@@ -152,7 +152,7 @@ class SourceMapDevToolPlugin {
152
152
  const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
153
153
  const requestShortener = compiler.requestShortener;
154
154
  const options = this.options;
155
- options.test = options.test || /\.(m?js|css)($|\?)/i;
155
+ options.test = options.test || /\.((c|m)?js|css)($|\?)/i;
156
156
 
157
157
  const matchObject = ModuleFilenameHelpers.matchObject.bind(
158
158
  undefined,
package/lib/Watching.js CHANGED
@@ -10,6 +10,7 @@ const Stats = require("./Stats");
10
10
  /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
11
11
  /** @typedef {import("./Compilation")} Compilation */
12
12
  /** @typedef {import("./Compiler")} Compiler */
13
+ /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
13
14
 
14
15
  /**
15
16
  * @template T
@@ -67,6 +68,10 @@ class Watching {
67
68
  });
68
69
  }
69
70
 
71
+ /**
72
+ * @param {ReadonlySet<string>} changedFiles changed files
73
+ * @param {ReadonlySet<string>} removedFiles removed files
74
+ */
70
75
  _mergeWithCollected(changedFiles, removedFiles) {
71
76
  if (!changedFiles) return;
72
77
  if (!this._collectedChangedFiles) {
@@ -84,6 +89,13 @@ class Watching {
84
89
  }
85
90
  }
86
91
 
92
+ /**
93
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files
94
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories
95
+ * @param {ReadonlySet<string>=} changedFiles changed files
96
+ * @param {ReadonlySet<string>=} removedFiles removed files
97
+ * @returns {void}
98
+ */
87
99
  _go(fileTimeInfoEntries, contextTimeInfoEntries, changedFiles, removedFiles) {
88
100
  this._initial = false;
89
101
  if (this.startTime === null) this.startTime = Date.now();
@@ -482,18 +482,6 @@ const applyModuleDefaults = (
482
482
  or: ["text/javascript", "application/javascript"]
483
483
  },
484
484
  ...esm
485
- },
486
- {
487
- dependency: "url",
488
- oneOf: [
489
- {
490
- scheme: /^data$/,
491
- type: "asset/inline"
492
- },
493
- {
494
- type: "asset/resource"
495
- }
496
- ]
497
485
  }
498
486
  ];
499
487
  if (asyncWebAssembly) {
@@ -541,6 +529,24 @@ const applyModuleDefaults = (
541
529
  ...wasm
542
530
  });
543
531
  }
532
+ rules.push(
533
+ {
534
+ dependency: "url",
535
+ oneOf: [
536
+ {
537
+ scheme: /^data$/,
538
+ type: "asset/inline"
539
+ },
540
+ {
541
+ type: "asset/resource"
542
+ }
543
+ ]
544
+ },
545
+ {
546
+ assert: { type: "json" },
547
+ type: "json"
548
+ }
549
+ );
544
550
  return rules;
545
551
  });
546
552
  };
@@ -12,7 +12,8 @@ const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency")
12
12
  const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
13
13
  const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
14
14
  const {
15
- harmonySpecifierTag
15
+ harmonySpecifierTag,
16
+ getAssertions
16
17
  } = require("./HarmonyImportDependencyParserPlugin");
17
18
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
18
19
 
@@ -48,7 +49,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
48
49
  parser.state.module.addPresentationalDependency(clearDep);
49
50
  const sideEffectDep = new HarmonyImportSideEffectDependency(
50
51
  source,
51
- parser.state.lastHarmonyImportOrder
52
+ parser.state.lastHarmonyImportOrder,
53
+ getAssertions(statement)
52
54
  );
53
55
  sideEffectDep.loc = Object.create(statement.loc);
54
56
  sideEffectDep.loc.index = -1;
@@ -127,7 +129,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
127
129
  harmonyNamedExports,
128
130
  null,
129
131
  this.strictExportPresence,
130
- null
132
+ null,
133
+ settings.assertions
131
134
  );
132
135
  } else {
133
136
  dep = new HarmonyExportSpecifierDependency(id, name);
@@ -159,6 +159,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
159
159
  * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency>} otherStarExports other star exports in the module before this import
160
160
  * @param {boolean} strictExportPresence when true, missing exports in the imported module lead to errors instead of warnings
161
161
  * @param {HarmonyStarExportsList} allStarExports all star exports in the module
162
+ * @param {Record<string, any>=} assertions import assertions
162
163
  */
163
164
  constructor(
164
165
  request,
@@ -168,9 +169,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
168
169
  activeExports,
169
170
  otherStarExports,
170
171
  strictExportPresence,
171
- allStarExports
172
+ allStarExports,
173
+ assertions
172
174
  ) {
173
- super(request, sourceOrder);
175
+ super(request, sourceOrder, assertions);
174
176
 
175
177
  this.ids = ids;
176
178
  this.name = name;
@@ -32,10 +32,12 @@ class HarmonyImportDependency extends ModuleDependency {
32
32
  *
33
33
  * @param {string} request request string
34
34
  * @param {number} sourceOrder source order
35
+ * @param {Record<string, any>=} assertions import assertions
35
36
  */
36
- constructor(request, sourceOrder) {
37
+ constructor(request, sourceOrder, assertions) {
37
38
  super(request);
38
39
  this.sourceOrder = sourceOrder;
40
+ this.assertions = assertions;
39
41
  }
40
42
 
41
43
  get category() {
@@ -201,12 +203,14 @@ class HarmonyImportDependency extends ModuleDependency {
201
203
  serialize(context) {
202
204
  const { write } = context;
203
205
  write(this.sourceOrder);
206
+ write(this.assertions);
204
207
  super.serialize(context);
205
208
  }
206
209
 
207
210
  deserialize(context) {
208
211
  const { read } = context;
209
212
  this.sourceOrder = read();
213
+ this.assertions = read();
210
214
  super.deserialize(context);
211
215
  }
212
216
  }
@@ -14,7 +14,11 @@ const HarmonyExports = require("./HarmonyExports");
14
14
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
15
15
  const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
16
16
 
17
+ /** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */
18
+ /** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */
17
19
  /** @typedef {import("estree").Identifier} Identifier */
20
+ /** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
21
+ /** @typedef {import("estree").ImportExpression} ImportExpression */
18
22
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
19
23
  /** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
20
24
  /** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
@@ -29,8 +33,32 @@ const harmonySpecifierTag = Symbol("harmony import");
29
33
  * @property {number} sourceOrder
30
34
  * @property {string} name
31
35
  * @property {boolean} await
36
+ * @property {Record<string, any> | undefined} assertions
32
37
  */
33
38
 
39
+ /**
40
+ * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
41
+ * @returns {Record<string, any> | undefined} assertions
42
+ */
43
+ function getAssertions(node) {
44
+ // TODO remove cast when @types/estree has been updated to import assertions
45
+ const assertions = /** @type {{ assertions?: ImportAttributeNode[] }} */ (
46
+ node
47
+ ).assertions;
48
+ if (assertions === undefined) {
49
+ return undefined;
50
+ }
51
+ const result = {};
52
+ for (const assertion of assertions) {
53
+ const key =
54
+ assertion.key.type === "Identifier"
55
+ ? assertion.key.name
56
+ : assertion.key.value;
57
+ result[key] = assertion.value.value;
58
+ }
59
+ return result;
60
+ }
61
+
34
62
  module.exports = class HarmonyImportDependencyParserPlugin {
35
63
  constructor(options) {
36
64
  this.strictExportPresence = options.strictExportPresence;
@@ -65,9 +93,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
65
93
  clearDep.loc = statement.loc;
66
94
  parser.state.module.addPresentationalDependency(clearDep);
67
95
  parser.unsetAsiPosition(statement.range[1]);
96
+ const assertions = getAssertions(statement);
68
97
  const sideEffectDep = new HarmonyImportSideEffectDependency(
69
98
  source,
70
- parser.state.lastHarmonyImportOrder
99
+ parser.state.lastHarmonyImportOrder,
100
+ assertions
71
101
  );
72
102
  sideEffectDep.loc = statement.loc;
73
103
  parser.state.module.addDependency(sideEffectDep);
@@ -82,7 +112,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
82
112
  name,
83
113
  source,
84
114
  ids,
85
- sourceOrder: parser.state.lastHarmonyImportOrder
115
+ sourceOrder: parser.state.lastHarmonyImportOrder,
116
+ assertions: getAssertions(statement)
86
117
  });
87
118
  return true;
88
119
  }
@@ -97,7 +128,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
97
128
  settings.ids,
98
129
  settings.name,
99
130
  expr.range,
100
- this.strictExportPresence
131
+ this.strictExportPresence,
132
+ settings.assertions
101
133
  );
102
134
  dep.shorthand = parser.scope.inShorthand;
103
135
  dep.directImport = true;
@@ -118,7 +150,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
118
150
  ids,
119
151
  settings.name,
120
152
  expr.range,
121
- this.strictExportPresence
153
+ this.strictExportPresence,
154
+ settings.assertions
122
155
  );
123
156
  dep.asiSafe = !parser.isAsiPosition(expr.range[0]);
124
157
  dep.loc = expr.loc;
@@ -138,7 +171,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
138
171
  ids,
139
172
  settings.name,
140
173
  callee.range,
141
- this.strictExportPresence
174
+ this.strictExportPresence,
175
+ settings.assertions
142
176
  );
143
177
  dep.directImport = members.length === 0;
144
178
  dep.call = true;
@@ -206,3 +240,4 @@ module.exports = class HarmonyImportDependencyParserPlugin {
206
240
  };
207
241
 
208
242
  module.exports.harmonySpecifierTag = harmonySpecifierTag;
243
+ module.exports.getAssertions = getAssertions;
@@ -20,8 +20,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
20
20
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
21
21
 
22
22
  class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
23
- constructor(request, sourceOrder) {
24
- super(request, sourceOrder);
23
+ constructor(request, sourceOrder, assertions) {
24
+ super(request, sourceOrder, assertions);
25
25
  }
26
26
 
27
27
  get type() {
@@ -29,8 +29,16 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
29
29
  const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
30
30
 
31
31
  class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
32
- constructor(request, sourceOrder, ids, name, range, strictExportPresence) {
33
- super(request, sourceOrder);
32
+ constructor(
33
+ request,
34
+ sourceOrder,
35
+ ids,
36
+ name,
37
+ range,
38
+ strictExportPresence,
39
+ assertions
40
+ ) {
41
+ super(request, sourceOrder, assertions);
34
42
  this.ids = ids;
35
43
  this.name = name;
36
44
  this.range = range;
@@ -22,13 +22,20 @@ class ModuleDependency extends Dependency {
22
22
  this.request = request;
23
23
  this.userRequest = request;
24
24
  this.range = undefined;
25
+ // assertions must be serialized by subclasses that use it
26
+ /** @type {Record<string, any> | undefined} */
27
+ this.assertions = undefined;
25
28
  }
26
29
 
27
30
  /**
28
31
  * @returns {string | null} an identifier to merge equal requests
29
32
  */
30
33
  getResourceIdentifier() {
31
- return `module${this.request}`;
34
+ let str = `module${this.request}`;
35
+ if (this.assertions !== undefined) {
36
+ str += JSON.stringify(this.assertions);
37
+ }
38
+ return str;
32
39
  }
33
40
 
34
41
  /**
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { Parser: AcornParser } = require("acorn");
9
+ const { importAssertions } = require("acorn-import-assertions");
9
10
  const { SyncBailHook, HookMap } = require("tapable");
10
11
  const vm = require("vm");
11
12
  const Parser = require("../Parser");
@@ -42,6 +43,10 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
42
43
  /** @typedef {import("estree").Node} AnyNode */
43
44
  /** @typedef {import("estree").Program} ProgramNode */
44
45
  /** @typedef {import("estree").Statement} StatementNode */
46
+ /** @typedef {import("estree").ImportDeclaration} ImportDeclarationNode */
47
+ /** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclarationNode */
48
+ /** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclarationNode */
49
+ /** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclarationNode */
45
50
  /** @typedef {import("estree").Super} SuperNode */
46
51
  /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpressionNode */
47
52
  /** @typedef {import("estree").TemplateLiteral} TemplateLiteralNode */
@@ -61,7 +66,7 @@ const ALLOWED_MEMBER_TYPES_ALL = 0b11;
61
66
 
62
67
  // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
63
68
 
64
- const parser = AcornParser;
69
+ const parser = AcornParser.extend(importAssertions);
65
70
 
66
71
  class VariableInfo {
67
72
  /**
@@ -190,31 +195,31 @@ class JavascriptParser extends Parser {
190
195
  ]),
191
196
  /** @type {HookMap<SyncBailHook<[LabeledStatementNode], boolean | void>>} */
192
197
  label: new HookMap(() => new SyncBailHook(["statement"])),
193
- /** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
198
+ /** @type {SyncBailHook<[ImportDeclarationNode, ImportSource], boolean | void>} */
194
199
  import: new SyncBailHook(["statement", "source"]),
195
- /** @type {SyncBailHook<[StatementNode, ImportSource, string, string], boolean | void>} */
200
+ /** @type {SyncBailHook<[ImportDeclarationNode, ImportSource, string, string], boolean | void>} */
196
201
  importSpecifier: new SyncBailHook([
197
202
  "statement",
198
203
  "source",
199
204
  "exportName",
200
205
  "identifierName"
201
206
  ]),
202
- /** @type {SyncBailHook<[StatementNode], boolean | void>} */
207
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode], boolean | void>} */
203
208
  export: new SyncBailHook(["statement"]),
204
- /** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
209
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, ImportSource], boolean | void>} */
205
210
  exportImport: new SyncBailHook(["statement", "source"]),
206
- /** @type {SyncBailHook<[StatementNode, DeclarationNode], boolean | void>} */
211
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, DeclarationNode], boolean | void>} */
207
212
  exportDeclaration: new SyncBailHook(["statement", "declaration"]),
208
- /** @type {SyncBailHook<[StatementNode, DeclarationNode], boolean | void>} */
213
+ /** @type {SyncBailHook<[ExportDefaultDeclarationNode, DeclarationNode], boolean | void>} */
209
214
  exportExpression: new SyncBailHook(["statement", "declaration"]),
210
- /** @type {SyncBailHook<[StatementNode, string, string, number | undefined], boolean | void>} */
215
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, string, string, number | undefined], boolean | void>} */
211
216
  exportSpecifier: new SyncBailHook([
212
217
  "statement",
213
218
  "identifierName",
214
219
  "exportName",
215
220
  "index"
216
221
  ]),
217
- /** @type {SyncBailHook<[StatementNode, ImportSource, string, string, number | undefined], boolean | void>} */
222
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, ImportSource, string, string, number | undefined], boolean | void>} */
218
223
  exportImportSpecifier: new SyncBailHook([
219
224
  "statement",
220
225
  "source",
@@ -72,7 +72,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
72
72
  render(source, { chunkGraph, moduleGraph, chunk }, { options, compilation }) {
73
73
  const modules = chunkGraph
74
74
  .getChunkModules(chunk)
75
- .filter(m => m instanceof ExternalModule);
75
+ .filter(m => m instanceof ExternalModule && m.externalType === "system");
76
76
  const externals = /** @type {ExternalModule[]} */ (modules);
77
77
 
78
78
  // The name this bundle should be registered as with System