Skip to content

Commit

Permalink
Fix bug in parsing of concise methods
Browse files Browse the repository at this point in the history
When the ES6 concise method syntax is used to declare a method, no new
entry is created in the local environment record. Because of this, the
method name should *not* be interpreted as a local variable, and
declaring a variable of that name should raise no warnings.

Resolves jshintgh-2022
  • Loading branch information
jugglinmike committed Dec 8, 2014
1 parent 41e5a45 commit b95f669
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jshint.js
Expand Up @@ -3250,7 +3250,7 @@ var JSHINT = (function () {
if (!state.option.inESNext()) {
warning("W104", state.tokens.curr, "concise methods");
}
doFunction(i, undefined, g);
doFunction(null, undefined, g);
} else {
advance(":");
expression(10);
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -3778,6 +3778,20 @@ conciseMethods.getWithoutSet = function (test) {
test.done();
};

// GH-2022: "Concise method names are colliding with params/variables"
conciseMethods.nameIsNotLocalVar = function (test) {
var code = [
"var obj = {",
" foo(foo) {},",
" bar() { var bar; }",
"};"
];

TestRun(test).test(code, {esnext: true});

test.done();
};

exports["object short notation: basic"] = function (test) {
var code = [
"var foo = 42;",
Expand Down

0 comments on commit b95f669

Please sign in to comment.