mol_tree2 1.0.126 → 1.0.128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.test.js CHANGED
@@ -609,152 +609,169 @@ var $;
609
609
  (function ($) {
610
610
  function $mol_tree2_js_to_text(js) {
611
611
  function sequence(open, separator, close) {
612
+ return (input, belt) => [
613
+ input.struct('line', [
614
+ ...open ? [input.data(open)] : [],
615
+ input.struct(separator && input.kids.length > 2 ? 'indent' : 'line', [].concat(...input.kids.map((kid, index) => [
616
+ kid.struct('line', [
617
+ ...kid.list([kid]).hack(belt),
618
+ ...(separator && index < input.kids.length - 1) ? [input.data(separator)] : [],
619
+ ]),
620
+ ]))),
621
+ ...close ? [input.data(close)] : [],
622
+ ]),
623
+ ];
624
+ }
625
+ function block(open, separator, close) {
612
626
  return (input, belt) => [
613
627
  ...open ? [input.data(open)] : [],
614
- input.struct(separator && input.kids.length > 2 ? 'indent' : 'line', [].concat(...input.kids.map((kid, index) => [
615
- kid.struct('line', [
628
+ ...input.kids.length === 0 ? [] : [input.struct('indent', input.kids.map((kid, index) => kid.struct('line', [
616
629
  ...kid.list([kid]).hack(belt),
617
- ...(separator && index < input.kids.length - 1) ? [input.data(separator)] : [],
618
- ]),
619
- ]))),
630
+ ...(separator) ? [input.data(separator)] : [],
631
+ ])))],
620
632
  ...close ? [input.data(close)] : [],
621
633
  ];
622
634
  }
623
635
  function duplet(open, separator, close) {
624
636
  return (input, belt) => [
625
- ...open ? [input.data(open)] : [],
626
- ...input.list(input.kids.slice(0, 1)).hack(belt),
627
- ...(separator && input.kids.length > 1) ? [input.data(separator)] : [],
628
- ...input.list(input.kids.slice(1, 2)).hack(belt),
629
- ...close ? [input.data(close)] : [],
637
+ input.struct('line', [
638
+ ...open ? [input.data(open)] : [],
639
+ ...input.list(input.kids.slice(0, 1)).hack(belt),
640
+ ...(separator && input.kids.length > 1) ? [input.data(separator)] : [],
641
+ ...input.list(input.kids.slice(1, 2)).hack(belt),
642
+ ...close ? [input.data(close)] : [],
643
+ ]),
630
644
  ];
631
645
  }
632
646
  function triplet(open, separator12, separator23, close) {
633
647
  return (input, belt) => [
634
- ...open ? [input.data(open)] : [],
635
- ...input.list(input.kids.slice(0, 1)).hack(belt),
636
- ...(separator12 && input.kids.length > 1) ? [input.data(separator12)] : [],
637
- ...input.list(input.kids.slice(1, 2)).hack(belt),
638
- ...(separator23 && input.kids.length > 2) ? [input.data(separator23)] : [],
639
- ...input.list(input.kids.slice(2, 3)).hack(belt),
640
- ...close ? [input.data(close)] : [],
648
+ input.struct('line', [
649
+ ...open ? [input.data(open)] : [],
650
+ ...input.list(input.kids.slice(0, 1)).hack(belt),
651
+ ...(separator12 && input.kids.length > 1) ? [input.data(separator12)] : [],
652
+ ...input.list(input.kids.slice(1, 2)).hack(belt),
653
+ ...(separator23 && input.kids.length > 2) ? [input.data(separator23)] : [],
654
+ ...input.list(input.kids.slice(2, 3)).hack(belt),
655
+ ...close ? [input.data(close)] : [],
656
+ ]),
641
657
  ];
642
658
  }
643
- return js.list([js.struct('line', js.hack({
644
- '+': sequence('+'),
645
- '-': sequence('-'),
646
- '!': sequence('!'),
647
- '~': sequence('~'),
648
- 'return': sequence('return '),
649
- 'break': sequence('break '),
650
- 'continue': sequence('continue '),
651
- 'yield': sequence('yield '),
652
- 'yield*': sequence('yield* '),
653
- 'await': sequence('await '),
654
- 'void': sequence('void '),
655
- 'delete': sequence('delete '),
656
- 'typeof': sequence('typeof '),
657
- 'new': sequence('new '),
658
- '...': sequence('...'),
659
- '@++': sequence('', '', '++'),
660
- '@--': sequence('', '', '--'),
661
- '(in)': sequence('(', ' in ', ')'),
662
- '(instanceof)': sequence('(', ' instanceof ', ')'),
663
- '(+)': sequence('(', ' + ', ')'),
664
- '(-)': sequence('(', ' - ', ')'),
665
- '(*)': sequence('(', ' * ', ')'),
666
- '(/)': sequence('(', ' / ', ')'),
667
- '(%)': sequence('(', ' % ', ')'),
668
- '(**)': sequence('(', ' ** ', ')'),
669
- '(<)': sequence('(', ' < ', ')'),
670
- '(<=)': sequence('(', ' <= ', ')'),
671
- '(>)': sequence('(', ' > ', ')'),
672
- '(>=)': sequence('(', ' >= ', ')'),
673
- '(==)': sequence('(', ' == ', ')'),
674
- '(!=)': sequence('(', ' != ', ')'),
675
- '(===)': sequence('(', ' === ', ')'),
676
- '(!==)': sequence('(', ' !== ', ')'),
677
- '(<<)': sequence('(', ' << ', ')'),
678
- '(>>)': sequence('(', ' >> ', ')'),
679
- '(>>>)': sequence('(', ' >>> ', ')'),
680
- '(&)': sequence('(', ' & ', ')'),
681
- '(|)': sequence('(', ' | ', ')'),
682
- '(^)': sequence('(', ' ^ ', ')'),
683
- '(&&)': sequence('(', ' && ', ')'),
684
- '(||)': sequence('(', ' || ', ')'),
685
- '(,)': sequence('(', ', ', ')'),
686
- '{;}': sequence('{', '; ', '}'),
687
- ';': sequence('', ';', ''),
688
- '[,]': sequence('[', ', ', ']'),
689
- '{,}': sequence('{', ', ', '}'),
690
- '()': sequence('(', '', ')'),
691
- '{}': sequence('{', '', '}'),
692
- '[]': (input, belt) => {
693
- const first = input.kids[0];
694
- if (first.type)
695
- return sequence('[', '', ']')(input, belt);
696
- else
697
- return [input.data('.' + first.text())];
698
- },
699
- ':': (input, belt) => {
700
- const first = input.kids[0];
701
- if (first.type)
702
- return duplet('[', ']: ')(input, belt);
703
- else
704
- return duplet('', ': ')(input, belt);
705
- },
706
- 'let': duplet('let ', ' = '),
707
- 'const': duplet('const ', ' = '),
708
- 'var': duplet('var ', ' = '),
709
- '=': duplet('', ' = '),
710
- '+=': duplet('', ' += '),
711
- '-=': duplet('', ' -= '),
712
- '*=': duplet('', ' *= '),
713
- '/=': duplet('', ' /= '),
714
- '%=': duplet('', ' %= '),
715
- '**=': duplet('', ' **= '),
716
- '<<=': duplet('', ' <<= '),
717
- '>>=': duplet('', ' >>= '),
718
- '>>>=': duplet('', ' >>>= '),
719
- '&=': duplet('', ' &= '),
720
- '|=': duplet('', ' |= '),
721
- '^=': duplet('', ' ^= '),
722
- '&&=': duplet('', ' &&= '),
723
- '||=': duplet('', ' ||= '),
724
- '=>': duplet('', ' => '),
725
- 'async=>': duplet('async ', ' => '),
726
- 'function': triplet('function '),
727
- 'function*': triplet('function* '),
728
- 'async': triplet('async function '),
729
- 'async*': triplet('async function* '),
730
- 'class': triplet('class ', ' '),
731
- 'extends': sequence('extends ', '', ' '),
732
- 'if': triplet('if', ' ', 'else'),
733
- '?:': triplet('', ' ? ', ' : '),
734
- '.': (input, belt) => {
735
- const first = input.kids[0];
736
- if (first.type)
737
- return triplet('[', ']')(input, belt);
738
- else
739
- return [
740
- input.data(first.text()),
741
- ...input.list(input.kids.slice(1)).hack(belt),
742
- ];
743
- },
744
- 'get': triplet('get [', ']'),
745
- 'set': triplet('set [', ']'),
746
- 'static': triplet('static [', ']'),
747
- '/./': sequence(),
748
- '.global': sequence('g'),
749
- '.multiline': sequence('m'),
750
- '.ignoreCase': sequence('i'),
751
- '.source': (input, belt) => [
752
- input.data('/'),
753
- input.data(JSON.stringify(input.text()).slice(1, -1)),
754
- input.data('/'),
755
- ],
756
- '``': (input, belt) => {
659
+ return js.list(js.hack({
660
+ '+': sequence('+'),
661
+ '-': sequence('-'),
662
+ '!': sequence('!'),
663
+ '~': sequence('~'),
664
+ 'return': sequence('return '),
665
+ 'break': sequence('break '),
666
+ 'continue': sequence('continue '),
667
+ 'yield': sequence('yield '),
668
+ 'yield*': sequence('yield* '),
669
+ 'await': sequence('await '),
670
+ 'void': sequence('void '),
671
+ 'delete': sequence('delete '),
672
+ 'typeof': sequence('typeof '),
673
+ 'new': sequence('new '),
674
+ '...': sequence('...'),
675
+ '@++': sequence('', '', '++'),
676
+ '@--': sequence('', '', '--'),
677
+ '(in)': sequence('(', ' in ', ')'),
678
+ '(instanceof)': sequence('(', ' instanceof ', ')'),
679
+ '(+)': sequence('(', ' + ', ')'),
680
+ '(-)': sequence('(', ' - ', ')'),
681
+ '(*)': sequence('(', ' * ', ')'),
682
+ '(/)': sequence('(', ' / ', ')'),
683
+ '(%)': sequence('(', ' % ', ')'),
684
+ '(**)': sequence('(', ' ** ', ')'),
685
+ '(<)': sequence('(', ' < ', ')'),
686
+ '(<=)': sequence('(', ' <= ', ')'),
687
+ '(>)': sequence('(', ' > ', ')'),
688
+ '(>=)': sequence('(', ' >= ', ')'),
689
+ '(==)': sequence('(', ' == ', ')'),
690
+ '(!=)': sequence('(', ' != ', ')'),
691
+ '(===)': sequence('(', ' === ', ')'),
692
+ '(!==)': sequence('(', ' !== ', ')'),
693
+ '(<<)': sequence('(', ' << ', ')'),
694
+ '(>>)': sequence('(', ' >> ', ')'),
695
+ '(>>>)': sequence('(', ' >>> ', ')'),
696
+ '(&)': sequence('(', ' & ', ')'),
697
+ '(|)': sequence('(', ' | ', ')'),
698
+ '(^)': sequence('(', ' ^ ', ')'),
699
+ '(&&)': sequence('(', ' && ', ')'),
700
+ '(||)': sequence('(', ' || ', ')'),
701
+ '(,)': sequence('(', ', ', ')'),
702
+ '{;}': block('{', ';', '}'),
703
+ ';': block('', ';', ''),
704
+ '[,]': sequence('[', ', ', ']'),
705
+ '{,}': sequence('{', ', ', '}'),
706
+ '()': sequence('(', '', ')'),
707
+ '{}': block('{', '', '}'),
708
+ '[]': (input, belt) => {
709
+ const first = input.kids[0];
710
+ if (first.type)
711
+ return sequence('[', '', ']')(input, belt);
712
+ else
713
+ return [input.data('.' + first.text())];
714
+ },
715
+ ':': (input, belt) => {
716
+ const first = input.kids[0];
717
+ if (first.type)
718
+ return duplet('[', ']: ')(input, belt);
719
+ else
720
+ return duplet('', ': ')(input, belt);
721
+ },
722
+ 'let': duplet('let ', ' = '),
723
+ 'const': duplet('const ', ' = '),
724
+ 'var': duplet('var ', ' = '),
725
+ '=': duplet('', ' = '),
726
+ '+=': duplet('', ' += '),
727
+ '-=': duplet('', ' -= '),
728
+ '*=': duplet('', ' *= '),
729
+ '/=': duplet('', ' /= '),
730
+ '%=': duplet('', ' %= '),
731
+ '**=': duplet('', ' **= '),
732
+ '<<=': duplet('', ' <<= '),
733
+ '>>=': duplet('', ' >>= '),
734
+ '>>>=': duplet('', ' >>>= '),
735
+ '&=': duplet('', ' &= '),
736
+ '|=': duplet('', ' |= '),
737
+ '^=': duplet('', ' ^= '),
738
+ '&&=': duplet('', ' &&= '),
739
+ '||=': duplet('', ' ||= '),
740
+ '=>': duplet('', ' => '),
741
+ 'async=>': duplet('async ', ' => '),
742
+ 'function': triplet('function '),
743
+ 'function*': triplet('function* '),
744
+ 'async': triplet('async function '),
745
+ 'async*': triplet('async function* '),
746
+ 'class': triplet('class ', ' '),
747
+ 'extends': sequence('extends ', '', ' '),
748
+ 'if': triplet('if', ' ', 'else'),
749
+ '?:': triplet('', ' ? ', ' : '),
750
+ '.': (input, belt) => {
751
+ const first = input.kids[0];
752
+ if (first.type)
753
+ return triplet('[', ']')(input, belt);
754
+ else
757
755
  return [
756
+ input.data(first.text()),
757
+ ...input.list(input.kids.slice(1)).hack(belt),
758
+ ];
759
+ },
760
+ 'get': triplet('get [', ']'),
761
+ 'set': triplet('set [', ']'),
762
+ 'static': triplet('static [', ']'),
763
+ '/./': sequence(),
764
+ '.global': sequence('g'),
765
+ '.multiline': sequence('m'),
766
+ '.ignoreCase': sequence('i'),
767
+ '.source': (input, belt) => [
768
+ input.data('/'),
769
+ input.data(JSON.stringify(input.text()).slice(1, -1)),
770
+ input.data('/'),
771
+ ],
772
+ '``': (input, belt) => {
773
+ return [
774
+ input.struct('line', [
758
775
  input.data('`'),
759
776
  ...[].concat(...input.kids.map(kid => {
760
777
  if (kid.type) {
@@ -771,24 +788,25 @@ var $;
771
788
  }
772
789
  })),
773
790
  input.data('`'),
791
+ ]),
792
+ ];
793
+ },
794
+ '': (input, belt) => {
795
+ if (!input.type)
796
+ return [
797
+ input.data(JSON.stringify(input.text())),
774
798
  ];
775
- },
776
- '': (input, belt) => {
777
- if (!input.type)
778
- return [
779
- input.data(JSON.stringify(input.text())),
780
- ];
781
- if (/^[\w$#][\w0-9$]*$/i.test(input.type))
782
- return [
783
- input.data(input.type),
784
- ];
785
- if (input.type === 'NaN' || !Number.isNaN(Number(input.type)))
786
- return [
787
- input.data(input.type)
788
- ];
789
- $mol_fail(new SyntaxError(`Wrong node type`));
790
- },
791
- }))]);
799
+ if (/^[\w$#][\w0-9$]*$/i.test(input.type))
800
+ return [
801
+ input.data(input.type),
802
+ ];
803
+ if (input.type === 'NaN' || !Number.isNaN(Number(input.type)))
804
+ return [
805
+ input.data(input.type)
806
+ ];
807
+ $mol_fail(new SyntaxError(`Wrong node type`));
808
+ },
809
+ }));
792
810
  }
793
811
  $.$mol_tree2_js_to_text = $mol_tree2_js_to_text;
794
812
  })($ || ($ = {}));
@@ -967,7 +985,7 @@ var $;
967
985
  visit(kid, prefix + 1, false);
968
986
  }
969
987
  if (inline)
970
- indent();
988
+ next_line();
971
989
  }
972
990
  else if (text.type === 'line') {
973
991
  if (!inline)
@@ -3130,7 +3148,7 @@ var $;
3130
3148
  {;}
3131
3149
  1
3132
3150
  2
3133
- `), '{1; 2}\n');
3151
+ `), '{\n\t1;\n\t2;\n}\n');
3134
3152
  },
