Skip to content

Commit

Permalink
fix: default context should be undefined instead of null (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbieh authored and evilebottnawi committed Jul 9, 2019
1 parent 9c3571c commit 9c32885
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ function getModulesPlugins(options, loaderContext) {
mode: 'local',
localIdentName: '[hash:base64]',
getLocalIdent,
context: null,
hashPrefix: '',
localIdentRegExp: null,
};
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 @@ -6564,6 +6564,36 @@ Array [
exports[`modules should correctly replace escaped symbols in selector with localIdentName option: warnings 1`] = `Array []`;
exports[`modules should have an undefined context if no context was given: errors 1`] = `Array []`;
exports[`modules should have an undefined context if no context was given: locals 1`] = `
Object {
"abc": "foo",
"def": "foo",
"ghi": "foo",
"jkl": "foo",
}
`;
exports[`modules should have an undefined context if no context was given: module (evaluated) 1`] = `
Array [
Array [
1,
".foo .foo {
color: red;
}
.foo .foo {
color: blue;
}
",
"",
],
]
`;
exports[`modules should have an undefined context if no context was given: warnings 1`] = `Array []`;
exports[`modules should prefixes leading hyphen + digit with underscore with localIdentName option: errors 1`] = `Array []`;
exports[`modules should prefixes leading hyphen + digit with underscore with localIdentName option: locals 1`] = `
Expand Down
25 changes: 25 additions & 0 deletions test/modules-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,31 @@ describe('modules', () => {
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should have an undefined context if no context was given', async () => {
const config = {
loader: {
options: {
modules: {
getLocalIdent(loaderContext, localIdentName, localName, options) {
expect(options.context).toBeUndefined();
return 'foo';
},
},
},
},
};
const testId = './modules/getLocalIdent.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should respects getLocalIdent option (global mode)', async () => {
const config = {
loader: {
Expand Down

0 comments on commit 9c32885

Please sign in to comment.