parse void as an identifier when inside a type annotation to avoid setting void keyword token - cc @DmitrySoshnikov
This commit is contained in:
parent
5b5d27c9b8
commit
f5540d19a4
@ -1,3 +1,4 @@
|
||||
Error.stackTraceLimit = Infinity;
|
||||
var acorn = require("../src/index")
|
||||
|
||||
var pp = acorn.Parser.prototype
|
||||
@ -352,12 +353,6 @@ pp.flow_parseGenericType = function (start, id) {
|
||||
return this.finishNode(node, "GenericTypeAnnotation")
|
||||
}
|
||||
|
||||
pp.flow_parseVoidType = function () {
|
||||
var node = this.startNode()
|
||||
this.expect(tt._void)
|
||||
return this.finishNode(node, "VoidTypeAnnotation")
|
||||
}
|
||||
|
||||
pp.flow_parseTypeofType = function () {
|
||||
var node = this.startNode()
|
||||
this.expect(tt._typeof)
|
||||
@ -411,6 +406,9 @@ pp.flow_identToTypeAnnotation = function (start, node, id) {
|
||||
case "any":
|
||||
return this.finishNode(node, "AnyTypeAnnotation")
|
||||
|
||||
case "void":
|
||||
return this.finishNode(node, "VoidTypeAnnotation")
|
||||
|
||||
case "bool":
|
||||
case "boolean":
|
||||
return this.finishNode(node, "BooleanTypeAnnotation")
|
||||
@ -524,16 +522,10 @@ pp.flow_parsePrimaryType = function () {
|
||||
return this.finishNode(node, "StringLiteralTypeAnnotation")
|
||||
|
||||
default:
|
||||
if (this.type.keyword) {
|
||||
switch (this.type.keyword) {
|
||||
case "void":
|
||||
return this.flow_parseVoidType()
|
||||
|
||||
case "typeof":
|
||||
if (this.type.keyword === "typeof") {
|
||||
return this.flow_parseTypeofType()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.unexpected()
|
||||
}
|
||||
@ -694,6 +686,14 @@ acorn.plugins.flow = function (instance) {
|
||||
}
|
||||
})
|
||||
|
||||
// don't consider `void` to be a keyword as then it'll use the void token type
|
||||
// and set startExpr
|
||||
instance.extend("isKeyword", function (inner) {
|
||||
return function(name) {
|
||||
return name !== "void" && inner.call(this, name)
|
||||
}
|
||||
})
|
||||
|
||||
instance.extend("readToken", function (inner) {
|
||||
return function(code) {
|
||||
if (this.inType && (code === 62 || code === 60)) {
|
||||
|
||||
@ -4,11 +4,11 @@ import {lineBreak} from "./whitespace"
|
||||
|
||||
export function Parser(options, input, startPos) {
|
||||
this.options = options
|
||||
this.loadPlugins(this.options.plugins)
|
||||
this.sourceFile = this.options.sourceFile || null
|
||||
this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5]
|
||||
this.isReservedWord = reservedWords[this.options.ecmaVersion]
|
||||
this.input = input
|
||||
this.loadPlugins(this.options.plugins)
|
||||
|
||||
// Set up token state
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user