Skip to content

Commit c1ca32f

Browse files
authoredNov 5, 2020
test: @ character (#1224)
1 parent 6412dd5 commit c1ca32f

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed
 

‎src/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const filenameReservedRegex = /[<>:"/\\|?*]/g;
4949
// eslint-disable-next-line no-control-regex
5050
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
5151

52-
function escapeLocalident(localident) {
52+
function escapeLocalIdent(localident) {
5353
return cssesc(
5454
localident
5555
// For `[hash]` placeholder
@@ -330,13 +330,13 @@ function getModulesPlugins(options, loaderContext) {
330330
}
331331
);
332332

333-
return escapeLocalident(localIdent).replace(
333+
return escapeLocalIdent(localIdent).replace(
334334
/\\\[local\\]/gi,
335335
exportName
336336
);
337337
}
338338

339-
return escapeLocalident(localIdent);
339+
return escapeLocalIdent(localIdent);
340340
},
341341
exportGlobals: options.modules.exportGlobals,
342342
}),

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

+30
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,36 @@ body {
42084208

42094209
exports[`"modules" option should work with "url": warnings 1`] = `Array []`;
42104210

4211+
exports[`"modules" option should work with \`@\` character in scoped packages: errors 1`] = `Array []`;
4212+
4213+
exports[`"modules" option should work with \`@\` character in scoped packages: module 1`] = `
4214+
"// Imports
4215+
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../../../src/runtime/api.js\\";
4216+
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]});
4217+
// Module
4218+
___CSS_LOADER_EXPORT___.push([module.id, \\".modules-issue-1223-\\\\\\\\@foo-bar--myClass {\\\\n color: red;\\\\n}\\", \\"\\"]);
4219+
// Exports
4220+
___CSS_LOADER_EXPORT___.locals = {
4221+
\\"myClass\\": \\"modules-issue-1223-@foo-bar--myClass\\"
4222+
};
4223+
export default ___CSS_LOADER_EXPORT___;
4224+
"
4225+
`;
4226+
4227+
exports[`"modules" option should work with \`@\` character in scoped packages: result 1`] = `
4228+
Array [
4229+
Array [
4230+
"./modules/issue-1223/@foo/bar/index.module.css",
4231+
".modules-issue-1223-\\\\@foo-bar--myClass {
4232+
color: red;
4233+
}",
4234+
"",
4235+
],
4236+
]
4237+
`;
4238+
4239+
exports[`"modules" option should work with \`@\` character in scoped packages: warnings 1`] = `Array []`;
4240+
42114241
exports[`"modules" option should work with a modules.auto Function that returns "false": errors 1`] = `Array []`;
42124242

42134243
exports[`"modules" option should work with a modules.auto Function that returns "false": module 1`] = `
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.myClass {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './@foo/bar/index.module.css';
2+
3+
__export__ = css;
4+
5+
export default css;

‎test/modules-option.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -1455,4 +1455,22 @@ describe('"modules" option', () => {
14551455
expect(getWarnings(stats)).toMatchSnapshot('warnings');
14561456
expect(getErrors(stats)).toMatchSnapshot('errors');
14571457
});
1458+
1459+
it('should work with `@` character in scoped packages', async () => {
1460+
const compiler = getCompiler('./modules/issue-1223/issue-1223.js', {
1461+
modules: {
1462+
localIdentName: '[path]-[local]',
1463+
},
1464+
});
1465+
const stats = await compile(compiler);
1466+
1467+
expect(
1468+
getModuleSource('./modules/issue-1223/@foo/bar/index.module.css', stats)
1469+
).toMatchSnapshot('module');
1470+
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
1471+
'result'
1472+
);
1473+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
1474+
expect(getErrors(stats)).toMatchSnapshot('errors');
1475+
});
14581476
});

0 commit comments

Comments
 (0)