Skip to content

Commit

Permalink
feat: add import-assertions to shippedProposals (#14556)
Browse files Browse the repository at this point in the history
* feat: add import-assertions to shippedProposals

* fix: import assertions are independent of targets
  • Loading branch information
JLHwung committed May 19, 2022
1 parent 1daded5 commit e57d081
Show file tree
Hide file tree
Showing 63 changed files with 94 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/babel-preset-env/data/shipped-proposals.js
@@ -1,9 +1,15 @@
/* eslint sort-keys: "error" */
// These mappings represent the syntax proposals that have been
// These mappings represent the transform plugins that have been
// shipped by browsers, and are enabled by the `shippedProposals` option.

const proposalPlugins = new Set();

// proposal syntax plugins enabled by the `shippedProposals` option.
// Unlike proposalPlugins above, they are independent of compiler targets.
const proposalSyntaxPlugins = [
"syntax-import-assertions"
]

// use intermediary object to enforce alphabetical key order
const pluginSyntaxObject = {
"proposal-async-generator-functions": "syntax-async-generators",
Expand All @@ -27,4 +33,4 @@ const pluginSyntaxEntries = Object.keys(pluginSyntaxObject).map(function (key) {

const pluginSyntaxMap = new Map(pluginSyntaxEntries);

module.exports = { pluginSyntaxMap, proposalPlugins };
module.exports = { pluginSyntaxMap, proposalPlugins, proposalSyntaxPlugins };
1 change: 1 addition & 0 deletions packages/babel-preset-env/package.json
Expand Up @@ -42,6 +42,7 @@
"@babel/plugin-syntax-class-static-block": "^7.14.5",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-export-namespace-from": "^7.8.3",
"@babel/plugin-syntax-import-assertions": "workspace:^",
"@babel/plugin-syntax-json-strings": "^7.8.3",
"@babel/plugin-syntax-logical-assignment-operators": "^7.10.4",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-preset-env/src/available-plugins.ts
Expand Up @@ -5,6 +5,7 @@ import syntaxClassProperties from "@babel/plugin-syntax-class-properties";
import syntaxClassStaticBlock from "@babel/plugin-syntax-class-static-block";
import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";
import syntaxExportNamespaceFrom from "@babel/plugin-syntax-export-namespace-from";
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions";
import syntaxJsonStrings from "@babel/plugin-syntax-json-strings";
import syntaxLogicalAssignmentOperators from "@babel/plugin-syntax-logical-assignment-operators";
import syntaxNullishCoalescingOperator from "@babel/plugin-syntax-nullish-coalescing-operator";
Expand Down Expand Up @@ -104,6 +105,7 @@ export default {
"syntax-class-static-block": () => syntaxClassStaticBlock,
"syntax-dynamic-import": () => syntaxDynamicImport,
"syntax-export-namespace-from": () => syntaxExportNamespaceFrom,
"syntax-import-assertions": () => syntaxImportAssertions,
"syntax-json-strings": () => syntaxJsonStrings,
"syntax-logical-assignment-operators": () => syntaxLogicalAssignmentOperators,
"syntax-nullish-coalescing-operator": () => syntaxNullishCoalescingOperator,
Expand Down
8 changes: 8 additions & 0 deletions packages/babel-preset-env/src/filter-items.ts
Expand Up @@ -4,6 +4,14 @@ import { minVersions } from "./available-plugins";
// $FlowIgnore
const has = Function.call.bind(Object.hasOwnProperty);

export function addProposalSyntaxPlugins(
items: Set<string>,
proposalSyntaxPlugins: string[],
) {
proposalSyntaxPlugins.forEach(plugin => {
items.add(plugin);
});
}
export function removeUnnecessaryItems(
items: Set<string>,
overlapping: { [name: string]: string[] },
Expand Down
15 changes: 13 additions & 2 deletions packages/babel-preset-env/src/index.ts
Expand Up @@ -2,10 +2,18 @@ import { lt } from "semver";
import type { SemVer } from "semver";
import { logPlugin } from "./debug";
import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
import { removeUnnecessaryItems, removeUnsupportedItems } from "./filter-items";
import {
addProposalSyntaxPlugins,
removeUnnecessaryItems,
removeUnsupportedItems,
} from "./filter-items";
import moduleTransformations from "./module-transformations";
import normalizeOptions from "./normalize-options";
import { proposalPlugins, pluginSyntaxMap } from "../data/shipped-proposals";
import {
pluginSyntaxMap,
proposalPlugins,
proposalSyntaxPlugins,
} from "../data/shipped-proposals";
import {
plugins as pluginsList,
pluginsBugfixes as pluginsBugfixesList,
Expand Down Expand Up @@ -375,6 +383,9 @@ option \`forceAllTransforms: true\` instead.
);
removeUnnecessaryItems(pluginNames, overlappingPlugins);
removeUnsupportedItems(pluginNames, api.version);
if (shippedProposals) {
addProposalSyntaxPlugins(pluginNames, proposalSyntaxPlugins);
}

const polyfillPlugins = getPolyfillPlugins({
useBuiltIns,
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -25,6 +25,7 @@ Using plugins:
proposal-export-namespace-from { samsung < 11.0 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,5 +23,6 @@ Using plugins:
transform-modules-commonjs
proposal-dynamic-import
proposal-export-namespace-from { }
syntax-import-assertions

Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.
Expand Up @@ -22,5 +22,6 @@ Using plugins:
transform-modules-commonjs
proposal-dynamic-import
proposal-export-namespace-from { }
syntax-import-assertions

Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.
Expand Up @@ -50,6 +50,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72, firefox < 80, ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -50,6 +50,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72, firefox < 80, ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -50,6 +50,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72, firefox < 80, ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -50,6 +50,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72, firefox < 80, ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs2: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -52,6 +52,7 @@ Using plugins:
proposal-export-namespace-from { ie }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down
Expand Up @@ -23,6 +23,7 @@ Using plugins:
proposal-export-namespace-from { chrome < 72 }
transform-modules-commonjs
proposal-dynamic-import
syntax-import-assertions
corejs3: `DEBUG` option

Using targets: {
Expand Down

0 comments on commit e57d081

Please sign in to comment.