@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 +37 -4
- package/bundler/package.json +1 -1
- package/bundler/tsz_wasm_bg.wasm +0 -0
- package/node/package.json +1 -1
- package/node/tsz_wasm_bg.wasm +0 -0
- package/package.json +1 -1
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 =
|
|
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
|
|
package/bundler/package.json
CHANGED
package/bundler/tsz_wasm_bg.wasm
CHANGED
|
Binary file
|
package/node/package.json
CHANGED
package/node/tsz_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED