add support for boolean flow literals - fixes #2127

This commit is contained in:
Sebastian McKenzie 2015-07-30 23:44:36 +01:00
parent ba2d18f025
commit 436874dac8
21 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,14 @@ export function BooleanTypeAnnotation(node) {
this.push("bool");
}
/**
* Prints BooleanLiteralTypeAnnotation.
*/
export function BooleanLiteralTypeAnnotation(node) {
this.push(node.value ? "true" : "false");
}
/**
* Prints DeclareClass, prints node.
*/

View File

@ -13,6 +13,10 @@ define("BooleanTypeAnnotation", {
aliases: ["Flow", "FlowBaseAnnotation"]
});
define("BooleanLiteralTypeAnnotation", {
aliases: ["Flow"]
});
define("ClassImplements", {
visitor: ["id", "typeParameters"],
aliases: ["Flow"]

View File

@ -0,0 +1,2 @@
var foo: true;
var bar: false;

View File

@ -0,0 +1,2 @@
var foo: true;
var bar: false;

View File

@ -493,6 +493,11 @@ pp.flowParsePrimaryType = function () {
this.next();
return this.finishNode(node, "StringLiteralTypeAnnotation");
case tt._true: case tt._false:
node.value = this.match(tt._true)
this.next();
return this.finishNode(node, "BooleanLiteralTypeAnnotation");
case tt.num:
node.rawValue = node.value = this.state.value;
node.raw = this.input.slice(this.state.start, this.state.end);

View File

@ -0,0 +1 @@
var foo: true

View File

@ -0,0 +1 @@
var foo: false