Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

support flow declarations correctly, lint - fixes #132 #133

Merged
merged 1 commit into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions acorn-to-esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ var astTransformVisitor = {
return node.argument;
}

// prevent "no-undef"
// flow: prevent "no-undef"
// for "Component" in: "let x: React.Component"
if (this.isQualifiedTypeIdentifier()) {
delete node.id;
Expand All @@ -201,15 +201,6 @@ var astTransformVisitor = {
delete node.name;
}

// flow

if (this.isDeclareModule() ||
this.isDeclareClass() ||
this.isDeclareFunction() ||
this.isDeclareVariable()) {
return this.dangerouslyRemove();
}

// modules

if (this.isImportDeclaration()) {
Expand Down
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function monkeypatch() {
}
scope.__define = function() {
return parentScope.__define.apply(parentScope, arguments);
}
};
return scope;
}

Expand Down Expand Up @@ -250,7 +250,7 @@ function monkeypatch() {
if (typeAnnotation) {
checkIdentifierOrVisit.call(this, typeAnnotation);
}
if (id.type === 'ObjectPattern') {
if (id.type === "ObjectPattern") {
for (var j = 0; j < id.properties.length; j++) {
this.visit(id.properties[j]);
}
Expand Down Expand Up @@ -304,6 +304,19 @@ function monkeypatch() {
this.visit(node.right);
}
};

referencer.prototype.DeclareModule =
referencer.prototype.DeclareFunction =
referencer.prototype.DeclareVariable =
referencer.prototype.DeclareClass = function(node) {
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope(this.scopeManager, node);
}
if (typeParamScope) {
this.close(node);
}
};
}

exports.attachComments = function (ast, comments, tokens) {
Expand Down
16 changes: 14 additions & 2 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe("verify", function () {
"var b: T = 1; b;"
].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 },
[ '1:20 T is defined but never used no-unused-vars',
[ "1:20 T is defined but never used no-unused-vars",
'3:7 "T" is not defined. no-undef' ]
);
});
Expand All @@ -371,6 +371,18 @@ describe("verify", function () {
);
});

it("support declarations #132", function () {
verifyAndAssertMessages([
"declare class A { static () : number }",
"declare module B { declare var x: number; }",
"declare function foo<T>(): void;",
"declare var bar"
].join("\n"),
{ "no-undef": 1, "no-unused-vars": 1 },
[]
);
});

it("1", function () {
verifyAndAssertMessages(
[
Expand Down Expand Up @@ -1133,6 +1145,6 @@ describe("verify", function () {
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
{ "no-undef": 1, "no-unused-vars": 1 },
[]
)
);
});
});