add do expressions
This commit is contained in:
parent
a14e979897
commit
9c3493e02f
@ -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()
|
||||
|
||||
15
src/babel/transformation/transformers/es7/do-expressions.js
Normal file
15
src/babel/transformation/transformers/es7/do-expressions.js
Normal 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");
|
||||
}
|
||||
}
|
||||
@ -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"),
|
||||
|
||||
|
||||
@ -57,6 +57,7 @@
|
||||
"CallExpression": ["Expression"],
|
||||
"ComprehensionExpression": ["Expression", "Scopable"],
|
||||
"ConditionalExpression": ["Expression"],
|
||||
"DoExpression": ["Expression"],
|
||||
"Identifier": ["Expression"],
|
||||
"Literal": ["Expression"],
|
||||
"MemberExpression": ["Expression"],
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
"ContinueStatement": ["label"],
|
||||
"DebuggerStatement": [],
|
||||
"DoWhileStatement": ["body", "test"],
|
||||
"DoExpression": ["body"],
|
||||
"EmptyStatement": [],
|
||||
"ExportAllDeclaration": ["source"],
|
||||
"ExportDefaultDeclaration": ["declaration"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user