Flow comment parsing (#7007)

This commit is contained in:
Raja Sekar 2017-12-31 04:23:08 +05:30 committed by Nicolò Ribaudo
parent ebbd5c7321
commit f3410e761c
36 changed files with 1660 additions and 6 deletions

View File

@ -121,6 +121,7 @@ require("babylon").parse("code", {
| `estree` ([repo](https://github.com/estree/estree)) | n/a |
| `jsx` ([repo](https://facebook.github.io/jsx/)) | `<a attr="b">{s}</a>` |
| `flow` ([repo](https://github.com/facebook/flow)) | `var a: string = "";` |
| `flowComments` ([docs](https://flow.org/en/docs/types/comments/)) | `/*:: type Foo = {...}; */` |
| `typescript` ([repo](https://github.com/Microsoft/TypeScript)) | `var a: string = "";` |
| `doExpressions` | `var a = do { if (true) { 'hi'; } };` |
| `objectRestSpread` ([proposal](https://github.com/tc39/proposal-object-rest-spread)) | `var a = { b, ...c };` |

View File

@ -7,6 +7,7 @@ import { types as tt, type TokenType } from "../tokenizer/types";
import * as N from "../types";
import type { Pos, Position } from "../util/location";
import type State from "../tokenizer/state";
import * as charCodes from "charcodes";
const primitiveTypes = [
"any",
@ -2278,4 +2279,66 @@ export default (superClass: Class<Parser>): Class<Parser> =>
/* isAsync */ true,
);
}
readToken_mult_modulo(code: number): void {
const next = this.input.charCodeAt(this.state.pos + 1);
if (
code === charCodes.asterisk &&
next === charCodes.slash &&
this.state.hasFlowComment
) {
this.state.hasFlowComment = false;
this.state.pos += 2;
this.nextToken();
return;
}
super.readToken_mult_modulo(code);
}
skipBlockComment(): void {
if (
this.hasPlugin("flow") &&
this.hasPlugin("flowComments") &&
this.skipFlowComment()
) {
this.hasFlowCommentCompletion();
this.state.pos += this.skipFlowComment();
this.state.hasFlowComment = true;
return;
}
let end;
if (this.hasPlugin("flow") && this.state.hasFlowComment) {
end = this.input.indexOf("*-/", (this.state.pos += 2));
if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment");
this.state.pos = end + 3;
return;
}
super.skipBlockComment();
}
skipFlowComment(): number | boolean {
const ch2 = this.input.charCodeAt(this.state.pos + 2);
const ch3 = this.input.charCodeAt(this.state.pos + 3);
if (ch2 === charCodes.colon && ch3 === charCodes.colon) {
return 4; // check for /*::
}
if (this.input.slice(this.state.pos + 2, 14) === "flow-include") {
return 14; // check for /*flow-include
}
if (ch2 === charCodes.colon && ch3 !== charCodes.colon && 2) {
return 2; // check for /*:, advance only 2 steps
}
return false;
}
hasFlowCommentCompletion(): void {
const end = this.input.indexOf("*/", this.state.pos);
if (end === -1) {
this.raise(this.state.pos, "Unterminated comment");
}
}
};

View File

@ -0,0 +1,3 @@
class MyClass {
/*:: prop: string; */
}

View File

@ -0,0 +1,120 @@
{
"type": "File",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "MyClass"
},
"name": "MyClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 14,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 3,
"column": 1
}
},
"body": [],
"leadingComments": null,
"innerComments": [
{
"type": "CommentBlock",
"value": ":: prop: string; ",
"start": 18,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 23
}
}
}
]
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": ":: prop: string; ",
"start": 18,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 23
}
}
}
]
}

View File

@ -0,0 +1,7 @@
/*::
type Foo = {
foo: number,
bar: boolean,
baz: string
};
*/

View File

@ -0,0 +1,70 @@
{
"type": "File",
"start": 0,
"end": 68,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"program": {
"type": "Program",
"start": 0,
"end": 68,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"sourceType": "module",
"body": [],
"directives": [],
"leadingComments": null,
"innerComments": [
{
"type": "CommentBlock",
"value": "::\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n",
"start": 0,
"end": 68,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
}
}
]
},
"comments": [
{
"type": "CommentBlock",
"value": "::\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n",
"start": 0,
"end": 68,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
}
}
]
}

View File

@ -0,0 +1,7 @@
/*flow-include
type Foo = {
foo: number,
bar: boolean,
baz: string
};
*/

View File

@ -0,0 +1,70 @@
{
"type": "File",
"start": 0,
"end": 78,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"program": {
"type": "Program",
"start": 0,
"end": 78,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"sourceType": "module",
"body": [],
"directives": [],
"leadingComments": null,
"innerComments": [
{
"type": "CommentBlock",
"value": "flow-include\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n",
"start": 0,
"end": 78,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
}
}
]
},
"comments": [
{
"type": "CommentBlock",
"value": "flow-include\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n",
"start": 0,
"end": 78,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
}
}
]
}

View File

@ -0,0 +1,3 @@
class MyClass {
/*flow-include prop: string; */
}

