Add a test to ensure `eval?.()` transpiles to indirect eval
This behavior is required by the ECMAScript spec.
@@ -91,6 +91,18 @@ public final class RewriteOptionalChainingOperatorTest {
public static final ImmutableList<Object> cases() {
return ImmutableList.copyOf(
new Object[][] {
+ {
+ "eval?.('foo()');",
+ lines(
+ "let tmp0;", //
+ "(tmp0 = eval) == null",
+ " ? void 0",
+ // The spec says that `eval?.()` must behave like an indirect
+ // eval, so it is important that `eval?.()` not be transpiled to
+ // anything that ends up containing `eval()`.
+ // We must be sure to call it using the temporary variable.
+ " : tmp0('foo()');")
+ },
{
"obj?.ary[getNum()].obj.obj?.obj.ary",
lines(
