Skip to content

Commit c2c0ef8

Browse files
committed
Fixing generatorFunction return bug
1 parent 51db805 commit c2c0ef8

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/BabelPlugin.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,34 @@ function Plugin(babel) {
435435
},
436436
// Transforms a ReturnStatement into an Instruction Token
437437
exit: function (path) {
438-
if (path.node.argument === null) path.node.argument = hzReturn();
439-
else path.node.argument = hzReturnArg(path.node.argument);
440-
if (path.getFunctionParent().node.generator) path.node.argument.arguments = [t.ObjectExpression([
441-
t.ObjectProperty(
442-
t.identifier("value"),
443-
path.node.argument.arguments[0]
444-
),
445-
t.ObjectProperty(
446-
t.identifier("done"),
447-
t.BooleanLiteral(true)
448-
)
449-
])];
438+
if (path.getFunctionParent().node.generator) {
439+
if (path.node.argument === null) {
440+
path.node.argument = hzReturnArg(t.ObjectExpression([
441+
t.ObjectProperty(
442+
t.identifier("value"),
443+
t.identifier("undefined")
444+
),
445+
t.ObjectProperty(
446+
t.identifier("done"),
447+
t.BooleanLiteral(true)
448+
)
449+
]));
450+
} else {
451+
path.node.argument = hzReturnArg(t.ObjectExpression([
452+
t.ObjectProperty(
453+
t.identifier("value"),
454+
path.node.argument.arguments[0]
455+
),
456+
t.ObjectProperty(
457+
t.identifier("done"),
458+
t.BooleanLiteral(true)
459+
)
460+
]));
461+
}
462+
} else {
463+
if (path.node.argument === null) path.node.argument = hzReturn();
464+
else path.node.argument = hzReturnArg(path.node.argument);
465+
}
450466
}
451467
},
452468
"BlockStatement": {

0 commit comments

Comments
 (0)