Skip to content

Commit

Permalink
test: @ character (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Nov 5, 2020
1 parent 6412dd5 commit c1ca32f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const filenameReservedRegex = /[<>:"/\\|?*]/g;
// eslint-disable-next-line no-control-regex
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;

function escapeLocalident(localident) {
function escapeLocalIdent(localident) {
return cssesc(
localident
// For `[hash]` placeholder
Expand Down Expand Up @@ -330,13 +330,13 @@ function getModulesPlugins(options, loaderContext) {
}
);

return escapeLocalident(localIdent).replace(
return escapeLocalIdent(localIdent).replace(
/\\\[local\\]/gi,
exportName
);
}

return escapeLocalident(localIdent);
return escapeLocalIdent(localIdent);
},
exportGlobals: options.modules.exportGlobals,
}),
Expand Down
30 changes: 30 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4208,6 +4208,36 @@ body {

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

exports[`"modules" option should work with \`@\` character in scoped packages: errors 1`] = `Array []`;

exports[`"modules" option should work with \`@\` character in scoped packages: module 1`] = `
"// Imports
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../../../src/runtime/api.js\\";
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]});
// Module
___CSS_LOADER_EXPORT___.push([module.id, \\".modules-issue-1223-\\\\\\\\@foo-bar--myClass {\\\\n color: red;\\\\n}\\", \\"\\"]);
// Exports
___CSS_LOADER_EXPORT___.locals = {
\\"myClass\\": \\"modules-issue-1223-@foo-bar--myClass\\"
};
export default ___CSS_LOADER_EXPORT___;
"
`;

exports[`"modules" option should work with \`@\` character in scoped packages: result 1`] = `
Array [
Array [
"./modules/issue-1223/@foo/bar/index.module.css",
".modules-issue-1223-\\\\@foo-bar--myClass {
color: red;
}",
"",
],
]
`;

exports[`"modules" option should work with \`@\` character in scoped packages: warnings 1`] = `Array []`;

exports[`"modules" option should work with a modules.auto Function that returns "false": errors 1`] = `Array []`;

exports[`"modules" option should work with a modules.auto Function that returns "false": module 1`] = `
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/modules/issue-1223/@foo/bar/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.myClass {
color: red;
}
5 changes: 5 additions & 0 deletions test/fixtures/modules/issue-1223/issue-1223.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import css from './@foo/bar/index.module.css';

__export__ = css;

export default css;
18 changes: 18 additions & 0 deletions test/modules-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,22 @@ describe('"modules" option', () => {
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should work with `@` character in scoped packages', async () => {
const compiler = getCompiler('./modules/issue-1223/issue-1223.js', {
modules: {
localIdentName: '[path]-[local]',
},
});
const stats = await compile(compiler);

expect(
getModuleSource('./modules/issue-1223/@foo/bar/index.module.css', stats)
).toMatchSnapshot('module');
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
'result'
);
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});
});

0 comments on commit c1ca32f

Please sign in to comment.