Revert "remove do expressions"

This reverts commit 420492388b06ff295a638adbea0f34c726056607.
This commit is contained in:
Sebastian McKenzie 2015-07-13 20:45:49 +01:00
parent 2b32a2781e
commit a286a86b6d
18 changed files with 97 additions and 4 deletions

View File

@ -13,10 +13,6 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 5.6.19
* Removed do expressions.
## 5.6.17
* **Bug Fix**

View File

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

View File

@ -0,0 +1,26 @@
import * as t from "../../../types";
export var metadata = {
optional: true,
stage: 0
};
/**
* [Please add a description.]
*/
export var visitor = {
/**
* [Please add a description.]
*/
DoExpression(node) {
var body = node.body.body;
if (body.length) {
return body;
} else {
return t.identifier("undefined");
}
}
};

View File

@ -48,6 +48,7 @@ export default {
"es6.constants": require("./es6/constants"),
"es7.exportExtensions": require("./es7/export-extensions"),
"spec.protoToAssign": require("babel-plugin-proto-to-assign"),
"es7.doExpressions": require("./es7/do-expressions"),
"es6.spec.symbols": require("./es6/spec.symbols"),
"es7.functionBind": require("./es7/function-bind"),
"spec.undefinedToVoid": require("babel-plugin-undefined-to-void"),

View File

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

View File

@ -21,6 +21,7 @@
"Decorator": ["expression"],
"DebuggerStatement": [],
"DoWhileStatement": ["body", "test"],
"DoExpression": ["body"],
"EmptyStatement": [],
"ExpressionStatement": ["expression"],
"File": ["program"],

View File

@ -0,0 +1,5 @@
assert.equal(do {
var i = 5;
do { i--; } while(i > 3);
i;
}, 3);

View File

@ -0,0 +1 @@
assert.equal(do {}, undefined);

View File

@ -0,0 +1,6 @@
assert.equal(do {
var obj = { foo: "bar", bar: "foo" };
for (var key in obj) {
obj[key];
}
}, "foo");

View File

@ -0,0 +1,5 @@
assert.equal(do {
for (var i = 0; i < 5; i++) {
i;
}
}, 4);

View File

@ -0,0 +1,7 @@
assert.equal(do {
if (false) {
"foo";
} else if (true) {
"bar";
}
}, "bar");

View File

@ -0,0 +1,7 @@
assert.equal(do {
if (false) {
"foo";
} else {
"bar";
}
}, "bar");

View File

@ -0,0 +1,5 @@
assert.equal(do {
if (true) {
"bar";
}
}, "bar");

View File

@ -0,0 +1,3 @@
{
"optional": ["es7.doExpressions"]
}

View File

@ -0,0 +1,3 @@
assert.equal(do {
"foo";
}, "foo");

View File

@ -0,0 +1,3 @@
assert.equal(do {
var bar = "foo";
}, undefined);

View File

@ -0,0 +1,4 @@
assert.equal(do {
var bar = "foo";
bar;
}, "foo");

View File

@ -0,0 +1,5 @@
assert.equal(do {
var i = 5;
while (i > 3) i--;
i;
}, 3);