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

Allow extending untranspiled classes #8656

Merged
merged 1 commit into from Mar 16, 2020
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
@@ -1,7 +1,7 @@
{
"plugins": [
"transform-classes",
"external-helpers",
["external-helpers", { "helperVersion": "7.100.0" }],
"transform-block-scoping"
]
}
Expand Up @@ -3,6 +3,8 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo(options) {
babelHelpers.classCallCheck(this, Foo);
var parentOptions = {};
Expand All @@ -11,7 +13,7 @@ var Foo = /*#__PURE__*/function (_Bar) {
this;
};

return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this, parentOptions));
return _super.call(this, parentOptions);
}

return Foo;
Expand Down
31 changes: 27 additions & 4 deletions packages/babel-helpers/src/helpers.js
Expand Up @@ -502,10 +502,8 @@ helpers.setPrototypeOf = helper("7.0.0-beta.0")`
}
`;

helpers.construct = helper("7.0.0-beta.0")`
import setPrototypeOf from "setPrototypeOf";

function isNativeReflectConstruct() {
helpers.isNativeReflectConstruct = helper("7.9.0")`
export default function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;

// core-js@3
Expand All @@ -529,6 +527,11 @@ helpers.construct = helper("7.0.0-beta.0")`
return false;
}
}
`;

helpers.construct = helper("7.0.0-beta.0")`
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
import setPrototypeOf from "setPrototypeOf";
import isNativeReflectConstruct from "isNativeReflectConstruct";

export default function _construct(Parent, args, Class) {
if (isNativeReflectConstruct()) {
Expand Down Expand Up @@ -732,6 +735,26 @@ helpers.possibleConstructorReturn = helper("7.0.0-beta.0")`
}
`;

helpers.createSuper = helper("7.9.0")`
import getPrototypeOf from "getPrototypeOf";
import isNativeReflectConstruct from "isNativeReflectConstruct";
import possibleConstructorReturn from "possibleConstructorReturn";

