ソースコード整形
jsbeautify - a javascript source code formatter : vim online
結局、上記スクリプトを使用する。
id:oppara:20070430
いろいろアップデートしてたので
- JavaScript-C 1.8.0 pre-release 1 2009-02-16
- JsDecoder.js 1.1.0
// usage: $ js -f $0 < hoge.js > moge.js load( ['/path/to/JsDecoder.js'] ); var jsdecoder = new JsDecoder(); var lines = ''; var ln; while ( ( ln = readline() ) !== null ) { lines += ln + "\n"; } jsdecoder.s = lines; print( jsdecoder.decode() ); ;
- インデントは、2スペース
- '{'は同じ行
--- bin/JsDecoder.js.org 2009-12-17 15:43:50.000000000 +0900 +++ bin/JsDecoder.js 2009-12-17 16:01:48.000000000 +0900 @@ -150,7 +150,7 @@ } if (/function\s*/.test(this.code[this.row]) || this.isBlockBig()) { - this.writeLine(); + this.write(' '); } else { if (this.prevChar != ' ' && this.prevChar != "\n" && this.prevChar != '(') { /* && this.prevChar != '(' && this.prevChar != '[' */ @@ -272,10 +272,10 @@ if (sw2.test(this.code[row])) { continue; } - this.replaceLine(' ' + this.code[row], row); + this.replaceLine(' ' + this.code[row], row); /* if (sw3.test(this.code[row])) { - this.replaceLine(' ' + this.code[row], row); + this.replaceLine(' ' + this.code[row], row); } */ } @@ -364,7 +364,7 @@ this.lvl2++; var indent = ''; for (var j = 0; j < this.lvl2; j++) { - indent += ' '; + indent += ' '; } this.write(indent); */ @@ -839,7 +839,7 @@ this.write(' ', true); } } else if ("\t" == c) { - this.write(' ', true); + this.write(' ', true); } else if ("\n" == c) { this.writeLine(); } @@ -1032,7 +1032,7 @@ if (0 === this.code[this.row].length) { var lvl = ('}' == s ? this.lvl - 1 : this.lvl); for (var i = 0; i < lvl; i++) { - this.code[this.row] += ' '; + this.code[this.row] += ' '; } this.code[this.row] += s; } else { @@ -1072,7 +1072,7 @@ }; this.writeTab = function () { - this.write(' '); + this.write(' '); this.prevChar = ' '; }; this.getCurrentLine = function () @@ -1146,4 +1146,4 @@ ret += ' ('+typeof arr+')'; } debug_w.document.body.innerHTML += '<pre>'+ret+'</pre>'; -} \ No newline at end of file +}