css-loader 5.2.0 → 5.2.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [5.2.4](https://github.com/webpack-contrib/css-loader/compare/v5.2.3...v5.2.4) (2021-04-19)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * do not crash on 'false' aliases ([#1292](https://github.com/webpack-contrib/css-loader/issues/1292)) ([e913cb1](https://github.com/webpack-contrib/css-loader/commit/e913cb1d73a4f5c3c4464e0446a885e9f677a005))
11
+
12
+ ### [5.2.3](https://github.com/webpack-contrib/css-loader/compare/v5.2.2...v5.2.3) (2021-04-19)
13
+
14
+ ### Bug Fixes
15
+
16
+ * improve performance
17
+
18
+ ### [5.2.2](https://github.com/webpack-contrib/css-loader/compare/v5.2.1...v5.2.2) (2021-04-16)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * avoid escape nonASCII characters in local names ([0722733](https://github.com/webpack-contrib/css-loader/commit/072273308a8ab4b7efdae31440689dc81978ca1d))
24
+
25
+ ### [5.2.1](https://github.com/webpack-contrib/css-loader/compare/v5.2.0...v5.2.1) (2021-04-09)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * do not crash on unescaped svg data uri ([#1288](https://github.com/webpack-contrib/css-loader/issues/1288)) ([4f289c5](https://github.com/webpack-contrib/css-loader/commit/4f289c5e4df6c666fdf6dd3402560ae74d4bf7ee))
31
+
5
32
  ## [5.2.0](https://github.com/webpack-contrib/css-loader/compare/v5.1.4...v5.2.0) (2021-03-24)
6
33
 
7
34
 
@@ -47,6 +47,12 @@ const plugin = (options = {}) => {
47
47
  context
48
48
  } = options;
49
49
  const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([normalizedUrl, request])]);
