Skip to content

Commit

Permalink
[[FIX]] Correct reporting of var name in list comprehensions
Browse files Browse the repository at this point in the history
Property raw_text is incorrectly referenced in warning W098.
  • Loading branch information
jshaptic committed Sep 14, 2017
1 parent ea6f361 commit 0ff6644
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5043,7 +5043,7 @@ var JSHINT = (function() {
unstack: function() {
_current.variables.filter(function(v) {
if (v.unused)
warning("W098", v.token, v.raw_text || v.value);
warning("W098", v.token, v.token.raw_text || v.value);
if (v.undef)
state.funct["(scope)"].block.use(v.value, v.token);
});
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3690,19 +3690,23 @@ exports["array comprehension unused and undefined"] = function (test) {
var code = [
"var range = [1, 2];",
"var a = [for (i of range) if (i % 2 === 0) i];",
"var b = [for (j of range) doesnotexist];"
"var b = [for (j of range) doesnotexist];",
"var c = [for (\\u0024 of range) 1];"
];
TestRun(test)
.addError(2, 5, "'a' is defined but never used.")
.addError(3, 15, "'j' is defined but never used.")
.addError(3, 27, "'doesnotexist' is not defined.")
.addError(3, 5, "'b' is defined but never used.")
.addError(4, 15, "'\\u0024' is defined but never used.")
.addError(4, 5, "'c' is defined but never used.")
.test(code, { esnext: true, unused: true, undef: true });

var unused = JSHINT.data().unused;
test.deepEqual([
{ name: 'a', line: 2, character: 5 },
{ name: 'b', line: 3, character: 5 }
{ name: 'b', line: 3, character: 5 },
{ name: 'c', line: 4, character: 5 }
//{ name: 'j', line: 3, character: 15 } // see gh-2440
], unused);

Expand Down

0 comments on commit 0ff6644

Please sign in to comment.