Skip to content

Commit f224671

Browse files
brad4dcopybara-github
authored andcommitted
Es6RewriteGenerators: correct use of ExpressionDecomposer
ExpressionDecomposer#maybeExposeExpression() guarantees the expression is fully exposed and should be used instead of exposeExpression(). PiperOrigin-RevId: 321817366
1 parent 6668a31 commit f224671

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

src/com/google/javascript/jscomp/Es6RewriteGenerators.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void visitYield(Node n) {
191191
}
192192
if (decomposer.canExposeExpression(n)
193193
!= ExpressionDecomposer.DecompositionType.UNDECOMPOSABLE) {
194-
decomposer.exposeExpression(n);
194+
decomposer.maybeExposeExpression(n);
195195
} else {
196196
String link =
197197
"https://github.com/google/closure-compiler/wiki/FAQ"

test/com/google/javascript/jscomp/Es6RewriteGeneratorsTest.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -463,32 +463,35 @@ public void testDecomposeComplexYieldExpression() {
463463
"}"),
464464
lines(
465465
"function f(){",
466-
"var obj;",
467-
"var JSCompiler_temp$jscomp$0;",
468-
"var JSCompiler_temp_const$jscomp$2;",
469-
"var JSCompiler_temp_const$jscomp$1;",
470-
"return $jscomp.generator.createGenerator(f,function($jscomp$generator$context) {",
471-
" switch($jscomp$generator$context.nextAddress) {",
472-
" case 1:",
473-
" obj = {bar:function(x){}};",
474-
" return $jscomp$generator$context.yield(5,2);",
475-
" case 2:",
476-
" if (!(JSCompiler_temp$jscomp$0 = $jscomp$generator$context.yieldResult)) {",
477-
" $jscomp$generator$context.jumpTo(3);",
478-
" break;",
479-
" }",
480-
" JSCompiler_temp_const$jscomp$2 = obj;",
481-
" JSCompiler_temp_const$jscomp$1 = JSCompiler_temp_const$jscomp$2.bar;",
482-
" return $jscomp$generator$context.yield(5,4);",
483-
" case 4:",
484-
" JSCompiler_temp$jscomp$0 = JSCompiler_temp_const$jscomp$1.call(",
485-
" JSCompiler_temp_const$jscomp$2,",
486-
" $jscomp$generator$context.yieldResult);",
487-
" case 3:",
488-
" JSCompiler_temp$jscomp$0;",
489-
" $jscomp$generator$context.jumpToEnd();",
490-
" }",
491-
" })",
466+
" var obj;",
467+
" var JSCompiler_temp$jscomp$0;",
468+
" var JSCompiler_temp_const$jscomp$2;",
469+
" var JSCompiler_temp_const$jscomp$1;",
470+
" var JSCompiler_temp_const$jscomp$3;",
471+
" return $jscomp.generator.createGenerator(f, function($jscomp$generator$context) {",
472+
" switch($jscomp$generator$context.nextAddress) {",
473+
" case 1:",
474+
" obj = {bar:function(x) {}};",
475+
" return $jscomp$generator$context.yield(5, 2);",
476+
" case 2:",
477+
" if (!(JSCompiler_temp$jscomp$0 = $jscomp$generator$context.yieldResult)) {",
478+
" $jscomp$generator$context.jumpTo(3);",
479+
" break;",
480+
" }",
481+
" JSCompiler_temp_const$jscomp$2 = obj;",
482+
" JSCompiler_temp_const$jscomp$1 = JSCompiler_temp_const$jscomp$2.bar;",
483+
" JSCompiler_temp_const$jscomp$3 = JSCompiler_temp_const$jscomp$2;",
484+
" return $jscomp$generator$context.yield(5, 4);",
485+
" case 4:",
486+
" JSCompiler_temp$jscomp$0 =",
487+
" JSCompiler_temp_const$jscomp$1.call(",
488+
" JSCompiler_temp_const$jscomp$3,",
489+
" $jscomp$generator$context.yieldResult);",
490+
" case 3:",
491+
" JSCompiler_temp$jscomp$0;",
492+
" $jscomp$generator$context.jumpToEnd();",
493+
" }",
494+
" });",
492495
"}"));
493496
}
494497

0 commit comments

Comments
 (0)