Skip to content

Commit

Permalink
feat: allow modules.getLocalIdent to return a falsy value (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziir authored and evilebottnawi committed Jun 28, 2019
1 parent c4b7f71 commit 9c3571c
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 69 deletions.
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 9c3571c

Please sign in to comment.