break your JS code into valid multilines as many as possible.
const breakline = require('breakline')
const code = 'var a = 1'
console.log(breakline(code))
/* the result is:
var
a
=
1
*/It uses acorn to parse code. You can pass acorn's options object as the second argument of breakline, like breakline(sourceCode, {ecmaVersion: 5}).
The default options of breakline is {ecmaVersion: 6, allowHashBang: true}.
This tool does nothing except inserts line feeds \n in appropriate positions, which would not trigger Automatic Semicolon Insertion. It won't delete anything or modify the AST(Abstrac Syntax Tree) of your code. It just inserts \n.
input:
function getScienceFiction () {
return 'The Three-Body Problem'
}
console.log(getScienceFiction())output:
function
getScienceFiction
(
)
{
return 'The Three-Body Problem'
}
console
.
log
(
getScienceFiction
(
)
)This tool can be used from the command line. Install it globally by npm install breakline -g.
breakline [options]
--help, -h
Show help info.
-d <directory>
Output directory.
--nosuffix
don't add '.breakline' suffix to the output files.
$ breakline your.jsThis command will create a file named 'your.js.breakline'.
MIT © flowmemo