add support for boolean flow literals - fixes #2127
This commit is contained in:
parent
ba2d18f025
commit
436874dac8
@ -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.
|
||||
*/
|
||||
|
||||
@ -13,6 +13,10 @@ define("BooleanTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"]
|
||||
});
|
||||
|
||||
define("BooleanLiteralTypeAnnotation", {
|
||||
aliases: ["Flow"]
|
||||
});
|
||||
|
||||
define("ClassImplements", {
|
||||
visitor: ["id", "typeParameters"],
|
||||
aliases: ["Flow"]
|
||||
|
||||
2
packages/babel/test/fixtures/generation/flow/boolean-literal-types/actual.js
vendored
Normal file
2
packages/babel/test/fixtures/generation/flow/boolean-literal-types/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var foo: true;
|
||||
var bar: false;
|
||||
2
packages/babel/test/fixtures/generation/flow/boolean-literal-types/expected.js
vendored
Normal file
2
packages/babel/test/fixtures/generation/flow/boolean-literal-types/expected.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var foo: true;
|
||||
var bar: false;
|
||||
@ -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);
|
||||
|
||||
1
packages/babylon/test/fixtures/flow/literal-types/boolean-false/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/literal-types/boolean-false/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var foo: true
|
||||
1
packages/babylon/test/fixtures/flow/literal-types/boolean-true/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/literal-types/boolean-true/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var foo: false
|
||||
Loading…
x
Reference in New Issue
Block a user