Skip to content

Commit

Permalink
Merge pull request #14660 from webpack/defaults/export-presence
Browse files Browse the repository at this point in the history
make exportsPresence strict by default in future
  • Loading branch information
sokra committed Nov 5, 2021
2 parents e96c1b5 + f9e6b68 commit 14dd4f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
18 changes: 14 additions & 4 deletions lib/config/defaults.js
Expand Up @@ -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, {
Expand Down Expand Up @@ -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);
Expand All @@ -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");
};

/**
Expand All @@ -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 => {
Expand All @@ -473,7 +481,9 @@ const applyModuleDefaults = (
}

F(module.parser, "javascript", () => ({}));
applyJavascriptParserOptionsDefaults(module.parser.javascript);
applyJavascriptParserOptionsDefaults(module.parser.javascript, {
futureDefaults
});

A(module, "defaultRules", () => {
const esm = {
Expand Down
1 change: 1 addition & 0 deletions lib/config/normalization.js
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/dependencies/HarmonyImportDependency.js
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions test/Defaults.unittest.js
Expand Up @@ -1923,21 +1923,23 @@ describe("Defaults", () => {
+ ],
+ "test": /\\.wasm$/i,
+ "type": "webassembly/async",
+ },
+ Object {
@@ ... @@
+ "mimetype": "application/wasm",
+ "rules": Array [
+ Object {
+ "descriptionData": Object {
+ "type": "module",
@@ ... @@
+ },
+ "resolve": Object {
+ "fullySpecified": true,
+ },
+ },
+ ],
+ "type": "webassembly/async",
+ },
+ Object {
@@ ... @@
+ "exportPresence": "error",
@@ ... @@
- "__dirname": "mock",
- "__filename": "mock",
Expand Down

0 comments on commit 14dd4f9

Please sign in to comment.