Remove classConstructorCall plugin (#291)
This commit is contained in:
parent
00f03bb3b0
commit
c5462e1a30
@ -636,7 +636,6 @@ pp.parseClassBody = function (node) {
|
|||||||
const oldStrict = this.state.strict;
|
const oldStrict = this.state.strict;
|
||||||
this.state.strict = true;
|
this.state.strict = true;
|
||||||
|
|
||||||
let hadConstructorCall = false;
|
|
||||||
let hadConstructor = false;
|
let hadConstructor = false;
|
||||||
let decorators = [];
|
let decorators = [];
|
||||||
const classBody = this.startNode();
|
const classBody = this.startNode();
|
||||||
@ -663,7 +662,6 @@ pp.parseClassBody = function (node) {
|
|||||||
decorators = [];
|
decorators = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let isConstructorCall = false;
|
|
||||||
const isMaybeStatic = this.match(tt.name) && this.state.value === "static";
|
const isMaybeStatic = this.match(tt.name) && this.state.value === "static";
|
||||||
let isGenerator = this.eat(tt.star);
|
let isGenerator = this.eat(tt.star);
|
||||||
let isGetSet = false;
|
let isGetSet = false;
|
||||||
@ -682,11 +680,6 @@ pp.parseClassBody = function (node) {
|
|||||||
classBody.body.push(this.parseClassProperty(method));
|
classBody.body.push(this.parseClassProperty(method));
|
||||||
continue;
|
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";
|
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
|
// disallow invalid constructors
|
||||||
const isConstructor = !isConstructorCall && !method.static && (
|
const isConstructor = !method.static && (
|
||||||
(key.type === "Identifier" && key.name === "constructor") ||
|
(key.type === "Identifier" && key.name === "constructor") ||
|
||||||
(key.type === "StringLiteral" && key.value === "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
|
// disallow decorators on class constructors
|
||||||
if ((method.kind === "constructor" || method.kind === "constructorCall") && method.decorators) {
|
if (method.kind === "constructor" && method.decorators) {
|
||||||
this.raise(method.start, "You can't attach decorators to a class constructor");
|
this.raise(method.start, "You can't attach decorators to a class constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
class Foo {
|
|
||||||
call constructor() {}
|
|
||||||
call constructor() {}
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
class Foo {
|
|
||||||
*call constructor() {
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"throws": "Unexpected token, expected ( (2:8)"
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
class Foo {
|
|
||||||
call foobar() {
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"throws": "Unexpected token, expected ( (2:7)"
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["classConstructorCall"]
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
class Foo {
|
|
||||||
call constructor() {
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user