@tsrx/content-mapper 0.1.4 → 0.1.6

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/dist/mapper.js CHANGED
@@ -1,3 +1,3 @@
1
- import { i as validate_options, n as require, r as to_diagnostic, t as create_tsrx_content_mapper } from "./mapper-SyX-87Od.js";
1
+ import { i as validate_options, n as require, r as to_diagnostic, t as create_tsrx_content_mapper } from "./mapper-CiYVAopk.js";
2
2
 
3
3
  export { create_tsrx_content_mapper, require, to_diagnostic, validate_options };
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as create_tsrx_content_mapper } from "./mapper-SyX-87Od.js";
2
+ import { t as create_tsrx_content_mapper } from "./mapper-CiYVAopk.js";
3
3
  import { redirect_console_to_stderr, run_mapper_server } from "./rpc.js";
4
4
 
5
5
  //#region src/server.js
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsrx/content-mapper",
3
3
  "description": "TypeScript 7 content mapper for .tsrx files",
4
- "version": "0.1.4",
4
+ "version": "0.1.6",
5
5
  "license": "MIT",
6
6
  "author": "Dominic Gannaway",
7
7
  "type": "module",
@@ -50,12 +50,12 @@
50
50
  "tsdown": "^0.23.0",
51
51
  "typescript": "^5.9.3",
52
52
  "vue": "3.6.0-rc.14",
53
- "@tsrx/core": "0.6.1",
54
- "@tsrx/preact": "0.4.1",
55
- "@tsrx/react": "0.5.1",
56
- "@tsrx/solid": "0.4.1",
57
- "@tsrx/typescript-plugin": "0.7.1",
58
- "@tsrx/vue": "0.4.1"
53
+ "@tsrx/core": "0.9.0",
54
+ "@tsrx/preact": "0.4.14",
55
+ "@tsrx/react": "0.5.14",
56
+ "@tsrx/typescript-plugin": "0.7.14",
57
+ "@tsrx/solid": "0.4.14",
58
+ "@tsrx/vue": "0.4.14"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"
@@ -2,7 +2,7 @@
2
2
  /** @import {CodeMapping, CompileError} from '@tsrx/core/types' */
3
3
  /** @import {DiagnosticDirectives} from './protocol.js' */
4
4
 
5
- import { DIAGNOSTIC_CODES } from '@tsrx/core/diagnostics';
5
+ import { DIAGNOSTIC_CODES, TS_ERRORS } from '@tsrx/core/diagnostics';
6
6
  import { DiagnosticDirectivePolicy } from './protocol.js';
7
7
 
8
8
  /**
@@ -13,6 +13,8 @@ import { DiagnosticDirectivePolicy } from './protocol.js';
13
13
  const HOLDER_TYPE =
14
14
  /(?:Statement|Declaration|Definition|Signature)$|^(?:StaticBlock|AccessorProperty|JSXElement|JSXFragment|JSXStyleElement)$/;
15
15
 
16
+ const JSX_NAME_ESCAPE_CODE = TS_ERRORS.JSX_NAME_UNICODE_ESCAPE.code;
17
+
16
18
  /** Keys of a tree node that hold no child nodes, or nodes that aren't its children. */
17
19
  const NOT_CHILDREN = new Set([
18
20
  'metadata',
@@ -77,7 +79,13 @@ export function ignore_directives(errors, source_ast, mappings, original_length,
77
79
  }
78
80
  const on_tag = reported_on_tag(error);
79
81
  const position = on_tag ? /** @type {number} */ (error.raisedAt) - 1 : error.pos;
80
- const holder = source_ast ? holder_at(source_ast, position) : null;
82
+ // An escape in a JSX name (TS17021) only misspells the name, which the
83
+ // output has the right way: TypeScript's errors elsewhere in the element,
84
+ // such as a wrong attribute value, stay. Only the name's own code is
85
+ // covered, so TypeScript's error on the name itself (TS2304 on
86
+ // `<Missin\u0067 />`) shows once.
87
+ const holder =
88
+ source_ast && error.code !== JSX_NAME_ESCAPE_CODE ? holder_at(source_ast, position) : null;
81
89
  const start = holder ? /** @type {number} */ (holder.start) : error.pos;
82
90
  const end = holder
83
91
  ? /** @type {number} */ (holder.end)
@@ -98,6 +98,14 @@ export function features_from_mapping_data(data) {
98
98
  * the span exactly show the authored name.
99
99
  * - Anything else → `Atom`.
100
100
  *
101
+ * Mappings over the same ranges in both files are one candidate. A container
102
+ * mapped for diagnostics only can cover exactly the text of the token inside
103
+ * it (`item` in a Vue `{item.label}`, a Solid `key i`), and the token keeps
104
+ * its hover and navigation whichever comes first: a mapping without features
105
+ * never takes the place of one with features. Of two with features, the first
106
+ * is kept, so the spans that coalesce stay the same. The candidate is
107
+ * position-only when one of its mappings is and none has a feature bit.
108
+ *
101
109
  * The transform emits container spans (statements, control-flow bodies) that
102
110
  * enclose token spans. TypeScript requires generated spans to be disjoint, so
103
111
  * candidates are ranked Verbatim first, then shorter before longer, and a
@@ -126,6 +134,13 @@ export function to_span_mappings(mappings, generated_text, original_text, option
126
134
  const language_features = options.languageFeatures !== false;
127
135
  /** @type {Candidate[]} */
128
136
  const candidates = [];
137
+ /**
138
+ * Candidates by their generated and original ranges. Kept apart, two
139
+ * candidates over the same ranges would tie in the ranking below, and the
140
+ * first in the transform's order would win even without features.
141
+ * @type {Map<string, Candidate>}
142
+ */
143
+ const by_ranges = new Map();
129
144
 
130
145
  for (const mapping of mappings) {
131
146
  const count = Math.min(mapping.sourceOffsets.length, mapping.generatedOffsets.length);
@@ -173,17 +188,30 @@ export function to_span_mappings(mappings, generated_text, original_text, option
173
188
  } else {
174
189
  kind = SpanMapKind.Atom;
175
190
  }
176
- candidates.push({
191
+ const features = language_features
192
+ ? features_from_mapping_data(mapping.data)
193
+ : SpanMapFeature.None;
194
+ const position_only = is_position_only(mapping.data);
195
+ const key = `${generated_start},${generated_end},${original_start},${original_end}`;
196
+ const same = by_ranges.get(key);
197
+ if (same) {
198
+ if (same.features === SpanMapFeature.None) same.features = features;
199
+ same.positionOnly =
200
+ (same.positionOnly || position_only) && same.features === SpanMapFeature.None;
201
+ continue;
202
+ }
203
+ /** @type {Candidate} */
204
+ const candidate = {
177
205
  generatedStart: generated_start,
178
206
  generatedEnd: generated_end,
179
207
  originalStart: original_start,
180
208
  originalEnd: original_end,
181
209
  kind,
182
- features: language_features
183
- ? features_from_mapping_data(mapping.data)
184
- : SpanMapFeature.None,
185
- positionOnly: is_position_only(mapping.data),
186
- });
210
+ features,
211
+ positionOnly: position_only,
212
+ };
213
+ by_ranges.set(key, candidate);
214
+ candidates.push(candidate);
187
215
  }
188
216
  }
189
217