add eval optional transformer
This commit is contained in:
parent
0a7dac8744
commit
7cb460d2f3
@ -4,6 +4,7 @@ export default {
|
||||
|
||||
//- builtin-setup
|
||||
strict: require("./other/strict"),
|
||||
eval: require("./other/eval"),
|
||||
_explode: require("./internal/explode"),
|
||||
_validation: require("./internal/validation"),
|
||||
_hoistDirectives: require("./internal/hoist-directives"),
|
||||
|
||||
22
src/babel/transformation/transformers/other/eval.js
Normal file
22
src/babel/transformation/transformers/other/eval.js
Normal file
@ -0,0 +1,22 @@
|
||||
import traverse from "../../../traversal";
|
||||
import parse from "../../../helpers/parse";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-pre",
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function CallExpression(node) {
|
||||
if (this.get("callee").isIdentifier({ name: "eval" }) && node.arguments.length === 1) {
|
||||
var evaluate = this.get("arguments")[0].evaluate();
|
||||
if (!evaluate.confident) return;
|
||||
|
||||
var code = evaluate.value;
|
||||
if (typeof code !== "string") return;
|
||||
|
||||
var ast = parse(code);
|
||||
traverse.removeProperties(ast);
|
||||
return ast.program;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user