escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Bug? options semicolons: false not behaving as expected

Open jochemstoel opened this issue 8 years ago • 3 comments

Hello, escodegen adds semicolons everywhere when I generate code from esprima AST. I dont use semi colons and I don't want this. Setting option semicolons to false does not help. Is this a bug? If not, how do I prevent this from happening?

The code:

/* test.js */
const file = there => String(require('fs').readFileSync(there))

const esprima = require('esprima')
const escodegen = require('escodegen')

let program = file('test.js') /* open itself (this snippet) */
let ast = esprima.parse(program) /* parse it using esprima */

/* generate code from AST, options from: https://github.com/estools/escodegen/wiki/API */
let code = escodegen.generate(ast, {
    format: {
        semicolons: false
    }
})

console.log(code)

The output below has semicolons added, except the last line. If this is not a bug then how do I disable this behaviour?

const file = there => String(require('fs').readFileSync(there));
const esprima = require('esprima');
const escodegen = require('escodegen');
let program = file('test.js');
let ast = esprima.parse(program);
let code = escodegen.generate(ast, { format: { semicolons: false } });
console.log(code)

jochemstoel avatar Oct 22 '16 00:10 jochemstoel

Same here, really annoying, have to run eslint --fix every time after escodegen.generate

ihorskyi avatar Oct 29 '16 20:10 ihorskyi

Any update on this?

iAmMrinal0 avatar Mar 06 '17 10:03 iAmMrinal0

Currently having this same issue. According to the documentation, it seems it only covers turning off the semicolons for block statements, so I don't think it's a bug.

Could their be an addition to turn off semicolons completely?

JulsRicketti avatar Oct 14 '17 23:10 JulsRicketti