Merge pull request babel/babel-eslint#133 from hzoo/i-132

support flow declarations correctly, lint - fixes babel/babel-eslint#132
This commit is contained in:
Henry Zhu 2015-06-17 07:17:26 -04:00
parent da3d4bf537
commit d224153cba
3 changed files with 30 additions and 14 deletions

View File

@ -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;
@ -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()) {

View File

@ -178,7 +178,7 @@ function monkeypatch() {
}
scope.__define = function() {
return parentScope.__define.apply(parentScope, arguments);
}
};
return scope;
}
@ -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]);
}
@ -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) {

View File

@ -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' ]
);
});
@ -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(
[
@ -1133,6 +1145,6 @@ describe("verify", function () {
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
{ "no-undef": 1, "no-unused-vars": 1 },
[]
)
);
});
});