Skip to content

Commit 9c32885

Browse files
manuelbiehevilebottnawi
authored andcommitted
fix: default context should be undefined instead of null (#965)
1 parent 9c3571c commit 9c32885

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/utils.js

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ function getModulesPlugins(options, loaderContext) {
120120
mode: 'local',
121121
localIdentName: '[hash:base64]',
122122
getLocalIdent,
123-
context: null,
124123
hashPrefix: '',
125124
localIdentRegExp: null,
126125
};

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

+30
Original file line numberDiff line numberDiff line change
@@ -6564,6 +6564,36 @@ Array [
65646564
65656565
exports[`modules should correctly replace escaped symbols in selector with localIdentName option: warnings 1`] = `Array []`;
65666566
6567+
exports[`modules should have an undefined context if no context was given: errors 1`] = `Array []`;
6568+
6569+
exports[`modules should have an undefined context if no context was given: locals 1`] = `
6570+
Object {
6571+
"abc": "foo",
6572+
"def": "foo",
6573+
"ghi": "foo",
6574+
"jkl": "foo",
6575+
}
6576+
`;
6577+
6578+
exports[`modules should have an undefined context if no context was given: module (evaluated) 1`] = `
6579+
Array [
6580+
Array [
6581+
1,
6582+
".foo .foo {
6583+
color: red;
6584+
}
6585+
6586+
.foo .foo {
6587+
color: blue;
6588+
}
6589+
",
6590+
"",
6591+
],
6592+
]
6593+
`;
6594+
6595+
exports[`modules should have an undefined context if no context was given: warnings 1`] = `Array []`;
6596+
65676597
exports[`modules should prefixes leading hyphen + digit with underscore with localIdentName option: errors 1`] = `Array []`;
65686598
65696599
exports[`modules should prefixes leading hyphen + digit with underscore with localIdentName option: locals 1`] = `

test/modules-option.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,31 @@ describe('modules', () => {
288288
expect(stats.compilation.errors).toMatchSnapshot('errors');
289289
});
290290

291+
it('should have an undefined context if no context was given', async () => {
292+
const config = {
293+
loader: {
294+
options: {
295+
modules: {
296+
getLocalIdent(loaderContext, localIdentName, localName, options) {
297+
expect(options.context).toBeUndefined();
298+
return 'foo';
299+
},
300+
},
301+
},
302+
},
303+
};
304+
const testId = './modules/getLocalIdent.css';
305+
const stats = await webpack(testId, config);
306+
const { modules } = stats.toJson();
307+
const module = modules.find((m) => m.id === testId);
308+
const evaluatedModule = evaluated(module.source);
309+
310+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
311+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
312+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
313+
expect(stats.compilation.errors).toMatchSnapshot('errors');
314+
});
315+
291316
it('should respects getLocalIdent option (global mode)', async () => {
292317
const config = {
293318
loader: {

0 commit comments

Comments
 (0)