Loose: Added support for shorthand properties.

This commit is contained in:
Ingvar Stepanyan 2014-10-27 00:07:40 +02:00 committed by Marijn Haverbeke
parent 963a26e46f
commit dda90580df

View File

@ -287,6 +287,7 @@
} }
function checkLVal(expr) { function checkLVal(expr) {
if (!expr) return expr;
switch (expr.type) { switch (expr.type) {
case "Identifier": case "Identifier":
case "MemberExpression": case "MemberExpression":
@ -742,10 +743,14 @@
next(); next();
if (curIndent + 1 < indent) { indent = curIndent; line = curLineStart; } if (curIndent + 1 < indent) { indent = curIndent; line = curLineStart; }
while (!closes(tt.braceR, indent, line)) { while (!closes(tt.braceR, indent, line)) {
var name = parsePropertyName(); var prop = startNode(), isGenerator;
if (!name) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; } if (options.ecmaVersion >= 6) {
var prop = startNode(); prop.method = false;
prop.key = name; prop.shorthand = false;
isGenerator = eat(tt.star);
}
parsePropertyName(prop);
if (!prop.key) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
if (eat(tt.colon)) { if (eat(tt.colon)) {
prop.value = parseExpression(true); prop.value = parseExpression(true);
prop.kind = "init"; prop.kind = "init";
@ -755,7 +760,9 @@
prop.key = parsePropertyName() || dummyIdent(); prop.key = parsePropertyName() || dummyIdent();
prop.value = parseFunction(startNode(), false); prop.value = parseFunction(startNode(), false);
} else { } else {
prop.value = dummyIdent(); prop.value = options.ecmaVersion >= 6 ? prop.key : dummyIdent();
prop.kind = "init";
prop.shorthand = true;
} }
node.properties.push(finishNode(prop, "Property")); node.properties.push(finishNode(prop, "Property"));
@ -766,9 +773,18 @@
return finishNode(node, "ObjectExpression"); return finishNode(node, "ObjectExpression");
} }
function parsePropertyName() { function parsePropertyName(prop) {
if (token.type === tt.num || token.type === tt.string) return parseExprAtom(); if (options.ecmaVersion >= 6) {
if (token.type === tt.name || token.type.keyword) return parseIdent(); if (eat(tt.bracketL)) {
prop.computed = true;
prop.key = parseExpression();
expect(tt.bracketR);
return;
} else {
prop.computed = false;
}
}
prop.key = (token.type === tt.num || token.type === tt.string) ? parseExprAtom() : parseIdent();
} }
function parsePropertyAccessor() { function parsePropertyAccessor() {