Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for TS declare modifier on fields (#10545)
* [parser] Add support for TS declare modifier on fields (#10484) * [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment * Add support for TS declare types to types and generator (#10544) * Transform TypeScript "declare" fields (#10546) * Transform TypeScript "declare" fields * Remove multiple spaces * declareFields -> allowDeclareFields * Update after rebase
- Loading branch information
1 parent
87feda7
commit e9c1bce
Showing
38 changed files
with
985 additions
and
166 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
5 changes: 5 additions & 0 deletions
5
packages/babel-generator/test/fixtures/typescript/class-field-declare/input.js
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,5 @@ | ||
class A { | ||
declare foo; | ||
declare bar: string; | ||
declare readonly bax: number; | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-generator/test/fixtures/typescript/class-field-declare/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,4 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["typescript", "classProperties"] | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-generator/test/fixtures/typescript/class-field-declare/output.js
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,5 @@ | ||
class A { | ||
declare foo; | ||
declare bar: string; | ||
declare readonly bax: number; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
packages/babel-helper-create-class-features-plugin/src/typescript.js
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,19 @@ | ||
// @flow | ||
|
||
import type { NodePath } from "@babel/traverse"; | ||
|
||
export function assertFieldTransformed(path: NodePath) { | ||
// TODO (Babel 8): Also check path.node.definite | ||
|
||
if (path.node.declare) { | ||
throw path.buildCodeFrameError( | ||
`TypeScript 'declare' fields must first be transformed by ` + | ||
`@babel/plugin-transform-typescript.\n` + | ||
`If you have already enabled that plugin (or '@babel/preset-typescript'), make sure ` + | ||
`that it runs before any plugin related to additional class features:\n` + | ||
` - @babel/plugin-proposal-class-properties\n` + | ||
` - @babel/plugin-proposal-private-methods\n` + | ||
` - @babel/plugin-proposal-decorators`, | ||
); | ||
} | ||
} |
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"; | ||
} |
Oops, something went wrong.