diff --git a/src/acorn/plugins/flow.js b/src/acorn/plugins/flow.js index c4b8490829..edd3e931ef 100644 --- a/src/acorn/plugins/flow.js +++ b/src/acorn/plugins/flow.js @@ -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,14 +522,8 @@ 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": - return this.flow_parseTypeofType() - } + if (this.type.keyword === "typeof") { + return this.flow_parseTypeofType() } } @@ -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)) { diff --git a/src/acorn/src/state.js b/src/acorn/src/state.js index c4f6d9292b..cfc38c90de 100755 --- a/src/acorn/src/state.js +++ b/src/acorn/src/state.js @@ -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 diff --git a/test/acorn/tests-flow.js b/test/acorn/tests-flow.js index 9092d98028..1690329c69 100644 --- a/test/acorn/tests-flow.js +++ b/test/acorn/tests-flow.js @@ -11148,3 +11148,9 @@ for (var ns in fbTestFixture) { }); } } + +test("", {}, { + ecmaVersion: 6, + sourceType: "module", + plugins: { jsx: true, flow: true }, +});