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

This commit is contained in:
Nicolò Ribaudo 2021-02-25 21:16:56 +01:00 committed by GitHub
parent 9a1b59f1f9
commit 962d81483e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 2 deletions

View File

@ -17,6 +17,8 @@
"babel-plugin" "babel-plugin"
], ],
"dependencies": { "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/helper-plugin-utils": "workspace:^7.13.0",
"@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-object-rest-spread": "^7.8.3",
"@babel/plugin-transform-parameters": "workspace:^7.13.0" "@babel/plugin-transform-parameters": "workspace:^7.13.0"

View File

@ -2,6 +2,8 @@ import { declare } from "@babel/helper-plugin-utils";
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread"; import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
import { types as t } from "@babel/core"; import { types as t } from "@babel/core";
import { convertFunctionParams } from "@babel/plugin-transform-parameters"; 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 // TODO: Remove in Babel 8
// @babel/types <=7.3.3 counts FOO as referenced in var { x: FOO }. // @babel/types <=7.3.3 counts FOO as referenced in var { x: FOO }.
@ -17,7 +19,12 @@ const ZERO_REFS = (() => {
export default declare((api, opts) => { export default declare((api, opts) => {
api.assertVersion(7); 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") { if (typeof loose !== "boolean") {
throw new Error(".loose must be a boolean, or undefined"); throw new Error(".loose must be a boolean, or undefined");

View File

@ -0,0 +1,3 @@
let a = Object.assign({
x: 1
}, b);

View File

@ -139,7 +139,7 @@ __metadata:
languageName: node languageName: node
linkType: hard 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 version: 0.0.0-use.local
resolution: "@babel/compat-data@workspace:packages/babel-compat-data" resolution: "@babel/compat-data@workspace:packages/babel-compat-data"
dependencies: dependencies:
@ -1287,7 +1287,9 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@babel/plugin-proposal-object-rest-spread@workspace:packages/babel-plugin-proposal-object-rest-spread" resolution: "@babel/plugin-proposal-object-rest-spread@workspace:packages/babel-plugin-proposal-object-rest-spread"
dependencies: dependencies:
"@babel/compat-data": "workspace:^7.13.6"
"@babel/core": "workspace:*" "@babel/core": "workspace:*"
"@babel/helper-compilation-targets": "workspace:^7.13.0"
"@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.13.0" "@babel/helper-plugin-utils": "workspace:^7.13.0"
"@babel/plugin-syntax-object-rest-spread": ^7.8.3 "@babel/plugin-syntax-object-rest-spread": ^7.8.3