From c1ca32f068a989060f667b7ad5c81df1a0a21f10 Mon Sep 17 00:00:00 2001 From: Alexander Akait Date: Thu, 5 Nov 2020 16:54:34 +0300 Subject: [PATCH] test: `@` character (#1224) --- src/utils.js | 6 ++-- .../__snapshots__/modules-option.test.js.snap | 30 +++++++++++++++++++ .../issue-1223/@foo/bar/index.module.css | 3 ++ .../fixtures/modules/issue-1223/issue-1223.js | 5 ++++ test/modules-option.test.js | 18 +++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/modules/issue-1223/@foo/bar/index.module.css create mode 100644 test/fixtures/modules/issue-1223/issue-1223.js diff --git a/src/utils.js b/src/utils.js index edfcb7ca..2410eb10 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 @@ -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, }), diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index c2b4c4b5..db80b85c 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -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`] = ` diff --git a/test/fixtures/modules/issue-1223/@foo/bar/index.module.css b/test/fixtures/modules/issue-1223/@foo/bar/index.module.css new file mode 100644 index 00000000..58869fbb --- /dev/null +++ b/test/fixtures/modules/issue-1223/@foo/bar/index.module.css @@ -0,0 +1,3 @@ +.myClass { + color: red; +} \ No newline at end of file diff --git a/test/fixtures/modules/issue-1223/issue-1223.js b/test/fixtures/modules/issue-1223/issue-1223.js new file mode 100644 index 00000000..a448802f --- /dev/null +++ b/test/fixtures/modules/issue-1223/issue-1223.js @@ -0,0 +1,5 @@ +import css from './@foo/bar/index.module.css'; + +__export__ = css; + +export default css; diff --git a/test/modules-option.test.js b/test/modules-option.test.js index d442c6cd..91c93b1f 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -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'); + }); });