export default function _createSuper(Derived) {
return function () {
var Super = getPrototypeOf(Derived), result;
if (isNativeReflectConstruct()) {
// NOTE: This doesn't work if this.__proto__.constructor has been modified.
var NewTarget = getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return possibleConstructorReturn(this, result);
}
}
`;

helpers.superPropBase = helper("7.0.0-beta.0")`
import getPrototypeOf from "getPrototypeOf";

Expand Down
@@ -1,6 +1,6 @@
{
"plugins": [
"external-helpers",
["external-helpers", { "helperVersion": "7.100.0" }],
"proposal-class-properties",
"transform-classes"
]
Expand Down
Expand Up @@ -13,13 +13,15 @@ let Hello = function Hello() {
let Outer = /*#__PURE__*/function (_Hello) {
babelHelpers.inherits(Outer, _Hello);

var _super = babelHelpers.createSuper(Outer);

function Outer() {
let _this2;

var _this;

babelHelpers.classCallCheck(this, Outer);
_this2 = _this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Outer).call(this));
_this2 = _this = _super.call(this);

let Inner = function Inner() {
babelHelpers.classCallCheck(this, Inner);
Expand Down
Expand Up @@ -17,13 +17,15 @@ let Hello = /*#__PURE__*/function () {
let Outer = /*#__PURE__*/function (_Hello) {
babelHelpers.inherits(Outer, _Hello);

var _super = babelHelpers.createSuper(Outer);

function Outer() {
let _babelHelpers$get$cal;

var _this;

babelHelpers.classCallCheck(this, Outer);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Outer).call(this));
_this = _super.call(this);
_babelHelpers$get$cal = babelHelpers.get(babelHelpers.getPrototypeOf(Outer.prototype), "toString", babelHelpers.assertThisInitialized(_this)).call(babelHelpers.assertThisInitialized(_this));

let Inner = function Inner() {
Expand Down
Expand Up @@ -3,19 +3,21 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo() {
var _this;

babelHelpers.classCallCheck(this, Foo);

if (condition) {
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this));
_this = _super.call(this);
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, {
writable: true,
value: "foo"
});
} else {
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this));
_this = _super.call(this);
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, {
writable: true,
value: "foo"
Expand Down
Expand Up @@ -15,11 +15,13 @@ var Bar = /*#__PURE__*/function (_Foo) {

babelHelpers.inherits(Bar, _Foo);

var _super = babelHelpers.createSuper(Bar);

function Bar(...args) {
var _this;

babelHelpers.classCallCheck(this, Bar);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Bar).call(this, ...args));
_this = _super.call(this, ...args);
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _prop2, {
writable: true,
value: "bar"
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Child = /*#__PURE__*/function (_Parent) {

babelHelpers.inherits(Child, _Parent);

var _super = babelHelpers.createSuper(Child);

function Child() {
var _this;

babelHelpers.classCallCheck(this, Child);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Child).call(this));
_this = _super.call(this);
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _scopedFunctionWithThis, {
writable: true,
value: function value() {
Expand Down
@@ -1,11 +1,6 @@
{
"plugins": [
[
"external-helpers",
{
"helperVersion": "7.0.2"
}
],
["external-helpers", { "helperVersion": "7.100.0" }],
["proposal-class-properties", { "loose": true }],
"transform-classes",
"transform-block-scoping",
Expand Down
Expand Up @@ -10,9 +10,11 @@ var Outer = function Outer() {
var Test = /*#__PURE__*/function (_babelHelpers$classPr) {
babelHelpers.inherits(Test, _babelHelpers$classPr);

var _super = babelHelpers.createSuper(Test);

function Test() {
babelHelpers.classCallCheck(this, Test);
return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Test).apply(this, arguments));
return _super.apply(this, arguments);
}

return Test;
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo() {
var _temp, _this;

babelHelpers.classCallCheck(this, Foo);
foo((_temp = _this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this)), Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, {
foo((_temp = _this = _super.call(this), Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, {
writable: true,
value: "foo"
}), _temp));
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo() {
var _this;

babelHelpers.classCallCheck(this, Foo);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this));
_this = _super.call(this);
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, {
writable: true,
value: "foo"
Expand Down
Expand Up @@ -3,20 +3,22 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo() {
var _this;

babelHelpers.classCallCheck(this, Foo);

if (condition) {
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this));
_this = _super.call(this);

_bar.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
value: "foo"
});
} else {
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this));
_this = _super.call(this);

_bar.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
Expand Down
Expand Up @@ -16,11 +16,13 @@ var Bar = /*#__PURE__*/function (_Foo) {

babelHelpers.inherits(Bar, _Foo);

var _super = babelHelpers.createSuper(Bar);

function Bar(...args) {
var _this;

babelHelpers.classCallCheck(this, Bar);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Bar).call(this, ...args));
_this = _super.call(this, ...args);

_prop2.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Child = /*#__PURE__*/function (_Parent) {

babelHelpers.inherits(Child, _Parent);

var _super = babelHelpers.createSuper(Child);

function Child() {
var _this;

babelHelpers.classCallCheck(this, Child);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Child).call(this));
_this = _super.call(this);

_scopedFunctionWithThis.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
Expand Down
@@ -1,11 +1,6 @@
{
"plugins": [
[
"external-helpers",
{
"helperVersion": "7.4.4"
}
],
["external-helpers", { "helperVersion": "7.100.0" }],
"proposal-class-properties",
"transform-classes",
"transform-block-scoping",
Expand Down
Expand Up @@ -11,9 +11,11 @@ var Outer = function Outer() {
var Test = /*#__PURE__*/function (_babelHelpers$classPr) {
babelHelpers.inherits(Test, _babelHelpers$classPr);

var _super = babelHelpers.createSuper(Test);

function Test() {
babelHelpers.classCallCheck(this, Test);
return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Test).apply(this, arguments));
return _super.apply(this, arguments);
}

return Test;
Expand Down
Expand Up @@ -19,11 +19,13 @@ var B = /*#__PURE__*/function (_A) {

babelHelpers.inherits(B, _A);

var _super = babelHelpers.createSuper(B);

function B(...args) {
var _this;

babelHelpers.classCallCheck(this, B);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(B).call(this, ...args));
_this = _super.call(this, ...args);

_foo.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo() {
var _temp, _this;

babelHelpers.classCallCheck(this, Foo);
foo((_temp = _this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this)), _bar.set(babelHelpers.assertThisInitialized(_this), {
foo((_temp = _this = _super.call(this), _bar.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
value: "foo"
}), _temp));
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo() {
var _this;

babelHelpers.classCallCheck(this, Foo);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this));
_this = _super.call(this);

_bar.set(babelHelpers.assertThisInitialized(_this), {
writable: true,
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Foo = /*#__PURE__*/function (_Bar) {

babelHelpers.inherits(Foo, _Bar);

var _super = babelHelpers.createSuper(Foo);

function Foo(...args) {
var _this;

babelHelpers.classCallCheck(this, Foo);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo).call(this, ...args));
_this = _super.call(this, ...args);
_this.bar = "foo";
return _this;
}
Expand Down
@@ -1,6 +1,6 @@
{
"plugins": [
"external-helpers",
["external-helpers", { "helperVersion": "7.100.0" }],
["proposal-class-properties", { "loose": true }]
],
"presets": ["env"]
Expand Down
Expand Up @@ -3,11 +3,13 @@ var Child = /*#__PURE__*/function (_Parent) {

babelHelpers.inherits(Child, _Parent);

var _super = babelHelpers.createSuper(Child);

function Child() {
var _this;

babelHelpers.classCallCheck(this, Child);
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Child).call(this));
_this = _super.call(this);

_this.scopedFunctionWithThis = function () {
_this.name = {};
Expand Down