Skip to content

Commit

Permalink
preset-env integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 24, 2020
1 parent 9ec23b4 commit a566679
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { isRequired } from "@babel/helper-compilation-targets";
export default declare((api, options) => {
api.assertVersion(7);

if (isRequired("proposal-class-properties", api.targets())) {
if (!api.targets || isRequired("proposal-class-properties", api.targets())) {
return createClassFeaturePlugin({
name: "proposal-private-methods",

Expand Down
16 changes: 14 additions & 2 deletions packages/babel-preset-env/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function isPluginRequired(targets: Targets, support: Targets) {
});
}

const pluginLists = {
const pluginLists: Object = {
withProposals: {
withoutBugfixes: pluginsList,
withBugfixes: Object.assign({}, pluginsList, pluginsBugfixesList),
Expand Down Expand Up @@ -285,6 +285,7 @@ export default declare((api, opts) => {
browserslistEnv,
} = normalizeOptions(opts);

let hasLocalTargets = false;
let targets = babelTargets;
let transformTargets = forceAllTransforms ? {} : babelTargets;

Expand All @@ -296,6 +297,8 @@ export default declare((api, opts) => {
opts.browserslistEnv ||
opts.ignoreBrowserslistConfig
) {
hasLocalTargets = true;

const { hasUglifyTarget, localTargets } = getLocalTargets(
optionsTargets,
ignoreBrowserslistConfig,
Expand All @@ -311,7 +314,16 @@ export default declare((api, opts) => {
const include = transformIncludesAndExcludes(optionsInclude);
const exclude = transformIncludesAndExcludes(optionsExclude);

const compatData = getPluginList(shippedProposals, bugfixes);
let compatData = getPluginList(shippedProposals, bugfixes);

if (hasLocalTargets && compatData["proposal-private-methods"]) {
// In @babel/core versions without api.targets support,
compatData = {
...compatData,
"proposal-class-properties": compatData["proposal-private-methods"],
};
}

const shouldSkipExportNamespaceFrom =
(modules === "auto" && api.caller?.(supportsExportNamespaceFrom)) ||
(modules === false &&
Expand Down
3 changes: 0 additions & 3 deletions packages/babel-preset-env/src/plugins-compat-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ for (const plugin of Object.keys(bugfixPlugins)) {
}
}

pluginsFiltered["proposal-class-properties"] =
pluginsFiltered["proposal-private-methods"];

export { pluginsFiltered as plugins, bugfixPluginsFiltered as pluginsBugfixes };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@babel/polyfill';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"validateLogs": true,
"ignoreOutput": true,
"targets": {
"browsers": "chrome 80"
},
"presets": [
[
"env",
{
"debug": true,
"shippedProposals": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@babel/preset-env: `DEBUG` option

Using targets:
{
"chrome": "80"
}

Using modules transform: auto

Using plugins:
syntax-class-properties { "chrome":"80" }
proposal-private-methods { "chrome":"80" }
syntax-numeric-separator { "chrome":"80" }
proposal-logical-assignment-operators { "chrome":"80" }
syntax-nullish-coalescing-operator { "chrome":"80" }
syntax-optional-chaining { "chrome":"80" }
syntax-json-strings { "chrome":"80" }
syntax-optional-catch-binding { "chrome":"80" }
syntax-async-generators { "chrome":"80" }
syntax-object-rest-spread { "chrome":"80" }
transform-modules-commonjs { "chrome":"80" }
proposal-dynamic-import { "chrome":"80" }
proposal-export-namespace-from {}

Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-class-properties { "chrome":"80" }
proposal-class-properties {}
proposal-private-methods { "chrome":"80" }
syntax-numeric-separator { "chrome":"80" }
proposal-logical-assignment-operators { "chrome":"80" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class A {
x = this.#y();

#y() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"targets": { "node": 12 },
"presets": [
["env", {
"shippedProposals": true
}]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var _y;

class A {
#y = _y || (_y = function () {});
x = this.#y();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class A {
x;

#y() {}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _y = new WeakSet();

class A {
constructor() {
_y.add(this);

_defineProperty(this, "x", void 0);
}

}

var _y2 = function _y2() {};

0 comments on commit a566679

Please sign in to comment.