Skip to content

Commit f599c70

Browse files
authoredDec 5, 2018
fix: broken unucode characters (#850)
1 parent 1e551f3 commit f599c70

File tree

6 files changed

+793
-2211
lines changed

6 files changed

+793
-2211
lines changed
 

‎package-lock.json

+370-2,178
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lodash": "^4.17.11",
4444
"postcss": "^7.0.6",
4545
"postcss-modules-extract-imports": "^2.0.0",
46-
"postcss-modules-local-by-default": "^2.0.1",
46+
"postcss-modules-local-by-default": "^2.0.2",
4747
"postcss-modules-scope": "^2.0.0",
4848
"postcss-modules-values": "^2.0.0",
4949
"postcss-value-parser": "^3.3.0",

‎test/__snapshots__/loader.test.js.snap

+373-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`loader should compile with \`css\` entry point: api 1`] = `
3+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`global\`): api 1`] = `
44
"/*
55
MIT License http://www.opensource.org/licenses/mit-license.php
66
Author Tobias Koppers @sokra
@@ -86,9 +86,9 @@ function toComment(sourceMap) {
8686
"
8787
`;
8888

89-
exports[`loader should compile with \`css\` entry point: errors 1`] = `Array []`;
89+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`global\`): errors 1`] = `Array []`;
9090

91-
exports[`loader should compile with \`css\` entry point: escape 1`] = `
91+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`global\`): escape 1`] = `
9292
"module.exports = function escape(url) {
9393
if (typeof url !== 'string') {
9494
return url;
@@ -109,7 +109,7 @@ exports[`loader should compile with \`css\` entry point: escape 1`] = `
109109
"
110110
`;
111111

