13

Do you know of a JS formatter that will support the comma-first coding style?

var a = 'ape'
  , b = 'bat'
  , c = 'cat'
  , d = 'dog'
  , e = 'elf'
  , f = 'fly'
  , g = 'gnu'
  , h = 'hat'
  , i = 'ibu'
  ;

So far, I've looked at JS Beautifier & SourceFormatX but couldn't find an option for it.

4

1 に答える 1

9

ここでjsbeautifierコードを少し変更しました:

http://jsfiddle.net/RabTN/29/

を押しdoitて、美化されたコードを表示します。

私は特に1080行目を変更しました:

        if (flags.var_line) {
            if (token_text === ',') {
                if (flags.var_line_tainted) {
                    flags.var_line_reindented = true;
                    flags.var_line_tainted = false;
                    print_newline();
                    print_token();
                    print_single_space();
                    break;
                } else {

および1123行目

        if (token_text === ',') {
            if (flags.var_line) {
                if (flags.var_line_tainted) {
                    print_newline();
                    print_token();
                    print_single_space();

                    flags.var_line_tainted = false;
                } else {
                    print_newline();
                    print_token();
                    print_single_space();
                }
            } else if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
                print_token();
                if (flags.mode === 'OBJECT' && last_text === '}') {
                    print_newline();
                } else {
                    print_single_space();
                }
            } else {
                if (flags.mode === 'OBJECT') {
                    print_newline();
                    print_token();
                    print_single_space();
                } else {
                    // EXPR or DO_BLOCK
                    print_token();
                    print_single_space();
                }
            }
            break
于 2012-06-03T17:14:15.513 に答える