handle ReturnStatements in block binding - closes #24

This commit is contained in:
Sebastian McKenzie
2014-10-09 20:19:22 +11:00
parent 235365f237
commit b6e533ec5d
6 changed files with 35 additions and 2 deletions

View File

@@ -0,0 +1 @@
return FUNCTION();

View File

@@ -0,0 +1 @@
return FUNCTION.call(this);

View File

@@ -31,7 +31,7 @@ exports.BlockStatement = function (node, parent, opts, generateUid) {
if (!hasLet(node.body)) return;
// ignore if we're the body of a closure already
if (parent.type === "FunctionExpression") return;
if (parent.type === "FunctionExpression" || parent.type === "FunctionDeclaration") return;
var body = node.body;
@@ -120,6 +120,7 @@ var buildNode = function (node) {
var templateName = "function-call";
if (traverse.hasType(node, "ThisExpression")) templateName += "-this";
if (traverse.hasType(node, "ReturnStatement", ["FunctionDeclaration", "FunctionExpression"])) templateName += "-return";
//

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into vanilla ES5 with source maps and no runtime",
"version": "1.5.2",
"version": "1.5.3",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/sebmck/6to5",
"repository": {

View File

@@ -0,0 +1,16 @@
function student () {
let isStudent = true;
return Object.freeze({
isStudent
});
}
function student () {
let isStudent = true;
while (true) {
let test = "foo";
return Object.freeze({
isStudent
});
}
}

View File

@@ -0,0 +1,14 @@
function student() {
var isStudent = true;
return Object.freeze({ isStudent: isStudent });
}
function student() {
var isStudent = true;
while (true) {
return function () {
var test = 'foo';
return Object.freeze({ isStudent: isStudent });
}();
}
}