Skip to content

Commit d60b05f

Browse files
brad4dcopybara-github
authored andcommitted
Add ExpressionDecomposerTest cases
In particular test a double-hook expression, which is what optional chains will be rewritten to be. PiperOrigin-RevId: 321676845
1 parent c4ce503 commit d60b05f

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141

4242
/**
4343
* Unit tests for {@link ExpressionDecomposer}
44-
*
45-
* @author [email protected] (John Lenz)
4644
*/
4745
// Note: functions "foo" and "goo" are external functions in the helper.
4846
@RunWith(JUnit4.class)
@@ -630,6 +628,42 @@ public void testExposeExpression6() {
630628
"if (goo()) foo();");
631629
}
632630

631+
@Test
632+
public void testExposeDoubleAndExpression() {
633+
helperExposeExpression(
634+
"a = boo() && goo() && foo()",
635+
"foo",
636+
lines(
637+
"var temp$jscomp$0;",
638+
"if (temp$jscomp$0 = boo() && goo()) {",
639+
" temp$jscomp$0 = foo();",
640+
"}",
641+
"a = temp$jscomp$0;",
642+
""));
643+
}
644+
645+
@Test
646+
public void testExposeDoubleHookExpression() {
647+
helperExposeExpression(
648+
"a = boo() ? void 0 : goo() ? void 0 : foo()",
649+
"foo",
650+
lines(
651+
"var temp$jscomp$0;",
652+
"if (boo()) {",
653+
" temp$jscomp$0 = void 0;",
654+
"} else {",
655+
" var temp$jscomp$1;",
656+
" if (goo()) {",
657+
" temp$jscomp$1 = void 0;",
658+
" } else {",
659+
" temp$jscomp$1 = foo();",
660+
" }",
661+
" temp$jscomp$0 = temp$jscomp$1;",
662+
"}",
663+
"a = temp$jscomp$0;",
664+
""));
665+
}
666+
633667
@Test
634668
public void exposeExpressionNullishCoalesceNoResult() {
635669
helperExposeExpression(

0 commit comments

Comments
 (0)