Skip to content

Commit

Permalink
Centralize transform-export-namespace-from handling as a normal plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 20, 2023
1 parent b0277c6 commit b5763e2
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 41 deletions.
39 changes: 18 additions & 21 deletions packages/babel-preset-env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,10 @@ export const transformIncludesAndExcludes = (opts: Array<string>): any => {
);
};

function getModulesPluginNames({
modules,
shouldTransformDynamicImport,
shouldTransformExportNamespaceFrom,
}: {
modules: Exclude<ModuleOption, "auto">;
shouldTransformDynamicImport: boolean;
shouldTransformExportNamespaceFrom: boolean;
}) {
function getSpecialModulesPluginNames(
modules: Exclude<ModuleOption, "auto">,
shouldTransformDynamicImport: boolean,
) {
const modulesPluginNames = [];
if (modules) {
modulesPluginNames.push(moduleTransformations[modules]);
Expand All @@ -143,10 +138,6 @@ function getModulesPluginNames({
}
}

if (shouldTransformExportNamespaceFrom) {
modulesPluginNames.push("transform-export-namespace-from");
}

if (!process.env.BABEL_8_BREAKING) {
// Enable module-related syntax plugins for older Babel versions
if (!shouldTransformDynamicImport) {
Expand Down Expand Up @@ -354,20 +345,26 @@ option \`forceAllTransforms: true\` instead.
: optionsModules;
const shouldTransformDynamicImport =
optionsModules === "auto" ? !api.caller(supportsDynamicImport) : !!modules;
const shouldTransformExportNamespaceFrom =
optionsModules === "auto" && !api.caller(supportsExportNamespaceFrom);
const modulesPluginNames = getModulesPluginNames({
modules,
shouldTransformDynamicImport,
shouldTransformExportNamespaceFrom,
});

// If the caller does not support export-namespace-from, we forcefully add
// the plugin to `includes`.
// TODO(Babel 8): stop doing this, similarly to how we don't do this for any
// other plugin. We can consider adding bundlers as targets in the future,
// but we should not have a one-off special case for this plugin.
if (
optionsModules === "auto" &&
!api.caller(supportsExportNamespaceFrom) &&
!exclude.plugins.has("transform-export-namespace-from")
) {
include.plugins.add("transform-export-namespace-from");
}

const pluginNames = filterItems(
compatData,
include.plugins,
exclude.plugins,
transformTargets,
modulesPluginNames,
getSpecialModulesPluginNames(modules, shouldTransformDynamicImport),
getOptionSpecificExcludesFor({ loose }),
pluginSyntaxMap,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
bugfix/transform-safari-id-destructuring-collision-in-function-expression { safari < 16.3 }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ Using plugins:
transform-parameters { safari < 16.3 }
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
bugfix/transform-v8-spread-parameters-in-optional-chaining { chrome < 91 }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ Using plugins:
transform-parameters { ios < 16.3, safari < 16.3 }
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ Using plugins:
transform-parameters { ios < 16.3, safari < 16.3 }
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta
syntax-import-attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta
syntax-import-attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Using plugins:
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
transform-export-namespace-from { }
transform-modules-commonjs
transform-dynamic-import
transform-export-namespace-from { }
syntax-top-level-await
syntax-import-meta

Expand Down

0 comments on commit b5763e2

Please sign in to comment.