Remove classConstructorCall plugin (#291)

This commit is contained in:
Brian Ng
2017-01-16 03:49:42 -06:00
committed by Daniel Tschinder
parent 00f03bb3b0
commit c5462e1a30
9 changed files with 3 additions and 231 deletions

View File

@@ -636,7 +636,6 @@ pp.parseClassBody = function (node) {
const oldStrict = this.state.strict;
this.state.strict = true;
let hadConstructorCall = false;
let hadConstructor = false;
let decorators = [];
const classBody = this.startNode();
@@ -663,7 +662,6 @@ pp.parseClassBody = function (node) {
decorators = [];
}
let isConstructorCall = false;
const isMaybeStatic = this.match(tt.name) && this.state.value === "static";
let isGenerator = this.eat(tt.star);
let isGetSet = false;
@@ -682,11 +680,6 @@ pp.parseClassBody = function (node) {
classBody.body.push(this.parseClassProperty(method));
continue;
}
if (method.key.type === "Identifier" && !method.computed && this.hasPlugin("classConstructorCall") && method.key.name === "call" && this.match(tt.name) && this.state.value === "constructor") {
isConstructorCall = true;
this.parsePropertyName(method);
}
}
const isAsyncMethod = !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async";
@@ -710,7 +703,7 @@ pp.parseClassBody = function (node) {
}
// disallow invalid constructors
const isConstructor = !isConstructorCall && !method.static && (
const isConstructor = !method.static && (
(key.type === "Identifier" && key.name === "constructor") ||
(key.type === "StringLiteral" && key.value === "constructor")
);
@@ -733,15 +726,8 @@ pp.parseClassBody = function (node) {
}
}
// convert constructor to a constructor call
if (isConstructorCall) {
if (hadConstructorCall) this.raise(method.start, "Duplicate constructor call in the same class");
method.kind = "constructorCall";
hadConstructorCall = true;
}
// disallow decorators on class constructors
if ((method.kind === "constructor" || method.kind === "constructorCall") && method.decorators) {
// disallow decorators on class constructors
if (method.kind === "constructor" && method.decorators) {
this.raise(method.start, "You can't attach decorators to a class constructor");
}