diff --git a/.travis.yml b/.travis.yml index cc4dba2..4e78449 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: node_js node_js: - - "0.8" + - 9 + - 8 + - 6 + - 4 - "0.10" diff --git a/index.js b/index.js index a4c4435..577984c 100644 --- a/index.js +++ b/index.js @@ -287,8 +287,31 @@ module.exports = function parse (modules, opts) { var xvars = copy(vars); xvars[node.name] = val; - + var res = evaluate(cur, xvars); + if (res === undefined && cur.type === 'CallExpression') { + // static-eval can't safely evaluate code with callbacks, so do it manually in a safe way + var callee = evaluate(cur.callee, xvars); + var args = cur.arguments.map(function (arg) { + // Return a function stub for callbacks so that `static-module` users + // can do `callback.toString()` and get the original source + if (arg.type === 'FunctionExpression' || arg.type === 'ArrowFunctionExpression') { + var fn = function () { + throw new Error('static-module: cannot call callbacks defined inside source code'); + }; + fn.toString = function () { + return body.slice(arg.start, arg.end); + }; + return fn; + } + return evaluate(arg, xvars); + }); + + if (callee !== undefined) { + res = callee.apply(null, args); + } + } + if (res !== undefined) { updates.push({ start: cur.start, diff --git a/package.json b/package.json index 1c2c3e4..fb06a40 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "quote-stream": "~1.0.2", "readable-stream": "~2.3.3", "shallow-copy": "~0.0.1", - "static-eval": "~0.2.0", + "static-eval": "^2.0.0", "through2": "~2.0.3" }, "devDependencies": {