View File

@ -0,0 +1,120 @@
{
"type": "File",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "MyClass"
},
"name": "MyClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 14,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 3,
"column": 1
}
},
"body": [],
"leadingComments": null,
"innerComments": [
{
"type": "CommentBlock",
"value": "flow-include prop: string; ",
"start": 18,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 33
}
}
}
]
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": "flow-include prop: string; ",
"start": 18,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 33
}
}
}
]
}

View File

@ -0,0 +1,2 @@
function method(param /*: string */) /*: number */ {
}

View File

@ -0,0 +1,191 @@
{
"type": "File",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "method"
},
"name": "method"
},
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 16,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "param"
},
"name": "param",
"leadingComments": null,
"trailingComments": [
{
"type": "CommentBlock",
"value": ": string ",
"start": 22,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 35
}
}
}
]
}
],
"body": {
"type": "BlockStatement",
"start": 51,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 51
},
"end": {
"line": 2,
"column": 1
}
},
"body": [],
"directives": [],
"leadingComments": [
{
"type": "CommentBlock",
"value": ": string ",
"start": 22,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 35
}
}
},
{
"type": "CommentBlock",
"value": ": number ",
"start": 37,
"end": 50,
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 50
}
}
}
]
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": ": string ",
"start": 22,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 35
}
}
},
{
"type": "CommentBlock",
"value": ": number ",
"start": 37,
"end": 50,
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 50
}
}
}
]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["jsx", "flow"]
}

View File

@ -0,0 +1,3 @@
class MyClass {
/*:: prop: string; */
}

View File

@ -0,0 +1,150 @@
{
"type": "File",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "MyClass"
},
"name": "MyClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 14,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ClassProperty",
"start": 23,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 20
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 23,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 11
},
"identifierName": "prop"
},
"name": "prop"
},
"computed": false,
"variance": null,
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 27,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 19
}
},
"typeAnnotation": {
"type": "StringTypeAnnotation",
"start": 29,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 13
},
"end": {
"line": 2,
"column": 19
}
}
}
},
"value": null
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,7 @@
/*::
type Foo = {
foo: number,
bar: boolean,
baz: string
};
*/

View File

@ -0,0 +1,243 @@
{
"type": "File",
"start": 0,
"end": 68,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"program": {
"type": "Program",
"start": 0,
"end": 68,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"sourceType": "module",
"body": [
{
"type": "TypeAlias",
"start": 5,
"end": 65,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 6,
"column": 2
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "Foo"
},
"name": "Foo"
},
"typeParameters": null,
"right": {
"type": "ObjectTypeAnnotation",
"start": 16,
"end": 64,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 6,
"column": 1
}
},
"callProperties": [],
"properties": [
{
"type": "ObjectTypeProperty",
"start": 20,
"end": 31,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 13
}
},
"key": {
"type": "Identifier",
"start": 20,
"end": 23,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
},
"static": false,
"kind": "init",
"method": false,
"value": {
"type": "NumberTypeAnnotation",
"start": 25,
"end": 31,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 13
}
}
},
"variance": null,
"optional": false
},
{
"type": "ObjectTypeProperty",
"start": 35,
"end": 47,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 14
}
},
"key": {
"type": "Identifier",
"start": 35,
"end": 38,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "bar"
},
"name": "bar"
},
"static": false,
"kind": "init",
"method": false,
"value": {
"type": "BooleanTypeAnnotation",
"start": 40,
"end": 47,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 14
}
}
},
"variance": null,
"optional": false
},
{
"type": "ObjectTypeProperty",
"start": 51,
"end": 62,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 13
}
},
"key": {
"type": "Identifier",
"start": 51,
"end": 54,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 5
},
"identifierName": "baz"
},
"name": "baz"
},
"static": false,
"kind": "init",
"method": false,
"value": {
"type": "StringTypeAnnotation",
"start": 56,
"end": 62,
"loc": {
"start": {
"line": 5,
"column": 7
},
"end": {
"line": 5,
"column": 13
}
}
},
"variance": null,
"optional": false
}
],
"indexers": [],
"exact": false
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,7 @@
/*flow-include
type Foo = {
foo: number,
bar: boolean,
baz: string
};
*/

View File

