-
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.
Summary: Manual port of D65822124. Class static blocks can't have return in them, so we have to check for the Return param and error in the parser, instead of waiting for SemanticValidator to error (where we'd have to track whether we are currently in the top-level of a class static block). We also have to forbid await expressions, which is easy to do by using the forbidAwaitExpression_ flag in SemanticValidator. The ESTree spec adds a StaticBlock node which is a BlockStatement. NOTE: We have to make SH-specific changes for typed mode. We have to allow return outside functions because we wrap in IIFE after the parse step. Reviewed By: fbmal7 Differential Revision: D66711283 fbshipit-source-id: 0b369d9cfd3f176f6c26d469c0960f038c6910cc
- Loading branch information
1 parent
9b403d0
commit 3ea2fe9
Showing
14 changed files
with
212 additions
and
6 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
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,22 @@ | ||
/** | ||
* 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 -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s | ||
|
||
async function foo() { | ||
// This is fine. | ||
class C extends (await 1) { | ||
static { | ||
// This is not fine. | ||
await 1; | ||
} | ||
} | ||
} | ||
|
||
// CHECK:{{.*}}class-static-block-await-error.js:15:7: error: 'await' not in an async function | ||
// CHECK-NEXT: await 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,28 @@ | ||
/** | ||
* 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 -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s | ||
|
||
class C { | ||
static { | ||
return 1; | ||
} | ||
} | ||
function foo() { | ||
class C { | ||
static { | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
// CHECK:{{.*}}class-static-block-return-error.js:12:5: error: 'return' not in a function | ||
// CHECK-NEXT: return 1; | ||
// CHECK-NEXT: ^~~~~~ | ||
// CHECK:{{.*}}class-static-block-return-error.js:18:7: error: 'return' not in a function | ||
// CHECK-NEXT: return 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,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 -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s | ||
|
||
function* foo() { | ||
class C { | ||
static { | ||
yield 1; | ||
} | ||
} | ||
} | ||
|
||
// CHECK:{{.*}}class-static-block-yield-error.js:13:7: error: invalid expression | ||
// CHECK-NEXT: yield 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,64 @@ | ||
/** | ||
* 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": [ | ||
|
||
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": [ | ||
|
||
static {} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "StaticBlock", | ||
// CHECK-NEXT: "body": [] | ||
// CHECK-NEXT: }, | ||
|
||
static { | ||
let x = 1; | ||
} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "StaticBlock", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "VariableDeclaration", | ||
// CHECK-NEXT: "kind": "let", | ||
// CHECK-NEXT: "declarations": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "VariableDeclarator", | ||
// CHECK-NEXT: "init": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "x" | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
|
||
} | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// 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
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