Skip to content

Instantly share code, notes, and snippets.

@iksose
Forked from loopmode/jsbeautifier-es6-hacks
Last active January 28, 2017 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iksose/f3622faaecba24719279 to your computer and use it in GitHub Desktop.
Save iksose/f3622faaecba24719279 to your computer and use it in GitHub Desktop.
Some (ugly!) hacks to fix es6/es7 formatting problems in jsbeautifier. I use it with the "html/css/js prettify" plugin for Sublime Text
// in Sublime Text, Preferences -> Browse Packages, find HTML-CSS-JS Prettify/scripts/node_modules/js-beautify/js/lib/beautify.js
// find the last line of the 'beautify' function, and place the next lines just before 'return sweet_code';
// https://gist.github.com/loopmode/d091bce3b76efaf15d63
// es7 decorators
sweet_code = sweet_code.replace(/@\n/g, '@');
sweet_code = sweet_code.replace(/\)@\s/g, ')\n@');
sweet_code = sweet_code.replace(/ @ /g, ' @');
sweet_code = sweet_code.replace(/@\s/g, '\n@');
// destructuring/spread: imports
sweet_code = sweet_code.replace(/(import {\n)(\t|\s*)/g, '\import {');
sweet_code = sweet_code.replace(/\n}\nfrom\s/g, '} from ');
// destructuring/spread: declarations
sweet_code = sweet_code.replace(/(const|let|var)(\s?)*(\{)(\s|\n|\t)*(.*)(\s|\n|\t)*(\})(\s?)*(.*)/g, '$1 {$5} $9');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment