Add support for leading pipes in Flow type alias RHS syntax

This commit is contained in:
Jeff Morrison
2016-02-04 15:50:19 -05:00
parent 5f0ece0bdb
commit acc946c09e
3 changed files with 455 additions and 2 deletions

View File

@@ -3,10 +3,15 @@ import Parser from "../parser";
let pp = Parser.prototype;
pp.flowParseTypeInitialiser = function (tok) {
pp.flowParseTypeInitialiser = function (tok, allowLeadingPipeOrAnd) {
let oldInType = this.state.inType;
this.state.inType = true;
this.expect(tok || tt.colon);
if (allowLeadingPipeOrAnd) {
if (this.match(tt.bitwiseAND) || this.match(tt.bitwiseOR)) {
this.next();
}
}
let type = this.flowParseType();
this.state.inType = oldInType;
return type;
@@ -172,7 +177,10 @@ pp.flowParseTypeAlias = function (node) {
node.typeParameters = null;
}
node.right = this.flowParseTypeInitialiser(tt.eq);
node.right = this.flowParseTypeInitialiser(
tt.eq,
/*allowLeadingPipeOrAnd*/ true
);
this.semicolon();
return this.finishNode(node, "TypeAlias");