Add support for flow's SymbolTypeAnnotation (#11077)

This commit is contained in:
Brian Ng
2020-03-16 17:00:17 -05:00
committed by GitHub
parent 2bce1e5e20
commit 4f394e30d2
14 changed files with 291 additions and 2 deletions

View File

@@ -1333,6 +1333,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
case "string":
return this.finishNode(node, "StringTypeAnnotation");
case "symbol":
return this.finishNode(node, "SymbolTypeAnnotation");
default:
this.checkNotUnderscore(id.name);
return this.flowParseGenericType(startPos, startLoc, id);

View File

@@ -0,0 +1 @@
declare var x: symbol;

View File

@@ -0,0 +1,97 @@
{
"type": "File",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"program": {
"type": "Program",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "DeclareVariable",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"id": {
"type": "Identifier",
"start": 12,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 13,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 21
}
},
"typeAnnotation": {
"type": "SymbolTypeAnnotation",
"start": 15,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 21
}
}
}
}
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
const x: symbol = Symbol();

View File

@@ -0,0 +1,148 @@
{
"type": "File",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 27
}
},
"program": {
"type": "Program",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 27
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 27
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 26
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 7,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 15
}
},
"typeAnnotation": {
"type": "SymbolTypeAnnotation",
"start": 9,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 15
}
}
}
}
},
"init": {
"type": "CallExpression",
"start": 18,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 26
}
},
"callee": {
"type": "Identifier",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 24
},
"identifierName": "Symbol"
},
"name": "Symbol"
},
"arguments": []
}
}
],
"kind": "const"
}
],
"directives": []
}
}