(node, val, binding)
| 266 | } |
| 267 | |
| 268 | function traverse (node, val, binding) { |
| 269 | for (var p = node; p; p = p.parent) { |
| 270 | if (p.start === undefined || p.end === undefined) continue; |
| 271 | } |
| 272 | |
| 273 | if (node.parent.type === 'CallExpression') { |
| 274 | if (typeof val !== 'function') { |
| 275 | return error( |
| 276 | 'tried to statically call ' + inspect(val) |
| 277 | + ' as a function' |
| 278 | ); |
| 279 | } |
| 280 | |
| 281 | var xvars = getVars(node.parent, vars); |
| 282 | xvars[node.name] = val; |
| 283 | |
| 284 | var res = evaluate(node.parent, xvars); |
| 285 | if (res !== undefined) { |
| 286 | if (binding) binding.remove(node) |
| 287 | updates.push({ |
| 288 | start: node.parent.start, |
| 289 | offset: node.parent.end - node.parent.start, |
| 290 | stream: isStream(res) ? wrapStream(res) : st(String(res)) |
| 291 | }); |
| 292 | } |
| 293 | } |
| 294 | else if (node.parent.type === 'MemberExpression') { |
| 295 | if (!isStaticProperty(node.parent.property)) { |
| 296 | return error( |
| 297 | 'dynamic property in member expression: ' |
| 298 | + body.slice(node.parent.start, node.parent.end) |
| 299 | ); |
| 300 | } |
| 301 | |
| 302 | var cur = node.parent.parent; |
| 303 | |
| 304 | if (cur.type === 'MemberExpression') { |
| 305 | cur = cur.parent; |
| 306 | if (cur.type !== 'CallExpression' |
| 307 | && cur.parent.type === 'CallExpression') { |
| 308 | cur = cur.parent; |
| 309 | } |
| 310 | } |
| 311 | if (node.parent.type === 'MemberExpression' |
| 312 | && (cur.type !== 'CallExpression' |
| 313 | && cur.type !== 'MemberExpression')) { |
| 314 | cur = node.parent; |
| 315 | } |
| 316 | |
| 317 | var xvars = getVars(cur, vars); |
| 318 | xvars[node.name] = val; |
| 319 | |
| 320 | var res = evaluate(cur, xvars); |
| 321 | if (res === undefined && cur.type === 'CallExpression') { |
| 322 | // static-eval can't safely evaluate code with callbacks, so do it manually in a safe way |
| 323 | var callee = evaluate(cur.callee, xvars); |
| 324 | var args = cur.arguments.map(function (arg) { |
| 325 | // Return a function stub for callbacks so that `static-module` users |
no test coverage detected
searching dependent graphs…