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

Commit

Permalink
Prevent escope referencer from traversing into param pattern type ann…
Browse files Browse the repository at this point in the history
…otations
  • Loading branch information
sebmck committed Feb 1, 2016
1 parent 0d30882 commit b26bc58
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.js
Expand Up @@ -47,17 +47,23 @@ function monkeypatch() {
estraverseRelative = createModule(esrecurseLoc);
} catch (err) {}

// contains all the instances of estraverse so we can modify them if necessary
var estraverses = [];

// monkeypatch estraverse
estraverse = estraverseRelative.require("estraverse");
estraverses.push(estraverse);
assign(estraverse.VisitorKeys, t.VISITOR_KEYS);

// monkeypatch estraverse-fb
var estraverseFb = eslintMod.require("estraverse-fb");
estraverses.push(estraverseFb);
assign(estraverseFb.VisitorKeys, t.VISITOR_KEYS);

// ESLint v1.9.0 uses estraverse directly to work around https://github.com/npm/npm/issues/9663
var estraverseOfEslint = eslintMod.require("estraverse");
if (estraverseOfEslint !== estraverseFb) {
estraverses.push(estraverseOfEslint);
assign(estraverseOfEslint.VisitorKeys, t.VISITOR_KEYS);
}

Expand Down Expand Up @@ -279,7 +285,18 @@ function monkeypatch() {
}
}
}
// set ArrayPattern/ObjectPattern visitor keys back to their original. otherwise
// escope will traverse into them and include the identifiers within as declarations
estraverses.forEach(function (estraverse) {
estraverse.VisitorKeys.ObjectPattern = ["properties"];
estraverse.VisitorKeys.ArrayPattern = ["elements"];
});
visitFunction.call(this, node);
// set them back to normal...
estraverses.forEach(function (estraverse) {
estraverse.VisitorKeys.ObjectPattern = t.VISITOR_KEYS.ObjectPattern;
estraverse.VisitorKeys.ObjectPattern = t.VISITOR_KEYS.ArrayPattern;
});
if (typeParamScope) {
this.close(node);
}
Expand Down
14 changes: 14 additions & 0 deletions test/non-regression.js
Expand Up @@ -1340,6 +1340,20 @@ describe("verify", function () {
);
});

it("", function () {

verifyAndAssertMessages([
"import type Foo from 'bar';",
"class Foobar {",
" foo({ bar }: Foo) {}",
" bar({ foo }: Foo) {}",
"}"
].join("\n"),
{ "no-unused-vars": 1 },
[]
);
});

// it("regex with es6 unicodeCodePointEscapes", function () {
// verifyAndAssertMessages(
// "string.replace(/[\u{0000A0}-\u{10FFFF}<>\&]/gmiu, (char) => `&#x${char.codePointAt(0).toString(16)};`);",
Expand Down

0 comments on commit b26bc58

Please sign in to comment.