@mohsen-azimi/tsz-dev 0.1.7 → 0.1.8

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/bin/tsz.js CHANGED
@@ -142,15 +142,36 @@ if (fs.existsSync(manifestPath)) {
142
142
  }
143
143
  }
144
144
 
145
+ // Map from absolute path → source text, used for offset→line/col conversion.
146
+ const sourceTexts = new Map();
147
+
145
148
  for (const file of inputFiles) {
146
149
  try {
147
150
  const text = fs.readFileSync(file, 'utf8');
148
151
  program.addSourceFile(file, text);
152
+ sourceTexts.set(file, text);
149
153
  } catch (err) {
150
154
  console.error(`tsz: cannot read ${file}: ${err.message}`);
151
155
  }
152
156
  }
153
157
 
158
+ /**
159
+ * Convert a 0-based UTF-16 character offset to { line, character } (0-based).
160
+ * This matches the position model used by tsc.
161
+ */
162
+ function offsetToLineChar(text, offset) {
163
+ const clamped = Math.max(0, Math.min(offset, text.length));
164
+ let line = 0;
165
+ let lineStart = 0;
166
+ for (let i = 0; i < clamped; i++) {
167
+ if (text[i] === '\n') {
168
+ line++;
169
+ lineStart = i + 1;
170
+ }
171
+ }
172
+ return { line, character: clamped - lineStart };
173
+ }
174
+
154
175
  let diagnostics;
155
176
  try {
156
177
  diagnostics = JSON.parse(program.getSemanticDiagnosticsJson(undefined));
@@ -164,17 +185,29 @@ try {
164
185
  let errorCount = 0;
165
186
  let warningCount = 0;
166
187
 
188
+ // tsc diagnostic category codes: 0=warning, 1=error, 2=suggestion, 3=message
189
+ const CATEGORY_NAMES = { 0: 'warning', 1: 'error', 2: 'suggestion', 3: 'message' };
190
+
167
191
  for (const d of diagnostics) {
168
- const category = String(d.category || 'error').toLowerCase();
192
+ const category = CATEGORY_NAMES[d.category] || 'error';
169
193
  if (category === 'error') errorCount++;
170
194
  else if (category === 'warning') warningCount++;
171
195
 
172
196
  const file = d.file || '<unknown>';
173
197
  const relFile = path.relative(process.cwd(), file);
174
- const line = (d.line != null ? d.line + 1 : '?');
175
- const col = (d.character != null ? d.character + 1 : '?');
176
- const code = d.code ? `TS${d.code}` : '';
177
198
 
199
+ // Compute 1-based line/character from byte offset if available
200
+ let line = '?', col = '?';
201
+ if (typeof d.start === 'number') {
202
+ const src = sourceTexts.get(file);
203
+ if (src != null) {
204
+ const pos = offsetToLineChar(src, d.start);
205
+ line = pos.line + 1;
206
+ col = pos.character + 1;
207
+ }
208
+ }
209
+
210
+ const code = d.code ? `TS${d.code}` : '';
178
211
  console.error(`${relFile}(${line},${col}): ${category} ${code}: ${d.messageText || d.message || ''}`);
179
212
  }
180
213
 
@@ -5,7 +5,7 @@
5
5
  "Mohsen Azimi <mohsen@users.noreply.github.com>"
6
6
  ],
7
7
  "description": "WebAssembly bindings for the tsz TypeScript compiler",
8
- "version": "0.1.7",
8
+ "version": "0.1.8",
9
9
  "license": "Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
Binary file
package/node/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "Mohsen Azimi <mohsen@users.noreply.github.com>"
5
5
  ],
6
6
  "description": "WebAssembly bindings for the tsz TypeScript compiler",
7
- "version": "0.1.7",
7
+ "version": "0.1.8",
8
8
  "license": "Apache-2.0",
9
9
  "repository": {
10
10
  "type": "git",
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohsen-azimi/tsz-dev",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "WebAssembly bindings for the tsz TypeScript compiler",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Mohsen Azimi <mohsen@users.noreply.github.com>",