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

Support frozen built-ins in @babel/runtime #14537

Merged
merged 5 commits into from May 25, 2022
Merged
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
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