Fix negative number literal typeannotations (#366)
* Fix negative number literal typeannotations Also use parseLiteral() to parser string and number literal typeannotations so that future changes (estree) to literals are also reflected to flow. * Instead of invalid fallthrough throw immediately * Increase coverage and better error mesage
This commit is contained in:
@@ -704,11 +704,7 @@ pp.flowParsePrimaryType = function () {
|
||||
return this.finishNode(node, "FunctionTypeAnnotation");
|
||||
|
||||
case tt.string:
|
||||
node.value = this.state.value;
|
||||
this.addExtra(node, "rawValue", node.value);
|
||||
this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end));
|
||||
this.next();
|
||||
return this.finishNode(node, "StringLiteralTypeAnnotation");
|
||||
return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
|
||||
|
||||
case tt._true: case tt._false:
|
||||
node.value = this.match(tt._true);
|
||||
@@ -718,21 +714,14 @@ pp.flowParsePrimaryType = function () {
|
||||
case tt.plusMin:
|
||||
if (this.state.value === "-") {
|
||||
this.next();
|
||||
if (!this.match(tt.num)) this.unexpected();
|
||||
if (!this.match(tt.num)) this.unexpected(null, "Unexpected token, expected number");
|
||||
|
||||
node.value = -this.state.value;
|
||||
this.addExtra(node, "rawValue", node.value);
|
||||
this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end));
|
||||
this.next();
|
||||
return this.finishNode(node, "NumericLiteralTypeAnnotation");
|
||||
return this.parseLiteral(-this.state.value, "NumericLiteralTypeAnnotation", node.start, node.loc.start);
|
||||
}
|
||||
|
||||
this.unexpected();
|
||||
case tt.num:
|
||||
node.value = this.state.value;
|
||||
this.addExtra(node, "rawValue", node.value);
|
||||
this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end));
|
||||
this.next();
|
||||
return this.finishNode(node, "NumericLiteralTypeAnnotation");
|
||||
return this.parseLiteral(this.state.value, "NumericLiteralTypeAnnotation");
|
||||
|
||||
case tt._null:
|
||||
node.value = this.match(tt._null);
|
||||
|
||||
Reference in New Issue
Block a user