diff --git a/src/parser/statement.js b/src/parser/statement.js index cfff7be0a7..421b044cfc 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -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"); } diff --git a/test/fixtures/experimental/class-constructor-call/.duplicate/actual.js b/test/fixtures/experimental/class-constructor-call/.duplicate/actual.js deleted file mode 100644 index 6fd5dd7d11..0000000000 --- a/test/fixtures/experimental/class-constructor-call/.duplicate/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -class Foo { - call constructor() {} - call constructor() {} -} diff --git a/test/fixtures/experimental/class-constructor-call/illegal-generator/actual.js b/test/fixtures/experimental/class-constructor-call/illegal-generator/actual.js deleted file mode 100644 index 9a3bd5d8d6..0000000000 --- a/test/fixtures/experimental/class-constructor-call/illegal-generator/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Foo { - *call constructor() { - foo(); - } -} diff --git a/test/fixtures/experimental/class-constructor-call/illegal-generator/options.json b/test/fixtures/experimental/class-constructor-call/illegal-generator/options.json deleted file mode 100644 index db35c194d3..0000000000 --- a/test/fixtures/experimental/class-constructor-call/illegal-generator/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected ( (2:8)" -} diff --git a/test/fixtures/experimental/class-constructor-call/illegal-key/actual.js b/test/fixtures/experimental/class-constructor-call/illegal-key/actual.js deleted file mode 100644 index e3155a24a8..0000000000 --- a/test/fixtures/experimental/class-constructor-call/illegal-key/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Foo { - call foobar() { - foo(); - } -} diff --git a/test/fixtures/experimental/class-constructor-call/illegal-key/options.json b/test/fixtures/experimental/class-constructor-call/illegal-key/options.json deleted file mode 100644 index 606cbed9d9..0000000000 --- a/test/fixtures/experimental/class-constructor-call/illegal-key/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected ( (2:7)" -} diff --git a/test/fixtures/experimental/class-constructor-call/options.json b/test/fixtures/experimental/class-constructor-call/options.json deleted file mode 100644 index 253cf5199b..0000000000 --- a/test/fixtures/experimental/class-constructor-call/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["classConstructorCall"] -} diff --git a/test/fixtures/experimental/class-constructor-call/plain/actual.js b/test/fixtures/experimental/class-constructor-call/plain/actual.js deleted file mode 100644 index 1f8b64ef4a..0000000000 --- a/test/fixtures/experimental/class-constructor-call/plain/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Foo { - call constructor() { - foo(); - } -} diff --git a/test/fixtures/experimental/class-constructor-call/plain/expected.json b/test/fixtures/experimental/class-constructor-call/plain/expected.json deleted file mode 100644 index 49c89dadbc..0000000000 --- a/test/fixtures/experimental/class-constructor-call/plain/expected.json +++ /dev/null @@ -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": [] - } -} \ No newline at end of file