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.
Allow parsing of 'static' in class properties
Summary: Original Author: [email protected] Original Git: 0d01268 `static` can be used as a property name as well as a method name now. Modify the checks in `parseClassElement` which special-case `static` to see whether it's a modifier or the property name to also check for class properties. Original Reviewed By: tmikov Original Revision: D42562106 Reviewed By: jpporto Differential Revision: D43197056 fbshipit-source-id: 5d07d9843c5303ca72f497c24d4dabda068cf70c
- Loading branch information
1 parent
95209da
commit ccdac85
Showing
3 changed files
with
255 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* 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 Foo { | ||
static = 1; | ||
} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "Foo" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "superClass": null, | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "ClassBody", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "static" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "computed": false, | ||
// CHECK-NEXT: "static": false, | ||
// CHECK-NEXT: "declare": false | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: }, | ||
|
||
class Foo { | ||
static; | ||
} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "Foo" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "superClass": null, | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "ClassBody", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "static" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": null, | ||
// CHECK-NEXT: "computed": false, | ||
// CHECK-NEXT: "static": false, | ||
// CHECK-NEXT: "declare": false | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: }, | ||
|
||
class Foo { | ||
public; | ||
} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "Foo" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "superClass": null, | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "ClassBody", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "public" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": null, | ||
// CHECK-NEXT: "computed": false, | ||
// CHECK-NEXT: "static": false, | ||
// CHECK-NEXT: "declare": false | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: }, | ||
|
||
class Foo { | ||
protected = 1; | ||
} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "Foo" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "superClass": null, | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "ClassBody", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "protected" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": { | ||
// CHECK-NEXT: "type": "NumericLiteral", | ||
// CHECK-NEXT: "value": 1, | ||
// CHECK-NEXT: "raw": "1" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "computed": false, | ||
// CHECK-NEXT: "static": false, | ||
// CHECK-NEXT: "declare": false | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: }, | ||
|
||
class Foo { | ||
static static; | ||
} | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassDeclaration", | ||
// CHECK-NEXT: "id": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "Foo" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "superClass": null, | ||
// CHECK-NEXT: "body": { | ||
// CHECK-NEXT: "type": "ClassBody", | ||
// CHECK-NEXT: "body": [ | ||
// CHECK-NEXT: { | ||
// CHECK-NEXT: "type": "ClassProperty", | ||
// CHECK-NEXT: "key": { | ||
// CHECK-NEXT: "type": "Identifier", | ||
// CHECK-NEXT: "name": "static" | ||
// CHECK-NEXT: }, | ||
// CHECK-NEXT: "value": null, | ||
// CHECK-NEXT: "computed": false, | ||
// CHECK-NEXT: "static": true, | ||
// CHECK-NEXT: "declare": false | ||
// 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