handle ReturnStatements in block binding - closes #24
This commit is contained in:
1
lib/6to5/templates/function-call-return.js
Normal file
1
lib/6to5/templates/function-call-return.js
Normal file
@@ -0,0 +1 @@
|
||||
return FUNCTION();
|
||||
1
lib/6to5/templates/function-call-this-return.js
Normal file
1
lib/6to5/templates/function-call-this-return.js
Normal file
@@ -0,0 +1 @@
|
||||
return FUNCTION.call(this);
|
||||
@@ -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";
|
||||
|
||||
//
|
||||
|
||||
|
||||
@@ -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": {
|
||||
|
||||
16
test/fixtures/block-binding/return/actual.js
vendored
Normal file
16
test/fixtures/block-binding/return/actual.js
vendored
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
||||
14
test/fixtures/block-binding/return/expected.js
vendored
Normal file
14
test/fixtures/block-binding/return/expected.js
vendored
Normal 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 });
|
||||
}();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user