Skip to content

Commit

Permalink
Support frozen built-ins in @babel/runtime (#14537)
Browse files Browse the repository at this point in the history
* Update helpers.ts

* Update helpers.ts

* Update helpers.ts

* Update helpers.ts

* Avoid error when `Object.assign` is not defined

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
  • Loading branch information
Jack-Works and nicolo-ribaudo committed May 25, 2022
1 parent a273a1d commit 62fd56f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/babel-helpers/src/helpers.ts
Expand Up @@ -289,9 +289,10 @@ helpers.defineProperty = helper("7.0.0-beta.0")`
}
`;

// need a bind because https://github.com/babel/babel/issues/14527
helpers.extends = helper("7.0.0-beta.0")`
export default function _extends() {
_extends = Object.assign || function (target) {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
Expand Down Expand Up @@ -360,10 +361,11 @@ helpers.inheritsLoose = helper("7.0.0-beta.0")`
}
`;

// need a bind because https://github.com/babel/babel/issues/14527
helpers.getPrototypeOf = helper("7.0.0-beta.0")`
export default function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf
? Object.getPrototypeOf
? Object.getPrototypeOf.bind()
: function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
Expand All @@ -373,10 +375,12 @@ helpers.getPrototypeOf = helper("7.0.0-beta.0")`

helpers.setPrototypeOf = helper("7.0.0-beta.0")`
export default function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
_setPrototypeOf = Object.setPrototypeOf
? Object.setPrototypeOf.bind()
: function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
`;
Expand Down Expand Up @@ -409,13 +413,14 @@ helpers.isNativeReflectConstruct = helper("7.9.0")`
}
`;

// need a bind because https://github.com/babel/babel/issues/14527
helpers.construct = helper("7.0.0-beta.0")`
import setPrototypeOf from "setPrototypeOf";
import isNativeReflectConstruct from "isNativeReflectConstruct";
export default function _construct(Parent, args, Class) {
if (isNativeReflectConstruct()) {
_construct = Reflect.construct;
_construct = Reflect.construct.bind();
} else {
// NOTE: If Parent !== Class, the correct __proto__ is set *after*
// calling the constructor.
Expand Down Expand Up @@ -656,6 +661,7 @@ helpers.superPropBase = helper("7.0.0-beta.0")`
}
`;

// need a bind because https://github.com/babel/babel/issues/14527
// https://tc39.es/ecma262/multipage/reflection.html#sec-reflect.get
//
// 28.1.5 Reflect.get ( target, propertyKey [ , receiver ] )
Expand All @@ -665,7 +671,7 @@ helpers.get = helper("7.0.0-beta.0")`
export default function _get() {
if (typeof Reflect !== "undefined" && Reflect.get) {
_get = Reflect.get;
_get = Reflect.get.bind();
} else {
_get = function _get(target, property, receiver) {
var base = superPropBase(target, property);
Expand Down

0 comments on commit 62fd56f

Please sign in to comment.