Merge pull request #3119 from loganfsmyth/default-export-generator-6733

Ensure that generator functions always have an identifier - fixes T6733
This commit is contained in:
Henry Zhu 2015-12-01 22:27:59 -05:00
commit 53877ec158
4 changed files with 43 additions and 3 deletions

View File

@ -141,6 +141,12 @@ function getOuterFnExpr(funPath) {
let node = funPath.node;
t.assertFunction(node);
if (!node.id){
// Default-exported function declarations, and function expressions may not
// have a name to reference, so we explicitly add one.
node.id = funPath.scope.parent.generateUidIdentifier("callee");
}
if (node.generator && // Non-generator functions don't need to be marked.
t.isFunctionDeclaration(node)) {
let pp = funPath.findParent(function (path) {
@ -166,9 +172,7 @@ function getOuterFnExpr(funPath) {
);
}
return node.id || (
node.id = funPath.scope.parent.generateUidIdentifier("callee")
);
return node.id;
}
function getRuntimeMarkDecl(blockPath) {

View File

@ -0,0 +1,4 @@
export default function * () {
var x = yield 5;
return 5;
}

View File

@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _callee;
var _marked = [_callee].map(regeneratorRuntime.mark);
function _callee() {
var x;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return 5;
case 2:
x = _context.sent;
return _context.abrupt("return", 5);
case 4:
case "end":
return _context.stop();
}
}, _marked[0], this);
}

View File

@ -0,0 +1,5 @@
{
"presets": [
"es2015"
]
}