Skip to content

Commit 9c3571c

Browse files
ziirevilebottnawi
authored andcommitted
feat: allow modules.getLocalIdent to return a falsy value (#963)
1 parent c4b7f71 commit 9c3571c

6 files changed

+109
-69
lines changed

package-lock.json

+38-66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"sass-loader": "^7.1.0",
8686
"standard-version": "^6.0.1",
8787
"strip-ansi": "^5.2.0",
88-
"webpack": "^4.33.0"
88+
"webpack": "^4.35.0"
8989
},
9090
"keywords": [
9191
"webpack",

src/utils.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function getModulesPlugins(options, loaderContext) {
141141
extractImports(),
142142
modulesScope({
143143
generateScopedName: function generateScopedName(exportName) {
144-
return modulesOptions.getLocalIdent(
144+
let localIdent = modulesOptions.getLocalIdent(
145145
loaderContext,
146146
modulesOptions.localIdentName,
147147
exportName,
@@ -151,6 +151,21 @@ function getModulesPlugins(options, loaderContext) {
151151
regExp: modulesOptions.localIdentRegExp,
152152
}
153153
);
154+
155+
if (!localIdent) {
156+
localIdent = getLocalIdent(
157+
loaderContext,
158+
modulesOptions.localIdentName,
159+
exportName,
160+
{
161+
context: modulesOptions.context,
162+
hashPrefix: modulesOptions.hashPrefix,
163+
regExp: modulesOptions.localIdentRegExp,
164+
}
165+
);
166+
}
167+
168+
return localIdent;
154169
},
155170
}),
156171
];

test/__snapshots__/loader.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ exports[`loader should throw error on invalid css syntax: warnings 1`] = `Array
12471247
exports[`loader should throws error when no loader for assets: errors 1`] = `
12481248
Array [
12491249
"ModuleParseError: Module parse failed: Unexpected character '�' (1:0)
1250-
You may need an appropriate loader to handle this file type.
1250+
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
12511251
(Source code omitted for this binary file)",
12521252
]
12531253
`;

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

+30
Original file line numberDiff line numberDiff line change
@@ -6201,6 +6201,36 @@ exports.locals = {
62016201
62026202
exports[`modules composes should supports resolving: warnings 1`] = `Array []`;
62036203
6204+
exports[`modules getLocalIdent should be allowed to return false: errors 1`] = `Array []`;
6205+
6206+
exports[`modules getLocalIdent should be allowed to return false: locals 1`] = `
6207+
Object {
6208+
"abc": "abc",
6209+
"def": "def",
6210+
"ghi": "ghi",
6211+
"jkl": "jkl",
6212+
}
6213+
`;
6214+
6215+
exports[`modules getLocalIdent should be allowed to return false: module (evaluated) 1`] = `
6216+
Array [
6217+
Array [
6218+
1,
6219+
".abc .def {
6220+
color: red;
6221+
}
6222+
6223+
.ghi .jkl {
6224+
color: blue;
6225+
}
6226+
",
6227+
"",
6228+
],
6229+
]
6230+
`;
6231+
6232+
exports[`modules getLocalIdent should be allowed to return false: warnings 1`] = `Array []`;
6233+
62046234
exports[`modules issue #286: errors 1`] = `Array []`;
62056235
62066236
exports[`modules issue #286: module (evaluated) 1`] = `

0 commit comments

Comments
 (0)