Indirect eval

This commit is contained in:
Justin Ridgewell 2017-09-29 04:12:46 -04:00 committed by Justin Ridgewell
parent 4b440110a1
commit e58409b144
4 changed files with 27 additions and 1 deletions

View File

@ -7,7 +7,9 @@ export default function({ types: t }) {
visitor: {
BinaryExpression(path) {
const { scope } = path;
const { operator, left, right } = path.node;
const { node } = path;
const { operator, left } = node;
let { right } = node;
if (operator !== "|>") return;
let optimizeArrow =
@ -21,6 +23,8 @@ export default function({ types: t }) {
} else if (params.length > 1) {
optimizeArrow = false;
}
} else if (t.isIdentifier(right, { name: "eval" })) {
right = t.sequenceExpression([t.numericLiteral(0), right]);
}
if (optimizeArrow && !param) {

View File

@ -0,0 +1,7 @@
(function() {
'use strict';
var result = '(function() { return this; })()'
|> eval;
assert.notEqual(result, undefined);
})();

View File

@ -0,0 +1,7 @@
(function() {
'use strict';
var result = '(function() { return this; })()'
|> eval;
assert.notEqual(result, undefined);
})();

View File

@ -0,0 +1,8 @@
(function () {
'use strict';
var _functionReturn;
var result = (_functionReturn = '(function() { return this; })()', (0, eval)(_functionReturn));
assert.notEqual(result, undefined);
})();