clean up default constructor in derived classes - fixes #1748
This commit is contained in:
parent
52c3c143f9
commit
eba9f0ffbd
@ -0,0 +1,3 @@
|
|||||||
|
(function () {
|
||||||
|
super(...arguments);
|
||||||
|
})
|
||||||
@ -1,3 +0,0 @@
|
|||||||
if (SUPER_NAME != null) {
|
|
||||||
SUPER_NAME.apply(this, arguments);
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
if (SUPER_NAME != null) {
|
|
||||||
SUPER_NAME.apply(this, arguments);
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
if (SUPER_NAME != null) {
|
|
||||||
var NATIVE_REF = new SUPER_NAME(...arguments);
|
|
||||||
NATIVE_REF.__proto__ = CLASS_NAME.prototype;
|
|
||||||
return NATIVE_REF;
|
|
||||||
}
|
|
||||||
@ -251,20 +251,43 @@ class ClassTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://www.youtube.com/watch?v=fWNaR-rxAic
|
||||||
|
*/
|
||||||
|
|
||||||
|
constructorMeMaybe() {
|
||||||
|
if (!this.hasSuper) return;
|
||||||
|
|
||||||
|
var hasConstructor = false;
|
||||||
|
var paths = this.path.get("body.body");
|
||||||
|
|
||||||
|
for (var path of (paths: Array)) {
|
||||||
|
hasConstructor = path.equals("kind", "constructor");
|
||||||
|
if (hasConstructor) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasConstructor) {
|
||||||
|
this.path.get("body").unshiftContainer("body", t.methodDefinition(
|
||||||
|
t.identifier("constructor"),
|
||||||
|
util.template("class-derived-default-constructor"),
|
||||||
|
"constructor"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buildBody() {
|
buildBody() {
|
||||||
|
this.constructorMeMaybe();
|
||||||
|
|
||||||
var constructorBody = this.constructorBody;
|
var constructorBody = this.constructorBody;
|
||||||
var classBody = this.node.body.body;
|
var classBodyPaths = this.path.get("body.body");
|
||||||
var body = this.body;
|
var body = this.body;
|
||||||
|
|
||||||
var classBodyPaths = this.path.get("body").get("body");
|
for (var path of (classBodyPaths: Array)) {
|
||||||
|
var node = path.node;
|
||||||
for (var i = 0; i < classBody.length; i++) {
|
|
||||||
var node = classBody[i];
|
|
||||||
var path = classBodyPaths[i];
|
|
||||||
|
|
||||||
if (node.decorators) {
|
if (node.decorators) {
|
||||||
memoiseDecorators(node.decorators, this.scope);
|
memoiseDecorators(node.decorators, this.scope);
|
||||||
@ -297,16 +320,6 @@ class ClassTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we have no constructor, but we're a derived class
|
|
||||||
if (!this.hasConstructor && this.hasSuper) {
|
|
||||||
var helperName = "class-super-constructor-call";
|
|
||||||
if (this.isLoose) helperName += "-loose";
|
|
||||||
constructorBody.body.push(util.template(helperName, {
|
|
||||||
CLASS_NAME: this.classRef,
|
|
||||||
SUPER_NAME: this.superName
|
|
||||||
}, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
this.placePropertyInitializers();
|
this.placePropertyInitializers();
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export function insertBefore(nodes) {
|
|||||||
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||||
if (this.node) nodes.push(this.node);
|
if (this.node) nodes.push(this.node);
|
||||||
this.replaceExpressionWithStatements(nodes);
|
this.replaceExpressionWithStatements(nodes);
|
||||||
} else if (this.isNodeType("Statement") || !this.type) {
|
} else {
|
||||||
this._maybePopFromStatements(nodes);
|
this._maybePopFromStatements(nodes);
|
||||||
if (Array.isArray(this.container)) {
|
if (Array.isArray(this.container)) {
|
||||||
return this._containerInsertBefore(nodes);
|
return this._containerInsertBefore(nodes);
|
||||||
@ -26,8 +26,6 @@ export function insertBefore(nodes) {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new Error("No clue what to do with this node type.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [this];
|
return [this];
|
||||||
@ -94,7 +92,7 @@ export function insertAfter(nodes) {
|
|||||||
nodes.push(t.expressionStatement(temp));
|
nodes.push(t.expressionStatement(temp));
|
||||||
}
|
}
|
||||||
this.replaceExpressionWithStatements(nodes);
|
this.replaceExpressionWithStatements(nodes);
|
||||||
} else if (this.isNodeType("Statement") || !this.type) {
|
} else {
|
||||||
this._maybePopFromStatements(nodes);
|
this._maybePopFromStatements(nodes);
|
||||||
if (Array.isArray(this.container)) {
|
if (Array.isArray(this.container)) {
|
||||||
return this._containerInsertAfter(nodes);
|
return this._containerInsertAfter(nodes);
|
||||||
@ -104,8 +102,6 @@ export function insertAfter(nodes) {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new Error("No clue what to do with this node type.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [this];
|
return [this];
|
||||||
|
|||||||
@ -4,9 +4,7 @@ var BaseController = (function (_Chaplin$Controller) {
|
|||||||
function BaseController() {
|
function BaseController() {
|
||||||
babelHelpers.classCallCheck(this, BaseController);
|
babelHelpers.classCallCheck(this, BaseController);
|
||||||
|
|
||||||
if (_Chaplin$Controller != null) {
|
_Chaplin$Controller.call.apply(_Chaplin$Controller, [this].concat(babelHelpers.slice.call(arguments)));
|
||||||
_Chaplin$Controller.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(BaseController, _Chaplin$Controller);
|
babelHelpers.inherits(BaseController, _Chaplin$Controller);
|
||||||
@ -17,9 +15,7 @@ var BaseController2 = (function (_Chaplin$Controller$Another) {
|
|||||||
function BaseController2() {
|
function BaseController2() {
|
||||||
babelHelpers.classCallCheck(this, BaseController2);
|
babelHelpers.classCallCheck(this, BaseController2);
|
||||||
|
|
||||||
if (_Chaplin$Controller$Another != null) {
|
_Chaplin$Controller$Another.call.apply(_Chaplin$Controller$Another, [this].concat(babelHelpers.slice.call(arguments)));
|
||||||
_Chaplin$Controller$Another.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
|
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
|
||||||
|
|||||||
@ -4,9 +4,7 @@ var Test = (function (_Foo) {
|
|||||||
function Test() {
|
function Test() {
|
||||||
babelHelpers.classCallCheck(this, Test);
|
babelHelpers.classCallCheck(this, Test);
|
||||||
|
|
||||||
if (_Foo != null) {
|
_Foo.call.apply(_Foo, [this].concat(babelHelpers.slice.call(arguments)));
|
||||||
_Foo.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(Test, _Foo);
|
babelHelpers.inherits(Test, _Foo);
|
||||||
|
|||||||
@ -3,10 +3,7 @@
|
|||||||
var TestEmpty = (function (_ref) {
|
var TestEmpty = (function (_ref) {
|
||||||
function TestEmpty() {
|
function TestEmpty() {
|
||||||
babelHelpers.classCallCheck(this, TestEmpty);
|
babelHelpers.classCallCheck(this, TestEmpty);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(TestEmpty.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_ref != null) {
|
|
||||||
_ref.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(TestEmpty, _ref);
|
babelHelpers.inherits(TestEmpty, _ref);
|
||||||
@ -22,10 +19,7 @@ var TestEmpty = (function (_ref) {
|
|||||||
var TestConstructorOnly = (function (_ref2) {
|
var TestConstructorOnly = (function (_ref2) {
|
||||||
function TestConstructorOnly() {
|
function TestConstructorOnly() {
|
||||||
babelHelpers.classCallCheck(this, TestConstructorOnly);
|
babelHelpers.classCallCheck(this, TestConstructorOnly);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(TestConstructorOnly.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_ref2 != null) {
|
|
||||||
_ref2.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(TestConstructorOnly, _ref2);
|
babelHelpers.inherits(TestConstructorOnly, _ref2);
|
||||||
@ -41,10 +35,7 @@ var TestConstructorOnly = (function (_ref2) {
|
|||||||
var TestMethodOnly = (function (_ref3) {
|
var TestMethodOnly = (function (_ref3) {
|
||||||
function TestMethodOnly() {
|
function TestMethodOnly() {
|
||||||
babelHelpers.classCallCheck(this, TestMethodOnly);
|
babelHelpers.classCallCheck(this, TestMethodOnly);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(TestMethodOnly.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_ref3 != null) {
|
|
||||||
_ref3.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(TestMethodOnly, _ref3);
|
babelHelpers.inherits(TestMethodOnly, _ref3);
|
||||||
@ -64,10 +55,7 @@ var TestMethodOnly = (function (_ref3) {
|
|||||||
var TestConstructorAndMethod = (function (_ref4) {
|
var TestConstructorAndMethod = (function (_ref4) {
|
||||||
function TestConstructorAndMethod() {
|
function TestConstructorAndMethod() {
|
||||||
babelHelpers.classCallCheck(this, TestConstructorAndMethod);
|
babelHelpers.classCallCheck(this, TestConstructorAndMethod);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(TestConstructorAndMethod.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_ref4 != null) {
|
|
||||||
_ref4.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(TestConstructorAndMethod, _ref4);
|
babelHelpers.inherits(TestConstructorAndMethod, _ref4);
|
||||||
@ -87,10 +75,7 @@ var TestConstructorAndMethod = (function (_ref4) {
|
|||||||
var TestMultipleMethods = (function (_ref5) {
|
var TestMultipleMethods = (function (_ref5) {
|
||||||
function TestMultipleMethods() {
|
function TestMultipleMethods() {
|
||||||
babelHelpers.classCallCheck(this, TestMultipleMethods);
|
babelHelpers.classCallCheck(this, TestMultipleMethods);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(TestMultipleMethods.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_ref5 != null) {
|
|
||||||
_ref5.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(TestMultipleMethods, _ref5);
|
babelHelpers.inherits(TestMultipleMethods, _ref5);
|
||||||
|
|||||||
@ -3,10 +3,7 @@
|
|||||||
var BaseController = (function (_Chaplin$Controller) {
|
var BaseController = (function (_Chaplin$Controller) {
|
||||||
function BaseController() {
|
function BaseController() {
|
||||||
babelHelpers.classCallCheck(this, BaseController);
|
babelHelpers.classCallCheck(this, BaseController);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(BaseController.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_Chaplin$Controller != null) {
|
|
||||||
_Chaplin$Controller.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(BaseController, _Chaplin$Controller);
|
babelHelpers.inherits(BaseController, _Chaplin$Controller);
|
||||||
@ -16,10 +13,7 @@ var BaseController = (function (_Chaplin$Controller) {
|
|||||||
var BaseController2 = (function (_Chaplin$Controller$Another) {
|
var BaseController2 = (function (_Chaplin$Controller$Another) {
|
||||||
function BaseController2() {
|
function BaseController2() {
|
||||||
babelHelpers.classCallCheck(this, BaseController2);
|
babelHelpers.classCallCheck(this, BaseController2);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(BaseController2.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_Chaplin$Controller$Another != null) {
|
|
||||||
_Chaplin$Controller$Another.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
|
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
|
||||||
|
|||||||
@ -3,10 +3,7 @@
|
|||||||
var Test = (function (_Foo) {
|
var Test = (function (_Foo) {
|
||||||
function Test() {
|
function Test() {
|
||||||
babelHelpers.classCallCheck(this, Test);
|
babelHelpers.classCallCheck(this, Test);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_Foo != null) {
|
|
||||||
_Foo.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(Test, _Foo);
|
babelHelpers.inherits(Test, _Foo);
|
||||||
|
|||||||
@ -3,11 +3,7 @@
|
|||||||
var Foo = (function (_Bar) {
|
var Foo = (function (_Bar) {
|
||||||
function Foo() {
|
function Foo() {
|
||||||
babelHelpers.classCallCheck(this, Foo);
|
babelHelpers.classCallCheck(this, Foo);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_Bar != null) {
|
|
||||||
_Bar.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bar = "foo";
|
this.bar = "foo";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,7 @@ var _ref = React.createElement(
|
|||||||
var App = (function (_React$Component) {
|
var App = (function (_React$Component) {
|
||||||
function App() {
|
function App() {
|
||||||
babelHelpers.classCallCheck(this, App);
|
babelHelpers.classCallCheck(this, App);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(App.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_React$Component != null) {
|
|
||||||
_React$Component.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(App, _React$Component);
|
babelHelpers.inherits(App, _React$Component);
|
||||||
|
|||||||
@ -9,10 +9,7 @@ var _store = require("./store");
|
|||||||
var Login = (function (_React$Component) {
|
var Login = (function (_React$Component) {
|
||||||
function Login() {
|
function Login() {
|
||||||
babelHelpers.classCallCheck(this, Login);
|
babelHelpers.classCallCheck(this, Login);
|
||||||
|
babelHelpers.get(Object.getPrototypeOf(Login.prototype), "constructor", this).apply(this, arguments);
|
||||||
if (_React$Component != null) {
|
|
||||||
_React$Component.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babelHelpers.inherits(Login, _React$Component);
|
babelHelpers.inherits(Login, _React$Component);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
||||||
|
|
||||||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
@ -10,9 +12,7 @@ var Foo = (function (_Bar) {
|
|||||||
function Foo() {
|
function Foo() {
|
||||||
_classCallCheck(this, Foo);
|
_classCallCheck(this, Foo);
|
||||||
|
|
||||||
if (_Bar != null) {
|
_get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
|
||||||
_Bar.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_inherits(Foo, _Bar);
|
_inherits(Foo, _Bar);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user