3135
3153
  'object'() {
3136
3154
  $mol_assert_equal(convert(`
@@ -3219,7 +3237,7 @@ var $;
3219
3237
  function
3220
3238
  (,) foo
3221
3239
  {;} debugger
3222
- `), 'function (foo){debugger}\n');
3240
+ `), 'function (foo){\n\tdebugger;\n}\n');
3223
3241
  $mol_assert_equal(convert(`
3224
3242
  function*
3225
3243
  (,)
@@ -3234,7 +3252,7 @@ var $;
3234
3252
  async*
3235
3253
  (,) foo
3236
3254
  {;} debugger
3237
- `), 'async function* (foo){debugger}\n');
3255
+ `), 'async function* (foo){\n\tdebugger;\n}\n');
3238
3256
  },
3239
3257
  'class'() {
3240
3258
  $mol_assert_equal(convert(`
@@ -3254,28 +3272,28 @@ var $;
3254
3272
  \\foo
3255
3273
  (,)
3256
3274
  {;}
3257
- `), 'class {foo(){}}\n');
3275
+ `), 'class {\n\tfoo(){}\n}\n');
3258
3276
  $mol_assert_equal(convert(`
3259
3277
  class {}
3260
3278
  static
3261
3279
  \\foo
3262
3280
  (,)
3263
3281
  {;}
3264
- `), 'class {static ["foo"](){}}\n');
3282
+ `), 'class {\n\tstatic ["foo"](){}\n}\n');
3265
3283
  $mol_assert_equal(convert(`
3266
3284
  class {}
3267
3285
  get
3268
3286
  \\foo
3269
3287
  (,)
3270
3288
  {;}
3271
- `), 'class {get ["foo"](){}}\n');
3289
+ `), 'class {\n\tget ["foo"](){}\n}\n');
3272
3290
  $mol_assert_equal(convert(`
3273
3291
  class {}
3274
3292
  set
3275
3293
  \\foo
3276
3294
  (,) bar
3277
3295
  {;}
3278
- `), 'class {set ["foo"](bar){}}\n');
3296
+ `), 'class {\n\tset ["foo"](bar){}\n}\n');
3279
3297
  },
3280
3298
  'if'() {
3281
3299
  $mol_assert_equal(convert(`
@@ -3288,13 +3306,13 @@ var $;
3288
3306
  if
3289
3307
  () 1
3290
3308
  {;} 2
3291
- `), 'if(1) {2}\n');
3309
+ `), 'if(1) {\n\t2;\n}\n');
3292
3310
  $mol_assert_equal(convert(`
3293
3311
  if
3294
3312
  () 1
3295
3313
  {;} 2
3296
3314
  {;} 3
3297
- `), 'if(1) {2}else{3}\n');
3315
+ `), 'if(1) {\n\t2;\n}else{\n\t3;\n}\n');
3298
3316
  },
3299
3317
  'assign'() {
3300
3318
  $mol_assert_equal(convert(`