forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow declarations as expression statements.
Summary: ExpressionStatements are no longer allowed to be parsed as declarations, in an attempt to avoid ambiguity. Add the simple checks for this. `{`, `function`, and `class` are no longer allowed at the start of expression statements. To handle `let [`, we use the `lexer_.seek` function to reset the `curCharPtr`; this case should be infrequent enough that going back one token is acceptable. Reviewed By: tmikov Differential Revision: D17270833 fbshipit-source-id: 1e58560b2d89b6fc3f6971c98b15d339d15f0d85
- Loading branch information
1 parent
5e185ca
commit 630c1ce
Showing
3 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Facebook, Inc. and its 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 2>&1 ) | %FileCheck --match-full-lines %s | ||
|
||
for (;false;) function foo() {} | ||
// CHECK: {{.*}}:8:15: error: declaration not allowed as expression statement | ||
// CHECK: for (;false;) function foo() {} | ||
// CHECK: ^~~~~~~~ | ||
|
||
for (;false;) class bar {} | ||
// CHECK: {{.*}}:13:15: error: declaration not allowed as expression statement | ||
// CHECK: for (;false;) class bar {} | ||
// CHECK: ^~~~~ | ||
|
||
for (;false;) let [x] = 3; | ||
// CHECK: {{.*}}:18:15: error: ambiguous 'let [': either a 'let' binding or a member expression | ||
// CHECK: for (;false;) let [x] = 3; | ||
// CHECK: ^~~~~ |
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