ripple 0.2.102 → 0.2.104

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.
@@ -99,15 +99,19 @@ export function convert_source_map_to_mappings(ast, source, generated_code) {
99
99
  /** @type {string[]} */
100
100
  const tokens = [];
101
101
 
102
+ // We have to visit everything in generated order to maintain correct indices
102
103
  walk(ast, null, {
103
- _(node, { next, visit }) {
104
+ _(node, { visit }) {
104
105
  // Collect key node types: Identifiers, Literals, and JSX Elements
105
106
  if (node.type === 'Identifier' && node.name) {
106
107
  tokens.push(node.name);
108
+ return; // Leaf node, don't traverse further
107
109
  } else if (node.type === 'JSXIdentifier' && node.name) {
108
110
  tokens.push(node.name);
111
+ return; // Leaf node, don't traverse further
109
112
  } else if (node.type === 'Literal' && node.raw) {
110
113
  tokens.push(node.raw);
114
+ return; // Leaf node, don't traverse further
111
115
  } else if (node.type === 'ImportDeclaration') {
112
116
  // Visit specifiers in source order
113
117
  if (node.specifiers) {
@@ -134,15 +138,15 @@ export function convert_source_map_to_mappings(ast, source, generated_code) {
134
138
  }
135
139
  return;
136
140
  } else if (node.type === 'ExportNamedDeclaration') {
137
- // Visit in source order: declaration, specifiers
138
- if (node.declaration) {
139
- visit(node.declaration);
140
- }
141
- if (node.specifiers) {
141
+ if (node.specifiers && node.specifiers.length > 0) {
142
142
  for (const specifier of node.specifiers) {
143
143
  visit(specifier);
144
144
  }
145
145
  }
146
+ if (node.declaration) {
147
+ // The declaration will be visited with proper ordering
148
+ visit(node.declaration);
149
+ }
146
150
  return;
147
151
  } else if (node.type === 'ExportDefaultDeclaration') {
148
152
  // Visit the declaration
@@ -153,6 +157,41 @@ export function convert_source_map_to_mappings(ast, source, generated_code) {
153
157
  } else if (node.type === 'ExportAllDeclaration') {
154
158
  // Nothing to visit (just source string)
155
159
  return;
160
+ } else if (node.type === 'JSXOpeningElement') {
161
+ // Visit name and attributes in source order
162
+ if (node.name) {
163
+ visit(node.name);
164
+ }
165
+ if (node.attributes) {
166
+ for (const attr of node.attributes) {
167
+ visit(attr);
168
+ }
169
+ }
170
+ return;
171
+ } else if (node.type === 'JSXAttribute') {
172
+ // Visit name and value in source order
173
+ if (node.name) {
174
+ visit(node.name);
175
+ }
176
+ if (node.value) {
177
+ visit(node.value);
178
+ }
179
+ return;
180
+ } else if (node.type === 'JSXSpreadAttribute') {
181
+ // Visit the spread argument
182
+ if (node.argument) {
183
+ visit(node.argument);
184
+ }
185
+ return;
186
+ } else if (node.type === 'JSXExpressionContainer') {
187
+ // Visit the expression inside {}
188
+ if (node.expression) {
189
+ visit(node.expression);
190
+ }
191
+ return;
192
+ } else if (node.type === 'JSXText') {
193
+ // Text content, no tokens to collect
194
+ return;
156
195
  } else if (node.type === 'JSXElement') {
157
196
  // Manually visit in source order: opening element, children, closing element
158
197
 
@@ -335,11 +374,18 @@ export function convert_source_map_to_mappings(ast, source, generated_code) {
335
374
  return;
336
375
  } else if (node.type === 'Property') {
337
376
  // Visit in source order: key, value
338
- if (node.key) {
339
- visit(node.key);
340
- }
341
- if (node.value) {
342
- visit(node.value);
377
+ // For shorthand properties ({ count }), key and value are the same node, only visit once
378
+ if (node.shorthand) {
379
+ if (node.value) {
380
+ visit(node.value);
381
+ }
382
+ } else {
383
+ if (node.key) {
384
+ visit(node.key);
385
+ }
386
+ if (node.value) {
387
+ visit(node.value);
388
+ }
343
389
  }
344
390
  return;
345
391
  } else if (node.type === 'ArrayExpression' || node.type === 'ArrayPattern') {
@@ -459,9 +505,482 @@ export function convert_source_map_to_mappings(ast, source, generated_code) {
459
505
  visit(node.value);
460
506
  }
461
507
  return;
508
+ } else if (node.type === 'SequenceExpression') {
509
+ // Visit expressions in order
510
+ if (node.expressions) {
511
+ for (const expr of node.expressions) {
512
+ visit(expr);
513
+ }
514
+ }
515
+ return;
516
+ } else if (node.type === 'SpreadElement' || node.type === 'RestElement') {
517
+ // Visit the argument
518
+ if (node.argument) {
519
+ visit(node.argument);
520
+ }
521
+ return;
522
+ } else if (node.type === 'YieldExpression' || node.type === 'AwaitExpression') {
523
+ // Visit the argument if present
524
+ if (node.argument) {
525
+ visit(node.argument);
526
+ }
527
+ return;
528
+ } else if (node.type === 'ChainExpression') {
529
+ // Visit the expression
530
+ if (node.expression) {
531
+ visit(node.expression);
532
+ }
533
+ return;
534
+ } else if (node.type === 'Super' || node.type === 'ThisExpression') {
535
+ // Leaf nodes, no children
536
+ return;
537
+ } else if (node.type === 'MetaProperty') {
538
+ // Visit meta and property (e.g., new.target, import.meta)
539
+ if (node.meta) {
540
+ visit(node.meta);
541
+ }
542
+ if (node.property) {
543
+ visit(node.property);
544
+ }
545
+ return;
546
+ } else if (node.type === 'EmptyStatement' || node.type === 'DebuggerStatement') {
547
+ // No children to visit
548
+ return;
549
+ } else if (node.type === 'LabeledStatement') {
550
+ // Visit label and statement
551
+ if (node.label) {
552
+ visit(node.label);
553
+ }
554
+ if (node.body) {
555
+ visit(node.body);
556
+ }
557
+ return;
558
+ } else if (node.type === 'BreakStatement' || node.type === 'ContinueStatement') {
559
+ // Visit label if present
560
+ if (node.label) {
561
+ visit(node.label);
562
+ }
563
+ return;
564
+ } else if (node.type === 'WithStatement') {
565
+ // Visit object and body
566
+ if (node.object) {
567
+ visit(node.object);
568
+ }
569
+ if (node.body) {
570
+ visit(node.body);
571
+ }
572
+ return;
573
+ } else if (node.type === 'JSXFragment') {
574
+ // Visit children in order
575
+ if (node.children) {
576
+ for (const child of node.children) {
577
+ visit(child);
578
+ }
579
+ }
580
+ return;
581
+ } else if (node.type === 'JSXClosingElement' || node.type === 'JSXClosingFragment' || node.type === 'JSXOpeningFragment') {
582
+ // These are handled by their parent nodes
583
+ return;
584
+ } else if (node.type === 'JSXMemberExpression') {
585
+ // Visit object and property (e.g., <Foo.Bar>)
586
+ if (node.object) {
587
+ visit(node.object);
588
+ }
589
+ if (node.property) {
590
+ visit(node.property);
591
+ }
592
+ return;
593
+ } else if (node.type === 'JSXNamespacedName') {
594
+ // Visit namespace and name (e.g., <svg:circle>)
595
+ if (node.namespace) {
596
+ visit(node.namespace);
597
+ }
598
+ if (node.name) {
599
+ visit(node.name);
600
+ }
601
+ return;
602
+ } else if (node.type === 'JSXEmptyExpression') {
603
+ // No children
604
+ return;
605
+ } else if (node.type === 'TemplateElement') {
606
+ // Leaf node, no children to visit
607
+ return;
608
+ } else if (node.type === 'PrivateIdentifier') {
609
+ // Leaf node
610
+ return;
611
+ } else if (node.type === 'PropertyDefinition') {
612
+ // Visit key and value
613
+ if (node.key) {
614
+ visit(node.key);
615
+ }
616
+ if (node.value) {
617
+ visit(node.value);
618
+ }
619
+ return;
620
+ } else if (node.type === 'StaticBlock') {
621
+ // Visit body
622
+ if (node.body) {
623
+ for (const statement of node.body) {
624
+ visit(statement);
625
+ }
626
+ }
627
+ return;
628
+ } else if (node.type === 'ImportExpression') {
629
+ // Visit source
630
+ if (node.source) {
631
+ visit(node.source);
632
+ }
633
+ return;
634
+ } else if (node.type === 'ParenthesizedExpression') {
635
+ // Visit the wrapped expression
636
+ if (node.expression) {
637
+ visit(node.expression);
638
+ }
639
+ return;
640
+ } else if (node.type === 'TSAsExpression' || node.type === 'TSSatisfiesExpression') {
641
+ // Type assertion: value as Type
642
+ if (node.expression) {
643
+ visit(node.expression);
644
+ }
645
+ // Skip typeAnnotation
646
+ return;
647
+ } else if (node.type === 'TSNonNullExpression') {
648
+ // Non-null assertion: value!
649
+ if (node.expression) {
650
+ visit(node.expression);
651
+ }
652
+ return;
653
+ } else if (node.type === 'TSTypeAssertion') {
654
+ // Type assertion: <Type>value
655
+ if (node.expression) {
656
+ visit(node.expression);
657
+ }
658
+ // Skip typeAnnotation
659
+ return;
660
+ } else if (node.type === 'TSTypeParameterInstantiation' || node.type === 'TSTypeParameterDeclaration') {
661
+ // Generic type parameters - visit to collect type variable names
662
+ if (node.params) {
663
+ for (const param of node.params) {
664
+ visit(param);
665
+ }
666
+ }
667
+ return;
668
+ } else if (node.type === 'TSTypeParameter') {
669
+ // Type parameter like T in <T>
670
+ if (node.name) {
671
+ visit(node.name);
672
+ }
673
+ if (node.constraint) {
674
+ visit(node.constraint);
675
+ }
676
+ if (node.default) {
677
+ visit(node.default);
678
+ }
679
+ return;
680
+ } else if (node.type === 'TSTypeAnnotation') {
681
+ // Type annotation - visit the type
682
+ if (node.typeAnnotation) {
683
+ visit(node.typeAnnotation);
684
+ }
685
+ return;
686
+ } else if (node.type === 'TSTypeReference') {
687
+ // Type reference like "string" or "Array<T>"
688
+ if (node.typeName) {
689
+ visit(node.typeName);
690
+ }
691
+ if (node.typeParameters) {
692
+ visit(node.typeParameters);
693
+ }
694
+ return;
695
+ } else if (node.type === 'TSQualifiedName') {
696
+ // Qualified name (e.g., Foo.Bar in types)
697
+ if (node.left) {
698
+ visit(node.left);
699
+ }
700
+ if (node.right) {
701
+ visit(node.right);
702
+ }
703
+ return;
704
+ } else if (node.type === 'TSArrayType') {
705
+ // Array type like T[]
706
+ if (node.elementType) {
707
+ visit(node.elementType);
708
+ }
709
+ return;
710
+ } else if (node.type === 'TSTupleType') {
711
+ // Tuple type like [string, number]
712
+ if (node.elementTypes) {
713
+ for (const type of node.elementTypes) {
714
+ visit(type);
715
+ }
716
+ }
717
+ return;
718
+ } else if (node.type === 'TSUnionType' || node.type === 'TSIntersectionType') {
719
+ // Union (A | B) or Intersection (A & B) types
720
+ if (node.types) {
721
+ for (const type of node.types) {
722
+ visit(type);
723
+ }
724
+ }
725
+ return;
726
+ } else if (node.type === 'TSFunctionType' || node.type === 'TSConstructorType') {
727
+ // Function or constructor type
728
+ if (node.typeParameters) {
729
+ visit(node.typeParameters);
730
+ }
731
+ if (node.parameters) {
732
+ for (const param of node.parameters) {
733
+ visit(param);
734
+ }
735
+ }
736
+ if (node.typeAnnotation) {
737
+ visit(node.typeAnnotation);
738
+ }
739
+ return;
740
+ } else if (node.type === 'TSTypeLiteral') {
741
+ // Object type literal { foo: string }
742
+ if (node.members) {
743
+ for (const member of node.members) {
744
+ visit(member);
745
+ }
746
+ }
747
+ return;
748
+ } else if (node.type === 'TSPropertySignature') {
749
+ // Property signature in type
750
+ if (node.key) {
751
+ visit(node.key);
752
+ }
753
+ if (node.typeAnnotation) {
754
+ visit(node.typeAnnotation);
755
+ }
756
+ return;
757
+ } else if (node.type === 'TSMethodSignature') {
758
+ // Method signature in type
759
+ if (node.key) {
760
+ visit(node.key);
761
+ }
762
+ if (node.typeParameters) {
763
+ visit(node.typeParameters);
764
+ }
765
+ if (node.parameters) {
766
+ for (const param of node.parameters) {
767
+ visit(param);
768
+ }
769
+ }
770
+ if (node.typeAnnotation) {
771
+ visit(node.typeAnnotation);
772
+ }
773
+ return;
774
+ } else if (node.type === 'TSIndexSignature') {
775
+ // Index signature [key: string]: Type
776
+ if (node.parameters) {
777
+ for (const param of node.parameters) {
778
+ visit(param);
779
+ }
780
+ }
781
+ if (node.typeAnnotation) {
782
+ visit(node.typeAnnotation);
783
+ }
784
+ return;
785
+ } else if (node.type === 'TSCallSignatureDeclaration' || node.type === 'TSConstructSignatureDeclaration') {
786
+ // Call or construct signature
787
+ if (node.typeParameters) {
788
+ visit(node.typeParameters);
789
+ }
790
+ if (node.parameters) {
791
+ for (const param of node.parameters) {
792
+ visit(param);
793
+ }
794
+ }
795
+ if (node.typeAnnotation) {
796
+ visit(node.typeAnnotation);
797
+ }
798
+ return;
799
+ } else if (node.type === 'TSConditionalType') {
800
+ // Conditional type: T extends U ? X : Y
801
+ if (node.checkType) {
802
+ visit(node.checkType);
803
+ }
804
+ if (node.extendsType) {
805
+ visit(node.extendsType);
806
+ }
807
+ if (node.trueType) {
808
+ visit(node.trueType);
809
+ }
810
+ if (node.falseType) {
811
+ visit(node.falseType);
812
+ }
813
+ return;
814
+ } else if (node.type === 'TSInferType') {
815
+ // Infer type: infer T
816
+ if (node.typeParameter) {
817
+ visit(node.typeParameter);
818
+ }
819
+ return;
820
+ } else if (node.type === 'TSParenthesizedType') {
821
+ // Parenthesized type: (T)
822
+ if (node.typeAnnotation) {
823
+ visit(node.typeAnnotation);
824
+ }
825
+ return;
826
+ } else if (node.type === 'TSTypeOperator') {
827
+ // Type operator: keyof T, readonly T
828
+ if (node.typeAnnotation) {
829
+ visit(node.typeAnnotation);
830
+ }
831
+ return;
832
+ } else if (node.type === 'TSIndexedAccessType') {
833
+ // Indexed access: T[K]
834
+ if (node.objectType) {
835
+ visit(node.objectType);
836
+ }
837
+ if (node.indexType) {
838
+ visit(node.indexType);
839
+ }
840
+ return;
841
+ } else if (node.type === 'TSMappedType') {
842
+ // Mapped type: { [K in keyof T]: ... }
843
+ if (node.typeParameter) {
844
+ visit(node.typeParameter);
845
+ }
846
+ if (node.typeAnnotation) {
847
+ visit(node.typeAnnotation);
848
+ }
849
+ return;
850
+ } else if (node.type === 'TSLiteralType') {
851
+ // Literal type: "foo" | 123 | true
852
+ if (node.literal) {
853
+ visit(node.literal);
854
+ }
855
+ return;
856
+ } else if (node.type === 'TSExpressionWithTypeArguments') {
857
+ // Expression with type arguments: Foo<Bar>
858
+ if (node.expression) {
859
+ visit(node.expression);
860
+ }
861
+ if (node.typeParameters) {
862
+ visit(node.typeParameters);
863
+ }
864
+ return;
865
+ } else if (node.type === 'TSImportType') {
866
+ // Import type: import("module").Type
867
+ if (node.argument) {
868
+ visit(node.argument);
869
+ }
870
+ if (node.qualifier) {
871
+ visit(node.qualifier);
872
+ }
873
+ if (node.typeParameters) {
874
+ visit(node.typeParameters);
875
+ }
876
+ return;
877
+ } else if (node.type === 'TSTypeQuery') {
878
+ // Type query: typeof x
879
+ if (node.exprName) {
880
+ visit(node.exprName);
881
+ }
882
+ return;
883
+ } else if (node.type === 'TSInterfaceDeclaration') {
884
+ // Interface declaration
885
+ if (node.id) {
886
+ visit(node.id);
887
+ }
888
+ if (node.typeParameters) {
889
+ visit(node.typeParameters);
890
+ }
891
+ if (node.extends) {
892
+ for (const ext of node.extends) {
893
+ visit(ext);
894
+ }
895
+ }
896
+ if (node.body) {
897
+ visit(node.body);
898
+ }
899
+ return;
900
+ } else if (node.type === 'TSInterfaceBody') {
901
+ // Interface body
902
+ if (node.body) {
903
+ for (const member of node.body) {
904
+ visit(member);
905
+ }
906
+ }
907
+ return;
908
+ } else if (node.type === 'TSTypeAliasDeclaration') {
909
+ // Type alias
910
+ if (node.id) {
911
+ visit(node.id);
912
+ }
913
+ if (node.typeParameters) {
914
+ visit(node.typeParameters);
915
+ }
916
+ if (node.typeAnnotation) {
917
+ visit(node.typeAnnotation);
918
+ }
919
+ return;
920
+ } else if (node.type === 'TSEnumDeclaration') {
921
+ // Visit id and members
922
+ if (node.id) {
923
+ visit(node.id);
924
+ }
925
+ if (node.members) {
926
+ for (const member of node.members) {
927
+ visit(member);
928
+ }
929
+ }
930
+ return;
931
+ } else if (node.type === 'TSEnumMember') {
932
+ // Visit id and initializer
933
+ if (node.id) {
934
+ visit(node.id);
935
+ }
936
+ if (node.initializer) {
937
+ visit(node.initializer);
938
+ }
939
+ return;
940
+ } else if (node.type === 'TSModuleDeclaration') {
941
+ // Namespace/module declaration
942
+ if (node.id) {
943
+ visit(node.id);
944
+ }
945
+ if (node.body) {
946
+ visit(node.body);
947
+ }
948
+ return;
949
+ } else if (node.type === 'TSModuleBlock') {
950
+ // Module body
951
+ if (node.body) {
952
+ for (const statement of node.body) {
953
+ visit(statement);
954
+ }
955
+ }
956
+ return;
957
+ } else if (node.type === 'TSNamedTupleMember') {
958
+ // Named tuple member: [name: Type]
959
+ if (node.label) {
960
+ visit(node.label);
961
+ }
962
+ if (node.elementType) {
963
+ visit(node.elementType);
964
+ }
965
+ return;
966
+ } else if (node.type === 'TSRestType') {
967
+ // Rest type: ...T[]
968
+ if (node.typeAnnotation) {
969
+ visit(node.typeAnnotation);
970
+ }
971
+ return;
972
+ } else if (node.type === 'TSOptionalType') {
973
+ // Optional type: T?
974
+ if (node.typeAnnotation) {
975
+ visit(node.typeAnnotation);
976
+ }
977
+ return;
978
+ } else if (node.type === 'TSAnyKeyword' || node.type === 'TSUnknownKeyword' || node.type === 'TSNumberKeyword' || node.type === 'TSObjectKeyword' || node.type === 'TSBooleanKeyword' || node.type === 'TSBigIntKeyword' || node.type === 'TSStringKeyword' || node.type === 'TSSymbolKeyword' || node.type === 'TSVoidKeyword' || node.type === 'TSUndefinedKeyword' || node.type === 'TSNullKeyword' || node.type === 'TSNeverKeyword' || node.type === 'TSThisType' || node.type === 'TSIntrinsicKeyword') {
979
+ // Primitive type keywords - leaf nodes, no children
980
+ return;
462
981
  }
463
982
 
464
- next();
983
+ throw new Error(`Unhandled AST node type in mapping walker: ${node.type}`);
465
984
  }
466
985
  });
467
986