Repro
escodegen strips parenthesis from return statements, changing the behavior of the code. This breaks ast serialization/deserialization for react here.
var acorn = require('acorn');
var escodegen = require('escodegen');
var file = `
console.log((function () {
return (
// do a thing
'hello world'
);
})());
`;
var tokens = [];
var comments = [];
var ast = acorn.parse(file,
{
onToken: tokens,
onComment: comments,
ranges: true,
});
escodegen.attachComments(ast, comments, tokens);
console.log(escodegen.generate(ast, { comment: true }));
Output
original
console.log((function () {
return (
// do a thing
'hello world'
);
})());
generated
console.log(function () {
return // do a thing
'hello world';
}());
Repro
escodegen strips parenthesis from return statements, changing the behavior of the code. This breaks ast serialization/deserialization for react here.
Output
original
generated