Skip to content

Commit

Permalink
[[FIX]] report line numbers of destructured params
Browse files Browse the repository at this point in the history
The extract to scope manager change introduced a regression where by
destructured params did not get the right line and char due to the token
not being passed to the scope manager.
Fixes #2494
  • Loading branch information
lukeapage committed Jul 19, 2015
1 parent 9f2b64c commit 7d25451
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,7 @@ var JSHINT = (function() {
t = tokens[t];
if (t.id) {
paramsIds.push(t.id);
currentParams.push([t.id, t]);
currentParams.push([t.id, t.token]);
}
}
} else {
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ exports.undef = function (test) {
test.ok(!JSHINT.data().implieds);

JSHINT("if (typeof foobar) {}", { undef: true });
console.log(JSHINT.data().implieds);

test.strictEqual(JSHINT.data().implieds, undefined);

test.done();
Expand Down Expand Up @@ -880,6 +880,37 @@ exports['let can re-use function and class name'] = function (test) {
test.done();
};

exports['unused with param destructuring'] = function(test) {
var code = [
"let b = ([...args], a) => a;",
"b = args => true;",
"b = function([...args], a) { return a; };",
"b = function([args], a) { return a; };",
"b = function({ args }, a) { return a; };",
"b = function({ a: args }, a) { return a; };",
"b = function({ a: [args] }, a) { return a; };",
"b = function({ a: [args] }, a) { return a; };"
];

TestRun(test)
.addError(2, "'args' is defined but never used.")
.test(code, { esnext: true, unused: true });

TestRun(test)
.addError(1, "'args' is defined but never used.")
.addError(2, "'args' is defined but never used.")
.addError(3, "'args' is defined but never used.")
.addError(4, "'args' is defined but never used.")
.addError(5, "'args' is defined but never used.")
.addError(6, "'args' is defined but never used.")
.addError(7, "'args' is defined but never used.")
.addError(8, "'args' is defined but never used.")
.test(code, { esnext: true, unused: "strict" });


test.done();
};

exports['unused data with options'] = function (test) {

// see gh-1894 for discussion on this test
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1803,9 +1803,9 @@ exports["non-identifier PropertyNames in object destructuring"] = function (test
.addError(2, "'d' is defined but never used.")
.addError(2, "'e' is defined but never used.")
.addError(3, "'fn' is defined but never used.")
.addError(0, "'f' is defined but never used.")
.addError(0, "'g' is defined but never used.")
.addError(0, "'h' is defined but never used.")
.addError(3, "'f' is defined but never used.")
.addError(3, "'g' is defined but never used.")
.addError(3, "'h' is defined but never used.")
.test(code, { esnext: true, unused: true });

test.done();
Expand Down

0 comments on commit 7d25451

Please sign in to comment.