@tsrx/core 0.1.14 → 0.1.15

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core compiler infrastructure for TSRX syntax",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.1.14",
6
+ "version": "0.1.15",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
@@ -605,6 +605,10 @@ export function get_comment_handlers(source, comments, index = 0) {
605
605
  node_array = parent.elements;
606
606
  } else if (parent.type === 'ObjectExpression') {
607
607
  node_array = parent.properties;
608
+ } else if (parent.type === 'ObjectPattern') {
609
+ node_array = parent.properties;
610
+ } else if (parent.type === 'TSTypeLiteral') {
611
+ node_array = parent.members;
608
612
  } else if (
609
613
  parent.type === 'FunctionDeclaration' ||
610
614
  parent.type === 'FunctionExpression' ||
@@ -622,11 +626,22 @@ export function get_comment_handlers(source, comments, index = 0) {
622
626
  is_last_in_array = node_array.indexOf(node) === node_array.length - 1;
623
627
  }
624
628
 
629
+ const trailingCommentBoundary =
630
+ parent &&
631
+ parent.type === 'ObjectPattern' &&
632
+ parent.typeAnnotation &&
633
+ parent.typeAnnotation.start !== undefined
634
+ ? parent.typeAnnotation.start
635
+ : parent?.end;
636
+
625
637
  if (is_last_in_array) {
626
638
  if (isParam || isArgument) {
627
639
  while (comments.length) {
628
640
  const potentialComment = comments[0];
629
- if (parent && potentialComment.start >= parent.end) {
641
+ if (
642
+ trailingCommentBoundary !== undefined &&
643
+ potentialComment.start >= trailingCommentBoundary
644
+ ) {
630
645
  break;
631
646
  }
632
647
 
@@ -653,7 +668,12 @@ export function get_comment_handlers(source, comments, index = 0) {
653
668
  // and they can be separated by newlines
654
669
  while (comments.length) {
655
670
  const comment = comments[0];
656
- if (parent && comment.start >= parent.end) break;
671
+ if (
672
+ trailingCommentBoundary !== undefined &&
673
+ comment.start >= trailingCommentBoundary
674
+ ) {
675
+ break;
676
+ }
657
677
 
658
678
  const maybeInner = getEmptyElementInnerCommentTarget(comment);
659
679
  if (maybeInner) {
@@ -235,6 +235,7 @@ export function tsx_with_ts_locations() {
235
235
  'AwaitExpression',
236
236
  'SwitchStatement',
237
237
  'TaggedTemplateExpression',
238
+ 'ArrowFunctionExpression',
238
239
  // JSX wrapper nodes: esrap writes `<`, `>`, `</`, `{`, `}` without
239
240
  // locations, so the opening/closing element's and expression
240
241
  // container's start and end don't resolve.
@@ -903,6 +903,23 @@ export function convert_source_map_to_mappings(
903
903
  node.type === 'ArrowFunctionExpression'
904
904
  ) {
905
905
  const is_method = node.metadata?.is_method;
906
+
907
+ if (node.type === 'ArrowFunctionExpression' && node.loc) {
908
+ const start_key = `${node.loc.start.line}:${node.loc.start.column}`;
909
+ const end_key = `${node.loc.end.line}:${node.loc.end.column}`;
910
+
911
+ if (src_to_gen_map.has(start_key) && src_to_gen_map.has(end_key)) {
912
+ mappings.push(
913
+ get_mapping_from_node(
914
+ node,
915
+ src_to_gen_map,
916
+ gen_line_offsets,
917
+ mapping_data_verify_only,
918
+ ),
919
+ );
920
+ }
921
+ }
922
+
906
923
  // Add function/component keyword token
907
924
  if (
908
925
  (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') &&