您是否知道将支持comma-first编码样式的JS格式化程序?

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

到目前为止,我已经查看了JS BeautifierSourceFormatX,但是找不到它的选项。

最佳答案

我在这里修改了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

10-06 06:11