Skip to content

Commit 1825e8a

Browse files
fix: getLocalIdent now accepts false value (#865)
1 parent 634ab49 commit 1825e8a

5 files changed

+65
-4
lines changed

src/options.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@
5252
"type": "string"
5353
},
5454
"getLocalIdent": {
55-
"instanceof": "Function"
55+
"anyOf": [
56+
{
57+
"type": "boolean"
58+
},
59+
{
60+
"instanceof": "Function"
61+
}
62+
]
5663
},
5764
"sourceMap": {
5865
"type": "boolean"

test/__snapshots__/errors.test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ options.hashPrefix should be string
7878
exports[`validation 10`] = `
7979
"CSS Loader Invalid Options
8080
81+
options.getLocalIdent should be boolean
8182
options.getLocalIdent should pass \\"instanceof\\" keyword validation
83+
options.getLocalIdent should match some schema in anyOf
8284
"
8385
`;
8486

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

+30
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@ Array [
3030

3131
exports[`getLocalIdent option should accepts arguments: warnings 1`] = `Array []`;
3232

33+
exports[`getLocalIdent option should allow to use \`false\` value: errors 1`] = `Array []`;
34+
35+
exports[`getLocalIdent option should allow to use \`false\` value: locals 1`] = `
36+
Object {
37+
"abc": "before_abc__1hk_after",
38+
"def": "before_def__3oo_after",
39+
"ghi": "before_ghi__2ZR_after",
40+
"jkl": "before_jkl__aQ1_after",
41+
}
42+
`;
43+
44+
exports[`getLocalIdent option should allow to use \`false\` value: module (evaluated) 1`] = `
45+
Array [
46+
Array [
47+
1,
48+
".before_abc__1hk_after .before_def__3oo_after {
49+
color: red;
50+
}
51+
52+
.before_ghi__2ZR_after .before_jkl__aQ1_after {
53+
color: blue;
54+
}
55+
",
56+
"",
57+
],
58+
]
59+
`;
60+
61+
exports[`getLocalIdent option should allow to use \`false\` value: warnings 1`] = `Array []`;
62+
3363
exports[`getLocalIdent option should respect \`context\` option: errors 1`] = `Array []`;
3464

3565
exports[`getLocalIdent option should respect \`context\` option: locals 1`] = `

test/errors.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ it('validation', () => {
5858
expect(() => validate({ hashPrefix: true })).toThrowErrorMatchingSnapshot();
5959

6060
expect(() => validate({ getLocalIdent: () => {} })).not.toThrow();
61-
expect(() =>
62-
validate({ getLocalIdent: true })
63-
).toThrowErrorMatchingSnapshot();
61+
expect(() => validate({ getLocalIdent: false })).not.toThrow();
62+
expect(() => validate({ getLocalIdent: [] })).toThrowErrorMatchingSnapshot();
6463

6564
expect(() => validate({ sourceMap: true })).not.toThrow();
6665
expect(() => validate({ sourceMap: false })).not.toThrow();

test/getLocalIdent-option.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,27 @@ describe('getLocalIdent option', () => {
104104
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
105105
expect(stats.compilation.errors).toMatchSnapshot('errors');
106106
});
107+
108+
it('should allow to use `false` value', async () => {
109+
const config = {
110+
loader: {
111+
options: {
112+
context: path.resolve(__dirname, 'fixtures/modules'),
113+
modules: true,
114+
localIdentName: 'before_[local]__[hash:base64:3]_after',
115+
getLocalIdent: false,
116+
},
117+
},
118+
};
119+
const testId = './modules/getLocalIdent.css';
120+
const stats = await webpack(testId, config);
121+
const { modules } = stats.toJson();
122+
const module = modules.find((m) => m.id === testId);
123+
const evaluatedModule = evaluated(module.source);
124+
125+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
126+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
127+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
128+
expect(stats.compilation.errors).toMatchSnapshot('errors');
129+
});
107130
});

0 commit comments

Comments
 (0)