From f9e6b682aba059d13aa3e170ac42b7a797a0ef3f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 5 Nov 2021 16:13:49 +0100 Subject: [PATCH] make exportsPresence strict by default in future --- lib/config/defaults.js | 18 ++++++++++++++---- lib/config/normalization.js | 1 + lib/dependencies/HarmonyImportDependency.js | 2 ++ test/Defaults.unittest.js | 8 +++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/config/defaults.js b/lib/config/defaults.js index ac425641c0f..8c5cdc4aa9a 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -183,7 +183,8 @@ const applyWebpackOptionsDefaults = options => { applyModuleDefaults(options.module, { cache, syncWebAssembly: options.experiments.syncWebAssembly, - asyncWebAssembly: options.experiments.asyncWebAssembly + asyncWebAssembly: options.experiments.asyncWebAssembly, + futureDefaults }); applyOutputDefaults(options.output, { @@ -428,9 +429,14 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => { /** * @param {JavascriptParserOptions} parserOptions parser options + * @param {Object} options options + * @param {boolean} options.futureDefaults is future defaults enabled * @returns {void} */ -const applyJavascriptParserOptionsDefaults = parserOptions => { +const applyJavascriptParserOptionsDefaults = ( + parserOptions, + { futureDefaults } +) => { D(parserOptions, "unknownContextRequest", "."); D(parserOptions, "unknownContextRegExp", false); D(parserOptions, "unknownContextRecursive", true); @@ -443,6 +449,7 @@ const applyJavascriptParserOptionsDefaults = parserOptions => { D(parserOptions, "wrappedContextRecursive", true); D(parserOptions, "wrappedContextCritical", false); D(parserOptions, "strictThisContextOnImports", false); + if (futureDefaults) D(parserOptions, "exportPresence", "error"); }; /** @@ -451,11 +458,12 @@ const applyJavascriptParserOptionsDefaults = parserOptions => { * @param {boolean} options.cache is caching enabled * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled + * @param {boolean} options.futureDefaults is future defaults enabled * @returns {void} */ const applyModuleDefaults = ( module, - { cache, syncWebAssembly, asyncWebAssembly } + { cache, syncWebAssembly, asyncWebAssembly, futureDefaults } ) => { if (cache) { D(module, "unsafeCache", module => { @@ -473,7 +481,9 @@ const applyModuleDefaults = ( } F(module.parser, "javascript", () => ({})); - applyJavascriptParserOptionsDefaults(module.parser.javascript); + applyJavascriptParserOptionsDefaults(module.parser.javascript, { + futureDefaults + }); A(module, "defaultRules", () => { const esm = { diff --git a/lib/config/normalization.js b/lib/config/normalization.js index 64d3f35c9c2..f63121c9988 100644 --- a/lib/config/normalization.js +++ b/lib/config/normalization.js @@ -229,6 +229,7 @@ const getNormalizedWebpackOptions = config => { wrappedContextRegExp: module.wrappedContextRegExp, wrappedContextRecursive: module.wrappedContextRecursive, wrappedContextCritical: module.wrappedContextCritical, + // TODO webpack 6 remove strictExportPresence: module.strictExportPresence, strictThisContextOnImports: module.strictThisContextOnImports, ...parserOptions diff --git a/lib/dependencies/HarmonyImportDependency.js b/lib/dependencies/HarmonyImportDependency.js index 7ee1621e1c5..c270262ca8a 100644 --- a/lib/dependencies/HarmonyImportDependency.js +++ b/lib/dependencies/HarmonyImportDependency.js @@ -38,6 +38,8 @@ const ExportPresenceModes = { return ExportPresenceModes.ERROR; case "warn": return ExportPresenceModes.WARN; + case "auto": + return ExportPresenceModes.AUTO; case false: return ExportPresenceModes.NONE; default: diff --git a/test/Defaults.unittest.js b/test/Defaults.unittest.js index dcf983fced4..24cc153a7f2 100644 --- a/test/Defaults.unittest.js +++ b/test/Defaults.unittest.js @@ -1923,14 +1923,13 @@ describe("Defaults", () => { + ], + "test": /\\.wasm$/i, + "type": "webassembly/async", - + }, - + Object { + @@ ... @@ + "mimetype": "application/wasm", + "rules": Array [ + Object { + "descriptionData": Object { + "type": "module", - @@ ... @@ + + }, + "resolve": Object { + "fullySpecified": true, + }, @@ -1938,6 +1937,9 @@ describe("Defaults", () => { + ], + "type": "webassembly/async", + }, + + Object { + @@ ... @@ + + "exportPresence": "error", @@ ... @@ - "__dirname": "mock", - "__filename": "mock",