escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Minor fix to preserveBlankLines (plus an IIFE tweak)

Open ishmal opened this issue 8 years ago • 1 comments

At line 1714, there is a potential bug, if a Program block has a child with no range attached. This can cause an exception:

TypeError: Cannot read property '0' of undefined
    at CodeGenerator.Program (/Volumes/DevPartition/pdev/toolbox/node/m12n/node_modules/escodegen/escodegen.js:1714:93)
    at CodeGenerator.generateStatement (/Volumes/DevPartition/pdev/toolbox/node/m12n/node_modules/escodegen/escodegen.js:2479:33)
    at generateInternal (/Volumes/DevPartition/pdev/toolbox/node/m12n/node_modules/escodegen/escodegen.js:2500:28)
    at Object.generate (/Volumes/DevPartition/pdev/toolbox/node/m12n/node_modules/escodegen/escodegen.js:2569:18)
    at Translator.write (/Volumes/DevPartition/pdev/toolbox/node/m12n/src/translator.js:98:24)
    at DestroyableTransform._transform (/Volumes/DevPartition/pdev/toolbox/node/m12n/src/translator.js:417:23)
    at DestroyableTransform.Transform._read (/Volumes/DevPartition/pdev/toolbox/node/m12n/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)

This fix simply checks for the existence of a range. Made the same fix for BlockStatement.

ishmal avatar Apr 03 '17 21:04 ishmal

Hmm. I inadvertently made 2 Pull Requests out of one.

The other one is providing an option to wrap IIFE's in parens.

I can split them and re-submit if you need.

After these tweeks, I can re-serialize 1800 of our messy source files almost flawlessly. Thanks for a VERY useful project.

ishmal avatar Apr 03 '17 21:04 ishmal