@ -0,0 +1,243 @@
{
"type": "File",
"start": 0,
"end": 78,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"program": {
"type": "Program",
"start": 0,
"end": 78,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 2
}
},
"sourceType": "module",
"body": [
{
"type": "TypeAlias",
"start": 15,
"end": 75,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 6,
"column": 2
}
},
"id": {
"type": "Identifier",
"start": 20,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "Foo"
},
"name": "Foo"
},
"typeParameters": null,
"right": {
"type": "ObjectTypeAnnotation",
"start": 26,
"end": 74,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 6,
"column": 1
}
},
"callProperties": [],
"properties": [
{
"type": "ObjectTypeProperty",
"start": 30,
"end": 41,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 13
}
},
"key": {
"type": "Identifier",
"start": 30,
"end": 33,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
},
"static": false,
"kind": "init",
"method": false,
"value": {
"type": "NumberTypeAnnotation",
"start": 35,
"end": 41,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 13
}
}
},
"variance": null,
"optional": false
},
{
"type": "ObjectTypeProperty",
"start": 45,
"end": 57,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 14
}
},
"key": {
"type": "Identifier",
"start": 45,
"end": 48,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "bar"
},
"name": "bar"
},
"static": false,
"kind": "init",
"method": false,
"value": {
"type": "BooleanTypeAnnotation",
"start": 50,
"end": 57,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 14
}
}
},
"variance": null,
"optional": false
},
{
"type": "ObjectTypeProperty",
"start": 61,
"end": 72,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 13
}
},
"key": {
"type": "Identifier",
"start": 61,
"end": 64,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 5
},
"identifierName": "baz"
},
"name": "baz"
},
"static": false,
"kind": "init",
"method": false,
"value": {
"type": "StringTypeAnnotation",
"start": 66,
"end": 72,
"loc": {
"start": {
"line": 5,
"column": 7
},
"end": {
"line": 5,
"column": 13
}
}
},
"variance": null,
"optional": false
}
],
"indexers": [],
"exact": false
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
class MyClass {
/*flow-include prop: string; */
}

View File

@ -0,0 +1,120 @@
{
"type": "File",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "MyClass"
},
"name": "MyClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 14,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 3,
"column": 1
}
},
"body": [],
"leadingComments": null,
"innerComments": [
{
"type": "CommentBlock",
"value": "flow-include prop: string; ",
"start": 18,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 33
}
}
}
]
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": "flow-include prop: string; ",
"start": 18,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 33
}
}
}
]
}

View File

@ -0,0 +1,2 @@
function method(param /*: string */) /*: number */ {
}

View File

@ -0,0 +1,165 @@
{
"type": "File",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "method"
},
"name": "method"
},
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 16,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 32
},
"identifierName": "param"
},
"name": "param",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 24,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 32
}
},
"typeAnnotation": {
"type": "StringTypeAnnotation",
"start": 26,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 32
}
}
}
}
}
],
"predicate": null,
"returnType": {
"type": "TypeAnnotation",
"start": 39,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 39
},
"end": {
"line": 1,
"column": 47
}
},
"typeAnnotation": {
"type": "NumberTypeAnnotation",
"start": 41,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 41
},
"end": {
"line": 1,
"column": 47
}
}
}
},
"body": {
"type": "BlockStatement",
"start": 51,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 51
},
"end": {
"line": 2,
"column": 1
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
class MyClass {
/*:: prop: string;
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unterminated comment (2:2)"
}

View File

@ -0,0 +1,6 @@
/*::
type Foo = {
foo: number,
bar: boolean,
baz: string
};

View File

@ -0,0 +1,3 @@
{
"throws": "Unterminated comment (1:0)"
}

View File

@ -0,0 +1,6 @@
/*flow-include
type Foo = {
foo: number,
bar: boolean,
baz: string
};

View File

@ -0,0 +1,3 @@
{
"throws": "Unterminated comment (1:0)"
}

View File

@ -0,0 +1,3 @@
class MyClass {
/*flow-include prop: string;
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unterminated comment (2:2)"
}

View File

@ -0,0 +1,2 @@
function method(param /*: string) {
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unterminated comment (1:22)"
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["jsx", "flow", "flowComments"]
}

View File

@ -36,11 +36,7 @@ invalid_syntax/migrated_0003.js
invalid_syntax/migrated_0010.js
private_class_properties/valid.js
types/annotations/migrated_0001.js
types/annotations_in_comments_invalid/migrated_0000.js
types/annotations_in_comments_invalid/migrated_0001.js
types/annotations_in_comments_invalid/migrated_0002.js
types/annotations_in_comments_invalid/migrated_0003.js
types/annotations_in_comments_invalid/migrated_0004.js
types/annotations/static_is_reserved_param.js
types/annotations/static_is_reserved_type.js
types/annotations/void_is_reserved_param.js

View File

@ -99,7 +99,13 @@ function update_whitelist(summary) {
}
const options = {
plugins: ["jsx", "flow", "asyncGenerators", "objectRestSpread"],
plugins: [
"jsx",
"flow",
"flowComments",
"asyncGenerators",
"objectRestSpread",
],
sourceType: "module",
ranges: true,
};
@ -109,6 +115,7 @@ const flowOptionsMapping = {
esproposal_class_static_fields: "classProperties",
esproposal_export_star_as: "exportNamespaceFrom",
esproposal_decorators: "decorators",
types: "flowComments",
};
const summary = {
@ -142,7 +149,15 @@ tests.forEach(section => {
if (test.options) {
Object.keys(test.options).forEach(option => {
if (!test.options[option]) return;
if (!test.options[option]) {
const idx = babylonOptions.plugins.indexOf(
flowOptionsMapping[option]
);
if (idx) {
babylonOptions.plugins.splice(idx, 1);
}
return;
}
if (!flowOptionsMapping[option]) {
throw new Error("Parser options not mapped " + option);
}