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 TS declare modifier on fields (#10484)
* [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment
- Loading branch information
1 parent
d25262e
commit aa2363d
Showing
10 changed files
with
467 additions
and
47 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
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/class/declare-field-initializer/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 { | ||
declare bar: string = "test"; | ||
} |
170 changes: 170 additions & 0 deletions
170
packages/babel-parser/test/fixtures/typescript/class/declare-field-initializer/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,170 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 43, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 43, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start": 0, | ||
"end": 43, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"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": 43, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 8 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start": 12, | ||
"end": 41, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 31 | ||
} | ||
}, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start": 20, | ||
"end": 23, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 10 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 13 | ||
}, | ||
"identifierName": "bar" | ||
}, | ||
"name": "bar" | ||
}, | ||
"computed": false, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start": 23, | ||
"end": 31, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 13 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 21 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start": 25, | ||
"end": 31, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 15 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 21 | ||
} | ||
} | ||
} | ||
}, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start": 34, | ||
"end": 40, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 24 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 30 | ||
} | ||
}, | ||
"extra": { | ||
"rawValue": "test", | ||
"raw": "\"test\"" | ||
}, | ||
"value": "test" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/class/declare-field/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 { | ||
declare foo; | ||
declare bar: string; | ||
} |
Oops, something went wrong.