@vesk/compiler 0.2.40 → 0.2.41
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/typecheck.d.ts.map +1 -1
- package/dist/typecheck.js +52 -6
- package/package.json +2 -2
package/dist/typecheck.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typecheck.d.ts","sourceRoot":"","sources":["../src/typecheck.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD,eAAO,MAAM,OAAO,6xoBAkhBnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,uZAS5B,CAAC;AA6LF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC5B;
|
|
1
|
+
{"version":3,"file":"typecheck.d.ts","sourceRoot":"","sources":["../src/typecheck.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD,eAAO,MAAM,OAAO,6xoBAkhBnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,uZAS5B,CAAC;AA6LF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC5B;AAuCD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB,GAAG,eAAe,CA2GlG;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAItE;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM,CAI1E"}
|
package/dist/typecheck.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
|
2
2
|
import { join, dirname, normalize, relative, resolve, sep } from 'node:path';
|
|
3
3
|
import * as ts from 'typescript';
|
|
4
4
|
import { parse } from '@vesk/compiler/src/parser';
|
|
5
|
-
import {
|
|
5
|
+
import { compileVskCodegen, generateVskDts } from '@vesk/compiler/src/vsk-tsx';
|
|
6
6
|
import { resolveAliasModule } from '@vesk/compiler/src/module-imports';
|
|
7
7
|
const SKIP_DIRS = new Set(['node_modules', '.vesk', '.git', 'dist', 'tarballs', '.next']);
|
|
8
8
|
const SKIP_FILES = new Set(['__vesk_ambient.d.ts', '__vesk_runtime_override.d.ts']);
|
|
@@ -642,7 +642,7 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
|
|
|
642
642
|
content = '';
|
|
643
643
|
}
|
|
644
644
|
else if (vskFiles.has(file)) {
|
|
645
|
-
content =
|
|
645
|
+
content = compileVskCodegen(vskFiles.get(file)).code;
|
|
646
646
|
}
|
|
647
647
|
else if (ts.sys.fileExists(file)) {
|
|
648
648
|
content = ts.sys.readFile(file);
|
|
@@ -684,7 +684,7 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
|
|
|
684
684
|
if (file.endsWith('.css.d.ts'))
|
|
685
685
|
return '';
|
|
686
686
|
if (vskFiles.has(file))
|
|
687
|
-
return
|
|
687
|
+
return compileVskCodegen(vskFiles.get(file)).code;
|
|
688
688
|
return ts.sys.readFile(file);
|
|
689
689
|
},
|
|
690
690
|
writeFile: () => { },
|
|
@@ -739,6 +739,35 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
|
|
|
739
739
|
};
|
|
740
740
|
return host;
|
|
741
741
|
}
|
|
742
|
+
function mapGeneratedOffset(mappings, generatedOffset) {
|
|
743
|
+
let nearest = null;
|
|
744
|
+
for (const mapping of mappings) {
|
|
745
|
+
for (let i = 0; i < mapping.generatedOffsets.length; i++) {
|
|
746
|
+
const generated = mapping.generatedOffsets[i];
|
|
747
|
+
const length = mapping.lengths[i] ?? 0;
|
|
748
|
+
const source = mapping.sourceOffsets[i];
|
|
749
|
+
if (generated <= generatedOffset && generated + length >= generatedOffset) {
|
|
750
|
+
return source + (generatedOffset - generated);
|
|
751
|
+
}
|
|
752
|
+
if (generated <= generatedOffset && (!nearest || generated > nearest.generated)) {
|
|
753
|
+
nearest = { source, generated, length };
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return nearest ? nearest.source + Math.min(nearest.length, Math.max(0, generatedOffset - nearest.generated)) : null;
|
|
758
|
+
}
|
|
759
|
+
function sourcePosition(source, offset) {
|
|
760
|
+
const bounded = Math.max(0, Math.min(offset, source.length));
|
|
761
|
+
let line = 1;
|
|
762
|
+
let lineStart = 0;
|
|
763
|
+
for (let i = 0; i < bounded; i++) {
|
|
764
|
+
if (source.charCodeAt(i) === 10) {
|
|
765
|
+
line++;
|
|
766
|
+
lineStart = i + 1;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return { line, character: bounded - lineStart + 1 };
|
|
770
|
+
}
|
|
742
771
|
export function typecheckProject(projectRoot, opts = {}) {
|
|
743
772
|
const appDir = opts.appDir ?? join(projectRoot, 'app');
|
|
744
773
|
const vskFiles = new Map();
|
|
@@ -820,12 +849,29 @@ export function typecheckProject(projectRoot, opts = {}) {
|
|
|
820
849
|
}
|
|
821
850
|
if (!rootSet.has(filePath) && !vskSet.has(filePath))
|
|
822
851
|
continue;
|
|
823
|
-
|
|
852
|
+
let sourceOffset = diag.start ?? 0;
|
|
853
|
+
let line;
|
|
854
|
+
let column;
|
|
855
|
+
if (vskFiles.has(filePath)) {
|
|
856
|
+
const source = vskFiles.get(filePath);
|
|
857
|
+
const generated = compileVskCodegen(source);
|
|
858
|
+
const mapped = mapGeneratedOffset(generated.mappings, sourceOffset);
|
|
859
|
+
if (mapped !== null)
|
|
860
|
+
sourceOffset = mapped;
|
|
861
|
+
const pos = sourcePosition(source, sourceOffset);
|
|
862
|
+
line = pos.line;
|
|
863
|
+
column = pos.character;
|
|
864
|
+
}
|
|
865
|
+
else {
|
|
866
|
+
const pos = file.getLineAndCharacterOfPosition(diag.start ?? 0);
|
|
867
|
+
line = pos.line + 1;
|
|
868
|
+
column = pos.character + 1;
|
|
869
|
+
}
|
|
824
870
|
const code = typeof diag.code === 'number' ? `TS${diag.code}` : String(diag.code);
|
|
825
871
|
errors.push({
|
|
826
872
|
file: relative(projectRoot, filePath),
|
|
827
|
-
line
|
|
828
|
-
column
|
|
873
|
+
line,
|
|
874
|
+
column,
|
|
829
875
|
code,
|
|
830
876
|
message: ts.flattenDiagnosticMessageText(diag.messageText, '\n'),
|
|
831
877
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesk/compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@sveltejs/acorn-typescript": "^1.0.0",
|
|
23
|
-
"@vesk/types": "^0.2.
|
|
23
|
+
"@vesk/types": "^0.2.41",
|
|
24
24
|
"acorn": "^8.15.0",
|
|
25
25
|
"esrap": "^2.3.0",
|
|
26
26
|
"is-reference": "^3.0.0",
|