Fix predicate attachment to match flow parser (#428)
This commit is contained in:
committed by
Daniel Tschinder
parent
cbf4203237
commit
bdfa92464b
@@ -40,7 +40,7 @@ pp.flowParsePredicate = function() {
|
||||
this.raise(moduloPos, "Spaces between ´%´ and ´checks´ are not allowed here.");
|
||||
}
|
||||
if (this.eat(tt.parenL)) {
|
||||
node.expression = this.parseExpression();
|
||||
node.value = this.parseExpression();
|
||||
this.expect(tt.parenR);
|
||||
return this.finishNode(node, "DeclaredPredicate");
|
||||
} else {
|
||||
@@ -92,10 +92,10 @@ pp.flowParseDeclareFunction = function (node) {
|
||||
typeNode.params = tmp.params;
|
||||
typeNode.rest = tmp.rest;
|
||||
this.expect(tt.parenR);
|
||||
let predicate = null;
|
||||
[typeNode.returnType, predicate] = this.flowParseTypeAndPredicateInitialiser();
|
||||
|
||||
[typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
|
||||
typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
|
||||
typeContainer.predicate = predicate;
|
||||
|
||||
id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
|
||||
|
||||
this.finishNode(id, id.type);
|
||||
@@ -836,12 +836,6 @@ pp.flowParseTypeAnnotation = function () {
|
||||
return this.finishNode(node, "TypeAnnotation");
|
||||
};
|
||||
|
||||
pp.flowParseTypeAndPredicateAnnotation = function () {
|
||||
const node = this.startNode();
|
||||
[node.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
|
||||
return this.finishNode(node, "TypeAnnotation");
|
||||
};
|
||||
|
||||
pp.flowParseTypeAnnotatableIdentifier = function () {
|
||||
const ident = this.flowParseRestrictedIdentifier();
|
||||
if (this.match(tt.colon)) {
|
||||
@@ -884,7 +878,12 @@ export default function (instance) {
|
||||
if (this.match(tt.colon) && !allowExpression) {
|
||||
// if allowExpression is true then we're parsing an arrow function and if
|
||||
// there's a return type then it's been handled elsewhere
|
||||
node.returnType = this.flowParseTypeAndPredicateAnnotation();
|
||||
const typeNode = this.startNode();
|
||||
[typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
|
||||
|
||||
node.returnType = typeNode.typeAnnotation
|
||||
? this.finishNode(typeNode, "TypeAnnotation")
|
||||
: null;
|
||||
}
|
||||
|
||||
return inner.call(this, node, allowExpression);
|
||||
@@ -1437,13 +1436,19 @@ export default function (instance) {
|
||||
try {
|
||||
const oldNoAnonFunctionType = this.state.noAnonFunctionType;
|
||||
this.state.noAnonFunctionType = true;
|
||||
const returnType = this.flowParseTypeAndPredicateAnnotation();
|
||||
|
||||
const typeNode = this.startNode();
|
||||
[typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
|
||||
|
||||
this.state.noAnonFunctionType = oldNoAnonFunctionType;
|
||||
|
||||
if (this.canInsertSemicolon()) this.unexpected();
|
||||
if (!this.match(tt.arrow)) this.unexpected();
|
||||
|
||||
// assign after it is clear it is an arrow
|
||||
node.returnType = returnType;
|
||||
node.returnType = typeNode.typeAnnotation
|
||||
? this.finishNode(typeNode, "TypeAnnotation")
|
||||
: null;
|
||||
} catch (err) {
|
||||
if (err instanceof SyntaxError) {
|
||||
this.state = state;
|
||||
|
||||
Reference in New Issue
Block a user