-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for
declare
on class fields with Flow (#11178)
* Add parser support for Flow declare fields * Add generator test * Add "allowDeclareFields" option to flow-strip-types * Add test * Update error messages * More tests
- Loading branch information
1 parent
286aaea
commit 5c1a821
Showing
51 changed files
with
2,439 additions
and
51 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/babel-generator/test/fixtures/flow/declare-field/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,4 @@ | ||
class A { | ||
declare x | ||
declare static y | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/flow/declare-field/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 @@ | ||
{ | ||
"plugins": ["flow", "classProperties"] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-generator/test/fixtures/flow/declare-field/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,4 @@ | ||
class A { | ||
declare x; | ||
declare static y; | ||
} |
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
...babel-parser/test/fixtures/flow/class-private-property/declare-field-initializer/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,3 @@ | ||
class A { | ||
declare #foo = 2 | ||
} |
158 changes: 158 additions & 0 deletions
158
...el-parser/test/fixtures/flow/class-private-property/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,158 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 30, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"errors": [ | ||
"SyntaxError: Initializers are not allowed in fields with the `declare` modifier. (2:17)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 30, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start": 0, | ||
"end": 30, | ||
"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": 30, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 8 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"body": [ | ||
{ | ||
"type": "ClassPrivateProperty", | ||
"start": 12, | ||
"end": 28, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 18 | ||
} | ||
}, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start": 20, | ||
"end": 24, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 10 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 14 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 21, | ||
"end": 24, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 14 | ||
}, | ||
"identifierName": "foo" | ||
}, | ||
"name": "foo" | ||
} | ||
}, | ||
"variance": null, | ||
"value": { | ||
"type": "NumericLiteral", | ||
"start": 27, | ||
"end": 28, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 17 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 18 | ||
} | ||
}, | ||
"extra": { | ||
"rawValue": 2, | ||
"raw": "2" | ||
}, | ||
"value": 2 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/flow/class-private-property/declare-field/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,3 @@ | ||
class A { | ||
declare #foo | ||
} |
Oops, something went wrong.