-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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