Skip to content

Instantly share code, notes, and snippets.

@Lokua
Created July 18, 2017 21:05
Show Gist options
  • Save Lokua/b66455641ee5636dcffd8bea399a4907 to your computer and use it in GitHub Desktop.
Save Lokua/b66455641ee5636dcffd8bea399a4907 to your computer and use it in GitHub Desktop.
convert es5 js to es2015 using lebab and prettier
// requires node > 8
const lebab = require('lebab')
const prettier = require('prettier')
const util = require('util')
const readFile = util.promisify(require('fs').readFile)
;(async () => {
try {
const input = process.argv.slice(2)[0]
const body = await readFile(input, 'utf8')
const { code, warnings } = lebab.transform(body, [
'arrow',
'for-of',
'arg-spread',
'obj-method',
'obj-shorthand',
'no-strict',
'commonjs',
'exponent',
'multi-var',
'let',
'class',
'template',
'default-param',
'includes'
])
const prettied = prettier.format(code, {
semi: false,
singleQuote: true
})
console.log(prettied)
} catch (e) {
console.error('e:', e)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment