Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip _extends helper for {…x} with modern targets #12899

Merged
merged 1 commit into from Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,8 @@
"babel-plugin"
],
"dependencies": {
"@babel/compat-data": "workspace:^7.13.6",
"@babel/helper-compilation-targets": "workspace:^7.13.0",
"@babel/helper-plugin-utils": "workspace:^7.13.0",
"@babel/plugin-syntax-object-rest-spread": "^7.8.0",
"@babel/plugin-transform-parameters": "workspace:^7.13.0"
Expand Down
Expand Up @@ -2,6 +2,8 @@ import { declare } from "@babel/helper-plugin-utils";
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
import { types as t } from "@babel/core";
import { convertFunctionParams } from "@babel/plugin-transform-parameters";
import { isRequired } from "@babel/helper-compilation-targets";
import compatData from "@babel/compat-data/corejs2-built-ins";

// TODO: Remove in Babel 8
// @babel/types <=7.3.3 counts FOO as referenced in var { x: FOO }.
Expand All @@ -17,7 +19,12 @@ const ZERO_REFS = (() => {
export default declare((api, opts) => {
api.assertVersion(7);

const { useBuiltIns = false, loose = false } = opts;
const targets = api.targets();
const supportsObjectAssign = !isRequired("es6.object.assign", targets, {
compatData,
});

const { useBuiltIns = supportsObjectAssign, loose = false } = opts;

if (typeof loose !== "boolean") {
throw new Error(".loose must be a boolean, or undefined");
Expand Down
@@ -0,0 +1 @@
let a = { x: 1, ...b };
@@ -0,0 +1,3 @@
{
"targets": "firefox 70"
}
@@ -0,0 +1,3 @@
let a = Object.assign({
x: 1
}, b);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this PR, the output would be something like

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

let a = _extends({
  x: 1
}, b);

@@ -0,0 +1 @@
let a = { x: 1, ...b };
@@ -0,0 +1,3 @@
{
"targets": "firefox 70"
}
@@ -0,0 +1,3 @@
let a = Object.assign({
x: 1
}, b);
4 changes: 3 additions & 1 deletion yarn.lock
Expand Up @@ -139,7 +139,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/compat-data@workspace:^7.13.0, @babel/compat-data@workspace:^7.13.5, @babel/compat-data@workspace:packages/babel-compat-data":
"@babel/compat-data@workspace:^7.13.0, @babel/compat-data@workspace:^7.13.5, @babel/compat-data@workspace:^7.13.6, @babel/compat-data@workspace:packages/babel-compat-data":
version: 0.0.0-use.local
resolution: "@babel/compat-data@workspace:packages/babel-compat-data"
dependencies:
Expand Down Expand Up @@ -1307,7 +1307,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/plugin-proposal-object-rest-spread@workspace:packages/babel-plugin-proposal-object-rest-spread"
dependencies:
"@babel/compat-data": "workspace:^7.13.6"
"@babel/core": "workspace:*"
"@babel/helper-compilation-targets": "workspace:^7.13.0"
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.13.0"
"@babel/plugin-syntax-object-rest-spread": ^7.8.0
Expand Down