112-
exports[`loader should compile with \`css\` entry point: module (evaluated) 1`] = `
112+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`global\`): module (evaluated) 1`] = `
113113
Array [
114114
Array [
115115
null,
@@ -150,17 +150,374 @@ Array [
150150
}
151151
}
152152
153-
/*
154-
Need uncomment after resolve https://github.com/css-modules/postcss-modules-local-by-default/issues/108
153+
.class {
154+
content: \\"\\\\2193\\";
155+
content: \\"\\\\2193\\\\2193\\";
156+
content: \\"\\\\2193 \\\\2193\\";
157+
content: \\"\\\\2193\\\\2193\\\\2193\\";
158+
content: \\"\\\\2193 \\\\2193 \\\\2193\\";
159+
}
160+
",
161+
"",
162+
],
163+
]
164+
`;
165+
166+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`global\`): module 1`] = `
167+
"var escape = require(\\"../../src/runtime/escape.js\\");
168+
exports = module.exports = require(\\"../../src/runtime/api.js\\")(false);
169+
// imports
170+
exports.i(require(\\"-!../../src/index.js??ref--4-0!./imported.css\\"), \\"\\");
171+
172+
// module
173+
exports.push([module.id, \\"@charset \\\\\\"UTF-8\\\\\\";\\\\n\\\\n/* Comment */\\\\n\\\\n.class {\\\\n color: red;\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n.class-duplicate-url {\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n:root {\\\\n --foo: 1px;\\\\n --bar: 2px;\\\\n}\\\\n\\\\n.class { a: b c d; }\\\\n\\\\n.two {}\\\\n\\\\n.u-m\\\\\\\\+ { a: b c d; }\\\\n\\\\n.class { content: \\\\\\"\\\\\\\\F10C\\\\\\" }\\\\n\\\\n@media only screen and (max-width: 600px) {\\\\n body {\\\\n background-color: lightblue;\\\\n }\\\\n}\\\\n\\\\n.class {\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n}\\\\n\\", \\"\\"]);
174+
175+
// exports
176+
"
177+
`;
178+
179+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`global\`): warnings 1`] = `Array []`;
180+
181+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`local\`): api 1`] = `
182+
"/*
183+
MIT License http://www.opensource.org/licenses/mit-license.php
184+
Author Tobias Koppers @sokra
185+
*/
186+
// css base code, injected by the css-loader
187+
module.exports = function(useSourceMap) {
188+
var list = [];
189+
190+
// return the list of modules as css string
191+
list.toString = function toString() {
192+
return this.map(function(item) {
193+
var content = cssWithMappingToString(item, useSourceMap);
194+
if (item[2]) {
195+
return '@media ' + item[2] + '{' + content + '}';
196+
} else {
197+
return content;
198+
}
199+
}).join('');
200+
};
201+
202+
// import a list of modules into the list
203+
list.i = function(modules, mediaQuery) {
204+
if (typeof modules === 'string') {
205+
modules = [[null, modules, '']];
206+
}
207+
var alreadyImportedModules = {};
208+
for (var i = 0; i < this.length; i++) {
209+
var id = this[i][0];
210+
if (id != null) {
211+
alreadyImportedModules[id] = true;
212+
}
213+
}
214+
for (i = 0; i < modules.length; i++) {
215+
var item = modules[i];
216+
// skip already imported module
217+
// this implementation is not 100% perfect for weird media query combinations
218+
// when a module is imported multiple times with different media queries.
219+
// I hope this will never occur (Hey this way we have smaller bundles)
220+
if (item[0] == null || !alreadyImportedModules[item[0]]) {
221+
if (mediaQuery && !item[2]) {
222+
item[2] = mediaQuery;
223+
} else if (mediaQuery) {
224+
item[2] = '(' + item[2] + ') and (' + mediaQuery + ')';
225+
}
226+
list.push(item);
227+
}
228+
}
229+
};
230+
return list;
231+
};
232+
233+
function cssWithMappingToString(item, useSourceMap) {
234+
var content = item[1] || '';
235+
var cssMapping = item[3];
236+
if (!cssMapping) {
237+
return content;
238+
}
239+
240+
if (useSourceMap && typeof btoa === 'function') {
241+
var sourceMapping = toComment(cssMapping);
242+
var sourceURLs = cssMapping.sources.map(function(source) {
243+
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */';
244+
});
245+
246+
return [content]
247+
.concat(sourceURLs)
248+
.concat([sourceMapping])
249+
.join('\\\\n');
250+
}
251+
252+
return [content].join('\\\\n');
253+
}
254+
255+
// Adapted from convert-source-map (MIT)
256+
function toComment(sourceMap) {
257+
// eslint-disable-next-line no-undef
258+
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
259+
var data =
260+
'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
261+
262+
return '/*# ' + data + ' */';
263+
}
264+
"
265+
`;
266+
267+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`local\`): errors 1`] = `Array []`;
268+
269+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`local\`): escape 1`] = `
270+
"module.exports = function escape(url) {
271+
if (typeof url !== 'string') {
272+
return url;
273+
}
274+
275+
// If url is already wrapped in quotes, remove them
276+
if (/^['\\"].*['\\"]$/.test(url)) {
277+
url = url.slice(1, -1);
278+
}
279+
// Should url be wrapped?
280+
// See https://drafts.csswg.org/css-values-3/#urls
281+
if (/[\\"'() \\\\t\\\\n]/.test(url)) {
282+
return '\\"' + url.replace(/\\"/g, '\\\\\\\\\\"').replace(/\\\\n/g, '\\\\\\\\n') + '\\"';
283+
}
284+
285+
return url;
286+
};
287+
"
288+
`;
289+
290+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`local\`): module (evaluated) 1`] = `
291+
Array [
292+
Array [
293+
null,
294+
"nothing",
295+
"",
296+
],
297+
Array [
298+
1,
299+
"@charset \\"UTF-8\\";
300+
301+
/* Comment */
302+
303+
._1PSZ4tK4URrenXyNSoawrx {
304+
color: red;
305+
background: url(nothing);
306+
}
307+
308+
._3YYoEr128Gk7ZgfRycu4tr {
309+
background: url(nothing);
310+
}
311+
312+
:root {
313+
--foo: 1px;
314+
--bar: 2px;
315+
}
316+
317+
._1PSZ4tK4URrenXyNSoawrx { a: b c d; }
318+
319+
._1LWD9ZV4XMmN23IPiMONS3 {}
320+
321+
._3i3CD1fyX8bvzRt1H0IV-f { a: b c d; }
322+
323+
._1PSZ4tK4URrenXyNSoawrx { content: \\"\\\\F10C\\" }
324+
325+
@media only screen and (max-width: 600px) {
326+
body {
327+
background-color: lightblue;
328+
}
329+
}
330+
331+
._1PSZ4tK4URrenXyNSoawrx {
332+
content: \\"\\\\2193\\";
333+
content: \\"\\\\2193\\\\2193\\";
334+
content: \\"\\\\2193 \\\\2193\\";
335+
content: \\"\\\\2193\\\\2193\\\\2193\\";
336+
content: \\"\\\\2193 \\\\2193 \\\\2193\\";
337+
}
338+
",
339+
"",
340+
],
341+
]
342+
`;
343+
344+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`local\`): module 1`] = `
345+
"var escape = require(\\"../../src/runtime/escape.js\\");
346+
exports = module.exports = require(\\"../../src/runtime/api.js\\")(false);
347+
// imports
348+
exports.i(require(\\"-!../../src/index.js??ref--4-0!./imported.css\\"), \\"\\");
349+
350+
// module
351+
exports.push([module.id, \\"@charset \\\\\\"UTF-8\\\\\\";\\\\n\\\\n/* Comment */\\\\n\\\\n._1PSZ4tK4URrenXyNSoawrx {\\\\n color: red;\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n._3YYoEr128Gk7ZgfRycu4tr {\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n:root {\\\\n --foo: 1px;\\\\n --bar: 2px;\\\\n}\\\\n\\\\n._1PSZ4tK4URrenXyNSoawrx { a: b c d; }\\\\n\\\\n._1LWD9ZV4XMmN23IPiMONS3 {}\\\\n\\\\n._3i3CD1fyX8bvzRt1H0IV-f { a: b c d; }\\\\n\\\\n._1PSZ4tK4URrenXyNSoawrx { content: \\\\\\"\\\\\\\\F10C\\\\\\" }\\\\n\\\\n@media only screen and (max-width: 600px) {\\\\n body {\\\\n background-color: lightblue;\\\\n }\\\\n}\\\\n\\\\n._1PSZ4tK4URrenXyNSoawrx {\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n}\\\\n\\", \\"\\"]);
352+
353+
// exports
354+
exports.locals = {
355+
\\"class\\": \\"_1PSZ4tK4URrenXyNSoawrx\\",
356+
\\"class-duplicate-url\\": \\"_3YYoEr128Gk7ZgfRycu4tr\\",
357+
\\"two\\": \\"_1LWD9ZV4XMmN23IPiMONS3\\",
358+
\\"u-m+\\": \\"_3i3CD1fyX8bvzRt1H0IV-f\\"
359+
};"
360+
`;
361+
362+
exports[`loader should compile with \`css\` entry point (with \`modules\` and scope \`local\`): warnings 1`] = `Array []`;
363+
364+
exports[`loader should compile with \`css\` entry point: api 1`] = `
365+
"/*
366+
MIT License http://www.opensource.org/licenses/mit-license.php
367+
Author Tobias Koppers @sokra
368+
*/
369+
// css base code, injected by the css-loader
370+
module.exports = function(useSourceMap) {
371+
var list = [];
372+
373+
// return the list of modules as css string
374+
list.toString = function toString() {
375+
return this.map(function(item) {
376+
var content = cssWithMappingToString(item, useSourceMap);
377+
if (item[2]) {
378+
return '@media ' + item[2] + '{' + content + '}';
379+
} else {
380+
return content;
381+
}
382+
}).join('');
383+
};
384+
385+
// import a list of modules into the list
386+
list.i = function(modules, mediaQuery) {
387+
if (typeof modules === 'string') {
388+
modules = [[null, modules, '']];
389+
}
390+
var alreadyImportedModules = {};
391+
for (var i = 0; i < this.length; i++) {
392+
var id = this[i][0];
393+
if (id != null) {
394+
alreadyImportedModules[id] = true;
395+
}
396+
}
397+
for (i = 0; i < modules.length; i++) {
398+
var item = modules[i];
399+
// skip already imported module
400+
// this implementation is not 100% perfect for weird media query combinations
401+
// when a module is imported multiple times with different media queries.
402+
// I hope this will never occur (Hey this way we have smaller bundles)
403+
if (item[0] == null || !alreadyImportedModules[item[0]]) {
404+
if (mediaQuery && !item[2]) {
405+
item[2] = mediaQuery;
406+
} else if (mediaQuery) {
407+
item[2] = '(' + item[2] + ') and (' + mediaQuery + ')';
408+
}
409+
list.push(item);
410+
}
411+
}
412+
};
413+
return list;
414+
};
415+
416+
function cssWithMappingToString(item, useSourceMap) {
417+
var content = item[1] || '';
418+
var cssMapping = item[3];
419+
if (!cssMapping) {
420+
return content;
421+
}
422+
423+
if (useSourceMap && typeof btoa === 'function') {
424+
var sourceMapping = toComment(cssMapping);
425+
var sourceURLs = cssMapping.sources.map(function(source) {
426+
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */';
427+
});
428+
429+
return [content]
430+
.concat(sourceURLs)
431+
.concat([sourceMapping])
432+
.join('\\\\n');
433+
}
434+
435+
return [content].join('\\\\n');
436+
}
437+
438+
// Adapted from convert-source-map (MIT)
439+
function toComment(sourceMap) {
440+
// eslint-disable-next-line no-undef
441+
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
442+
var data =
443+
'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
444+
445+
return '/*# ' + data + ' */';
446+
}
447+
"
448+
`;
449+
450+
exports[`loader should compile with \`css\` entry point: errors 1`] = `Array []`;
451+
452+
exports[`loader should compile with \`css\` entry point: escape 1`] = `
453+
"module.exports = function escape(url) {
454+
if (typeof url !== 'string') {
455+
return url;
456+
}
457+
458+
// If url is already wrapped in quotes, remove them
459+
if (/^['\\"].*['\\"]$/.test(url)) {
460+
url = url.slice(1, -1);
461+
}
462+
// Should url be wrapped?
463+
// See https://drafts.csswg.org/css-values-3/#urls
464+
if (/[\\"'() \\\\t\\\\n]/.test(url)) {
465+
return '\\"' + url.replace(/\\"/g, '\\\\\\\\\\"').replace(/\\\\n/g, '\\\\\\\\n') + '\\"';
466+
}
467+
468+
return url;
469+
};
470+
"
471+
`;
472+
473+
exports[`loader should compile with \`css\` entry point: module (evaluated) 1`] = `
474+
Array [
475+
Array [
476+
null,
477+
"nothing",
478+
"",
479+
],
480+
Array [
481+
1,
482+
"@charset \\"UTF-8\\";
483+
484+
/* Comment */
155485
156486
.class {
157-
content: \\\\\\"\\\\\\\\f10C\\\\\\"
487+
color: red;
488+
background: url(nothing);
489+
}
490+
491+
.class-duplicate-url {
492+
background: url(nothing);
493+
}
494+
495+
:root {
496+
--foo: 1px;
497+
--bar: 2px;
498+
}
499+
500+
.class { a: b c d; }
501+
502+
.two {}
503+
504+
.u-m\\\\+ { a: b c d; }
505+
506+
.class { content: \\"\\\\F10C\\" }
507+
508+
@media only screen and (max-width: 600px) {
509+
body {
510+
background-color: lightblue;
511+
}
158512
}
159513
160514
.class {
161-
content: \\\\\\"\\\\\\\\F10C \\\\\\\\F10D\\\\\\"
515+
content: \\"\\\\2193\\";
516+
content: \\"\\\\2193\\\\2193\\";
517+
content: \\"\\\\2193 \\\\2193\\";
518+
content: \\"\\\\2193\\\\2193\\\\2193\\";
519+
content: \\"\\\\2193 \\\\2193 \\\\2193\\";
162520
}
163-
*/
164521
",
165522
"",
166523
],
@@ -174,7 +531,7 @@ exports = module.exports = require(\\"../../src/runtime/api.js\\")(false);
174531
exports.i(require(\\"-!../../src/index.js??ref--4-0!./imported.css\\"), \\"\\");
175532
176533
// module
177-
exports.push([module.id, \\"@charset \\\\\\"UTF-8\\\\\\";\\\\n\\\\n/* Comment */\\\\n\\\\n.class {\\\\n color: red;\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n.class-duplicate-url {\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n:root {\\\\n --foo: 1px;\\\\n --bar: 2px;\\\\n}\\\\n\\\\n.class { a: b c d; }\\\\n\\\\n.two {}\\\\n\\\\n.u-m\\\\\\\\+ { a: b c d; }\\\\n\\\\n.class { content: \\\\\\"\\\\\\\\F10C\\\\\\" }\\\\n\\\\n@media only screen and (max-width: 600px) {\\\\n body {\\\\n background-color: lightblue;\\\\n }\\\\n}\\\\n\\\\n/*\\\\nNeed uncomment after resolve https://github.com/css-modules/postcss-modules-local-by-default/issues/108\\\\n\\\\n.class {\\\\n content: \\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\f10C\\\\\\\\\\\\\\"\\\\n}\\\\n\\\\n.class {\\\\n content: \\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\F10C \\\\\\\\\\\\\\\\F10D\\\\\\\\\\\\\\"\\\\n}\\\\n*/\\\\n\\", \\"\\"]);
534+
exports.push([module.id, \\"@charset \\\\\\"UTF-8\\\\\\";\\\\n\\\\n/* Comment */\\\\n\\\\n.class {\\\\n color: red;\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n.class-duplicate-url {\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n:root {\\\\n --foo: 1px;\\\\n --bar: 2px;\\\\n}\\\\n\\\\n.class { a: b c d; }\\\\n\\\\n.two {}\\\\n\\\\n.u-m\\\\\\\\+ { a: b c d; }\\\\n\\\\n.class { content: \\\\\\"\\\\\\\\F10C\\\\\\" }\\\\n\\\\n@media only screen and (max-width: 600px) {\\\\n body {\\\\n background-color: lightblue;\\\\n }\\\\n}\\\\n\\\\n.class {\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n}\\\\n\\", \\"\\"]);
178535
179536
// exports
180537
"
@@ -332,17 +689,13 @@ Array [
332689
}
333690
}
334691
335-
/*
336-
Need uncomment after resolve https://github.com/css-modules/postcss-modules-local-by-default/issues/108
337-
338692
.class {
339-
content: \\\\\\"\\\\\\\\f10C\\\\\\"
693+
content: \\"\\\\2193\\";
694+
content: \\"\\\\2193\\\\2193\\";
695+
content: \\"\\\\2193 \\\\2193\\";
696+
content: \\"\\\\2193\\\\2193\\\\2193\\";
697+
content: \\"\\\\2193 \\\\2193 \\\\2193\\";
340698
}
341-
342-
.class {
343-
content: \\\\\\"\\\\\\\\F10C \\\\\\\\F10D\\\\\\"
344-
}
345-
*/
346699
",
347700
"",
348701
],
@@ -356,7 +709,7 @@ exports = module.exports = require(\\"../../src/runtime/api.js\\")(false);
356709
exports.i(require(\\"-!../../src/index.js??ref--4-0!./imported.css\\"), \\"\\");
357710
358711
// module
359-
exports.push([module.id, \\"@charset \\\\\\"UTF-8\\\\\\";\\\\n\\\\n/* Comment */\\\\n\\\\n.class {\\\\n color: red;\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n.class-duplicate-url {\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n:root {\\\\n --foo: 1px;\\\\n --bar: 2px;\\\\n}\\\\n\\\\n.class { a: b c d; }\\\\n\\\\n.two {}\\\\n\\\\n.u-m\\\\\\\\+ { a: b c d; }\\\\n\\\\n.class { content: \\\\\\"\\\\\\\\F10C\\\\\\" }\\\\n\\\\n@media only screen and (max-width: 600px) {\\\\n body {\\\\n background-color: lightblue;\\\\n }\\\\n}\\\\n\\\\n/*\\\\nNeed uncomment after resolve https://github.com/css-modules/postcss-modules-local-by-default/issues/108\\\\n\\\\n.class {\\\\n content: \\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\f10C\\\\\\\\\\\\\\"\\\\n}\\\\n\\\\n.class {\\\\n content: \\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\F10C \\\\\\\\\\\\\\\\F10D\\\\\\\\\\\\\\"\\\\n}\\\\n*/\\\\n\\", \\"\\"]);
712+
exports.push([module.id, \\"@charset \\\\\\"UTF-8\\\\\\";\\\\n\\\\n/* Comment */\\\\n\\\\n.class {\\\\n color: red;\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n.class-duplicate-url {\\\\n background: url(\\" + escape(require(\\"./url/img.png\\")) + \\");\\\\n}\\\\n\\\\n:root {\\\\n --foo: 1px;\\\\n --bar: 2px;\\\\n}\\\\n\\\\n.class { a: b c d; }\\\\n\\\\n.two {}\\\\n\\\\n.u-m\\\\\\\\+ { a: b c d; }\\\\n\\\\n.class { content: \\\\\\"\\\\\\\\F10C\\\\\\" }\\\\n\\\\n@media only screen and (max-width: 600px) {\\\\n body {\\\\n background-color: lightblue;\\\\n }\\\\n}\\\\n\\\\n.class {\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193\\\\\\\\2193\\\\\\\\2193\\\\\\";\\\\n content: \\\\\\"\\\\\\\\2193 \\\\\\\\2193 \\\\\\\\2193\\\\\\";\\\\n}\\\\n\\", \\"\\"]);
360713
361714
// exports
362715
"

‎test/__snapshots__/url-option.test.js.snap

+12-3
Large diffs are not rendered by default.

‎test/fixtures/basic.css

+5-9
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@
3232
}
3333
}
3434

35-
/*
36-
Need uncomment after resolve https://github.com/css-modules/postcss-modules-local-by-default/issues/108
37-
38-
.class {
39-
content: \"\\f10C\"
40-
}
41-
4235
.class {
43-
content: \"\\F10C \\F10D\"
36+
content: "\2193";
37+
content: "\2193\2193";
38+
content: "\2193 \2193";
39+
content: "\2193\2193\2193";
40+
content: "\2193 \2193 \2193";
4441
}
45-
*/

‎test/loader.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@ describe('loader', () => {
3535
expect(stats.compilation.errors).toMatchSnapshot('errors');
3636
});
3737

38+
it('should compile with `css` entry point (with `modules` and scope `local`)', async () => {
39+
const config = { loader: { options: { modules: 'local' } } };
40+
const stats = await webpack('basic.css', config);
41+
const { modules } = stats.toJson();
42+
const [, runtime, escape, module] = modules;
43+
44+
expect(runtime.source).toMatchSnapshot('api');
45+
expect(escape.source).toMatchSnapshot('escape');
46+
expect(module.source).toMatchSnapshot('module');
47+
expect(evaluated(module.source, modules)).toMatchSnapshot(
48+
'module (evaluated)'
49+
);
50+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
51+
expect(stats.compilation.errors).toMatchSnapshot('errors');
52+
});
53+
54+
it('should compile with `css` entry point (with `modules` and scope `global`)', async () => {
55+
const config = { loader: { options: { modules: 'global' } } };
56+
const stats = await webpack('basic.css', config);
57+
const { modules } = stats.toJson();
58+
const [, runtime, escape, module] = modules;
59+
60+
expect(runtime.source).toMatchSnapshot('api');
61+
expect(escape.source).toMatchSnapshot('escape');
62+
expect(module.source).toMatchSnapshot('module');
63+
expect(evaluated(module.source, modules)).toMatchSnapshot(
64+
'module (evaluated)'
65+
);
66+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
67+
expect(stats.compilation.errors).toMatchSnapshot('errors');
68+
});
69+
3870
it('should compile with empty css entry point', async () => {
3971
const testId = './empty.css';
4072
const stats = await webpack(testId);

0 commit comments

Comments
 (0)
Please sign in to comment.