webpack 5.59.0 → 5.71.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.

Files changed (209) hide show
  1. package/README.md +1 -7
  2. package/hot/lazy-compilation-node.js +3 -1
  3. package/hot/poll.js +1 -1
  4. package/hot/signal.js +1 -1
  5. package/lib/APIPlugin.js +33 -0
  6. package/lib/BannerPlugin.js +10 -4
  7. package/lib/Cache.js +1 -1
  8. package/lib/CacheFacade.js +4 -11
  9. package/lib/Chunk.js +6 -3
  10. package/lib/ChunkGraph.js +1 -2
  11. package/lib/ChunkGroup.js +1 -1
  12. package/lib/CleanPlugin.js +81 -20
  13. package/lib/Compilation.js +179 -91
  14. package/lib/Compiler.js +86 -17
  15. package/lib/ConstPlugin.js +2 -2
  16. package/lib/ContextModule.js +142 -51
  17. package/lib/ContextModuleFactory.js +65 -25
  18. package/lib/DelegatedModule.js +1 -1
  19. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  20. package/lib/Dependency.js +17 -0
  21. package/lib/DependencyTemplate.js +9 -0
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllModule.js +1 -1
  24. package/lib/EntryOptionPlugin.js +2 -0
  25. package/lib/ErrorHelpers.js +2 -2
  26. package/lib/EvalDevToolModulePlugin.js +16 -1
  27. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  28. package/lib/ExportsInfo.js +4 -4
  29. package/lib/ExternalModule.js +94 -54
  30. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  31. package/lib/FileSystemInfo.js +89 -44
  32. package/lib/Generator.js +3 -0
  33. package/lib/HookWebpackError.js +1 -1
  34. package/lib/HotModuleReplacementPlugin.js +3 -1
  35. package/lib/LoaderOptionsPlugin.js +1 -1
  36. package/lib/Module.js +27 -4
  37. package/lib/ModuleFilenameHelpers.js +8 -4
  38. package/lib/ModuleHashingError.js +29 -0
  39. package/lib/MultiCompiler.js +1 -1
  40. package/lib/MultiWatching.js +1 -1
  41. package/lib/NodeStuffPlugin.js +10 -0
  42. package/lib/NormalModule.js +41 -26
  43. package/lib/NormalModuleFactory.js +42 -37
  44. package/lib/ProgressPlugin.js +4 -5
  45. package/lib/RawModule.js +1 -1
  46. package/lib/RuntimeGlobals.js +29 -1
  47. package/lib/RuntimeModule.js +1 -1
  48. package/lib/RuntimePlugin.js +77 -1
  49. package/lib/RuntimeTemplate.js +114 -2
  50. package/lib/Template.js +2 -1
  51. package/lib/TemplatedPathPlugin.js +48 -23
  52. package/lib/WatchIgnorePlugin.js +19 -7
  53. package/lib/Watching.js +33 -19
  54. package/lib/WebpackOptionsApply.js +57 -11
  55. package/lib/asset/AssetGenerator.js +193 -63
  56. package/lib/asset/AssetModulesPlugin.js +3 -0
  57. package/lib/asset/RawDataUrlModule.js +148 -0
  58. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  59. package/lib/buildChunkGraph.js +36 -6
  60. package/lib/cache/PackFileCacheStrategy.js +7 -4
  61. package/lib/cache/ResolverCachePlugin.js +90 -29
  62. package/lib/cli.js +44 -3
  63. package/lib/config/browserslistTargetHandler.js +41 -6
  64. package/lib/config/defaults.js +115 -19
  65. package/lib/config/normalization.js +9 -0
  66. package/lib/config/target.js +10 -0
  67. package/lib/container/ContainerEntryModule.js +8 -5
  68. package/lib/container/FallbackModule.js +4 -4
  69. package/lib/container/RemoteModule.js +4 -2
  70. package/lib/css/CssExportsGenerator.js +139 -0
  71. package/lib/css/CssGenerator.js +109 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  73. package/lib/css/CssModulesPlugin.js +462 -0
  74. package/lib/css/CssParser.js +618 -0
  75. package/lib/css/walkCssTokens.js +659 -0
  76. package/lib/debug/ProfilingPlugin.js +24 -21
  77. package/lib/dependencies/AMDRequireDependency.js +6 -6
  78. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  79. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  80. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
  81. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  82. package/lib/dependencies/ContextDependency.js +1 -0
  83. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  84. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  85. package/lib/dependencies/ContextElementDependency.js +41 -3
  86. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  87. package/lib/dependencies/CssExportDependency.js +85 -0
  88. package/lib/dependencies/CssImportDependency.js +75 -0
  89. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  90. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  91. package/lib/dependencies/CssUrlDependency.js +132 -0
  92. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  93. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  94. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  95. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  96. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  97. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  98. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  99. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  100. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  102. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  103. package/lib/dependencies/ImportContextDependency.js +0 -2
  104. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  105. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  106. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  107. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  108. package/lib/dependencies/LoaderPlugin.js +4 -2
  109. package/lib/dependencies/RequireContextDependency.js +0 -16
  110. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  111. package/lib/dependencies/URLDependency.js +3 -8
  112. package/lib/dependencies/URLPlugin.js +1 -1
  113. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  114. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  115. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  116. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  117. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  118. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  119. package/lib/hmr/lazyCompilationBackend.js +51 -12
  120. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  121. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  122. package/lib/ids/IdHelpers.js +25 -11
  123. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  124. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  125. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  126. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  127. package/lib/index.js +13 -0
  128. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  129. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  130. package/lib/javascript/ChunkHelpers.js +33 -0
  131. package/lib/javascript/JavascriptGenerator.js +1 -0
  132. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  133. package/lib/javascript/JavascriptParser.js +82 -48
  134. package/lib/javascript/StartupHelpers.js +7 -30
  135. package/lib/library/AssignLibraryPlugin.js +39 -15
  136. package/lib/library/EnableLibraryPlugin.js +11 -0
  137. package/lib/library/UmdLibraryPlugin.js +5 -3
  138. package/lib/node/NodeTargetPlugin.js +3 -0
  139. package/lib/node/NodeWatchFileSystem.js +85 -31
  140. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  141. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  142. package/lib/optimize/ConcatenatedModule.js +21 -9
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  144. package/lib/optimize/SplitChunksPlugin.js +8 -1
  145. package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
  146. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  147. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  148. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  149. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  150. package/lib/schemes/HttpUriPlugin.js +77 -14
  151. package/lib/serialization/FileMiddleware.js +44 -9
  152. package/lib/sharing/ConsumeSharedModule.js +8 -2
  153. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  154. package/lib/sharing/ProvideSharedModule.js +4 -2
  155. package/lib/sharing/ShareRuntimeModule.js +1 -1
  156. package/lib/sharing/utils.js +1 -1
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  158. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  159. package/lib/util/ArrayHelpers.js +30 -0
  160. package/lib/util/AsyncQueue.js +1 -1
  161. package/lib/util/compileBooleanMatcher.js +1 -1
  162. package/lib/util/create-schema-validation.js +9 -2
  163. package/lib/util/createHash.js +12 -0
  164. package/lib/util/deprecation.js +10 -2
  165. package/lib/util/deterministicGrouping.js +1 -1
  166. package/lib/util/extractUrlAndGlobal.js +3 -0
  167. package/lib/util/fs.js +11 -0
  168. package/lib/util/hash/BatchedHash.js +7 -4
  169. package/lib/util/hash/md4.js +20 -0
  170. package/lib/util/hash/wasm-hash.js +163 -0
  171. package/lib/util/hash/xxhash64.js +5 -139
  172. package/lib/util/identifier.js +65 -44
  173. package/lib/util/internalSerializables.js +15 -0
  174. package/lib/util/nonNumericOnlyHash.js +22 -0
  175. package/lib/util/semver.js +17 -10
  176. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  177. package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
  178. package/lib/webpack.js +10 -3
  179. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  180. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  181. package/module.d.ts +215 -0
  182. package/package.json +23 -28
  183. package/schemas/WebpackOptions.check.js +1 -1
  184. package/schemas/WebpackOptions.json +254 -29
  185. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  186. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  187. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  188. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  189. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  190. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  191. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  192. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  194. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  195. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  197. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  198. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  199. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  200. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  201. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  202. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  203. package/schemas/plugins/css/CssParserOptions.json +3 -0
  204. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  209. package/types.d.ts +628 -179
