Skip to content

Commit

Permalink
Added support for concise methods declaration in objects.
Browse files Browse the repository at this point in the history
Closes GH-975.
Closes GH-955.
  • Loading branch information
guyzmo authored and valueof committed Apr 9, 2013
1 parent e32ae7e commit 8c1cf12
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/stable/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ var JSHINT = (function () {

(function (x) {
x.nud = function () {
var b, f, i, p, t;
var b, f, i, p, t, g;
var props = {}; // All properties, including accessors

function saveProperty(name, tkn) {
Expand Down Expand Up @@ -2802,16 +2802,31 @@ var JSHINT = (function () {
warning("W077", t, i);
}
} else {
g = false;
if (state.tokens.next.value === "*" && state.tokens.next.type === "(punctuator)") {
if (!state.option.inESNext()) {
warning("W104", state.tokens.next, "generator functions");
}
advance("*");
g = true;
}
i = property_name();
saveProperty(i, state.tokens.next);

if (typeof i !== "string") {
break;
}

advance(":");
nonadjacent(state.tokens.curr, state.tokens.next);
expression(10);
if (state.tokens.next.value === "(") {
if (!state.option.inESNext()) {
warning("W104", state.tokens.curr, "concise methods");
}
doFunction(i, undefined, g);
} else {
advance(":");
nonadjacent(state.tokens.curr, state.tokens.next);
expression(10);
}
}

countMember(i);
Expand Down
1 change: 0 additions & 1 deletion src/stable/lex.js
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,6 @@ Lexer.prototype = {
line: this.line,
character: this.char
}, checks, function () {
// console.log("W115", state.directive["use strict"], token.base === 8);
return state.directive["use strict"] && token.base === 8;
});

Expand Down
30 changes: 30 additions & 0 deletions tests/stable/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2946,3 +2946,33 @@ exports["fat arrows support"] = function (test) {

test.done();
};

exports["consise methods support"] = function (test) {
var code = [
"var foobar = {",
" foo () {",
" return 'foo';",
" },",
" *bar () {",
" yield 'bar';",
" }",
"};"
];

var run = TestRun(test);
run.test(code, {esnext: true});
run.test(code, {moz: true});

run = TestRun(test)
.addError(2, "'concise methods' is only available in JavaScript 1.7.")
.addError(5, "'generator functions' is only available in JavaScript 1.7.")
.addError(5, "'concise methods' is only available in JavaScript 1.7.")
.addError(6, "'yield' is only available in JavaScript 1.7.");

run.test(code); // es5
run.test(code, {es3: true});

test.done();

};

0 comments on commit 8c1cf12

Please sign in to comment.