Skip to content

Commit

Permalink
fix: eval?.() is indirect (#11850)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 20, 2020
1 parent 238cadd commit e51a91e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
Expand Up @@ -78,7 +78,11 @@ export default declare((api, options) => {

let ref;
let check;
if (loose && isCall && isSimpleMemberExpression(chain)) {
if (isCall && t.isIdentifier(chain, { name: "eval" })) {
check = ref = chain;
// `eval?.()` is an indirect eval call transformed to `(0,eval)()`
node[replaceKey] = t.sequenceExpression([t.numericLiteral(0), ref]);
} else if (loose && isCall && isSimpleMemberExpression(chain)) {
// If we are using a loose transform (avoiding a Function#call) and we are at the call,
// we can avoid a needless memoize. We only do this if the callee is a simple member
// expression, to avoid multiple calls to nested call expressions.
Expand Down
@@ -0,0 +1,22 @@
var foo;

/* indirect eval calls */
eval?.(foo);

(eval)?.(foo);

eval?.()();

eval?.().foo;

/* direct eval calls */

eval()?.();

eval()?.foo;

/* plain function calls */

foo.eval?.(foo);

eval.foo?.(foo);
@@ -0,0 +1,3 @@
{
"plugins": [["proposal-optional-chaining", { "loose": true }]]
}
@@ -0,0 +1,17 @@
var _eval, _eval2;

var foo;
/* indirect eval calls */

eval == null ? void 0 : (0, eval)(foo);
eval == null ? void 0 : (0, eval)(foo);
eval == null ? void 0 : (0, eval)()();
eval == null ? void 0 : (0, eval)().foo;
/* direct eval calls */

(_eval = eval()) == null ? void 0 : _eval();
(_eval2 = eval()) == null ? void 0 : _eval2.foo;
/* plain function calls */

foo.eval == null ? void 0 : foo.eval(foo);
eval.foo == null ? void 0 : eval.foo(foo);
@@ -0,0 +1,22 @@
var foo;

/* indirect eval calls */
eval?.(foo);

(eval)?.(foo);

eval?.()();

eval?.().foo;

/* direct eval calls */

eval()?.();

eval()?.foo;

/* plain function calls */

foo.eval?.(foo);

eval.foo?.(foo);
@@ -0,0 +1,17 @@
var _eval, _eval2, _foo$eval, _eval$foo;

var foo;
/* indirect eval calls */

eval === null || eval === void 0 ? void 0 : (0, eval)(foo);
eval === null || eval === void 0 ? void 0 : (0, eval)(foo);
eval === null || eval === void 0 ? void 0 : (0, eval)()();
eval === null || eval === void 0 ? void 0 : (0, eval)().foo;
/* direct eval calls */

(_eval = eval()) === null || _eval === void 0 ? void 0 : _eval();
(_eval2 = eval()) === null || _eval2 === void 0 ? void 0 : _eval2.foo;
/* plain function calls */

(_foo$eval = foo.eval) === null || _foo$eval === void 0 ? void 0 : _foo$eval.call(foo, foo);
(_eval$foo = eval.foo) === null || _eval$foo === void 0 ? void 0 : _eval$foo.call(eval, foo);

0 comments on commit e51a91e

Please sign in to comment.