Permalink
Browse files

Added support for concise methods declaration in objects.

Closes GH-975.
Closes GH-955.
  • Loading branch information...
1 parent e32ae7e commit 8c1cf12bbb2fe596bbc10141ec3b12326936ed95 @guyzmo guyzmo committed with valueof Apr 9, 2013
Showing with 49 additions and 5 deletions.
  1. +19 −4 src/stable/jshint.js
  2. +0 −1 src/stable/lex.js
  3. +30 −0 tests/stable/unit/parser.js
View
@@ -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) {
@@ -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);
View
@@ -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;
});
@@ -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.