LivelyKernel / lively.ast

Parsing JS code into ASTs and tools to query and transform these trees.
4 stars 0 forks source link

Errors when using `printAst` and other helper methods related to parsed ASTs #9

Open dylemma opened 7 years ago

dylemma commented 7 years ago

In versions 0.9.0 and up, I can't successfully call any of the AST helper methods.

> var ast = require('lively.ast')
undefined
> ast.printAst(ast.parse("1 + 2"))
TypeError: Cannot read property 'string' of undefined
    at Object.printAst (<yadda\yadda>\node_modules\lively.ast\dist\lively.ast.js:12910:23)
    at repl:1:5
    at sigintHandlersWrap (vm.js:32:31)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInContext (vm.js:31:12)
    at REPLServer.defaultEval (repl.js:308:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:489:10)
    at emitOne (events.js:101:20)
>

The code above works fine if I use 0.8.1.

rksm commented 7 years ago

Yeah, we don't auto-load the dependencies anymore, we will probably do that in the future again.

require('lively.lang');
var ast = require('lively.ast');
ast.printAst(ast.parse("1 + 2"));

should do the job.

dylemma commented 7 years ago

Thanks, that did the trick! It would be helpful if that extra require call was mentioned in the readme/examples.