Skip to content

Commit

Permalink
Merge pull request #1927 from jshint/1926
Browse files Browse the repository at this point in the history
Only treat props named "[" as computed prop when punctuator. Fixes gh-1926
  • Loading branch information
rwaldron committed Oct 29, 2014
2 parents 0c4962d + 6a93570 commit 36f7ddc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3227,7 +3227,7 @@ var JSHINT = (function () {

expression(10);
} else {
if (state.tokens.next.value === "[") {
if (state.tokens.next.id === "[") {
// ComputedPropertyName
advance();
if (!state.option.esnext) {
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3790,7 +3790,11 @@ exports["object ComputedPropertyName"] = function (test) {
"[vals[0]]: true,",
"[(1)]: true,",
"};",
"fn({ [a / 7]: true });"
"fn({ [a / 7]: true });",
"var b = { '[': 1 };",
"var c = { [b]: 1 };",
"var d = { 0: 1 };",
"var e = { ['s']: 1 };",
];

TestRun(test).test(code, { esnext: true });
Expand All @@ -3804,6 +3808,8 @@ exports["object ComputedPropertyName"] = function (test) {
.addError(10, "'computed property names' is only available in ES6 (use esnext option).")
.addError(11, "'computed property names' is only available in ES6 (use esnext option).")
.addError(13, "'computed property names' is only available in ES6 (use esnext option).")
.addError(15, "'computed property names' is only available in ES6 (use esnext option).")
.addError(17, "'computed property names' is only available in ES6 (use esnext option).")
.test(code);

test.done();
Expand Down

0 comments on commit 36f7ddc

Please sign in to comment.