-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid await/yield/arguments in class field inits
Summary: Certain language features aren't allowed in class field initializers. 'arguments' is forbidden by the spec. Yield/await should be forbidden: tc39/ecma262#3333 Reviewed By: fbmal7 Differential Revision: D66266912 fbshipit-source-id: 859ab611add5b7e4cdd01a3167113255de4bff61
- Loading branch information
1 parent
d1b0f84
commit a642414
Showing
7 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: (! %hermesc -dump-transformed-ast %s 2>&1 ) | %FileCheckOrRegen --match-full-lines %s | ||
|
||
function* foo() { | ||
class C { | ||
x = () => arguments; | ||
} | ||
} | ||
|
||
// Auto-generated content below. Please do not modify manually. | ||
|
||
// CHECK:{{.*}}arguments-field-error.js:12:15: error: invalid use of 'arguments' | ||
// CHECK-NEXT: x = () => arguments; | ||
// CHECK-NEXT: ^~~~~~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: (! %hermesc -dump-transformed-ast %s 2>&1 ) | %FileCheck --match-full-lines %s | ||
|
||
async function foo() { | ||
class C { | ||
x = await 1; | ||
} | ||
|
||
class D { | ||
x = class { [await 1] = 1; }; | ||
} | ||
} | ||
|
||
|
||
// CHECK:{{.*}}await-field-error.js:12:9: error: 'await' not in an async function | ||
// CHECK-NEXT: x = await 1; | ||
// CHECK-NEXT: ^~~~~~~ | ||
// CHECK-NEXT:{{.*}}await-field-error.js:16:18: error: 'await' not in an async function | ||
// CHECK-NEXT: x = class { [await 1] = 1; }; | ||
// CHECK-NEXT: ^~~~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %hermesc -dump-ast -pretty-json %s | %FileCheck %s --match-full-lines | ||
|
||
// CHECK-LABEL: { | ||
// CHECK-NEXT: "type": "Program", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
|
||
async function* foo() { | ||
// CHECK-NEXT: "type": "FunctionDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "foo" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "params": [], | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "BlockStatement", | ||
// CHECK-NEXT: "body": [ | ||
|
||
class C { | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "C" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "superClass": null, | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "ClassBody", | ||
// CHECK-NEXT: "body": [ | ||
|
||
[yield 1] = 1; | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "YieldExpression", | ||
// CHECK-NEXT: "argument": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "delegate": false | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "computed": true, | ||
// CHECK-NEXT: "static": false, | ||
// CHECK-NEXT: "declare": false | ||
// CHECK-NEXT: }, | ||
|
||
[await 1] = 1; | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "AwaitExpression", | ||
// CHECK-NEXT: "argument": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "computed": true, | ||
// CHECK-NEXT: "static": false, | ||
// CHECK-NEXT: "declare": false | ||
// CHECK-NEXT: } | ||
|
||
} | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
|
||
} | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "generator": true, | ||
// CHECK-NEXT: "async": true | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: (! %hermesc -dump-ast %s 2>&1 ) | %FileCheckOrRegen --match-full-lines %s | ||
|
||
function* foo() { | ||
class C { | ||
x = yield; | ||
} | ||
} | ||
|
||
// Auto-generated content below. Please do not modify manually. | ||
|
||
// CHECK:{{.*}}yield-field-error.js:12:9: error: invalid expression | ||
// CHECK-NEXT: x = yield; | ||
// CHECK-NEXT: ^ |