add do expressions

This commit is contained in:
Sebastian McKenzie 2015-03-22 04:06:15 +11:00
parent a14e979897
commit 9c3493e02f
5 changed files with 27 additions and 0 deletions

View File

@ -245,6 +245,14 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
case tt._yield:
if (this.inGenerator) unexpected()
case tt._do:
if (this.options.features["es7.doExpressions"]) {
let node = this.startNode()
this.next()
node.body = this.parseBlock()
return this.finishNode(node, "DoExpression")
}
case tt.name:
let start = this.markPosition()
node = this.startNode()

View File

@ -0,0 +1,15 @@
import * as t from "../../../types";
export var metadata = {
experimental: true,
optional: true
};
export function DoExpression(node) {
var body = node.body.body;
if (body.length) {
return body;
} else {
return t.identifier("undefined");
}
}

View File

@ -90,6 +90,8 @@ export default {
_shadowFunctions: require("./internal/alias-functions"),
"es7.doExpressions": require("./es7/do-expressions"),
"es6.symbols": require("./es6/symbols"),
"spec.undefinedToVoid": require("./spec/undefined-to-void"),

View File

@ -57,6 +57,7 @@
"CallExpression": ["Expression"],
"ComprehensionExpression": ["Expression", "Scopable"],
"ConditionalExpression": ["Expression"],
"DoExpression": ["Expression"],
"Identifier": ["Expression"],
"Literal": ["Expression"],
"MemberExpression": ["Expression"],

View File

@ -19,6 +19,7 @@
"ContinueStatement": ["label"],
"DebuggerStatement": [],
"DoWhileStatement": ["body", "test"],
"DoExpression": ["body"],
"EmptyStatement": [],
"ExportAllDeclaration": ["source"],
"ExportDefaultDeclaration": ["declaration"],