Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow modules.getLocalIdent to return a falsy value #963

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 38 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -85,7 +85,7 @@
"sass-loader": "^7.1.0",
"standard-version": "^6.0.1",
"strip-ansi": "^5.2.0",
"webpack": "^4.33.0"
"webpack": "^4.35.0"
},
"keywords": [
"webpack",
Expand Down
17 changes: 16 additions & 1 deletion src/utils.js
Expand Up @@ -141,7 +141,7 @@ function getModulesPlugins(options, loaderContext) {
extractImports(),
modulesScope({
generateScopedName: function generateScopedName(exportName) {
return modulesOptions.getLocalIdent(
let localIdent = modulesOptions.getLocalIdent(
loaderContext,
modulesOptions.localIdentName,
exportName,
Expand All @@ -151,6 +151,21 @@ function getModulesPlugins(options, loaderContext) {
regExp: modulesOptions.localIdentRegExp,
}
);

if (!localIdent) {
localIdent = getLocalIdent(
loaderContext,
modulesOptions.localIdentName,
exportName,
{
context: modulesOptions.context,
hashPrefix: modulesOptions.hashPrefix,
regExp: modulesOptions.localIdentRegExp,
}
);
}

return localIdent;
},
}),
];
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/loader.test.js.snap
Expand Up @@ -1247,7 +1247,7 @@ exports[`loader should throw error on invalid css syntax: warnings 1`] = `Array
exports[`loader should throws error when no loader for assets: errors 1`] = `
Array [
"ModuleParseError: Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)",
]
`;
Expand Down
30 changes: 30 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap
Expand Up @@ -6201,6 +6201,36 @@ exports.locals = {

exports[`modules composes should supports resolving: warnings 1`] = `Array []`;

exports[`modules getLocalIdent should be allowed to return false: errors 1`] = `Array []`;

exports[`modules getLocalIdent should be allowed to return false: locals 1`] = `
Object {
"abc": "abc",
"def": "def",
"ghi": "ghi",
"jkl": "jkl",
}
`;

exports[`modules getLocalIdent should be allowed to return false: module (evaluated) 1`] = `
Array [
Array [
1,
".abc .def {
color: red;
}

.ghi .jkl {
color: blue;
}
",
"",
],
]
`;

exports[`modules getLocalIdent should be allowed to return false: warnings 1`] = `Array []`;

exports[`modules issue #286: errors 1`] = `Array []`;

exports[`modules issue #286: module (evaluated) 1`] = `
Expand Down