@tsrx/core 0.0.2 → 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dominic Gannaway
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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.0.2",
6
+ "version": "0.0.3",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
@@ -29,25 +29,25 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@jridgewell/sourcemap-codec": "catalog:default",
33
- "@sveltejs/acorn-typescript": "catalog:default",
34
- "acorn": "catalog:default",
35
- "esrap": "catalog:default",
36
- "is-reference": "catalog:default",
37
- "magic-string": "catalog:default",
38
- "zimmerframe": "catalog:default",
39
- "@types/estree": "catalog:default",
40
- "@types/estree-jsx": "catalog:default"
32
+ "@jridgewell/sourcemap-codec": "^1.5.5",
33
+ "@sveltejs/acorn-typescript": "^1.0.9",
34
+ "acorn": "^8.15.0",
35
+ "esrap": "^2.1.0",
36
+ "is-reference": "^3.0.3",
37
+ "magic-string": "^0.30.18",
38
+ "zimmerframe": "^1.1.2",
39
+ "@types/estree": "^1.0.8",
40
+ "@types/estree-jsx": "^1.0.5"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "catalog:default",
44
- "@typescript-eslint/types": "catalog:default",
45
- "typescript": "catalog:default",
46
- "@volar/language-core": "catalog:default",
47
- "vscode-languageserver-types": "catalog:default"
43
+ "@types/node": "^24.3.0",
44
+ "@typescript-eslint/types": "^8.40.0",
45
+ "typescript": "^5.9.3",
46
+ "@volar/language-core": "~2.4.28",
47
+ "vscode-languageserver-types": "^3.17.5"
48
48
  },
49
49
  "files": [
50
50
  "src",
51
51
  "types"
52
52
  ]
53
- }
53
+ }
package/src/index.js CHANGED
@@ -132,11 +132,7 @@ export { escape } from './utils/escaping.js';
132
132
 
133
133
  // Transform
134
134
  export { render_stylesheets as renderStylesheets } from './transform/stylesheet.js';
135
- export {
136
- convert_source_map_to_mappings as convertSourceMapToMappings,
137
- create_volar_mappings_result as createVolarMappingsResult,
138
- create_basic_volar_mappings_result as createBasicVolarMappingsResult,
139
- } from './transform/segments.js';
135
+ export { convert_source_map_to_mappings as convertSourceMapToMappings } from './transform/segments.js';
140
136
 
141
137
  // Analyze
142
138
  export { analyze_css as analyzeCss } from './analyze/css-analyze.js';
@@ -9,7 +9,6 @@
9
9
  CodeMapping,
10
10
  VolarMappingsResult,
11
11
  PostProcessingChanges,
12
- LineOffsets,
13
12
  } from '../../types/index';
14
13
  @import { CodeMapping as VolarCodeMapping } from '@volar/language-core';
15
14
  */
@@ -983,11 +982,9 @@ export function convert_source_map_to_mappings(
983
982
  visit(node.body);
984
983
  }
985
984
 
986
- if (node.loc) {
987
- mappings.push(
988
- get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
989
- );
990
- }
985
+ mappings.push(
986
+ get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
987
+ );
991
988
 
992
989
  return;
993
990
  } else if (node.type === 'WhileStatement' || node.type === 'DoWhileStatement') {
@@ -1324,11 +1321,9 @@ export function convert_source_map_to_mappings(
1324
1321
  }
1325
1322
  }
1326
1323
 
1327
- if (node.loc) {
1328
- mappings.push(
1329
- get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
1330
- );
1331
- }
1324
+ mappings.push(
1325
+ get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
1326
+ );
1332
1327
 
1333
1328
  return;
1334
1329
  } else if (node.type === 'SwitchCase') {
@@ -2035,16 +2030,11 @@ export function convert_source_map_to_mappings(
2035
2030
  );
2036
2031
  const source_length = source_text.length;
2037
2032
  const gen_length = gen_text.length;
2038
- let gen_line_col;
2039
- try {
2040
- gen_line_col = get_generated_position(
2041
- token.loc.start.line,
2042
- token.loc.start.column,
2043
- src_to_gen_map,
2044
- );
2045
- } catch {
2046
- continue;
2047
- }
2033
+ const gen_line_col = get_generated_position(
2034
+ token.loc.start.line,
2035
+ token.loc.start.column,
2036
+ src_to_gen_map,
2037
+ );
2048
2038
  const gen_start = loc_to_offset(gen_line_col.line, gen_line_col.column, gen_line_offsets);
2049
2039
 
2050
2040
  /** @type {CustomMappingData} */
@@ -2148,83 +2138,3 @@ export function convert_source_map_to_mappings(
2148
2138
  cssMappings,
2149
2139
  };
2150
2140
  }
2151
-
2152
- /**
2153
- * Build a `VolarMappingsResult` from generated code plus source-map metadata.
2154
- *
2155
- * Framework packages are responsible for producing the generated AST/code/map.
2156
- * Core owns the generic mapping conversion and result envelope so the editor
2157
- * integration is not coupled to any specific framework package.
2158
- *
2159
- * @param {{
2160
- * ast: AST.Program,
2161
- * ast_from_source: AST.Program,
2162
- * source: string,
2163
- * generated_code: string,
2164
- * source_map: RawSourceMap,
2165
- * errors?: import('../../types/index').CompileError[],
2166
- * post_processing_changes?: PostProcessingChanges,
2167
- * line_offsets?: LineOffsets,
2168
- * }} params
2169
- * @returns {VolarMappingsResult}
2170
- */
2171
- export function create_volar_mappings_result({
2172
- ast,
2173
- ast_from_source,
2174
- source,
2175
- generated_code,
2176
- source_map,
2177
- errors = [],
2178
- post_processing_changes,
2179
- line_offsets,
2180
- }) {
2181
- return {
2182
- ...convert_source_map_to_mappings(
2183
- ast,
2184
- ast_from_source,
2185
- source,
2186
- generated_code,
2187
- source_map,
2188
- /** @type {PostProcessingChanges} */ (post_processing_changes),
2189
- line_offsets ?? build_line_offsets(generated_code),
2190
- ),
2191
- errors,
2192
- };
2193
- }
2194
-
2195
- /**
2196
- * Build a coarse `VolarMappingsResult` when a framework can emit valid TS/TSX
2197
- * for checking but does not yet produce a location-rich generated AST for the
2198
- * fine-grained source-map conversion path.
2199
- *
2200
- * @param {{
2201
- * source: string,
2202
- * generated_code: string,
2203
- * errors?: import('../../types/index').CompileError[],
2204
- * }} params
2205
- * @returns {VolarMappingsResult}
2206
- */
2207
- export function create_basic_volar_mappings_result({ source, generated_code, errors = [] }) {
2208
- const shared_length = Math.min(source.length, generated_code.length);
2209
-
2210
- return {
2211
- code: generated_code,
2212
- mappings:
2213
- shared_length > 0
2214
- ? [
2215
- {
2216
- sourceOffsets: [0],
2217
- generatedOffsets: [0],
2218
- lengths: [shared_length],
2219
- generatedLengths: [shared_length],
2220
- data: {
2221
- ...mapping_data,
2222
- customData: {},
2223
- },
2224
- },
2225
- ]
2226
- : [],
2227
- cssMappings: [],
2228
- errors,
2229
- };
2230
- }