abstract subclassing into declaration #88
This commit is contained in:
@@ -1 +0,0 @@
|
||||
CLASS_NAME.__proto__ = SUPER_NAME;
|
||||
@@ -1,8 +0,0 @@
|
||||
CLASS_NAME.prototype = Object.create(SUPER_NAME.prototype, {
|
||||
constructor: {
|
||||
value: CLASS_NAME,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
11
lib/6to5/templates/extends.js
Normal file
11
lib/6to5/templates/extends.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
child.__proto__ = parent;
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
var traverse = require("../traverse");
|
||||
var util = require("../util");
|
||||
var b = require("ast-types").builders;
|
||||
var b = require("acorn-ast-types").builders;
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, file) {
|
||||
@@ -50,17 +50,7 @@ var buildClass = function (node, file) {
|
||||
var returnStatement = body.pop();
|
||||
|
||||
if (superName) {
|
||||
// inherit prototype
|
||||
body.push(util.template("class-inherits-prototype", {
|
||||
SUPER_NAME: superName,
|
||||
CLASS_NAME: className
|
||||
}, true));
|
||||
|
||||
// inherit static properties
|
||||
body.push(util.template("class-inherits-properties", {
|
||||
SUPER_NAME: superName,
|
||||
CLASS_NAME: className
|
||||
}, true));
|
||||
body.push(b.expressionStatement(b.callExpression(file.addDeclaration("extends"), [className, superName])));
|
||||
|
||||
container.arguments.push(superClassArgument);
|
||||
container.callee.params.push(superClassCallee);
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
woops.super.test();
|
||||
super();
|
||||
super.test();
|
||||
foob(super);
|
||||
woops.super.test();
|
||||
super();
|
||||
super.test();
|
||||
foob(super);
|
||||
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
|
||||
super.test(...arguments);
|
||||
super.test("test", ...arguments);
|
||||
super.test(...arguments);
|
||||
super.test("test", ...arguments);
|
||||
}
|
||||
|
||||
test() {
|
||||
super();
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
super();
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
}
|
||||
|
||||
static foo() {
|
||||
super();
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
super();
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
"use strict";
|
||||
var _slice = Array.prototype.slice;
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Test = function(Foo) {
|
||||
var Test = function Test() {
|
||||
@@ -13,16 +25,7 @@ var Test = function(Foo) {
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
|
||||
Test.prototype = Object.create(Foo.prototype, {
|
||||
constructor: {
|
||||
value: Test,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
Test.__proto__ = Foo;
|
||||
_extends(Test, Foo);
|
||||
|
||||
Object.defineProperties(Test.prototype, {
|
||||
test: {
|
||||
@@ -49,4 +52,4 @@ var Test = function(Foo) {
|
||||
});
|
||||
|
||||
return Test;
|
||||
}(Foo);
|
||||
}(Foo);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
super.test;
|
||||
super.test.whatever;
|
||||
super.test;
|
||||
super.test.whatever;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Test = function(Foo) {
|
||||
var Test = function Test() {
|
||||
Foo.prototype.test;
|
||||
Foo.prototype.test.whatever;
|
||||
};
|
||||
|
||||
Test.prototype = Object.create(Foo.prototype, {
|
||||
constructor: {
|
||||
value: Test,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
_extends(Test, Foo);
|
||||
|
||||
Test.__proto__ = Foo;
|
||||
return Test;
|
||||
}(Foo);
|
||||
}(Foo);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
super.test.whatever();
|
||||
super.test();
|
||||
super.test.whatever();
|
||||
super.test();
|
||||
}
|
||||
|
||||
static test() {
|
||||
return super.wow();
|
||||
return super.wow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
|
||||
var Test = function(Foo) {
|
||||
var Test = function Test() {
|
||||
Foo.prototype.test.whatever();
|
||||
Foo.prototype.test.call(this);
|
||||
};
|
||||
|
||||
Test.prototype = Object.create(Foo.prototype, {
|
||||
constructor: {
|
||||
value: Test,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
Test.__proto__ = Foo;
|
||||
_extends(Test, Foo);
|
||||
|
||||
Object.defineProperties(Test, {
|
||||
test: {
|
||||
@@ -28,4 +33,4 @@ var Test = function(Foo) {
|
||||
});
|
||||
|
||||
return Test;
|
||||
}(Foo);
|
||||
}(Foo);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
class Test {
|
||||
constructor() {
|
||||
this.state = "test";
|
||||
this.state = "test";
|
||||
}
|
||||
}
|
||||
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
this.state = "test";
|
||||
this.state = "test";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Test = function() {
|
||||
var Test = function Test() {
|
||||
this.state = "test";
|
||||
@@ -13,15 +26,7 @@ var Foo = function(Bar) {
|
||||
this.state = "test";
|
||||
};
|
||||
|
||||
Foo.prototype = Object.create(Bar.prototype, {
|
||||
constructor: {
|
||||
value: Foo,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
_extends(Foo, Bar);
|
||||
|
||||
Foo.__proto__ = Bar;
|
||||
return Foo;
|
||||
}(Bar);
|
||||
}(Bar);
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
var BaseController = function(Chaplin) {
|
||||
var BaseController = function BaseController() {
|
||||
Chaplin.Controller.apply(this, arguments);
|
||||
};
|
||||
|
||||
BaseController.prototype = Object.create(Chaplin.Controller.prototype, {
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: BaseController,
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
BaseController.__proto__ = Chaplin.Controller;
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var BaseController = function(Chaplin) {
|
||||
var BaseController = function BaseController() {
|
||||
Chaplin.Controller.apply(this, arguments);
|
||||
};
|
||||
|
||||
_extends(BaseController, Chaplin.Controller);
|
||||
|
||||
return BaseController;
|
||||
}(Chaplin);
|
||||
|
||||
@@ -23,15 +28,7 @@ var BaseController2 = function(Chaplin) {
|
||||
Chaplin.Controller.Another.apply(this, arguments);
|
||||
};
|
||||
|
||||
BaseController2.prototype = Object.create(Chaplin.Controller.Another.prototype, {
|
||||
constructor: {
|
||||
value: BaseController2,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
_extends(BaseController2, Chaplin.Controller.Another);
|
||||
|
||||
BaseController2.__proto__ = Chaplin.Controller.Another;
|
||||
return BaseController2;
|
||||
}(Chaplin);
|
||||
}(Chaplin);
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
var Q = function(_ref) {
|
||||
var Q = function Q() {
|
||||
_ref.apply(this, arguments);
|
||||
};
|
||||
|
||||
Q.prototype = Object.create(_ref.prototype, {
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: Q,
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
Q.__proto__ = _ref;
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Q = function(_ref) {
|
||||
var Q = function Q() {
|
||||
_ref.apply(this, arguments);
|
||||
};
|
||||
|
||||
_extends(Q, _ref);
|
||||
|
||||
return Q;
|
||||
}(function() {});
|
||||
}(function() {});
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
var Test = function(Foo) {
|
||||
var Test = function Test() {
|
||||
Foo.apply(this, arguments);
|
||||
};
|
||||
|
||||
Test.prototype = Object.create(Foo.prototype, {
|
||||
var _extends = function (child, parent) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: Test,
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
|
||||
Test.__proto__ = Foo;
|
||||
child.__proto__ = parent;
|
||||
};
|
||||
|
||||
var Test = function(Foo) {
|
||||
var Test = function Test() {
|
||||
Foo.apply(this, arguments);
|
||||
};
|
||||
|
||||
_extends(Test, Foo);
|
||||
|
||||
return Test;
|
||||
}(Foo);
|
||||
}(Foo);
|
||||
|
||||
Reference in New Issue
Block a user