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);
|
||||
|
||||
Reference in New Issue
Block a user