@@ -0,0 +1,618 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const Parser = require("../Parser");
9
+ const ConstDependency = require("../dependencies/ConstDependency");
10
+ const CssExportDependency = require("../dependencies/CssExportDependency");
11
+ const CssImportDependency = require("../dependencies/CssImportDependency");
12
+ const CssLocalIdentifierDependency = require("../dependencies/CssLocalIdentifierDependency");
13
+ const CssSelfLocalIdentifierDependency = require("../dependencies/CssSelfLocalIdentifierDependency");
14
+ const CssUrlDependency = require("../dependencies/CssUrlDependency");
15
+ const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
16
+ const walkCssTokens = require("./walkCssTokens");
17
+
18
+ /** @typedef {import("../Parser").ParserState} ParserState */
19
+ /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
20
+
21
+ const CC_LEFT_CURLY = "{".charCodeAt(0);
22
+ const CC_RIGHT_CURLY = "}".charCodeAt(0);
23
+ const CC_COLON = ":".charCodeAt(0);
24
+ const CC_SLASH = "/".charCodeAt(0);
25
+ const CC_SEMICOLON = ";".charCodeAt(0);
26
+
27
+ const cssUnescape = str => {
28
+ return str.replace(/\\([0-9a-fA-F]{1,6}[ \t\n\r\f]?|[\s\S])/g, match => {
29
+ if (match.length > 2) {
30
+ return String.fromCharCode(parseInt(match.slice(1).trim(), 16));
31
+ } else {
32
+ return match[1];
33
+ }
34
+ });
35
+ };
36
+
37
+ class LocConverter {
38
+ constructor(input) {
39
+ this._input = input;
40
+ this.line = 1;
41
+ this.column = 0;
42
+ this.pos = 0;
43
+ }
44
+
45
+ get(pos) {
46
+ if (this.pos !== pos) {
47
+ if (this.pos < pos) {
48
+ const str = this._input.slice(this.pos, pos);
49
+ let i = str.lastIndexOf("\n");
50
+ if (i === -1) {
51
+ this.column += str.length;
52
+ } else {
53
+ this.column = str.length - i - 1;
54
+ this.line++;
55
+ while (i > 0 && (i = str.lastIndexOf("\n", i - 1)) !== -1)
56
+ this.line++;
57
+ }
58
+ } else {
59
+ let i = this._input.lastIndexOf("\n", this.pos);
60
+ while (i >= pos) {
61
+ this.line--;
62
+ i = i > 0 ? this._input.lastIndexOf("\n", i - 1) : -1;
63
+ }
64
+ this.column = pos - i;
65
+ }
66
+ this.pos = pos;
67
+ }
68
+ return this;
69
+ }
70
+ }
71
+
72
+ const CSS_MODE_TOP_LEVEL = 0;
73
+ const CSS_MODE_IN_RULE = 1;
74
+ const CSS_MODE_IN_LOCAL_RULE = 2;
75
+ const CSS_MODE_AT_IMPORT_EXPECT_URL = 3;
76
+ // TODO implement layer and supports for @import
77
+ const CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS = 4;
78
+ const CSS_MODE_AT_IMPORT_EXPECT_MEDIA = 5;
79
+ const CSS_MODE_AT_OTHER = 6;
80
+
81
+ const explainMode = mode => {
82
+ switch (mode) {
83
+ case CSS_MODE_TOP_LEVEL:
84
+ return "parsing top level css";
85
+ case CSS_MODE_IN_RULE:
86
+ return "parsing css rule content (global)";
87
+ case CSS_MODE_IN_LOCAL_RULE:
88
+ return "parsing css rule content (local)";
89
+ case CSS_MODE_AT_IMPORT_EXPECT_URL:
90
+ return "parsing @import (expecting url)";
91
+ case CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS:
92
+ return "parsing @import (expecting optionally supports or media query)";
93
+ case CSS_MODE_AT_IMPORT_EXPECT_MEDIA:
94
+ return "parsing @import (expecting optionally media query)";
95
+ case CSS_MODE_AT_OTHER:
96
+ return "parsing at-rule";
97
+ default:
98
+ return mode;
99
+ }
100
+ };
101
+
102
+ class CssParser extends Parser {
103
+ constructor({
104
+ allowPseudoBlocks = true,
105
+ allowModeSwitch = true,
106
+ defaultMode = "global"
107
+ } = {}) {
108
+ super();
109
+ this.allowPseudoBlocks = allowPseudoBlocks;
110
+ this.allowModeSwitch = allowModeSwitch;
111
+ this.defaultMode = defaultMode;
112
+ }
113
+
114
+ /**
115
+ * @param {string | Buffer | PreparsedAst} source the source to parse
116
+ * @param {ParserState} state the parser state
117
+ * @returns {ParserState} the parser state
118
+ */
119
+ parse(source, state) {
120
+ if (Buffer.isBuffer(source)) {
121
+ source = source.toString("utf-8");
122
+ } else if (typeof source === "object") {
123
+ throw new Error("webpackAst is unexpected for the CssParser");
124
+ }
125
+ if (source[0] === "\ufeff") {
126
+ source = source.slice(1);
127
+ }
128
+
129
+ const module = state.module;
130
+
131
+ const declaredCssVariables = new Set();
132
+
133
+ const locConverter = new LocConverter(source);
134
+ let mode = CSS_MODE_TOP_LEVEL;
135
+ let modePos = 0;
136
+ let modeNestingLevel = 0;
137
+ let modeData = undefined;
138
+ let singleClassSelector = undefined;
139
+ let lastIdentifier = undefined;
140
+ const modeStack = [];
141
+ const isTopLevelLocal = () =>
142
+ modeData === "local" ||
143
+ (this.defaultMode === "local" && modeData === undefined);
144
+ const eatWhiteLine = (input, pos) => {
145
+ for (;;) {
146
+ const cc = input.charCodeAt(pos);
147
+ if (cc === 32 || cc === 9) {
148
+ pos++;
149
+ continue;
150
+ }
151
+ if (cc === 10) pos++;
152
+ break;
153
+ }
154
+ return pos;
155
+ };
156
+ const eatUntil = chars => {
157
+ const charCodes = Array.from({ length: chars.length }, (_, i) =>
158
+ chars.charCodeAt(i)
159
+ );
160
+ const arr = Array.from(
161
+ { length: charCodes.reduce((a, b) => Math.max(a, b), 0) + 1 },
162
+ () => false
163
+ );
164
+ charCodes.forEach(cc => (arr[cc] = true));
165
+ return (input, pos) => {
166
+ for (;;) {
167
+ const cc = input.charCodeAt(pos);
168
+ if (cc < arr.length && arr[cc]) {
169
+ return pos;
170
+ }
171
+ pos++;
172
+ if (pos === input.length) return pos;
173
+ }
174
+ };
175
+ };
176
+ const eatText = (input, pos, eater) => {
177
+ let text = "";
178
+ for (;;) {
179
+ if (input.charCodeAt(pos) === CC_SLASH) {
180
+ const newPos = walkCssTokens.eatComments(input, pos);
181
+ if (pos !== newPos) {
182
+ pos = newPos;
183
+ if (pos === input.length) break;
184
+ } else {
185
+ text += "/";
186
+ pos++;
187
+ if (pos === input.length) break;
188
+ }
189
+ }
190
+ const newPos = eater(input, pos);
191
+ if (pos !== newPos) {
192
+ text += input.slice(pos, newPos);
193
+ pos = newPos;
194
+ } else {
195
+ break;
196
+ }
197
+ if (pos === input.length) break;
198
+ }
199
+ return [pos, text.trimRight()];
200
+ };
201
+ const eatExportName = eatUntil(":};/");
202
+ const eatExportValue = eatUntil("};/");
203
+ const parseExports = (input, pos) => {
204
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
205
+ const cc = input.charCodeAt(pos);
206
+ if (cc !== CC_LEFT_CURLY)
207
+ throw new Error(
208
+ `Unexpected ${input[pos]} at ${pos} during parsing of ':export' (expected '{')`
209
+ );
210
+ pos++;
211
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
212
+ for (;;) {
213
+ if (input.charCodeAt(pos) === CC_RIGHT_CURLY) break;
214
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
215
+ if (pos === input.length) return pos;
216
+ let start = pos;
217
+ let name;
218
+ [pos, name] = eatText(input, pos, eatExportName);
219
+ if (pos === input.length) return pos;
220
+ if (input.charCodeAt(pos) !== CC_COLON) {
221
+ throw new Error(
222
+ `Unexpected ${input[pos]} at ${pos} during parsing of export name in ':export' (expected ':')`
223
+ );
224
+ }
225
+ pos++;
226
+ if (pos === input.length) return pos;
227
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
228
+ if (pos === input.length) return pos;
229
+ let value;
230
+ [pos, value] = eatText(input, pos, eatExportValue);
231
+ if (pos === input.length) return pos;
232
+ const cc = input.charCodeAt(pos);
233
+ if (cc === CC_SEMICOLON) {
234
+ pos++;
235
+ if (pos === input.length) return pos;
236
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
237
+ if (pos === input.length) return pos;
238
+ } else if (cc !== CC_RIGHT_CURLY) {
239
+ throw new Error(
240
+ `Unexpected ${input[pos]} at ${pos} during parsing of export value in ':export' (expected ';' or '}')`
241
+ );
242
+ }
243
+ const dep = new CssExportDependency(name, value);
244
+ const { line: sl, column: sc } = locConverter.get(start);
245
+ const { line: el, column: ec } = locConverter.get(pos);
246
+ dep.setLoc(sl, sc, el, ec);
247
+ module.addDependency(dep);
248
+ }
249
+ pos++;
250
+ if (pos === input.length) return pos;
251
+ pos = eatWhiteLine(input, pos);
252
+ return pos;
253
+ };
254
+ const eatPropertyName = eatUntil(":{};");
255
+ const processLocalDeclaration = (input, pos) => {
256
+ modeData = undefined;
257
+ const start = pos;
258
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
259
+ const propertyNameStart = pos;
260
+ const [propertyNameEnd, propertyName] = eatText(
261
+ input,
262
+ pos,
263
+ eatPropertyName
264
+ );
265
+ if (input.charCodeAt(propertyNameEnd) !== CC_COLON) return start;
266
+ pos = propertyNameEnd + 1;
267
+ if (propertyName.startsWith("--")) {
268
+ // CSS Variable
269
+ const { line: sl, column: sc } = locConverter.get(propertyNameStart);
270
+ const { line: el, column: ec } = locConverter.get(propertyNameEnd);
271
+ const name = propertyName.slice(2);
272
+ const dep = new CssLocalIdentifierDependency(
273
+ name,
274
+ [propertyNameStart, propertyNameEnd],
275
+ "--"
276
+ );
277
+ dep.setLoc(sl, sc, el, ec);
278
+ module.addDependency(dep);
279
+ declaredCssVariables.add(name);
280
+ } else if (
281
+ propertyName === "animation-name" ||
282
+ propertyName === "animation"
283
+ ) {
284
+ modeData = "animation";
285
+ lastIdentifier = undefined;
286
+ }
287
+ return pos;
288
+ };
289
+ const processDeclarationValueDone = (input, pos) => {
290
+ if (modeData === "animation" && lastIdentifier) {
291
+ const { line: sl, column: sc } = locConverter.get(lastIdentifier[0]);
292
+ const { line: el, column: ec } = locConverter.get(lastIdentifier[1]);
293
+ const name = input.slice(lastIdentifier[0], lastIdentifier[1]);
294
+ const dep = new CssSelfLocalIdentifierDependency(name, lastIdentifier);
295
+ dep.setLoc(sl, sc, el, ec);
296
+ module.addDependency(dep);
297
+ }
298
+ };
299
+ const eatKeyframes = eatUntil("{};/");
300
+ const eatNameInVar = eatUntil(",)};/");
301
+ walkCssTokens(source, {
302
+ isSelector: () => {
303
+ return mode !== CSS_MODE_IN_RULE && mode !== CSS_MODE_IN_LOCAL_RULE;
304
+ },
305
+ url: (input, start, end, contentStart, contentEnd) => {
306
+ const value = cssUnescape(input.slice(contentStart, contentEnd));
307
+ switch (mode) {
308
+ case CSS_MODE_AT_IMPORT_EXPECT_URL: {
309
+ modeData.url = value;
310
+ mode = CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS;
311
+ break;
312
+ }
313
+ case CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS:
314
+ case CSS_MODE_AT_IMPORT_EXPECT_MEDIA:
315
+ throw new Error(
316
+ `Unexpected ${input.slice(
317
+ start,
318
+ end
319
+ )} at ${start} during ${explainMode(mode)}`
320
+ );
321
+ default: {
322
+ const dep = new CssUrlDependency(value, [start, end], "url");
323
+ const { line: sl, column: sc } = locConverter.get(start);
324
+ const { line: el, column: ec } = locConverter.get(end);
325
+ dep.setLoc(sl, sc, el, ec);
326
+ module.addDependency(dep);
327
+ module.addCodeGenerationDependency(dep);
328
+ break;
329
+ }
330
+ }
331
+ return end;
332
+ },
333
+ string: (input, start, end) => {
334
+ switch (mode) {
335
+ case CSS_MODE_AT_IMPORT_EXPECT_URL: {
336
+ modeData.url = cssUnescape(input.slice(start + 1, end - 1));
337
+ mode = CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS;
338
+ break;
339
+ }
340
+ }
341
+ return end;
342
+ },
343
+ atKeyword: (input, start, end) => {
344
+ const name = input.slice(start, end);
345
+ if (name === "@namespace") {
346
+ throw new Error("@namespace is not supported in bundled CSS");
347
+ }
348
+ if (name === "@import") {
349
+ if (mode !== CSS_MODE_TOP_LEVEL) {
350
+ throw new Error(
351
+ `Unexpected @import at ${start} during ${explainMode(mode)}`
352
+ );
353
+ }
354
+ mode = CSS_MODE_AT_IMPORT_EXPECT_URL;
355
+ modePos = end;
356
+ modeData = {
357
+ start: start,
358
+ url: undefined,
359
+ supports: undefined
360
+ };
361
+ }
362
+ if (name === "@keyframes") {
363
+ let pos = end;
364
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
365
+ if (pos === input.length) return pos;
366
+ const [newPos, name] = eatText(input, pos, eatKeyframes);
367
+ const { line: sl, column: sc } = locConverter.get(pos);
368
+ const { line: el, column: ec } = locConverter.get(newPos);
369
+ const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
370
+ dep.setLoc(sl, sc, el, ec);
371
+ module.addDependency(dep);
372
+ pos = newPos;
373
+ if (pos === input.length) return pos;
374
+ if (input.charCodeAt(pos) !== CC_LEFT_CURLY) {
375
+ throw new Error(
376
+ `Unexpected ${input[pos]} at ${pos} during parsing of @keyframes (expected '{')`
377
+ );
378
+ }
379
+ mode = CSS_MODE_IN_LOCAL_RULE;
380
+ modeNestingLevel = 1;
381
+ return pos + 1;
382
+ }
383
+ return end;
384
+ },
385
+ semicolon: (input, start, end) => {
386
+ switch (mode) {
387
+ case CSS_MODE_AT_IMPORT_EXPECT_URL:
388
+ throw new Error(`Expected URL for @import at ${start}`);
389
+ case CSS_MODE_AT_IMPORT_EXPECT_MEDIA:
390
+ case CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS: {
391
+ const { line: sl, column: sc } = locConverter.get(modeData.start);
392
+ const { line: el, column: ec } = locConverter.get(end);
393
+ end = eatWhiteLine(input, end);
394
+ const media = input.slice(modePos, start).trim();
395
+ const dep = new CssImportDependency(
396
+ modeData.url,
397
+ [modeData.start, end],
398
+ modeData.supports,
399
+ media
400
+ );
401
+ dep.setLoc(sl, sc, el, ec);
402
+ module.addDependency(dep);
403
+ break;
404
+ }
405
+ case CSS_MODE_IN_LOCAL_RULE: {
406
+ processDeclarationValueDone(input, start);
407
+ return processLocalDeclaration(input, end);
408
+ }
409
+ case CSS_MODE_IN_RULE: {
410
+ return end;
411
+ }
412
+ }
413
+ mode = CSS_MODE_TOP_LEVEL;
414
+ modeData = undefined;
415
+ singleClassSelector = undefined;
416
+ return end;
417
+ },
418
+ leftCurlyBracket: (input, start, end) => {
419
+ switch (mode) {
420
+ case CSS_MODE_TOP_LEVEL:
421
+ mode = isTopLevelLocal()
422
+ ? CSS_MODE_IN_LOCAL_RULE
423
+ : CSS_MODE_IN_RULE;
424
+ modeNestingLevel = 1;
425
+ if (mode === CSS_MODE_IN_LOCAL_RULE)
426
+ return processLocalDeclaration(input, end);
427
+ break;
428
+ case CSS_MODE_IN_RULE:
429
+ case CSS_MODE_IN_LOCAL_RULE:
430
+ modeNestingLevel++;
431
+ break;
432
+ }
433
+ return end;
434
+ },
435
+ rightCurlyBracket: (input, start, end) => {
436
+ switch (mode) {
437
+ case CSS_MODE_IN_LOCAL_RULE:
438
+ processDeclarationValueDone(input, start);
439
+ /* falls through */
440
+ case CSS_MODE_IN_RULE:
441
+ if (--modeNestingLevel === 0) {
442
+ mode = CSS_MODE_TOP_LEVEL;
443
+ modeData = undefined;
444
+ singleClassSelector = undefined;
445
+ }
446
+ break;
447
+ }
448
+ return end;
449
+ },
450
+ id: (input, start, end) => {
451
+ singleClassSelector = false;
452
+ switch (mode) {
453
+ case CSS_MODE_TOP_LEVEL:
454
+ if (isTopLevelLocal()) {
455
+ const name = input.slice(start + 1, end);
456
+ const dep = new CssLocalIdentifierDependency(name, [
457
+ start + 1,
458
+ end
459
+ ]);
460
+ const { line: sl, column: sc } = locConverter.get(start);
461
+ const { line: el, column: ec } = locConverter.get(end);
462
+ dep.setLoc(sl, sc, el, ec);
463
+ module.addDependency(dep);
464
+ }
465
+ break;
466
+ }
467
+ return end;
468
+ },
469
+ identifier: (input, start, end) => {
470
+ singleClassSelector = false;
471
+ switch (mode) {
472
+ case CSS_MODE_IN_LOCAL_RULE:
473
+ if (modeData === "animation") {
474
+ lastIdentifier = [start, end];
475
+ }
476
+ break;
477
+ }
478
+ return end;
479
+ },
480
+ class: (input, start, end) => {
481
+ switch (mode) {
482
+ case CSS_MODE_TOP_LEVEL: {
483
+ if (isTopLevelLocal()) {
484
+ const name = input.slice(start + 1, end);
485
+ const dep = new CssLocalIdentifierDependency(name, [
486
+ start + 1,
487
+ end
488
+ ]);
489
+ const { line: sl, column: sc } = locConverter.get(start);
490
+ const { line: el, column: ec } = locConverter.get(end);
491
+ dep.setLoc(sl, sc, el, ec);
492
+ module.addDependency(dep);
493
+ if (singleClassSelector === undefined) singleClassSelector = name;
494
+ } else {
495
+ singleClassSelector = false;
496
+ }
497
+ break;
498
+ }
499
+ }
500
+ return end;
501
+ },
502
+ leftParenthesis: (input, start, end) => {
503
+ switch (mode) {
504
+ case CSS_MODE_TOP_LEVEL: {
505
+ modeStack.push(false);
506
+ break;
507
+ }
508
+ }
509
+ return end;
510
+ },
511
+ rightParenthesis: (input, start, end) => {
512
+ switch (mode) {
513
+ case CSS_MODE_TOP_LEVEL: {
514
+ const newModeData = modeStack.pop();
515
+ if (newModeData !== false) {
516
+ modeData = newModeData;
517
+ const dep = new ConstDependency("", [start, end]);
518
+ module.addPresentationalDependency(dep);
519
+ }
520
+ break;
521
+ }
522
+ }
523
+ return end;
524
+ },
525
+ pseudoClass: (input, start, end) => {
526
+ singleClassSelector = false;
527
+ switch (mode) {
528
+ case CSS_MODE_TOP_LEVEL: {
529
+ const name = input.slice(start, end);
530
+ if (this.allowModeSwitch && name === ":global") {
531
+ modeData = "global";
532
+ const dep = new ConstDependency("", [start, end]);
533
+ module.addPresentationalDependency(dep);
534
+ } else if (this.allowModeSwitch && name === ":local") {
535
+ modeData = "local";
536
+ const dep = new ConstDependency("", [start, end]);
537
+ module.addPresentationalDependency(dep);
538
+ } else if (this.allowPseudoBlocks && name === ":export") {
539
+ const pos = parseExports(input, end);
540
+ const dep = new ConstDependency("", [start, pos]);
541
+ module.addPresentationalDependency(dep);
542
+ return pos;
543
+ }
544
+ break;
545
+ }
546
+ }
547
+ return end;
548
+ },
549
+ pseudoFunction: (input, start, end) => {
550
+ switch (mode) {
551
+ case CSS_MODE_TOP_LEVEL: {
552
+ const name = input.slice(start, end - 1);
553
+ if (this.allowModeSwitch && name === ":global") {
554
+ modeStack.push(modeData);
555
+ modeData = "global";
556
+ const dep = new ConstDependency("", [start, end]);
557
+ module.addPresentationalDependency(dep);
558
+ } else if (this.allowModeSwitch && name === ":local") {
559
+ modeStack.push(modeData);
560
+ modeData = "local";
561
+ const dep = new ConstDependency("", [start, end]);
562
+ module.addPresentationalDependency(dep);
563
+ } else {
564
+ modeStack.push(false);
565
+ }
566
+ break;
567
+ }
568
+ }
569
+ return end;
570
+ },
571
+ function: (input, start, end) => {
572
+ switch (mode) {
573
+ case CSS_MODE_IN_LOCAL_RULE: {
574
+ const name = input.slice(start, end - 1);
575
+ if (name === "var") {
576
+ let pos = walkCssTokens.eatWhitespaceAndComments(input, end);
577
+ if (pos === input.length) return pos;
578
+ const [newPos, name] = eatText(input, pos, eatNameInVar);
579
+ if (!name.startsWith("--")) return end;
580
+ const { line: sl, column: sc } = locConverter.get(pos);
581
+ const { line: el, column: ec } = locConverter.get(newPos);
582
+ const dep = new CssSelfLocalIdentifierDependency(
583
+ name.slice(2),
584
+ [pos, newPos],
585
+ "--",
586
+ declaredCssVariables
587
+ );
588
+ dep.setLoc(sl, sc, el, ec);
589
+ module.addDependency(dep);
590
+ return newPos;
591
+ }
592
+ break;
593
+ }
594
+ }
595
+ return end;
596
+ },
597
+ comma: (input, start, end) => {
598
+ switch (mode) {
599
+ case CSS_MODE_TOP_LEVEL:
600
+ modeData = undefined;
601
+ modeStack.length = 0;
602
+ break;
603
+ case CSS_MODE_IN_LOCAL_RULE:
604
+ processDeclarationValueDone(input, start);
605
+ break;
606
+ }
607
+ return end;
608
+ }
609
+ });
610
+
611
+ module.buildInfo.strict = true;
612
+ module.buildMeta.exportsType = "namespace";
613
+ module.addDependency(new StaticExportsDependency([], true));
614
+ return state;
615
+ }
616
+ }
617
+
618
+ module.exports = CssParser;