Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[parser] Add support for private fields in TypeScript (#10483)
* [parser] Add support for private fields in TypeScript * Fix flow
- Loading branch information
1 parent
f1bc6c4
commit 1d1fab4
Showing
17 changed files
with
931 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
2 changes: 1 addition & 1 deletion
2
packages/babel-parser/test/fixtures/typescript/class/options.json
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["typescript", "classProperties"] | ||
"plugins": ["typescript", "classProperties", "classPrivateProperties"] | ||
} |
3 changes: 3 additions & 0 deletions
3
...ges/babel-parser/test/fixtures/typescript/class/private-fields-modifier-abstract/input.ts
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,3 @@ | ||
abstract class A { | ||
abstract #a; | ||
} |
3 changes: 3 additions & 0 deletions
3
...babel-parser/test/fixtures/typescript/class/private-fields-modifier-abstract/options.json
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,3 @@ | ||
{ | ||
"throws": "Private elements cannot have the 'abstract' modifier. (2:2)" | ||
} |
3 changes: 3 additions & 0 deletions
3
...ages/babel-parser/test/fixtures/typescript/class/private-fields-modifier-private/input.ts
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,3 @@ | ||
class A { | ||
private #a; | ||
} |
3 changes: 3 additions & 0 deletions
3
.../babel-parser/test/fixtures/typescript/class/private-fields-modifier-private/options.json
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,3 @@ | ||
{ | ||
"throws": "Private elements cannot have an accessibility modifier ('private') (2:2)" | ||
} |
3 changes: 3 additions & 0 deletions
3
...es/babel-parser/test/fixtures/typescript/class/private-fields-modifier-protected/input.ts
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,3 @@ | ||
class A { | ||
protected #a; | ||
} |
3 changes: 3 additions & 0 deletions
3
...abel-parser/test/fixtures/typescript/class/private-fields-modifier-protected/options.json
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,3 @@ | ||
{ | ||
"throws": "Private elements cannot have an accessibility modifier ('protected') (2:2)" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/class/private-fields-modifier-public/input.ts
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,3 @@ | ||
class A { | ||
public #a; | ||
} |
3 changes: 3 additions & 0 deletions
3
...s/babel-parser/test/fixtures/typescript/class/private-fields-modifier-public/options.json
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,3 @@ | ||
{ | ||
"throws": "Private elements cannot have an accessibility modifier ('public') (2:2)" | ||
} |
4 changes: 4 additions & 0 deletions
4
...ges/babel-parser/test/fixtures/typescript/class/private-fields-modifier-readonly/input.ts
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,4 @@ | ||
class A { | ||
readonly #a; | ||
readonly #b: string; | ||
} |
215 changes: 215 additions & 0 deletions
215
.../babel-parser/test/fixtures/typescript/class/private-fields-modifier-readonly/output.json
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,215 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 49, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 1 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 49, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 1 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start": 0, | ||
"end": 49, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 1 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 6, | ||
"end": 7, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 6 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 7 | ||
}, | ||
"identifierName": "A" | ||
}, | ||
"name": "A" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start": 8, | ||
"end": 49, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 8 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 1 | ||
} | ||
}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start": 12, | ||
"end": 24, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 14 | ||
} | ||
}, | ||
"readonly": true, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start": 21, | ||
"end": 23, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 13 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 22, | ||
"end": 23, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 13 | ||
}, | ||
"identifierName": "a" | ||
}, | ||
"name": "a" | ||
} | ||
}, | ||
"value": null | ||
}, | ||
{ | ||
"type": "ClassProperty", | ||
"start": 27, | ||
"end": 47, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 22 | ||
} | ||
}, | ||
"readonly": true, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start": 36, | ||
"end": 38, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 13 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 37, | ||
"end": 38, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 13 | ||
}, | ||
"identifierName": "b" | ||
}, | ||
"name": "b" | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start": 38, | ||
"end": 46, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 13 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 21 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start": 40, | ||
"end": 46, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 15 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 21 | ||
} | ||
} | ||
} | ||
}, | ||
"value": null | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/class/private-fields-static/input.ts
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,4 @@ | ||
class A { | ||
static #x; | ||
static #y: string; | ||
} |
Oops, something went wrong.