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");
}

View File

@ -1,4 +0,0 @@
class Foo {
call constructor() {}
call constructor() {}
}

View File

@ -1,5 +0,0 @@
class Foo {
*call constructor() {
foo();
}
}

View File

@ -1,3 +0,0 @@
{
"throws": "Unexpected token, expected ( (2:8)"
}

View File

@ -1,5 +0,0 @@
class Foo {
call foobar() {
foo();
}
}

View File

@ -1,3 +0,0 @@
{
"throws": "Unexpected token, expected ( (2:7)"
}

View File

@ -1,3 +0,0 @@
{
"plugins": ["classConstructorCall"]
}

View File

@ -1,5 +0,0 @@
class Foo {
call constructor() {
foo();
}
}

View File

@ -1,186 +0,0 @@
{
"type": "File",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
}
},
"name": "Foo"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 10,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 5,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 14,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 4,
"column": 3
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 19,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
},
"name": "constructor"
},
"static": false,
"kind": "constructorCall",
"id": null,
"generator": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 33,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 4,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 39,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 10
}
},
"expression": {
"type": "CallExpression",
"start": 39,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 9
}
},
"callee": {
"type": "Identifier",
"start": 39,
"end": 42,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 7
}
},
"name": "foo"
},
"arguments": []
}
}
],
"directives": []
}
}
]
}
}
],
"directives": []
}
}