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 jshint#2494
  • Loading branch information
lukeapage committed Jul 5, 2015
1 parent 6148c4c commit 479465e
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 @@ -2742,7 +2742,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 @@ -735,7 +735,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 @@ -861,6 +861,37 @@ exports.unused = 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 @@ -1785,9 +1785,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 479465e

Please sign in to comment.