Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default context should be undefined instead of null #965

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/utils.js
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
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
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