diff --git a/src/utils.js b/src/utils.js index 4b9f0b9c..e23bb8df 100644 --- a/src/utils.js +++ b/src/utils.js @@ -120,7 +120,6 @@ function getModulesPlugins(options, loaderContext) { mode: 'local', localIdentName: '[hash:base64]', getLocalIdent, - context: null, hashPrefix: '', localIdentRegExp: null, }; diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index b9063875..d3e52c60 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -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`] = ` diff --git a/test/modules-option.test.js b/test/modules-option.test.js index 73630a77..a412de09 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -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: {