webpack 5.102.1 → 5.104.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.
- package/README.md +121 -134
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
package/lib/css/walkCssTokens.js
CHANGED
|
@@ -10,16 +10,18 @@
|
|
|
10
10
|
* @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url
|
|
11
11
|
* @property {((input: string, start: number, end: number) => number)=} comment
|
|
12
12
|
* @property {((input: string, start: number, end: number) => number)=} string
|
|
13
|
+
* @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
|
|
14
|
+
* @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
|
|
13
15
|
* @property {((input: string, start: number, end: number) => number)=} leftParenthesis
|
|
14
16
|
* @property {((input: string, start: number, end: number) => number)=} rightParenthesis
|
|
17
|
+
* @property {((input: string, start: number, end: number) => number)=} leftSquareBracket
|
|
18
|
+
* @property {((input: string, start: number, end: number) => number)=} rightSquareBracket
|
|
15
19
|
* @property {((input: string, start: number, end: number) => number)=} function
|
|
16
20
|
* @property {((input: string, start: number, end: number) => number)=} colon
|
|
17
21
|
* @property {((input: string, start: number, end: number) => number)=} atKeyword
|
|
18
22
|
* @property {((input: string, start: number, end: number) => number)=} delim
|
|
19
23
|
* @property {((input: string, start: number, end: number) => number)=} identifier
|
|
20
24
|
* @property {((input: string, start: number, end: number, isId: boolean) => number)=} hash
|
|
21
|
-
* @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
|
|
22
|
-
* @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
|
|
23
25
|
* @property {((input: string, start: number, end: number) => number)=} semicolon
|
|
24
26
|
* @property {((input: string, start: number, end: number) => number)=} comma
|
|
25
27
|
* @property {(() => boolean)=} needTerminate
|
|
@@ -717,14 +719,22 @@ const consumeRightParenthesis = (input, pos, callbacks) => {
|
|
|
717
719
|
};
|
|
718
720
|
|
|
719
721
|
/** @type {CharHandler} */
|
|
720
|
-
const consumeLeftSquareBracket = (input, pos,
|
|
722
|
+
const consumeLeftSquareBracket = (input, pos, callbacks) => {
|
|
721
723
|
// Return a <]-token>.
|
|
722
|
-
|
|
724
|
+
if (callbacks.leftSquareBracket !== undefined) {
|
|
725
|
+
return callbacks.leftSquareBracket(input, pos - 1, pos);
|
|
726
|
+
}
|
|
727
|
+
return pos;
|
|
728
|
+
};
|
|
723
729
|
|
|
724
730
|
/** @type {CharHandler} */
|
|
725
|
-
const consumeRightSquareBracket = (input, pos,
|
|
731
|
+
const consumeRightSquareBracket = (input, pos, callbacks) => {
|
|
726
732
|
// Return a <]-token>.
|
|
727
|
-
|
|
733
|
+
if (callbacks.rightSquareBracket !== undefined) {
|
|
734
|
+
return callbacks.rightSquareBracket(input, pos - 1, pos);
|
|
735
|
+
}
|
|
736
|
+
return pos;
|
|
737
|
+
};
|
|
728
738
|
|
|
729
739
|
/** @type {CharHandler} */
|
|
730
740
|
const consumeLeftCurlyBracket = (input, pos, callbacks) => {
|
|
@@ -1197,6 +1207,106 @@ module.exports = (input, pos = 0, callbacks = {}) => {
|
|
|
1197
1207
|
return pos;
|
|
1198
1208
|
};
|
|
1199
1209
|
|
|
1210
|
+
/**
|
|
1211
|
+
* @param {string} input input css
|
|
1212
|
+
* @param {number} pos pos
|
|
1213
|
+
* @param {CssTokenCallbacks} callbacks callbacks
|
|
1214
|
+
* @param {CssTokenCallbacks=} additional additional callbacks
|
|
1215
|
+
* @param {{ onlyTopLevel?: boolean, declarationValue?: boolean, atRulePrelude?: boolean, functionValue?: boolean }=} options options
|
|
1216
|
+
* @returns {number} pos
|
|
1217
|
+
*/
|
|
1218
|
+
const consumeUntil = (input, pos, callbacks, additional, options = {}) => {
|
|
1219
|
+
let needHandle = true;
|
|
1220
|
+
let needTerminate = false;
|
|
1221
|
+
|
|
1222
|
+
/** @type {CssTokenCallbacks} */
|
|
1223
|
+
const servicedCallbacks = {};
|
|
1224
|
+
|
|
1225
|
+
let balanced = 0;
|
|
1226
|
+
|
|
1227
|
+
if (options.onlyTopLevel) {
|
|
1228
|
+
servicedCallbacks.function = (input, start, end) => {
|
|
1229
|
+
balanced++;
|
|
1230
|
+
if (!options.functionValue) {
|
|
1231
|
+
needHandle = false;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (additional && additional.function !== undefined) {
|
|
1235
|
+
return additional.function(input, start, end);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
return end;
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
servicedCallbacks.leftParenthesis = (_input, _start, end) => {
|
|
1242
|
+
balanced++;
|
|
1243
|
+
needHandle = false;
|
|
1244
|
+
return end;
|
|
1245
|
+
};
|
|
1246
|
+
servicedCallbacks.rightParenthesis = (_input, _start, end) => {
|
|
1247
|
+
balanced--;
|
|
1248
|
+
if (balanced === 0) {
|
|
1249
|
+
needHandle = true;
|
|
1250
|
+
}
|
|
1251
|
+
return end;
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
if (options.declarationValue) {
|
|
1256
|
+
servicedCallbacks.semicolon = (_input, _start, end) => {
|
|
1257
|
+
needTerminate = true;
|
|
1258
|
+
return end;
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
servicedCallbacks.rightCurlyBracket = (_input, _start, end) => {
|
|
1262
|
+
needTerminate = true;
|
|
1263
|
+
return end;
|
|
1264
|
+
};
|
|
1265
|
+
} else if (options.functionValue) {
|
|
1266
|
+
servicedCallbacks.rightParenthesis = (_input, _start, end) => {
|
|
1267
|
+
balanced--;
|
|
1268
|
+
if (balanced === 0) {
|
|
1269
|
+
needTerminate = true;
|
|
1270
|
+
}
|
|
1271
|
+
return end;
|
|
1272
|
+
};
|
|
1273
|
+
} else if (options.atRulePrelude) {
|
|
1274
|
+
servicedCallbacks.leftCurlyBracket = (_input, _start, end) => {
|
|
1275
|
+
needTerminate = true;
|
|
1276
|
+
return end;
|
|
1277
|
+
};
|
|
1278
|
+
servicedCallbacks.semicolon = (_input, _start, end) => {
|
|
1279
|
+
needTerminate = true;
|
|
1280
|
+
return end;
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
while (pos < input.length) {
|
|
1285
|
+
// Consume comments.
|
|
1286
|
+
pos = consumeComments(
|
|
1287
|
+
input,
|
|
1288
|
+
pos,
|
|
1289
|
+
needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
|
|
1290
|
+
);
|
|
1291
|
+
|
|
1292
|
+
const start = pos;
|
|
1293
|
+
|
|
1294
|
+
// Consume the next input code point.
|
|
1295
|
+
pos++;
|
|
1296
|
+
pos = consumeAToken(
|
|
1297
|
+
input,
|
|
1298
|
+
pos,
|
|
1299
|
+
needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
|
|
1300
|
+
);
|
|
1301
|
+
|
|
1302
|
+
if (needTerminate) {
|
|
1303
|
+
return start;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
return pos;
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1200
1310
|
/**
|
|
1201
1311
|
* @param {string} input input
|
|
1202
1312
|
* @param {number} pos position
|
|
@@ -1230,13 +1340,18 @@ const eatWhitespace = (input, pos) => {
|
|
|
1230
1340
|
/**
|
|
1231
1341
|
* @param {string} input input
|
|
1232
1342
|
* @param {number} pos position
|
|
1233
|
-
* @returns {number} position after whitespace and comments
|
|
1343
|
+
* @returns {[number, boolean]} position after whitespace and comments
|
|
1234
1344
|
*/
|
|
1235
1345
|
const eatWhitespaceAndComments = (input, pos) => {
|
|
1346
|
+
let foundWhitespace = false;
|
|
1347
|
+
|
|
1236
1348
|
for (;;) {
|
|
1237
1349
|
const originalPos = pos;
|
|
1238
1350
|
pos = consumeComments(input, pos, {});
|
|
1239
1351
|
while (_isWhiteSpace(input.charCodeAt(pos))) {
|
|
1352
|
+
if (!foundWhitespace) {
|
|
1353
|
+
foundWhitespace = true;
|
|
1354
|
+
}
|
|
1240
1355
|
pos++;
|
|
1241
1356
|
}
|
|
1242
1357
|
if (originalPos === pos) {
|
|
@@ -1244,7 +1359,7 @@ const eatWhitespaceAndComments = (input, pos) => {
|
|
|
1244
1359
|
}
|
|
1245
1360
|
}
|
|
1246
1361
|
|
|
1247
|
-
return pos;
|
|
1362
|
+
return [pos, foundWhitespace];
|
|
1248
1363
|
};
|
|
1249
1364
|
|
|
1250
1365
|
/**
|
|
@@ -1298,7 +1413,7 @@ const skipCommentsAndEatIdentSequence = (input, pos) => {
|
|
|
1298
1413
|
* @returns {[number, number] | undefined} positions of ident sequence
|
|
1299
1414
|
*/
|
|
1300
1415
|
const eatString = (input, pos) => {
|
|
1301
|
-
pos = eatWhitespaceAndComments(input, pos);
|
|
1416
|
+
pos = eatWhitespaceAndComments(input, pos)[0];
|
|
1302
1417
|
|
|
1303
1418
|
const start = pos;
|
|
1304
1419
|
|
|
@@ -1531,7 +1646,7 @@ const eatImportTokens = (input, pos, cbs) => {
|
|
|
1531
1646
|
* @returns {[number, number] | undefined} positions of ident sequence
|
|
1532
1647
|
*/
|
|
1533
1648
|
const eatIdentSequence = (input, pos) => {
|
|
1534
|
-
pos = eatWhitespaceAndComments(input, pos);
|
|
1649
|
+
pos = eatWhitespaceAndComments(input, pos)[0];
|
|
1535
1650
|
|
|
1536
1651
|
const start = pos;
|
|
1537
1652
|
|
|
@@ -1556,7 +1671,7 @@ const eatIdentSequence = (input, pos) => {
|
|
|
1556
1671
|
* @returns {[number, number, boolean] | undefined} positions of ident sequence or string
|
|
1557
1672
|
*/
|
|
1558
1673
|
const eatIdentSequenceOrString = (input, pos) => {
|
|
1559
|
-
pos = eatWhitespaceAndComments(input, pos);
|
|
1674
|
+
pos = eatWhitespaceAndComments(input, pos)[0];
|
|
1560
1675
|
|
|
1561
1676
|
const start = pos;
|
|
1562
1677
|
|
|
@@ -1608,6 +1723,7 @@ const eatUntil = (chars) => {
|
|
|
1608
1723
|
};
|
|
1609
1724
|
};
|
|
1610
1725
|
|
|
1726
|
+
module.exports.consumeUntil = consumeUntil;
|
|
1611
1727
|
module.exports.eatComments = eatComments;
|
|
1612
1728
|
module.exports.eatIdentSequence = eatIdentSequence;
|
|
1613
1729
|
module.exports.eatIdentSequenceOrString = eatIdentSequenceOrString;
|
|
@@ -1619,5 +1735,6 @@ module.exports.eatWhiteLine = eatWhiteLine;
|
|
|
1619
1735
|
module.exports.eatWhitespace = eatWhitespace;
|
|
1620
1736
|
module.exports.eatWhitespaceAndComments = eatWhitespaceAndComments;
|
|
1621
1737
|
module.exports.isIdentStartCodePoint = isIdentStartCodePoint;
|
|
1738
|
+
module.exports.isWhiteSpace = _isWhiteSpace;
|
|
1622
1739
|
module.exports.skipCommentsAndEatIdentSequence =
|
|
1623
1740
|
skipCommentsAndEatIdentSequence;
|
|
@@ -22,15 +22,22 @@ const NullDependency = require("./NullDependency");
|
|
|
22
22
|
class CachedConstDependency extends NullDependency {
|
|
23
23
|
/**
|
|
24
24
|
* @param {string} expression expression
|
|
25
|
-
* @param {Range} range range
|
|
25
|
+
* @param {Range | null} range range
|
|
26
26
|
* @param {string} identifier identifier
|
|
27
|
+
* @param {number=} place place where we inject the expression
|
|
27
28
|
*/
|
|
28
|
-
constructor(
|
|
29
|
+
constructor(
|
|
30
|
+
expression,
|
|
31
|
+
range,
|
|
32
|
+
identifier,
|
|
33
|
+
place = CachedConstDependency.PLACE_MODULE
|
|
34
|
+
) {
|
|
29
35
|
super();
|
|
30
36
|
|
|
31
37
|
this.expression = expression;
|
|
32
38
|
this.range = range;
|
|
33
39
|
this.identifier = identifier;
|
|
40
|
+
this.place = place;
|
|
34
41
|
this._hashUpdate = undefined;
|
|
35
42
|
}
|
|
36
43
|
|
|
@@ -38,7 +45,7 @@ class CachedConstDependency extends NullDependency {
|
|
|
38
45
|
* @returns {string} hash update
|
|
39
46
|
*/
|
|
40
47
|
_createHashUpdate() {
|
|
41
|
-
return `${this.identifier}${this.range}${this.expression}`;
|
|
48
|
+
return `${this.place}${this.identifier}${this.range}${this.expression}`;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
/**
|
|
@@ -63,6 +70,7 @@ class CachedConstDependency extends NullDependency {
|
|
|
63
70
|
write(this.expression);
|
|
64
71
|
write(this.range);
|
|
65
72
|
write(this.identifier);
|
|
73
|
+
write(this.place);
|
|
66
74
|
|
|
67
75
|
super.serialize(context);
|
|
68
76
|
}
|
|
@@ -76,11 +84,15 @@ class CachedConstDependency extends NullDependency {
|
|
|
76
84
|
this.expression = read();
|
|
77
85
|
this.range = read();
|
|
78
86
|
this.identifier = read();
|
|
87
|
+
this.place = read();
|
|
79
88
|
|
|
80
89
|
super.deserialize(context);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
92
|
|
|
93
|
+
CachedConstDependency.PLACE_MODULE = 10;
|
|
94
|
+
CachedConstDependency.PLACE_CHUNK = 20;
|
|
95
|
+
|
|
84
96
|
makeSerializable(
|
|
85
97
|
CachedConstDependency,
|
|
86
98
|
"webpack/lib/dependencies/CachedConstDependency"
|
|
@@ -95,25 +107,27 @@ CachedConstDependency.Template = class CachedConstDependencyTemplate extends (
|
|
|
95
107
|
* @param {DependencyTemplateContext} templateContext the context object
|
|
96
108
|
* @returns {void}
|
|
97
109
|
*/
|
|
98
|
-
apply(dependency, source, { initFragments }) {
|
|
110
|
+
apply(dependency, source, { initFragments, chunkInitFragments }) {
|
|
99
111
|
const dep = /** @type {CachedConstDependency} */ (dependency);
|
|
100
112
|
|
|
101
|
-
|
|
113
|
+
(dep.place === CachedConstDependency.PLACE_MODULE
|
|
114
|
+
? initFragments
|
|
115
|
+
: chunkInitFragments
|
|
116
|
+
).push(
|
|
102
117
|
new InitFragment(
|
|
103
118
|
`var ${dep.identifier} = ${dep.expression};\n`,
|
|
104
119
|
InitFragment.STAGE_CONSTANTS,
|
|
105
|
-
|
|
120
|
+
// For a chunk we inject expression after imports
|
|
121
|
+
dep.place === CachedConstDependency.PLACE_MODULE ? 0 : 10,
|
|
106
122
|
`const ${dep.identifier}`
|
|
107
123
|
)
|
|
108
124
|
);
|
|
109
125
|
|
|
110
126
|
if (typeof dep.range === "number") {
|
|
111
127
|
source.insert(dep.range, dep.identifier);
|
|
112
|
-
|
|
113
|
-
|
|
128
|
+
} else if (dep.range !== null) {
|
|
129
|
+
source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
|
|
114
130
|
}
|
|
115
|
-
|
|
116
|
-
source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
|
|
117
131
|
}
|
|
118
132
|
};
|
|
119
133
|
|
|
@@ -126,15 +126,6 @@ class CommonJsImportsParserPlugin {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
// #region Unsupported
|
|
129
|
-
parser.hooks.expression
|
|
130
|
-
.for("require.main")
|
|
131
|
-
.tap(
|
|
132
|
-
PLUGIN_NAME,
|
|
133
|
-
expressionIsUnsupported(
|
|
134
|
-
parser,
|
|
135
|
-
"require.main is not supported by webpack."
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
129
|
parser.hooks.call
|
|
139
130
|
.for("require.main.require")
|
|
140
131
|
.tap(
|
|
@@ -15,6 +15,7 @@ const SelfModuleFactory = require("../SelfModuleFactory");
|
|
|
15
15
|
const Template = require("../Template");
|
|
16
16
|
const {
|
|
17
17
|
evaluateToIdentifier,
|
|
18
|
+
expressionIsUnsupported,
|
|
18
19
|
toConstantDependency
|
|
19
20
|
} = require("../javascript/JavascriptParserHelpers");
|
|
20
21
|
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
|
|
@@ -198,6 +199,17 @@ class CommonJsPlugin {
|
|
|
198
199
|
[RuntimeGlobals.moduleCache, RuntimeGlobals.entryModuleId]
|
|
199
200
|
)
|
|
200
201
|
);
|
|
202
|
+
|
|
203
|
+
parser.hooks.expression
|
|
204
|
+
.for("require.extensions")
|
|
205
|
+
.tap(
|
|
206
|
+
PLUGIN_NAME,
|
|
207
|
+
expressionIsUnsupported(
|
|
208
|
+
parser,
|
|
209
|
+
"require.extensions is not supported by webpack. Use a loader instead."
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
|
|
201
213
|
parser.hooks.expression
|
|
202
214
|
.for(RuntimeGlobals.moduleLoaded)
|
|
203
215
|
.tap(PLUGIN_NAME, (expr) => {
|
|
@@ -19,7 +19,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
|
|
|
19
19
|
* @param {ContextDependencyOptions} options options for the context module
|
|
20
20
|
* @param {Range} range location in source code
|
|
21
21
|
* @param {Range | undefined} valueRange location of the require call
|
|
22
|
-
* @param {boolean | string
|
|
22
|
+
* @param {boolean | string} inShorthand true or name
|
|
23
23
|
* @param {string=} context context
|
|
24
24
|
*/
|
|
25
25
|
constructor(options, range, valueRange, inShorthand, context) {
|
|
@@ -42,14 +42,14 @@ const splitContextFromPrefix = (prefix) => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
|
|
45
|
-
/** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args:
|
|
45
|
+
/** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: EXPECTED_ANY[]): ContextDependency }} ContextDependencyConstructor */
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* @param {ContextDependencyConstructor} Dep the Dependency class
|
|
49
49
|
* @param {Range} range source range
|
|
50
50
|
* @param {BasicEvaluatedExpression} param context param
|
|
51
51
|
* @param {Expression} expr expr
|
|
52
|
-
* @param {Pick<JavascriptParserOptions, `${"expr"|"wrapped"}Context${"Critical"|"Recursive"|"RegExp"}` | "exprContextRequest">} options options for context creation
|
|
52
|
+
* @param {Pick<JavascriptParserOptions, `${"expr" | "wrapped"}Context${"Critical" | "Recursive" | "RegExp"}` | "exprContextRequest">} options options for context creation
|
|
53
53
|
* @param {PartialContextDependencyOptions} contextOptions options for the ContextModule
|
|
54
54
|
* @param {JavascriptParser} parser the parser
|
|
55
55
|
* @param {...EXPECTED_ANY} depArgs depArgs
|
|
@@ -12,7 +12,9 @@ const ContextDependency = require("./ContextDependency");
|
|
|
12
12
|
/** @typedef {import("../Dependency")} Dependency */
|
|
13
13
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
14
14
|
|
|
15
|
-
class ContextDependencyTemplateAsRequireCall
|
|
15
|
+
class ContextDependencyTemplateAsRequireCall
|
|
16
|
+
extends ContextDependency.Template
|
|
17
|
+
{
|
|
16
18
|
/**
|
|
17
19
|
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
18
20
|
* @param {ReplaceSource} source the current replace source which can be modified
|