Skip to content

Commit 7290646

Browse files
brad4dcopybara-github
authored andcommitted
Add a test to ensure eval?.() transpiles to indirect eval
This behavior is required by the ECMAScript spec. PiperOrigin-RevId: 322468581
1 parent 3cb4944 commit 7290646

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ public static class BaseTestClass extends CompilerTestCase {
9191
public static final ImmutableList<Object> cases() {
9292
return ImmutableList.copyOf(
9393
new Object[][] {
94+
{
95+
"eval?.('foo()');",
96+
lines(
97+
"let tmp0;", //
98+
"(tmp0 = eval) == null",
99+
" ? void 0",
100+
// The spec says that `eval?.()` must behave like an indirect
101+
// eval, so it is important that `eval?.()` not be transpiled to
102+
// anything that ends up containing `eval()`.
103+
// We must be sure to call it using the temporary variable.
104+
" : tmp0('foo()');")
105+
},
94106
{
95107
"obj?.ary[getNum()].obj.obj?.obj.ary",
96108
lines(

0 commit comments

Comments
 (0)