diff --git a/acorn-to-esprima.js b/acorn-to-esprima.js index 8a26e10d..c54ae4d6 100644 --- a/acorn-to-esprima.js +++ b/acorn-to-esprima.js @@ -187,10 +187,6 @@ var astTransformVisitor = { return node.expression; } - if (t.isFlow(node)) { - return this.remove(); - } - if (t.isRestElement(node)) { return node.argument; } diff --git a/index.js b/index.js index 613d1fc7..4cafb784 100644 --- a/index.js +++ b/index.js @@ -89,6 +89,18 @@ function monkeypatch() { visitDecorators.call(this, node); visitProperty.call(this, node); } + + // monkeypatch referencer methods to visit flow type annotations + visitFunction = referencer.prototype.visitFunction; + referencer.prototype.visitFunction = function (node) { + for (var i = 0; i < node.params.length; i++) { + var p = node.params[i]; + if (p.typeAnnotation && p.typeAnnotation.typeAnnotation) { + this.visit(p.typeAnnotation.typeAnnotation.id); + } + } + visitFunction.call(this, node); + } } exports.attachComments = function (ast, comments, tokens) { diff --git a/test/non-regression.js b/test/non-regression.js index 1b2a2a8a..f71d2db1 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -132,6 +132,19 @@ describe("verify", function () { ); }); + it("flow import type #108", function () { + verifyAndAssertMessages([ + "import type Foo from 'foo';", + "function log(foo: Foo) {", + "console.log(foo);", + "}", + "log(a);" + ].join("\n"), + { "no-unused-vars": 1 }, + [] + ); + }); + it("type cast expression #102", function () { verifyAndAssertMessages( "for (let a of (a: Array)) {}",