Skip to content

Commit

Permalink
visit parameter flow types - fixes babel#108
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed May 21, 2015
1 parent a98b1ba commit fb5c8b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 0 additions & 4 deletions acorn-to-esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ var astTransformVisitor = {
return node.expression;
}

if (t.isFlow(node)) {
return this.remove();
}

if (t.isRestElement(node)) {
return node.argument;
}
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}",
Expand Down

0 comments on commit fb5c8b9

Please sign in to comment.