Skip to content

Commit

Permalink
Add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sstern6 committed Sep 5, 2016
1 parent de26c3c commit 1a2661d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4911,8 +4911,22 @@ var JSHINT = (function() {
var value = expression(10);
advance("]");

/**
* Test if {value.type} is not a string because we will not currently check non-string values
* in ES6 for computed properties. Else if the value has a left and a right property that are not strings,
* we combine the values to ensure the combined value is being evaluated, not each individual item of the expression.
* @param {value.type} string
* @param {value.identifier} boolean
* @returns {token}
*/

if (value.type !== "(string)" && value.identifier) {
value = null ;
} else if (value.left && value.right) {
if (value.right.type !== "(string)" && value.left.type !== "(string)") {
var currValue = value;
value.value = value.left + currValue.value + value.right;
}
}

return value;
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6036,10 +6036,41 @@ exports["computed property names for getters and setters"] = function (test) {
"val: null,",
"get ['bar']() { return this.val; },",
"set ['bar'](arg) { this.val = arg; }",
"};",
"let y = {",
"get[2](x){ return 1; },",
"get[1](){ return 'bar'; }",
"};",
"let z = {",
"get['a'](){ return true; },",
"get['a']() { return false; }",
"};",
"let zz = {",
"get [1 + 2]() {return 'foo'; },",
"get '+'() { return 'bar'; }",
"};"
];

TestRun(test)
.addError(11, "Unexpected parameter 'x' in get 2 function.")
.addError(16, "Duplicate key 'a'.")
.test(code, { esversion: 6 });

test.done();
};

exports["computed property names for getters and setters with members"] = function (test) {
var code = [
"/* members abc, d */",
"let test = {",
"get ['a' + 'b' + 'c'](){ return 'bar'; }, ",
"get['e'](){ return foo; }",
"};"
];

TestRun(test).test(code, { esversion: 6 });
TestRun(test)
.addError(4, "Unexpected /*member 'e'.")
.test(code, { esversion: 6 });

test.done();
};
Expand Down

0 comments on commit 1a2661d

Please sign in to comment.