escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Unknown node type ExportDefaultDeclaration

Open kraftwer1 opened this issue 9 years ago • 2 comments

According to #228 it should be possible to use import statements via Esprima 2.x in the current master. Unfortunately, I still got the above error when running:

var esprima = require("esprima"); // 2.6.0
var escodegen = require("escodegen"); // master

var code = "export default 'test'";

var tree = esprima.parse(code, {
    range: true,
    tokens: true,
    comment: true,
    sourceType: "module"
});

tree = escodegen.attachComments(tree, tree.comments, tree.tokens);

escodegen.generate(tree);

kraftwer1 avatar Oct 05 '15 19:10 kraftwer1

seeing the same error here, the issue comes from escodegen.attachComments which is due to fact that estraverse dependency is super outdated https://github.com/estools/escodegen/pull/266

callmephilip avatar May 02 '16 17:05 callmephilip

Please update the estraverse dependency. I am currently having this issue when doing:

var program = esprima.parse(existingJs, { sourceType: 'module', range: true, tokens: true, comment: true});
...
var ast = escodegen.attachComments(program, program.comments, program.tokens);

No way to get escodegen working with comments =(.

When I manually replace estraverse in the escodegen package folder with version 4.2.0, it works fine.

walnutfalls avatar May 31 '17 18:05 walnutfalls