50
+
51
+ if (!resolvedUrl) {
52
+ return;
53
+ } // eslint-disable-next-line consistent-return
54
+
55
+
50
56
  return {
51
57
  url: resolvedUrl,
52
58
  prefix,
@@ -60,12 +66,14 @@ const plugin = (options = {}) => {
60
66
  const results = await Promise.all(tasks);
61
67
 
62
68
  for (let index = 0; index <= results.length - 1; index++) {
63
- const {
64
- url,
65
- prefix,
66
- tokens
67
- } = results[index];
68
- const newUrl = prefix ? `${prefix}!${url}` : url;
69
+ const item = results[index];
70
+
71
+ if (!item) {
72
+ // eslint-disable-next-line no-continue
73
+ continue;
74
+ }
75
+
76
+ const newUrl = item.prefix ? `${item.prefix}!${item.url}` : item.url;
69
77
  const importKey = newUrl;
70
78
  let importName = imports.get(importKey);
71
79
 
@@ -85,9 +93,9 @@ const plugin = (options = {}) => {
85
93
  });
86
94
  }
87
95
 
88
- for (const [replacementIndex, token] of Object.keys(tokens).entries()) {
96
+ for (const [replacementIndex, token] of Object.keys(item.tokens).entries()) {
89
97
  const replacementName = `___CSS_LOADER_ICSS_IMPORT_${index}_REPLACEMENT_${replacementIndex}___`;
90
- const localName = tokens[token];
98
+ const localName = item.tokens[token];
91
99
  importReplacements[token] = replacementName;
92
100
  options.replacements.push({
93
101
  replacementName,
@@ -19,7 +19,7 @@ function parseNode(atRule, key) {
19
19
 
20
20
  if (atRule.raws && atRule.raws.afterName && atRule.raws.afterName.trim().length > 0) {
21
21
  const lastCommentIndex = atRule.raws.afterName.lastIndexOf("/*");
22
- const matched = atRule.raws.afterName.slice(lastCommentIndex).match(_utils.webpackIgnoreCommentRegexp);
22
+ const matched = atRule.raws.afterName.slice(lastCommentIndex).match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
23
23
 
24
24
  if (matched && matched[2] === "true") {
25
25
  return;
@@ -29,7 +29,7 @@ function parseNode(atRule, key) {
29
29
  const prevNode = atRule.prev();
30
30
 
31
31
  if (prevNode && prevNode.type === "comment") {
32
- const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
32
+ const matched = prevNode.text.match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
33
33
 
34
34
  if (matched && matched[2] === "true") {
35
35
  return;
@@ -155,12 +155,10 @@ const plugin = (options = {}) => {
155
155
  const needKeep = await options.filter(url, media);
156
156
 
157
157
  if (!needKeep) {
158
- return null;
158
+ return;
159
159
  }
160
160
  }
161
161
 
162
- atRule.remove();
163
-
164
162
  if (isRequestable) {
165
163
  const request = (0, _utils.requestify)(url, options.rootContext);
166
164
  const {
@@ -168,6 +166,13 @@ const plugin = (options = {}) => {
168
166
  context
169
167
  } = options;
170
168
  const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, url])]);
169
+
170
+ if (!resolvedUrl) {
171
+ return;
172
+ }
173
+
174
+ atRule.remove(); // eslint-disable-next-line consistent-return
175
+
171
176
  return {
172
177
  url: resolvedUrl,
173
178
  media,
@@ -176,6 +181,8 @@ const plugin = (options = {}) => {
176
181
  };
177
182
  }
178
183
 
184
+ atRule.remove(); // eslint-disable-next-line consistent-return
185
+
179
186
  return {
180
187
  url,
181
188
  media,
@@ -45,7 +45,7 @@ function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
45
45
  return;
46
46
  }
47
47
 
48
- const matched = prevValueNode.value.match(_utils.webpackIgnoreCommentRegexp);
48
+ const matched = prevValueNode.value.match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
49
49
  return matched && matched[2] === "true";
50
50
  }
51
51
 
@@ -74,7 +74,7 @@ function parseDeclaration(declaration, key, result) {
74
74
 
75
75
  if (declaration.raws && declaration.raws.between) {
76
76
  const lastCommentIndex = declaration.raws.between.lastIndexOf("/*");
77
- const matched = declaration.raws.between.slice(lastCommentIndex).match(_utils.webpackIgnoreCommentRegexp);
77
+ const matched = declaration.raws.between.slice(lastCommentIndex).match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
78
78
 
79
79
  if (matched) {
80
80
  inBetween = matched[2] === "true";
@@ -85,7 +85,7 @@ function parseDeclaration(declaration, key, result) {
85
85
  const prevNode = declaration.prev();
86
86
 
87
87
  if (prevNode && prevNode.type === "comment") {
88
- const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
88
+ const matched = prevNode.text.match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
89
89
 
90
90
  if (matched) {
91
91
  isIgnoreOnDeclaration = matched[2] === "true";
@@ -268,7 +268,7 @@ const plugin = (options = {}) => {
268
268
  const needKeep = await options.filter(url);
269
269
 
270
270
  if (!needKeep) {
271
- return null;
271
+ return;
272
272
  }
273
273
  }
274
274
 
@@ -282,18 +282,23 @@ const plugin = (options = {}) => {
282
282
  context
283
283
  } = options;
284
284
  const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, url])]);
285
+
286
+ if (!resolvedUrl) {
287
+ return;
288
+ } // eslint-disable-next-line consistent-return
289
+
290
+
285
291
  return { ...parsedDeclaration,
286
292
  url: resolvedUrl,
287
293
  hash
288
294
  };
289
295
  }));
290
- const results = await Promise.all(resolvedDeclarations);
291
296
  const urlToNameMap = new Map();
292
297
  const urlToReplacementMap = new Map();
293
298
  let hasUrlImportHelper = false;
294
299
 
295
- for (let index = 0; index <= results.length - 1; index++) {
296
- const item = results[index];
300
+ for (let index = 0; index <= resolvedDeclarations.length - 1; index++) {
301
+ const item = resolvedDeclarations[index];
297
302
 
298
303
  if (!item) {
299
304
  // eslint-disable-next-line no-continue
package/dist/utils.js CHANGED
@@ -22,7 +22,7 @@ exports.resolveRequests = resolveRequests;
22
22
  exports.isUrlRequestable = isUrlRequestable;
23
23
  exports.sort = sort;
24
24
  exports.combineRequests = combineRequests;
25
- exports.webpackIgnoreCommentRegexp = void 0;
25
+ exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
26
26
 
27
27
  var _url = require("url");
28
28
 
@@ -30,8 +30,6 @@ var _path = _interopRequireDefault(require("path"));
30
30
 
31
31
  var _loaderUtils = require("loader-utils");
32
32
 
33
- var _cssesc = _interopRequireDefault(require("cssesc"));
34
-
35
33
  var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
36
34
 
37
35
  var _postcssModulesLocalByDefault = _interopRequireDefault(require("postcss-modules-local-by-default"));
@@ -48,26 +46,137 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
48
46
  MIT License http://www.opensource.org/licenses/mit-license.php
49
47
  Author Tobias Koppers @sokra
50
48
  */
51
- const whitespace = "[\\x20\\t\\r\\n\\f]";
52
- const unescapeRegExp = new RegExp(`\\\\([\\da-f]{1,6}${whitespace}?|(${whitespace})|.)`, "ig");
53
- const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
54
- const webpackIgnoreCommentRegexp = /webpackIgnore:(\s+)?(true|false)/;
55
- exports.webpackIgnoreCommentRegexp = webpackIgnoreCommentRegexp;
49
+ const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/; // eslint-disable-next-line no-useless-escape
50
+
51
+ exports.WEBPACK_IGNORE_COMMENT_REGEXP = WEBPACK_IGNORE_COMMENT_REGEXP;
52
+ const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/;
53
+ const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
54
+
55
+ function escape(string) {
56
+ let output = "";
57
+ let counter = 0;
58
+
59
+ while (counter < string.length) {
60
+ // eslint-disable-next-line no-plusplus
61
+ const character = string.charAt(counter++);
62
+ let value; // eslint-disable-next-line no-control-regex
63
+
64
+ if (/[\t\n\f\r\x0B]/.test(character)) {
65
+ const codePoint = character.charCodeAt();
66
+ value = `\\${codePoint.toString(16).toUpperCase()} `;
67
+ } else if (character === "\\" || regexSingleEscape.test(character)) {
68
+ value = `\\${character}`;
69
+ } else {
70
+ value = character;
71
+ }
56
72
 
57
- function unescape(str) {
58
- return str.replace(unescapeRegExp, (_, escaped, escapedWhitespace) => {
59
- const high = `0x${escaped}` - 0x10000;
60
- /* eslint-disable line-comment-position */
61
- // NaN means non-codepoint
62
- // Workaround erroneous numeric interpretation of +"0x"
63
- // eslint-disable-next-line no-self-compare
64
-
65
- return high !== high || escapedWhitespace ? escaped : high < 0 ? // BMP codepoint
66
- String.fromCharCode(high + 0x10000) : // Supplemental Plane codepoint (surrogate pair)
67
- // eslint-disable-next-line no-bitwise
68
- String.fromCharCode(high >> 10 | 0xd800, high & 0x3ff | 0xdc00);
69
- /* eslint-enable line-comment-position */
73
+ output += value;
74
+ }
75
+
76
+ const firstChar = string.charAt(0);
77
+
78
+ if (/^-[-\d]/.test(output)) {
79
+ output = `\\-${output.slice(1)}`;
80
+ } else if (/\d/.test(firstChar)) {
81
+ output = `\\3${firstChar} ${output.slice(1)}`;
82
+ } // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
83
+ // since they’re redundant. Note that this is only possible if the escape
84
+ // sequence isn’t preceded by an odd number of backslashes.
85
+
86
+
87
+ output = output.replace(regexExcessiveSpaces, ($0, $1, $2) => {
88
+ if ($1 && $1.length % 2) {
89
+ // It’s not safe to remove the space, so don’t.
90
+ return $0;
91
+ } // Strip the space.
92
+
93
+
94
+ return ($1 || "") + $2;
70
95
  });
96
+ return output;
97
+ }
98
+
99
+ function gobbleHex(str) {
100
+ const lower = str.toLowerCase();
101
+ let hex = "";
102
+ let spaceTerminated = false; // eslint-disable-next-line no-undefined
103
+
104
+ for (let i = 0; i < 6 && lower[i] !== undefined; i++) {
105
+ const code = lower.charCodeAt(i); // check to see if we are dealing with a valid hex char [a-f|0-9]
106
+
107
+ const valid = code >= 97 && code <= 102 || code >= 48 && code <= 57; // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
108
+
109
+ spaceTerminated = code === 32;
110
+
111
+ if (!valid) {
112
+ break;
113
+ }
114
+
115
+ hex += lower[i];
116
+ }
117
+
118
+ if (hex.length === 0) {
119
+ // eslint-disable-next-line no-undefined
120
+ return undefined;
121
+ }
122
+
123
+ const codePoint = parseInt(hex, 16);
124
+ const isSurrogate = codePoint >= 0xd800 && codePoint <= 0xdfff; // Add special case for
125
+ // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
126
+ // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
127
+
128
+ if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10ffff) {
129
+ return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
130
+ }
131
+
132
+ return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
133
+ }
134
+
135
+ const CONTAINS_ESCAPE = /\\/;
136
+
137
+ function unescape(str) {
138
+ const needToProcess = CONTAINS_ESCAPE.test(str);
139
+
140
+ if (!needToProcess) {
141
+ return str;
142
+ }
143
+
144
+ let ret = "";
145
+
146
+ for (let i = 0; i < str.length; i++) {
147
+ if (str[i] === "\\") {
148
+ const gobbled = gobbleHex(str.slice(i + 1, i + 7)); // eslint-disable-next-line no-undefined
149
+
150
+ if (gobbled !== undefined) {
151
+ ret += gobbled[0];
152
+ i += gobbled[1]; // eslint-disable-next-line no-continue
153
+
154
+ continue;
155
+ } // Retain a pair of \\ if double escaped `\\\\`
156
+ // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
157
+
158
+
159
+ if (str[i + 1] === "\\") {
160
+ ret += "\\";
161
+ i += 1; // eslint-disable-next-line no-continue
162
+
163
+ continue;
164
+ } // if \\ is at the end of the string retain it
165
+ // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
166
+
167
+
168
+ if (str.length === i + 1) {
169
+ ret += str[i];
170
+ } // eslint-disable-next-line no-continue
171
+
172
+
173
+ continue;
174
+ }
175
+
176
+ ret += str[i];
177
+ }
178
+
179
+ return ret;
71
180
  }
72
181
 
73
182
  function normalizePath(file) {
@@ -80,10 +189,9 @@ const filenameReservedRegex = /[<>:"/\\|?*]/g; // eslint-disable-next-line no-co
80
189
  const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
81
190
 
82
191
  function escapeLocalIdent(localident) {
83
- return (0, _cssesc.default)(localident // For `[hash]` placeholder
84
- .replace(/^((-?[0-9])|--)/, "_$1").replace(filenameReservedRegex, "-").replace(reControlChars, "-").replace(/\./g, "-"), {
85
- isIdentifier: true
86
- });
192
+ // TODO simplify in the next major release
193
+ return escape(localident // For `[hash]` placeholder
194
+ .replace(/^((-?[0-9])|--)/, "_$1").replace(filenameReservedRegex, "-").replace(reControlChars, "-").replace(/\./g, "-"));
87
195
  }
88
196
 
89
197
  function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
@@ -100,6 +208,8 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
100
208
  return (0, _loaderUtils.interpolateName)(loaderContext, localIdentName, options);
101
209
  }
102
210
 
211
+ const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
212
+
103
213
  function normalizeUrl(url, isStringValue) {
104
214
  let normalizedUrl = url.replace(/^( |\t\n|\r\n|\r|\f)*/g, "").replace(/( |\t\n|\r\n|\r|\f)*$/g, "");
105
215
 
@@ -107,11 +217,23 @@ function normalizeUrl(url, isStringValue) {
107
217
  normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, "");
108
218
  }
109
219
 
110
- if (matchNativeWin32Path.test(url)) {
111
- return decodeURI(normalizedUrl);
220
+ if (NATIVE_WIN32_PATH.test(url)) {
221
+ try {
222
+ normalizedUrl = decodeURI(normalizedUrl);
223
+ } catch (error) {// Ignore
224
+ }
225
+
226
+ return normalizedUrl;
227
+ }
228
+
229
+ normalizedUrl = unescape(normalizedUrl);
230
+
231
+ try {
232
+ normalizedUrl = decodeURI(normalizedUrl);
233
+ } catch (error) {// Ignore
112
234
  }
113
235
 
114
- return decodeURI(unescape(normalizedUrl));
236
+ return normalizedUrl;
115
237
  }
116
238
 
117
239
  function requestify(url, rootContext) {
@@ -629,7 +751,7 @@ function isUrlRequestable(url) {
629
751
  } // Absolute URLs
630
752
 
631
753
 
632
- if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !matchNativeWin32Path.test(url)) {
754
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !NATIVE_WIN32_PATH.test(url)) {
633
755
  return false;
634
756
  } // `#` URLs
635
757
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "5.2.0",
3
+ "version": "5.2.4",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -43,32 +43,31 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "camelcase": "^6.2.0",
46
- "cssesc": "^3.0.0",
47
46
  "icss-utils": "^5.1.0",
48
47
  "loader-utils": "^2.0.0",
49
- "postcss": "^8.2.8",
48
+ "postcss": "^8.2.10",
50
49
  "postcss-modules-extract-imports": "^3.0.0",
51
50
  "postcss-modules-local-by-default": "^4.0.0",
52
51
  "postcss-modules-scope": "^3.0.0",
53
52
  "postcss-modules-values": "^4.0.0",
54
53
  "postcss-value-parser": "^4.1.0",
55
54
  "schema-utils": "^3.0.0",
56
- "semver": "^7.3.4"
55
+ "semver": "^7.3.5"
57
56
  },
58
57
  "devDependencies": {
59
- "@babel/cli": "^7.13.10",
60
- "@babel/core": "^7.13.10",
61
- "@babel/preset-env": "^7.13.10",
62
- "@commitlint/cli": "^12.0.1",
63
- "@commitlint/config-conventional": "^12.0.1",
58
+ "@babel/cli": "^7.13.14",
59
+ "@babel/core": "^7.13.15",
60
+ "@babel/preset-env": "^7.13.15",
61
+ "@commitlint/cli": "^12.1.1",
62
+ "@commitlint/config-conventional": "^12.1.1",
64
63
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
65
64
  "babel-jest": "^26.6.3",
66
65
  "cross-env": "^7.0.3",
67
66
  "del": "^6.0.0",
68
67
  "del-cli": "^3.0.1",
69
68
  "es-check": "^5.2.3",
70
- "eslint": "^7.22.0",
71
- "eslint-config-prettier": "^8.1.0",
69
+ "eslint": "^7.24.0",
70
+ "eslint-config-prettier": "^8.2.0",
72
71
  "eslint-plugin-import": "^2.22.1",
73
72
  "file-loader": "^6.2.0",
74
73
  "husky": "^4.3.8",
@@ -76,21 +75,21 @@
76
75
  "less": "^4.1.1",
77
76
  "less-loader": "^7.1.0",
78
77
  "lint-staged": "^10.5.4",
79
- "memfs": "^3.2.0",
80
- "mini-css-extract-plugin": "^1.3.9",
78
+ "memfs": "^3.2.2",
79
+ "mini-css-extract-plugin": "^1.4.1",
81
80
  "npm-run-all": "^4.1.5",
82
81
  "postcss-loader": "^4.0.4",
83
82
  "postcss-preset-env": "^6.7.0",
84
83
  "prettier": "^2.1.2",
85
84
  "sass": "^1.32.8",
86
85
  "sass-loader": "^10.1.0",
87
- "standard-version": "^9.1.1",
86
+ "standard-version": "^9.2.0",
88
87
  "strip-ansi": "^6.0.0",
89
88
  "style-loader": "^2.0.0",
90
89
  "stylus": "^0.54.8",
91
90
  "stylus-loader": "^4.3.0",
92
91
  "url-loader": "^4.1.1",
93
- "webpack": "^5.26.0"
92
+ "webpack": "^5.34.0"
94
93
  },
95
94
  "keywords": [
96
95
  "webpack",