Merge pull request babel/babel-eslint#209 from Constellation/pattern-visitor

Patch SpreadProperty to escope's PatternVisitor
This commit is contained in:
Henry Zhu 2015-11-23 13:34:48 -05:00
parent 5352ad41c5
commit 0859607b4e

View File

@ -81,6 +81,19 @@ function monkeypatch() {
var referencerMod = createModule(referencerLoc);
var referencer = require(referencerLoc);
// monkeypatch escope/pattern-visitor
var patternVisitorLoc;
var patternVisitorMod;
var patternVisitor;
try {
patternVisitorLoc = Module._resolveFilename("./pattern-visitor", escopeMod);
patternVisitorMod = createModule(patternVisitorLoc);
patternVisitor = require(patternVisitorLoc);
} catch (err) {
// When eslint uses old escope, we cannot find pattern visitor.
// Fallback to the old way.
}
// reference Definition
var definitionLoc;
try {
@ -266,6 +279,12 @@ function monkeypatch() {
}
};
if (patternVisitor) {
patternVisitor.prototype.SpreadProperty = function (node) {
this.visit(node.argument);
};
}
// visit flow type in VariableDeclaration
var variableDeclaration = referencer.prototype.VariableDeclaration;
referencer.prototype.VariableDeclaration = function(node) {
@ -276,6 +295,8 @@ function monkeypatch() {
if (typeAnnotation) {
checkIdentifierOrVisit.call(this, typeAnnotation);
}
if (!patternVisitor) {
// Old method. Once escope in eslint is updated, this code is not necessary.
if (id.type === "ObjectPattern") {
// check if object destructuring has a spread
var hasSpread = id.properties.filter(function(p) {
@ -290,6 +311,7 @@ function monkeypatch() {
}
}
}
}
variableDeclaration.call(this, node);
};