@torpor/check 1.0.18 → 1.0.20
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/bin/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { n as check$1, r as check, t as printErrors } from "../printErrors-
|
|
2
|
+
import { n as check$1, r as check, t as printErrors } from "../printErrors-DnnJTDYl.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import chalk from "chalk";
|
|
5
|
-
import fs, { existsSync, readdirSync, statSync } from "node:fs";
|
|
6
5
|
import path from "node:path";
|
|
6
|
+
import fs, { existsSync, readdirSync, statSync } from "node:fs";
|
|
7
7
|
//#region src/warnStaleView.ts
|
|
8
8
|
/**
|
|
9
9
|
* Warns when the `@torpor/view` dist that the compiler resolves to is older
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["check"],"sources":["../src/types/Diagnostic.ts","../src/check.ts","../src/checkFile.ts","../src/printErrors.ts"],"mappings":";UAAyB;EACxB;EACA;EACA;EACA;IACC;MAAS;MAAc;;IACvB;MAAO;MAAc;;;EAEtB;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["check"],"sources":["../src/types/Diagnostic.ts","../src/check.ts","../src/checkFile.ts","../src/printErrors.ts"],"mappings":";UAAyB;EACxB;EACA;EACA;EACA;IACC;MAAS;MAAc;;IACvB;MAAO;MAAc;;;EAEtB;;;;iBCCuB,MAAM,iBAAiB;;;iBCLvBA,QAAM,eAAe;;;iBCArB,YAAY,gBAAgB,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { r as check, n as checkFile, t as printErrors } from "./printErrors-
|
|
1
|
+
export { r as check, n as checkFile, t as printErrors } from "./printErrors-DnnJTDYl.mjs";
|
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import tsvfs from "@typescript/vfs";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
+
import path from "node:path";
|
|
4
5
|
import fg from "fast-glob";
|
|
5
6
|
import fs from "node:fs";
|
|
6
|
-
import path from "node:path";
|
|
7
7
|
import path$1 from "path";
|
|
8
8
|
import { build, parse } from "@torpor/view/compile";
|
|
9
|
+
//#region src/findFiles.ts
|
|
10
|
+
/**
|
|
11
|
+
* Finds the files to check in a folder, from its tsconfig `include` and
|
|
12
|
+
* `exclude` paths, matching the files tsc would take:
|
|
13
|
+
*
|
|
14
|
+
* - the paths are relative to the tsconfig's folder, and only the files
|
|
15
|
+
* inside `folder` are kept (so checking a subfolder checks the part of the
|
|
16
|
+
* project in it), along with the project's declaration files, which can
|
|
17
|
+
* declare modules and globals for it (e.g. `declare module "*.torp"`)
|
|
18
|
+
* - a path without wildcards is a folder to take everything from, unless
|
|
19
|
+
* it's a file (e.g. "site.config.ts")
|
|
20
|
+
* - JavaScript files are only taken when the project allows them (so built
|
|
21
|
+
* bundles, e.g. under `src/public`, aren't checked)
|
|
22
|
+
*
|
|
23
|
+
* @param folder The folder to check
|
|
24
|
+
* @param configFolder The folder the tsconfig is in, which its paths are relative to
|
|
25
|
+
*
|
|
26
|
+
* @returns The files' paths, relative to `folder` (declaration files outside it start with "..")
|
|
27
|
+
*/
|
|
28
|
+
function findFiles(folder, configFolder, include, exclude, allowJs) {
|
|
29
|
+
const toGlob = (f) => {
|
|
30
|
+
const isFile = !f.includes("*") && fs.statSync(path.resolve(configFolder, f), { throwIfNoEntry: false })?.isFile();
|
|
31
|
+
f = fg.convertPathToPattern(f).replaceAll("\\*", "*");
|
|
32
|
+
if (!f.includes("*") && !isFile) {
|
|
33
|
+
if (!f.endsWith("/")) f += "/";
|
|
34
|
+
f += "**";
|
|
35
|
+
}
|
|
36
|
+
return f;
|
|
37
|
+
};
|
|
38
|
+
const globs = include.map(toGlob);
|
|
39
|
+
if (globs.length === 0) globs.push("**");
|
|
40
|
+
const ignore = exclude.map(toGlob);
|
|
41
|
+
const root = path.resolve(folder);
|
|
42
|
+
return fg.globSync(globs, {
|
|
43
|
+
cwd: configFolder,
|
|
44
|
+
ignore,
|
|
45
|
+
absolute: true
|
|
46
|
+
}).map((f) => path.relative(root, f)).filter((f) => f.endsWith(".d.ts") || f !== "" && !f.startsWith("..") && !path.isAbsolute(f)).filter((f) => allowJs && f.endsWith(".js") || f.endsWith(".ts") || f.endsWith(".torp"));
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
9
49
|
//#region src/typescriptLoader.ts
|
|
10
50
|
/**
|
|
11
51
|
* Checks that a TypeScript module provides the API surface that the check
|
|
@@ -76,7 +116,7 @@ function loadVts(vtsPath) {
|
|
|
76
116
|
exclude: []
|
|
77
117
|
};
|
|
78
118
|
try {
|
|
79
|
-
let fileConfig = loadTypeScriptConfig(ts);
|
|
119
|
+
let fileConfig = loadTypeScriptConfig(ts, vtsPath);
|
|
80
120
|
if (fileConfig?.options) vts.config = {
|
|
81
121
|
options: fileConfig.options,
|
|
82
122
|
include: fileConfig.raw.include ?? [],
|
|
@@ -92,12 +132,18 @@ function loadVts(vtsPath) {
|
|
|
92
132
|
}
|
|
93
133
|
return vts;
|
|
94
134
|
}
|
|
95
|
-
|
|
96
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Loads the tsconfig.json nearest to the checked folder (or file), as tsc
|
|
137
|
+
* finds it, so that a subfolder's own config is used. Its paths are relative
|
|
138
|
+
* to its own folder.
|
|
139
|
+
*/
|
|
140
|
+
function loadTypeScriptConfig(ts, vtsPath) {
|
|
141
|
+
const searchFolder = fs.existsSync(vtsPath) && fs.statSync(vtsPath).isFile() ? path$1.dirname(vtsPath) : vtsPath;
|
|
142
|
+
const configFileName = ts.findConfigFile(searchFolder, (fileName) => ts.sys.fileExists(fileName));
|
|
97
143
|
if (configFileName) {
|
|
98
144
|
vts.configPath = path$1.dirname(configFileName);
|
|
99
145
|
const configFile = ts.readConfigFile(configFileName, (fileName) => ts.sys.readFile(fileName));
|
|
100
|
-
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.
|
|
146
|
+
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.configPath);
|
|
101
147
|
}
|
|
102
148
|
}
|
|
103
149
|
//#endregion
|
|
@@ -145,7 +191,10 @@ function transformDocument(vts, filename, source, debug = false) {
|
|
|
145
191
|
content: "",
|
|
146
192
|
map: []
|
|
147
193
|
};
|
|
148
|
-
let { code, map } = build(parsed.template, {
|
|
194
|
+
let { code, map } = build(parsed.template, {
|
|
195
|
+
mapped: true,
|
|
196
|
+
check: true
|
|
197
|
+
});
|
|
149
198
|
code = importComponentFiles(vts, filename, code, map, debug);
|
|
150
199
|
return {
|
|
151
200
|
ok: true,
|
|
@@ -205,8 +254,12 @@ function importComponentFiles(vts, filename, content, map, _debug = false) {
|
|
|
205
254
|
if (!vts.virtualFiles.has(key) && fs.existsSync(typeFile)) {
|
|
206
255
|
vts.virtualFiles.set(key, "");
|
|
207
256
|
const typeSource = fs.readFileSync(typeFile, "utf8");
|
|
208
|
-
const { content } = transformDocument(vts, typeFile, typeSource);
|
|
257
|
+
const { content, map: importedMap } = transformDocument(vts, typeFile, typeSource);
|
|
209
258
|
vts.virtualFiles.set(key, content);
|
|
259
|
+
vts.virtualFileMaps.set(key, {
|
|
260
|
+
sourceFile: typeFile,
|
|
261
|
+
map: importedMap
|
|
262
|
+
});
|
|
210
263
|
vts.env.createFile(key, content);
|
|
211
264
|
}
|
|
212
265
|
let oldLength = content.length;
|
|
@@ -286,6 +339,29 @@ function updateVirtualFile(vts, key, content, sourceFile, map) {
|
|
|
286
339
|
}
|
|
287
340
|
//#endregion
|
|
288
341
|
//#region src/processErrors.ts
|
|
342
|
+
/**
|
|
343
|
+
* TypeScript's "declared but never read" codes: TS6133, all imports unused
|
|
344
|
+
* (TS6192), TS6196 (types), TS6198 (destructured), TS6199 (variables),
|
|
345
|
+
* TS6205 (type parameters).
|
|
346
|
+
*/
|
|
347
|
+
const UNUSED_CODES = /* @__PURE__ */ new Set([
|
|
348
|
+
6133,
|
|
349
|
+
6192,
|
|
350
|
+
6196,
|
|
351
|
+
6198,
|
|
352
|
+
6199,
|
|
353
|
+
6205
|
|
354
|
+
]);
|
|
355
|
+
const EMPTY_RANGE = {
|
|
356
|
+
start: {
|
|
357
|
+
line: 0,
|
|
358
|
+
character: 0
|
|
359
|
+
},
|
|
360
|
+
end: {
|
|
361
|
+
line: 0,
|
|
362
|
+
character: 0
|
|
363
|
+
}
|
|
364
|
+
};
|
|
289
365
|
function processErrors(vts, errors) {
|
|
290
366
|
return errors.map((d) => {
|
|
291
367
|
let message = getMessageText(d);
|
|
@@ -353,6 +429,11 @@ function processErrors(vts, errors) {
|
|
|
353
429
|
mapped = void 0;
|
|
354
430
|
message = "!";
|
|
355
431
|
}
|
|
432
|
+
if (!mapped && d.code !== void 0 && UNUSED_CODES.has(d.code)) return {
|
|
433
|
+
path: filename,
|
|
434
|
+
message: "!",
|
|
435
|
+
range: EMPTY_RANGE
|
|
436
|
+
};
|
|
356
437
|
if (!mapped) return {
|
|
357
438
|
path: filename,
|
|
358
439
|
message,
|
|
@@ -423,26 +504,12 @@ function getMessages(chain, messages) {
|
|
|
423
504
|
//#endregion
|
|
424
505
|
//#region src/check.ts
|
|
425
506
|
function check$1(folder) {
|
|
426
|
-
|
|
507
|
+
folder = path.resolve(folder);
|
|
427
508
|
console.log("Checking files in", folder);
|
|
428
509
|
const vts = loadVts(folder);
|
|
429
510
|
if (vts === void 0) return [];
|
|
430
511
|
const ts = vts.ts;
|
|
431
|
-
|
|
432
|
-
f = fg.convertPathToPattern(f).replaceAll("\\*", "*");
|
|
433
|
-
if (!f.includes("*")) {
|
|
434
|
-
if (!f.endsWith("/")) f += "/";
|
|
435
|
-
f += "**";
|
|
436
|
-
}
|
|
437
|
-
return f;
|
|
438
|
-
};
|
|
439
|
-
let include = vts.config.include.map(pathToGlob);
|
|
440
|
-
if (include.length === 0) include.push("**");
|
|
441
|
-
const ignore = vts.config.exclude.map(pathToGlob);
|
|
442
|
-
let files = fg.globSync(include, {
|
|
443
|
-
cwd: folder,
|
|
444
|
-
ignore
|
|
445
|
-
}).filter((f) => f.endsWith(".js") || f.endsWith(".ts") || f.endsWith(".torp"));
|
|
512
|
+
const files = findFiles(folder, vts.configPath ?? folder, vts.config.include, vts.config.exclude, vts.config.options.allowJs === true);
|
|
446
513
|
console.log(`Found ${chalk.green(files.length)} file${files.length === 1 ? "" : "s"} to check`);
|
|
447
514
|
let errors = [];
|
|
448
515
|
for (let file of files) {
|
|
@@ -479,7 +546,7 @@ function validateScript(filename) {
|
|
|
479
546
|
//#endregion
|
|
480
547
|
//#region src/checkFile.ts
|
|
481
548
|
function check(file) {
|
|
482
|
-
|
|
549
|
+
file = path.resolve(file);
|
|
483
550
|
console.log("Checking file", file);
|
|
484
551
|
return validateScript(file);
|
|
485
552
|
}
|
|
@@ -503,4 +570,4 @@ function printErrors(folder, errors) {
|
|
|
503
570
|
//#endregion
|
|
504
571
|
export { check as n, check$1 as r, printErrors as t };
|
|
505
572
|
|
|
506
|
-
//# sourceMappingURL=printErrors-
|
|
573
|
+
//# sourceMappingURL=printErrors-DnnJTDYl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printErrors-DnnJTDYl.mjs","names":["path","check"],"sources":["../src/findFiles.ts","../src/typescriptLoader.ts","../src/loadVts.ts","../src/pathReplace.ts","../src/transformDocument.ts","../src/loadDocument.ts","../src/processErrors.ts","../src/check.ts","../src/validateScript.ts","../src/checkFile.ts","../src/printErrors.ts"],"sourcesContent":["import fg from \"fast-glob\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Finds the files to check in a folder, from its tsconfig `include` and\n * `exclude` paths, matching the files tsc would take:\n *\n * - the paths are relative to the tsconfig's folder, and only the files\n * inside `folder` are kept (so checking a subfolder checks the part of the\n * project in it), along with the project's declaration files, which can\n * declare modules and globals for it (e.g. `declare module \"*.torp\"`)\n * - a path without wildcards is a folder to take everything from, unless\n * it's a file (e.g. \"site.config.ts\")\n * - JavaScript files are only taken when the project allows them (so built\n * bundles, e.g. under `src/public`, aren't checked)\n *\n * @param folder The folder to check\n * @param configFolder The folder the tsconfig is in, which its paths are relative to\n *\n * @returns The files' paths, relative to `folder` (declaration files outside it start with \"..\")\n */\nexport default function findFiles(\n\tfolder: string,\n\tconfigFolder: string,\n\tinclude: string[],\n\texclude: string[],\n\tallowJs: boolean,\n): string[] {\n\tconst toGlob = (f: string) => {\n\t\tconst isFile =\n\t\t\t!f.includes(\"*\") &&\n\t\t\tfs.statSync(path.resolve(configFolder, f), { throwIfNoEntry: false })?.isFile();\n\t\tf = fg.convertPathToPattern(f).replaceAll(\"\\\\*\", \"*\");\n\t\tif (!f.includes(\"*\") && !isFile) {\n\t\t\tif (!f.endsWith(\"/\")) f += \"/\";\n\t\t\tf += \"**\";\n\t\t}\n\t\treturn f;\n\t};\n\tconst globs = include.map(toGlob);\n\tif (globs.length === 0) {\n\t\tglobs.push(\"**\");\n\t}\n\tconst ignore = exclude.map(toGlob);\n\n\tconst root = path.resolve(folder);\n\treturn fg\n\t\t.globSync(globs, { cwd: configFolder, ignore, absolute: true })\n\t\t.map((f) => path.relative(root, f))\n\t\t.filter((f) => f.endsWith(\".d.ts\") || (f !== \"\" && !f.startsWith(\"..\") && !path.isAbsolute(f)))\n\t\t.filter((f) => (allowJs && f.endsWith(\".js\")) || f.endsWith(\".ts\") || f.endsWith(\".torp\"));\n}\n","import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type TS from \"typescript\";\n\nexport type TypeScriptModule = typeof TS;\n\n/**\n * Checks that a TypeScript module provides the API surface that the check\n * pipeline uses. Newer versions of TypeScript may drop or change the compiler\n * API (e.g. the TypeScript 7 native package does not expose the compiler\n * enums), in which case the version bundled with this package is used instead.\n */\nfunction isCompatible(ts: TypeScriptModule): boolean {\n\tconst api = ts as unknown as Record<string, any> | undefined;\n\treturn (\n\t\t!!api &&\n\t\ttypeof api.version === \"string\" &&\n\t\ttypeof api.createProgram === \"function\" &&\n\t\ttypeof api.createLanguageService === \"function\" &&\n\t\t!!api.sys &&\n\t\ttypeof api.sys.getExecutingFilePath === \"function\" &&\n\t\t!!api.ScriptTarget &&\n\t\t!!api.ModuleKind &&\n\t\t!!api.ModuleResolutionKind\n\t);\n}\n\n/**\n * Loads the TypeScript module to check a project with.\n *\n * Prefers the project's own installed version (resolved from the project\n * root, like Node would), so that diagnostics match the user's build.\n * TypeScript 7 (the native package) doesn't expose the compiler API that the\n * check needs, and a project may not have TypeScript installed at all, so it\n * falls back to the version bundled with this package.\n */\nexport default function loadTypeScriptModule(projectRoot: string): TypeScriptModule {\n\ttry {\n\t\tconst require = createRequire(path.join(projectRoot, \"package.json\"));\n\t\tconst ts = require(\"typescript\") as TypeScriptModule;\n\t\tif (isCompatible(ts)) {\n\t\t\tconsole.log(`Using TypeScript ${ts.version} from the project`);\n\t\t\treturn ts;\n\t\t}\n\t\tconsole.log(\n\t\t\t`Project TypeScript ${ts.version} does not provide the compiler API, ` +\n\t\t\t\t`falling back to the bundled version`,\n\t\t);\n\t} catch {\n\t\t// The project does not have TypeScript installed\n\t}\n\n\tconst require = createRequire(import.meta.url);\n\tconst ts = require(\"typescript\") as TypeScriptModule;\n\tconsole.log(`Using bundled TypeScript ${ts.version}`);\n\treturn ts;\n}\n","import tsvfs from \"@typescript/vfs\";\nimport fs from \"node:fs\";\nimport path from \"path\";\nimport type { LanguageService } from \"typescript\";\nimport loadTypeScriptModule, { type TypeScriptModule } from \"./typescriptLoader\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nlet vts: VirtualTypeScript = {\n\t// @ts-ignore This will definitely be set\n\tts: undefined,\n\t// @ts-ignore This will definitely be set\n\tenv: undefined,\n\t// @ts-ignore This will definitely be set\n\tlang: undefined,\n\tprojectRoot: \"\",\n\tconfigPath: undefined,\n\t// This is just the default config, it should be overwritten by the one from\n\t// the user's tsconfig.json (it's built in loadVts, once the TypeScript\n\t// module -- which owns the compiler enums -- has been loaded)\n\tconfig: {\n\t\toptions: {},\n\t\tinclude: [],\n\t\texclude: [],\n\t},\n\tvirtualFiles: new Map<string, string>(),\n\tvirtualFileMaps: new Map<string, { sourceFile: string; map: SourceMap[] }>(),\n};\n\nexport default function loadVts(vtsPath: string): VirtualTypeScript | undefined {\n\tif (vts.env === undefined) {\n\t\t// If using imports where the types don't directly match up to\n\t\t// their FS representation (like the imports for node) then use\n\t\t// triple-slash directives to make sure globals are set up\n\t\t// first.\n\t\t//const content = `\n\t\t//\t/// <reference types=\"node\" />\n\t\t//\timport * as path from 'path';\n\t\t//\tpath.`.replaceAll(/\\s+/, \" \").trim();\n\n\t\t// By providing a project root, the system knows how to resolve\n\t\t// node_modules correctly\n\t\tvts.projectRoot = path.join(vtsPath, \".\");\n\t\twhile (vts.projectRoot && !fs.existsSync(path.join(vts.projectRoot, \"node_modules\"))) {\n\t\t\tvts.projectRoot = path.join(vts.projectRoot, \"..\");\n\t\t}\n\t\tif (!vts.projectRoot) {\n\t\t\tconsole.log(\"No project root found\");\n\t\t\treturn;\n\t\t}\n\n\t\t// The TypeScript module to check with: the project's own version when\n\t\t// it provides the compiler API, otherwise the one bundled with this\n\t\t// package (TypeScript 7's native package does not)\n\t\tconst ts = loadTypeScriptModule(vts.projectRoot);\n\t\tvts.ts = ts;\n\n\t\t// The default config, used when the user's tsconfig.json can't be read\n\t\tvts.config = {\n\t\t\toptions: {\n\t\t\t\ttarget: ts.ScriptTarget.ES2022,\n\t\t\t\tmodule: ts.ModuleKind.ESNext,\n\t\t\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\t\t\tesModuleInterop: true,\n\t\t\t},\n\t\t\tinclude: [],\n\t\t\texclude: [],\n\t\t};\n\n\t\t// Maybe load tsconfig from a file\n\t\t// TODO: reload if the file is changed\n\t\ttry {\n\t\t\tlet fileConfig = loadTypeScriptConfig(ts, vtsPath);\n\t\t\tif (fileConfig?.options) {\n\t\t\t\tvts.config = {\n\t\t\t\t\toptions: fileConfig.options,\n\t\t\t\t\tinclude: fileConfig.raw.include ?? [],\n\t\t\t\t\texclude: fileConfig.raw.exclude ?? [],\n\t\t\t\t};\n\t\t\t}\n\t\t} catch {\n\t\t\tconsole.log(\"No tsconfig.json file found, using default\");\n\t\t}\n\n\t\tconst system = tsvfs.createFSBackedSystem(vts.virtualFiles, vts.projectRoot, ts);\n\t\tvts.env = tsvfs.createVirtualTypeScriptEnvironment(system, [], ts, vts.config.options);\n\t\tvts.lang = vts.env.languageService as LanguageService;\n\n\t\tconsole.log(\"Torpor type checking loaded\");\n\t}\n\treturn vts;\n}\n\n/**\n * Loads the tsconfig.json nearest to the checked folder (or file), as tsc\n * finds it, so that a subfolder's own config is used. Its paths are relative\n * to its own folder.\n */\nfunction loadTypeScriptConfig(\n\tts: TypeScriptModule,\n\tvtsPath: string,\n): Record<string, any> | undefined {\n\tconst searchFolder =\n\t\tfs.existsSync(vtsPath) && fs.statSync(vtsPath).isFile() ? path.dirname(vtsPath) : vtsPath;\n\tconst configFileName = ts.findConfigFile(searchFolder, (fileName) => ts.sys.fileExists(fileName));\n\tif (configFileName) {\n\t\tvts.configPath = path.dirname(configFileName);\n\t\tconst configFile = ts.readConfigFile(configFileName, (fileName) => ts.sys.readFile(fileName));\n\t\treturn ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.configPath);\n\t}\n}\n","// TODO: Implement more logic from https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths\nexport default function pathReplace(pattern: string, replacement: string, value: string): string {\n\tpattern = \"^\" + pattern.replaceAll(\"*\", \"(.+?)\");\n\treplacement = replacement.replaceAll(\"*\", \"$1\");\n\n\tconst regex1 = new RegExp(pattern);\n\treturn value.replace(regex1, replacement);\n}\n","import { build, parse } from \"@torpor/view/compile\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport pathReplace from \"./pathReplace\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ninterface TransformResult {\n\tok: boolean;\n\terrors: Diagnostic[];\n\tcontent: string;\n\tmap: SourceMap[];\n}\n\nexport default function transformDocument(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tsource: string,\n\tdebug = false,\n): TransformResult {\n\ttry {\n\t\t// Build the main file as a component\n\t\tconst parsed = parse(source);\n\n\t\t// If not ok, don't validate\n\t\tif (!parsed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: parsed.errors.map((e) => {\n\t\t\t\t\tlet lineTextStart = e.startIndex;\n\t\t\t\t\twhile (lineTextStart >= 0) {\n\t\t\t\t\t\tif (source[lineTextStart] === \"\\n\") {\n\t\t\t\t\t\t\tlineTextStart++;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlineTextStart--;\n\t\t\t\t\t}\n\t\t\t\t\tlet lineTextEnd: number | undefined = source.indexOf(\"\\n\", e.startIndex);\n\t\t\t\t\tif (lineTextEnd === -1) lineTextEnd = undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpath: filename,\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\tstart: { line: e.startLine, character: e.startChar },\n\t\t\t\t\t\t\tend: { line: e.endLine, character: e.endChar },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlineText: source.substring(lineTextStart, lineTextEnd),\n\t\t\t\t\t} satisfies Diagnostic;\n\t\t\t\t}),\n\t\t\t\tcontent: \"\",\n\t\t\t\tmap: [],\n\t\t\t};\n\t\t}\n\n\t\t// Build for checking: the code keeps the template's control flow, so\n\t\t// narrowing and loop variable types carry into blocks\n\t\tlet { code, map } = build(parsed.template!, { mapped: true, check: true });\n\n\t\tcode = importComponentFiles(vts, filename, code, map, debug);\n\n\t\t//console.log(code);\n\t\t//console.log(map);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\terrors: [],\n\t\t\tcontent: code,\n\t\t\tmap,\n\t\t};\n\t} catch (ex) {\n\t\tconst message = ex instanceof Error ? ex.stack : String(ex);\n\t\tconsole.log(\"Failed to compile\", filename);\n\t\tconsole.log(message);\n\t\treturn {\n\t\t\tok: false,\n\t\t\terrors: [],\n\t\t\tcontent: \"\",\n\t\t\tmap: [],\n\t\t};\n\t}\n}\n\nfunction importComponentFiles(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tcontent: string,\n\tmap: SourceMap[],\n\t_debug = false,\n): string {\n\tif (!/^\\s*import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms.test(content)) {\n\t\treturn content;\n\t}\n\n\t// Build imported component files and add them to the virtual file map\n\t// TODO: Handle files from node_modules? Might get done automatically by typescript-vfs\n\n\t// HACK: We're assuming that all imports are at the top of the file, and\n\t// that there are not multiple imports on the one line\n\tconst first = map.shift()!;\n\tconst filepath = path.dirname(filename);\n\n\tlet moved = 0;\n\tlet newMaps: SourceMap[] = [];\n\n\tfor (let i = 0; i < first.script.length; i++) {\n\t\tif (first.script[i] === \"/\") {\n\t\t\t// Skip comments\n\t\t\tif (first.script[i + 1] === \"/\") {\n\t\t\t\ti = first.script.indexOf(\"\\n\", i);\n\t\t\t} else if (first.script[i + 1] === \"*\") {\n\t\t\t\ti = first.script.indexOf(\"*/\", i);\n\t\t\t}\n\t\t\tif (i === -1) {\n\t\t\t\treturn content;\n\t\t\t}\n\t\t} else if (first.script[i] === \"i\") {\n\t\t\tconst match = first.script.substring(i).match(/import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms);\n\t\t\tif (match === null) continue;\n\n\t\t\tconst oldImport = match[0];\n\t\t\t//const names = match[1];\n\t\t\tconst importedFile = match[2];\n\n\t\t\t// Strip quotes\n\t\t\tlet importFile = importedFile;\n\t\t\tif (\n\t\t\t\t(importFile.startsWith(\"'\") && importFile.endsWith(\"'\")) ||\n\t\t\t\t(importFile.startsWith('\"') && importFile.endsWith('\"'))\n\t\t\t) {\n\t\t\t\timportFile = importFile.substring(1, importFile.length - 1);\n\t\t\t}\n\n\t\t\t// Just map import files that aren't components\n\t\t\tif (!importFile.endsWith(\".torp\")) {\n\t\t\t\tnewMaps.push({\n\t\t\t\t\tscript: oldImport,\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tstart: i,\n\t\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t\tcompiled: {\n\t\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\t\tend: first.compiled.start + i + moved + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Get the absolute path of the import file\n\t\t\tlet typeFile = importFile.startsWith(\".\") ? path.join(filepath, importFile) : importFile;\n\n\t\t\t// Replace aliased paths from tsconfig.json\n\t\t\tif (vts.configPath && vts.config.options.paths) {\n\t\t\t\t// HACK: Get the longest match etc\n\t\t\t\tconst oldTypeFile = typeFile;\n\t\t\t\tfor (let [srcGlob, paths] of Object.entries(vts.config.options.paths)) {\n\t\t\t\t\tfor (let destGlob of paths) {\n\t\t\t\t\t\ttypeFile = pathReplace(srcGlob, destGlob, typeFile);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// The import may now be relative to the tsconfig file, so make it absolute\n\t\t\t\tif (typeFile !== oldTypeFile && typeFile.startsWith(\".\")) {\n\t\t\t\t\ttypeFile = path.join(vts.configPath, typeFile);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Create the virtual file for the component\n\t\t\tconst key = typeFile.replace(/\\.torp$/, \".ts\");\n\t\t\tif (!vts.virtualFiles.has(key) && fs.existsSync(typeFile)) {\n\t\t\t\t// Mark as in progress before transforming, so that circular\n\t\t\t\t// component imports don't recurse forever\n\t\t\t\tvts.virtualFiles.set(key, \"\");\n\t\t\t\tconst typeSource = fs.readFileSync(typeFile, \"utf8\");\n\t\t\t\tconst { content, map: importedMap } = transformDocument(vts, typeFile, typeSource);\n\t\t\t\tvts.virtualFiles.set(key, content);\n\t\t\t\t// Map it back to its source too, for errors reported in it\n\t\t\t\tvts.virtualFileMaps.set(key, { sourceFile: typeFile, map: importedMap });\n\t\t\t\tvts.env.createFile(key, content);\n\t\t\t}\n\n\t\t\t// Replace the import file with the virtual file\n\t\t\tlet oldLength = content.length;\n\t\t\tlet newValue = typeFile.replace(\".torp\", \".ts\");\n\t\t\t// HACK: We could concat this if we could be bothered\n\t\t\tlet newImport = oldImport.replace(importFile, newValue);\n\t\t\tcontent = content.replace(oldImport, newImport);\n\n\t\t\t// Move subsequent ranges around\n\t\t\tlet diff = content.length - oldLength;\n\t\t\tfor (let mapped of map) {\n\t\t\t\tmapped.compiled.start += diff;\n\t\t\t\tmapped.compiled.end += diff;\n\t\t\t}\n\n\t\t\t// Add a range for the changed import\n\t\t\tnewMaps.push({\n\t\t\t\tscript: oldImport,\n\t\t\t\tsource: {\n\t\t\t\t\tstart: i,\n\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t},\n\t\t\t\tcompiled: {\n\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\tend: first.compiled.start + i + moved + newImport.length,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tmoved += diff;\n\t\t\ti += oldImport.length;\n\t\t}\n\t}\n\n\tmap.unshift(...newMaps);\n\n\treturn content;\n}\n","import fs from \"node:fs\";\nimport loadVts from \"./loadVts\";\nimport transformDocument from \"./transformDocument\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ntype LoadResult =\n\t| { ok: false; errors: Diagnostic[] }\n\t| {\n\t\t\tok: true;\n\t\t\tfilename: string;\n\t\t\tkey: string;\n\t\t\ttext: string;\n\t\t\tcontent: string;\n\t\t\tmap: SourceMap[];\n\t\t\tvts: VirtualTypeScript;\n\t };\n\nexport function loadDocument(filename: string): LoadResult {\n\tconst key = filename.replace(/\\.torp$/, \".ts\");\n\n\tconst vts = loadVts(filename);\n\tif (vts === undefined) {\n\t\treturn { ok: false, errors: [] };\n\t}\n\n\tconst text = fs.readFileSync(filename, \"utf-8\");\n\tif (filename.endsWith(\".torp\")) {\n\t\tconst transformed = transformDocument(vts, filename, text);\n\t\tif (!transformed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: transformed.errors,\n\t\t\t};\n\t\t}\n\t\tconst { content, map } = transformed;\n\t\tupdateVirtualFile(vts, key, content, filename, map);\n\t\treturn { ok: true, filename, key, text, content, map, vts: vts };\n\t} else {\n\t\tupdateVirtualFile(vts, key, text, filename, []);\n\t\treturn { ok: true, filename, key, text, content: text, map: [], vts: vts };\n\t}\n}\n\nfunction updateVirtualFile(\n\tvts: VirtualTypeScript,\n\tkey: string,\n\tcontent: string,\n\tsourceFile: string,\n\tmap: SourceMap[],\n) {\n\tif (!vts.virtualFiles.has(key)) {\n\t\tvts.env.createFile(key, content);\n\t} else {\n\t\tvts.env.updateFile(key, content);\n\t}\n\tvts.virtualFiles.set(key, content);\n\tvts.virtualFileMaps.set(key, { sourceFile, map });\n}\n","import fs from \"node:fs\";\nimport type ts from \"typescript\";\nimport type { DiagnosticMessageChain } from \"typescript\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\n/**\n * TypeScript's \"declared but never read\" codes: TS6133, all imports unused\n * (TS6192), TS6196 (types), TS6198 (destructured), TS6199 (variables),\n * TS6205 (type parameters).\n */\nconst UNUSED_CODES = new Set([6133, 6192, 6196, 6198, 6199, 6205]);\n\nconst EMPTY_RANGE = {\n\tstart: { line: 0, character: 0 },\n\tend: { line: 0, character: 0 },\n};\n\nexport default function processErrors(\n\tvts: VirtualTypeScript,\n\terrors: ts.Diagnostic[],\n): Diagnostic[] {\n\treturn errors\n\t\t.map((d: ts.Diagnostic) => {\n\t\t\tlet message = getMessageText(d);\n\n\t\t\tif (d.file === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: \"\",\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet filename = d.file.fileName;\n\t\t\tlet map: SourceMap[] = [];\n\t\t\tif (vts.virtualFileMaps.has(filename)) {\n\t\t\t\tlet transformed = vts.virtualFileMaps.get(filename)!;\n\t\t\t\tfilename = transformed.sourceFile;\n\t\t\t\tmap = transformed.map;\n\t\t\t}\n\t\t\tconst source = fs.readFileSync(filename, \"utf-8\");\n\t\t\tlet lineText: string | undefined;\n\t\t\tif (!filename.endsWith(\".torp\")) {\n\t\t\t\tlet start = { line: 0, character: 0 };\n\t\t\t\tlet end = { line: 0, character: 0 };\n\t\t\t\tif (d.start !== undefined) {\n\t\t\t\t\t// @ts-ignore we know this exists\n\t\t\t\t\tlet lineMap: number[] = d.file.lineMap;\n\t\t\t\t\tif (lineMap === undefined) {\n\t\t\t\t\t\tlineMap = [0];\n\t\t\t\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\t\t\t\tif (source[i] === \"\\n\") lineMap.push(i);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// TODO: These need to be indexes\n\t\t\t\t\tstart.line = (lineMap.findIndex((l: number) => l > d.start!) ?? 1) - 1;\n\t\t\t\t\tstart.character = d.start - lineMap[start.line] - 1;\n\t\t\t\t\tlet endx = d.start! + (d.length ?? 0);\n\t\t\t\t\tend.line = (lineMap.findIndex((l: number) => l >= endx) ?? 1) - 1;\n\t\t\t\t\tend.character = endx - lineMap[end.line] - 1;\n\t\t\t\t\tlet lineStart = lineMap[start.line] + 1;\n\t\t\t\t\tlet lineEnd = lineMap[start.line + 1];\n\t\t\t\t\tlineText = source.substring(lineStart, lineEnd);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: { start, end },\n\t\t\t\t\tlineText,\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// Find the mapping between source and compiled, if it exists. If it\n\t\t\t// doesn't exist, the error must be in non-user code. Not great, but\n\t\t\t// the user doesn't need to know about it\n\t\t\tlet start = d.start ?? 0;\n\t\t\tlet end = (d.start ?? 0) + (d.length ?? 0);\n\t\t\tlet mapped = map.find((m: any) => start >= m.compiled.start && end <= m.compiled.end);\n\n\t\t\t// HACK: We don't care about these? Maybe there's a better way to\n\t\t\t// ignore/fix them\n\t\t\tif (\n\t\t\t\tmessage.startsWith(\"This import uses a '.ts' extension to resolve\") ||\n\t\t\t\t/Cannot find module '(.+?)\\?raw'/.test(message)\n\t\t\t) {\n\t\t\t\tmapped = undefined;\n\t\t\t\t// This special message will be filtered out\n\t\t\t\tmessage = \"!\";\n\t\t\t}\n\n\t\t\t//if (!mapped && message !== \"!\") {\n\t\t\t//\t// Log it for diagnostics\n\t\t\t//\tconsole.log(`Error${!mapped ? \" (unmapped)\" : \"\"}:`, message);\n\t\t\t//\t// @ts-ignore we know this exists\n\t\t\t//\tconst lineMap: number[] = d.file?.lineMap;\n\t\t\t//\tif (lineMap) {\n\t\t\t//\t\tconst line = (lineMap.findIndex((l: number) => l > start) ?? 1) - 1;\n\t\t\t//\t\tconst char = start - lineMap[line];\n\t\t\t//\t\tconsole.log(`(${line + 1}, ${char + 1}):`, content.split(\"\\n\")[line]);\n\t\t\t//\t}\n\t\t\t//}\n\n\t\t\t// Unused declarations in the generated code (runtime imports and\n\t\t\t// regions a check build doesn't call, unused row parameters) aren't\n\t\t\t// the user's to fix\n\t\t\tif (!mapped && d.code !== undefined && UNUSED_CODES.has(d.code)) {\n\t\t\t\treturn { path: filename, message: \"!\", range: EMPTY_RANGE } satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// HACK: Couldn't map back to the source, so just display it at the\n\t\t\t// first character\n\t\t\tif (!mapped) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// We have the mapping, so we know roughly where in the\n\t\t\t// source the error occurs, but now we need to narrow it\n\t\t\t// down to the exact location\n\t\t\tlet sourceStart = mapped.source.start + start - mapped.compiled.start;\n\t\t\tlet sourceEnd = mapped.source.start + end - mapped.compiled.start;\n\t\t\t// HACK: If the translated mapping is outside of the source mapping,\n\t\t\t// just highlight the source mapping. It won't be 100% accurate, but\n\t\t\t// better than showing it way off in the middle of nowhere. This\n\t\t\t// happens e.g. when the $props are bad (as `<Component>` maps to\n\t\t\t// something like `Component($parent, $anchor, $props)`\n\t\t\tif (sourceStart > mapped.source.end) {\n\t\t\t\tsourceStart = mapped.source.start;\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\t\t\t// Same thing for if the error extends too far\n\t\t\tif (sourceEnd > mapped.source.end) {\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\n\t\t\t// TODO: Store this, so we don't need to start from 0 every time\n\t\t\tlet lastLineStart = 0;\n\t\t\tlet startLine = 0;\n\t\t\tfor (let i = 0; i < sourceStart; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i + 1;\n\t\t\t\t\tstartLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet startChar = sourceStart - lastLineStart; /*- 1*/\n\n\t\t\tlet lastLineEnd: number | undefined = source.indexOf(\"\\n\", lastLineStart + 1);\n\t\t\tif (lastLineEnd === -1) lastLineEnd = undefined;\n\t\t\tlineText = source.substring(lastLineStart, lastLineEnd);\n\n\t\t\tlet endLine = startLine;\n\t\t\tfor (let i = sourceStart; i < sourceEnd; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i;\n\t\t\t\t\tendLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet endChar = sourceEnd - lastLineStart; // - 1;\n\n\t\t\treturn {\n\t\t\t\tpath: filename,\n\t\t\t\tmessage,\n\t\t\t\tcode: d.code,\n\t\t\t\trange: {\n\t\t\t\t\tstart: {\n\t\t\t\t\t\tline: startLine,\n\t\t\t\t\t\tcharacter: startChar,\n\t\t\t\t\t},\n\t\t\t\t\tend: {\n\t\t\t\t\t\tline: endLine,\n\t\t\t\t\t\tcharacter: endChar,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlineText,\n\t\t\t} satisfies Diagnostic;\n\t\t})\n\t\t.filter((d) => d.message !== \"!\");\n}\n\nfunction getMessageText(d: ts.Diagnostic): string {\n\tif (typeof d.messageText === \"string\") {\n\t\treturn d.messageText;\n\t} else {\n\t\tlet messages: string[] = [];\n\t\tgetMessages(d.messageText, messages);\n\t\treturn messages.map((m, i) => \" \".repeat(i * 2) + m).join(\"\\n\");\n\t}\n}\n\nfunction getMessages(chain: DiagnosticMessageChain, messages: string[]) {\n\tmessages.push(chain.messageText);\n\tif (chain.next !== undefined) {\n\t\tfor (let next of chain.next) {\n\t\t\tgetMessages(next, messages);\n\t\t}\n\t}\n}\n","import tsvfs from \"@typescript/vfs\";\nimport chalk from \"chalk\";\nimport path from \"node:path\";\nimport findFiles from \"./findFiles\";\nimport { loadDocument } from \"./loadDocument\";\nimport loadVts from \"./loadVts\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function check(folder: string): Diagnostic[] {\n\t// Absolute, so that the virtual files' imports resolve\n\tfolder = path.resolve(folder);\n\tconsole.log(\"Checking files in\", folder);\n\n\tconst vts = loadVts(folder);\n\tif (vts === undefined) {\n\t\treturn [];\n\t}\n\n\t// The compiler module the project is checked with (already loaded by\n\t// loadVts)\n\tconst ts = vts.ts;\n\n\t// The tsconfig's paths are relative to its own folder\n\tconst files = findFiles(\n\t\tfolder,\n\t\tvts.configPath ?? folder,\n\t\tvts.config.include,\n\t\tvts.config.exclude,\n\t\tvts.config.options.allowJs === true,\n\t);\n\tconsole.log(`Found ${chalk.green(files.length)} file${files.length === 1 ? \"\" : \"s\"} to check`);\n\n\tlet errors: Diagnostic[] = [];\n\n\t// Transform files and gather transform errors\n\tfor (let file of files) {\n\t\tfile = path.join(folder, file);\n\t\tconst loaded = loadDocument(file);\n\t\tif (!loaded.ok) {\n\t\t\terrors.push(...loaded.errors);\n\t\t}\n\t}\n\n\t// Build the typescript program with all compiling files\n\tconst host = tsvfs.createVirtualCompilerHost(vts.env.sys, vts.config.options, ts);\n\tconst program = ts.createProgram({\n\t\trootNames: [...vts.virtualFiles.keys()],\n\t\toptions: vts.config.options,\n\t\thost: host.compilerHost,\n\t});\n\n\t// Get typescript to check the compiled files\n\tconst compileErrors = program\n\t\t.getSemanticDiagnostics()\n\t\t.concat(program.getDeclarationDiagnostics())\n\t\t.concat(program.getConfigFileParsingDiagnostics())\n\t\t.concat(program.getGlobalDiagnostics())\n\t\t.concat(program.getOptionsDiagnostics())\n\t\t.concat(program.getSyntacticDiagnostics());\n\terrors.push(...processErrors(vts, compileErrors));\n\n\treturn errors;\n}\n","import { loadDocument } from \"./loadDocument\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function validateScript(filename: string): Diagnostic[] {\n\ttry {\n\t\tconst transformed = loadDocument(filename);\n\t\tif (!transformed.ok) {\n\t\t\t// If there were parse or build errors, return them immediately\n\t\t\t// TODO: Do we want to clear the virtual file??\n\t\t\tif (!transformed.ok) {\n\t\t\t\treturn transformed.errors;\n\t\t\t}\n\t\t}\n\n\t\tconst { key, vts } = transformed;\n\n\t\t// HACK: Is this ok to do every check? We're doing it because otherwise\n\t\t// changes to linked files (e.g. adding or removing a field in an interface)\n\t\t// don't get picked up. But doing it here also means that it only happens\n\t\t// when the file is edited...\n\t\tvts.lang.cleanupSemanticCache();\n\n\t\tconst diagnostics = processErrors(vts, [\n\t\t\t...vts.lang.getSyntacticDiagnostics(key),\n\t\t\t...vts.lang.getSemanticDiagnostics(key),\n\t\t]);\n\n\t\treturn diagnostics;\n\t} catch (ex) {\n\t\tconsole.log(\"VALIDATE ERROR:\", ex);\n\t\treturn [];\n\t}\n}\n","import path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport validateScript from \"./validateScript\";\n\nexport default function check(file: string): Diagnostic[] {\n\t// Absolute, so that the virtual files' imports resolve\n\tfile = path.resolve(file);\n\tconsole.log(\"Checking file\", file);\n\n\treturn validateScript(file);\n}\n","import chalk from \"chalk\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function printErrors(folder: string, errors: Diagnostic[]): void {\n\terrors.sort((a, b) => a.path.localeCompare(b.path));\n\n\tfor (let error of errors) {\n\t\tconsole.log(\n\t\t\t`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red(\"error\")}${error.code ? chalk.gray(` TS${error.code}`) : \"\"}: ${error.message}`,\n\t\t);\n\t\tif (error.lineText) {\n\t\t\t// HACK: If I were less lazy I'd replace tabs with 4 spaces and adjust positions\n\t\t\terror.lineText = error.lineText.replaceAll(\"\\t\", \" \");\n\t\t\tconsole.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);\n\t\t\tlet numberLength = error.range.start.line.toString().length;\n\t\t\tlet spacerLength = error.range.start.character;\n\t\t\tlet squiggleLength =\n\t\t\t\terror.range.start.line === error.range.end.line\n\t\t\t\t\t? error.range.end.character - error.range.start.character\n\t\t\t\t\t: error.lineText.length - error.range.start.character;\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.black.bgWhite(\" \".repeat(num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AM,MAAM,QAAQ,MAAM,MAAM,MAAM,IAAI,EAAE,GAAG,MAAM,UAAU;GAC9E,IAAI,eAAe,MAAM,MAAM,MAAM,KAAK,SAAS,CAAC,CAAC;GACrD,IAAI,eAAe,MAAM,MAAM,MAAM;GACrC,IAAI,iBACH,MAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI,OACxC,MAAM,MAAM,IAAI,YAAY,MAAM,MAAM,MAAM,YAC9C,MAAM,SAAS,SAAS,MAAM,MAAM,MAAM;GAC9C,QAAQ,IACP,GAAG,MAAM,MAAM,QAAQ,IAAI,OAAO,YAAY,CAAC,EAAE,GAAG,IAAI,OAAO,YAAY,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,cAAc,GACpH;EACD;EACA,QAAQ,IAAI;CACb;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/check",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Checks Torpor files for errors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"author": "",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@torpor/view": "^1.
|
|
26
|
+
"@torpor/view": "^1.4.1",
|
|
27
27
|
"@typescript/vfs": "^1.6.5",
|
|
28
28
|
"chalk": "^6.0.1",
|
|
29
29
|
"fast-glob": "^3.3.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"printErrors-il1swuxO.mjs","names":["path","check"],"sources":["../src/typescriptLoader.ts","../src/loadVts.ts","../src/pathReplace.ts","../src/transformDocument.ts","../src/loadDocument.ts","../src/processErrors.ts","../src/check.ts","../src/validateScript.ts","../src/checkFile.ts","../src/printErrors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type TS from \"typescript\";\n\nexport type TypeScriptModule = typeof TS;\n\n/**\n * Checks that a TypeScript module provides the API surface that the check\n * pipeline uses. Newer versions of TypeScript may drop or change the compiler\n * API (e.g. the TypeScript 7 native package does not expose the compiler\n * enums), in which case the version bundled with this package is used instead.\n */\nfunction isCompatible(ts: TypeScriptModule): boolean {\n\tconst api = ts as unknown as Record<string, any> | undefined;\n\treturn (\n\t\t!!api &&\n\t\ttypeof api.version === \"string\" &&\n\t\ttypeof api.createProgram === \"function\" &&\n\t\ttypeof api.createLanguageService === \"function\" &&\n\t\t!!api.sys &&\n\t\ttypeof api.sys.getExecutingFilePath === \"function\" &&\n\t\t!!api.ScriptTarget &&\n\t\t!!api.ModuleKind &&\n\t\t!!api.ModuleResolutionKind\n\t);\n}\n\n/**\n * Loads the TypeScript module to check a project with.\n *\n * Prefers the project's own installed version (resolved from the project\n * root, like Node would), so that diagnostics match the user's build.\n * TypeScript 7 (the native package) doesn't expose the compiler API that the\n * check needs, and a project may not have TypeScript installed at all, so it\n * falls back to the version bundled with this package.\n */\nexport default function loadTypeScriptModule(projectRoot: string): TypeScriptModule {\n\ttry {\n\t\tconst require = createRequire(path.join(projectRoot, \"package.json\"));\n\t\tconst ts = require(\"typescript\") as TypeScriptModule;\n\t\tif (isCompatible(ts)) {\n\t\t\tconsole.log(`Using TypeScript ${ts.version} from the project`);\n\t\t\treturn ts;\n\t\t}\n\t\tconsole.log(\n\t\t\t`Project TypeScript ${ts.version} does not provide the compiler API, ` +\n\t\t\t\t`falling back to the bundled version`,\n\t\t);\n\t} catch {\n\t\t// The project does not have TypeScript installed\n\t}\n\n\tconst require = createRequire(import.meta.url);\n\tconst ts = require(\"typescript\") as TypeScriptModule;\n\tconsole.log(`Using bundled TypeScript ${ts.version}`);\n\treturn ts;\n}\n","import tsvfs from \"@typescript/vfs\";\nimport fs from \"node:fs\";\nimport path from \"path\";\nimport type { LanguageService } from \"typescript\";\nimport loadTypeScriptModule, { type TypeScriptModule } from \"./typescriptLoader\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nlet vts: VirtualTypeScript = {\n\t// @ts-ignore This will definitely be set\n\tts: undefined,\n\t// @ts-ignore This will definitely be set\n\tenv: undefined,\n\t// @ts-ignore This will definitely be set\n\tlang: undefined,\n\tprojectRoot: \"\",\n\tconfigPath: undefined,\n\t// This is just the default config, it should be overwritten by the one from\n\t// the user's tsconfig.json (it's built in loadVts, once the TypeScript\n\t// module -- which owns the compiler enums -- has been loaded)\n\tconfig: {\n\t\toptions: {},\n\t\tinclude: [],\n\t\texclude: [],\n\t},\n\tvirtualFiles: new Map<string, string>(),\n\tvirtualFileMaps: new Map<string, { sourceFile: string; map: SourceMap[] }>(),\n};\n\nexport default function loadVts(vtsPath: string): VirtualTypeScript | undefined {\n\tif (vts.env === undefined) {\n\t\t// If using imports where the types don't directly match up to\n\t\t// their FS representation (like the imports for node) then use\n\t\t// triple-slash directives to make sure globals are set up\n\t\t// first.\n\t\t//const content = `\n\t\t//\t/// <reference types=\"node\" />\n\t\t//\timport * as path from 'path';\n\t\t//\tpath.`.replaceAll(/\\s+/, \" \").trim();\n\n\t\t// By providing a project root, the system knows how to resolve\n\t\t// node_modules correctly\n\t\tvts.projectRoot = path.join(vtsPath, \".\");\n\t\twhile (vts.projectRoot && !fs.existsSync(path.join(vts.projectRoot, \"node_modules\"))) {\n\t\t\tvts.projectRoot = path.join(vts.projectRoot, \"..\");\n\t\t}\n\t\tif (!vts.projectRoot) {\n\t\t\tconsole.log(\"No project root found\");\n\t\t\treturn;\n\t\t}\n\n\t\t// The TypeScript module to check with: the project's own version when\n\t\t// it provides the compiler API, otherwise the one bundled with this\n\t\t// package (TypeScript 7's native package does not)\n\t\tconst ts = loadTypeScriptModule(vts.projectRoot);\n\t\tvts.ts = ts;\n\n\t\t// The default config, used when the user's tsconfig.json can't be read\n\t\tvts.config = {\n\t\t\toptions: {\n\t\t\t\ttarget: ts.ScriptTarget.ES2022,\n\t\t\t\tmodule: ts.ModuleKind.ESNext,\n\t\t\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\t\t\tesModuleInterop: true,\n\t\t\t},\n\t\t\tinclude: [],\n\t\t\texclude: [],\n\t\t};\n\n\t\t// Maybe load tsconfig from a file\n\t\t// TODO: reload if the file is changed\n\t\ttry {\n\t\t\tlet fileConfig = loadTypeScriptConfig(ts);\n\t\t\tif (fileConfig?.options) {\n\t\t\t\tvts.config = {\n\t\t\t\t\toptions: fileConfig.options,\n\t\t\t\t\tinclude: fileConfig.raw.include ?? [],\n\t\t\t\t\texclude: fileConfig.raw.exclude ?? [],\n\t\t\t\t};\n\t\t\t}\n\t\t} catch {\n\t\t\tconsole.log(\"No tsconfig.json file found, using default\");\n\t\t}\n\n\t\tconst system = tsvfs.createFSBackedSystem(vts.virtualFiles, vts.projectRoot, ts);\n\t\tvts.env = tsvfs.createVirtualTypeScriptEnvironment(system, [], ts, vts.config.options);\n\t\tvts.lang = vts.env.languageService as LanguageService;\n\n\t\tconsole.log(\"Torpor type checking loaded\");\n\t}\n\treturn vts;\n}\n\nfunction loadTypeScriptConfig(ts: TypeScriptModule): Record<string, any> | undefined {\n\tconst configFileName = ts.findConfigFile(vts.projectRoot, (fileName) =>\n\t\tts.sys.fileExists(fileName),\n\t);\n\tif (configFileName) {\n\t\tvts.configPath = path.dirname(configFileName);\n\t\tconst configFile = ts.readConfigFile(configFileName, (fileName) => ts.sys.readFile(fileName));\n\t\treturn ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.projectRoot);\n\t}\n}\n","// TODO: Implement more logic from https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths\nexport default function pathReplace(pattern: string, replacement: string, value: string): string {\n\tpattern = \"^\" + pattern.replaceAll(\"*\", \"(.+?)\");\n\treplacement = replacement.replaceAll(\"*\", \"$1\");\n\n\tconst regex1 = new RegExp(pattern);\n\treturn value.replace(regex1, replacement);\n}\n","import { build, parse } from \"@torpor/view/compile\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport pathReplace from \"./pathReplace\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ninterface TransformResult {\n\tok: boolean;\n\terrors: Diagnostic[];\n\tcontent: string;\n\tmap: SourceMap[];\n}\n\nexport default function transformDocument(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tsource: string,\n\tdebug = false,\n): TransformResult {\n\ttry {\n\t\t// Build the main file as a component\n\t\tconst parsed = parse(source);\n\n\t\t// If not ok, don't validate\n\t\tif (!parsed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: parsed.errors.map((e) => {\n\t\t\t\t\tlet lineTextStart = e.startIndex;\n\t\t\t\t\twhile (lineTextStart >= 0) {\n\t\t\t\t\t\tif (source[lineTextStart] === \"\\n\") {\n\t\t\t\t\t\t\tlineTextStart++;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlineTextStart--;\n\t\t\t\t\t}\n\t\t\t\t\tlet lineTextEnd: number | undefined = source.indexOf(\"\\n\", e.startIndex);\n\t\t\t\t\tif (lineTextEnd === -1) lineTextEnd = undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpath: filename,\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\tstart: { line: e.startLine, character: e.startChar },\n\t\t\t\t\t\t\tend: { line: e.endLine, character: e.endChar },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlineText: source.substring(lineTextStart, lineTextEnd),\n\t\t\t\t\t} satisfies Diagnostic;\n\t\t\t\t}),\n\t\t\t\tcontent: \"\",\n\t\t\t\tmap: [],\n\t\t\t};\n\t\t}\n\n\t\tlet { code, map } = build(parsed.template!, { mapped: true });\n\n\t\tcode = importComponentFiles(vts, filename, code, map, debug);\n\n\t\t//console.log(code);\n\t\t//console.log(map);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\terrors: [],\n\t\t\tcontent: code,\n\t\t\tmap,\n\t\t};\n\t} catch (ex) {\n\t\tconst message = ex instanceof Error ? ex.stack : String(ex);\n\t\tconsole.log(\"Failed to compile\", filename);\n\t\tconsole.log(message);\n\t\treturn {\n\t\t\tok: false,\n\t\t\terrors: [],\n\t\t\tcontent: \"\",\n\t\t\tmap: [],\n\t\t};\n\t}\n}\n\nfunction importComponentFiles(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tcontent: string,\n\tmap: SourceMap[],\n\t_debug = false,\n): string {\n\tif (!/^\\s*import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms.test(content)) {\n\t\treturn content;\n\t}\n\n\t// Build imported component files and add them to the virtual file map\n\t// TODO: Handle files from node_modules? Might get done automatically by typescript-vfs\n\n\t// HACK: We're assuming that all imports are at the top of the file, and\n\t// that there are not multiple imports on the one line\n\tconst first = map.shift()!;\n\tconst filepath = path.dirname(filename);\n\n\tlet moved = 0;\n\tlet newMaps: SourceMap[] = [];\n\n\tfor (let i = 0; i < first.script.length; i++) {\n\t\tif (first.script[i] === \"/\") {\n\t\t\t// Skip comments\n\t\t\tif (first.script[i + 1] === \"/\") {\n\t\t\t\ti = first.script.indexOf(\"\\n\", i);\n\t\t\t} else if (first.script[i + 1] === \"*\") {\n\t\t\t\ti = first.script.indexOf(\"*/\", i);\n\t\t\t}\n\t\t\tif (i === -1) {\n\t\t\t\treturn content;\n\t\t\t}\n\t\t} else if (first.script[i] === \"i\") {\n\t\t\tconst match = first.script.substring(i).match(/import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms);\n\t\t\tif (match === null) continue;\n\n\t\t\tconst oldImport = match[0];\n\t\t\t//const names = match[1];\n\t\t\tconst importedFile = match[2];\n\n\t\t\t// Strip quotes\n\t\t\tlet importFile = importedFile;\n\t\t\tif (\n\t\t\t\t(importFile.startsWith(\"'\") && importFile.endsWith(\"'\")) ||\n\t\t\t\t(importFile.startsWith('\"') && importFile.endsWith('\"'))\n\t\t\t) {\n\t\t\t\timportFile = importFile.substring(1, importFile.length - 1);\n\t\t\t}\n\n\t\t\t// Just map import files that aren't components\n\t\t\tif (!importFile.endsWith(\".torp\")) {\n\t\t\t\tnewMaps.push({\n\t\t\t\t\tscript: oldImport,\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tstart: i,\n\t\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t\tcompiled: {\n\t\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\t\tend: first.compiled.start + i + moved + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Get the absolute path of the import file\n\t\t\tlet typeFile = importFile.startsWith(\".\") ? path.join(filepath, importFile) : importFile;\n\n\t\t\t// Replace aliased paths from tsconfig.json\n\t\t\tif (vts.configPath && vts.config.options.paths) {\n\t\t\t\t// HACK: Get the longest match etc\n\t\t\t\tconst oldTypeFile = typeFile;\n\t\t\t\tfor (let [srcGlob, paths] of Object.entries(vts.config.options.paths)) {\n\t\t\t\t\tfor (let destGlob of paths) {\n\t\t\t\t\t\ttypeFile = pathReplace(srcGlob, destGlob, typeFile);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// The import may now be relative to the tsconfig file, so make it absolute\n\t\t\t\tif (typeFile !== oldTypeFile && typeFile.startsWith(\".\")) {\n\t\t\t\t\ttypeFile = path.join(vts.configPath, typeFile);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Create the virtual file for the component\n\t\t\tconst key = typeFile.replace(/\\.torp$/, \".ts\");\n\t\t\tif (!vts.virtualFiles.has(key) && fs.existsSync(typeFile)) {\n\t\t\t\t// Mark as in progress before transforming, so that circular\n\t\t\t\t// component imports don't recurse forever\n\t\t\t\tvts.virtualFiles.set(key, \"\");\n\t\t\t\tconst typeSource = fs.readFileSync(typeFile, \"utf8\");\n\t\t\t\tconst { content } = transformDocument(vts, typeFile, typeSource);\n\t\t\t\tvts.virtualFiles.set(key, content);\n\t\t\t\tvts.env.createFile(key, content);\n\t\t\t}\n\n\t\t\t// Replace the import file with the virtual file\n\t\t\tlet oldLength = content.length;\n\t\t\tlet newValue = typeFile.replace(\".torp\", \".ts\");\n\t\t\t// HACK: We could concat this if we could be bothered\n\t\t\tlet newImport = oldImport.replace(importFile, newValue);\n\t\t\tcontent = content.replace(oldImport, newImport);\n\n\t\t\t// Move subsequent ranges around\n\t\t\tlet diff = content.length - oldLength;\n\t\t\tfor (let mapped of map) {\n\t\t\t\tmapped.compiled.start += diff;\n\t\t\t\tmapped.compiled.end += diff;\n\t\t\t}\n\n\t\t\t// Add a range for the changed import\n\t\t\tnewMaps.push({\n\t\t\t\tscript: oldImport,\n\t\t\t\tsource: {\n\t\t\t\t\tstart: i,\n\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t},\n\t\t\t\tcompiled: {\n\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\tend: first.compiled.start + i + moved + newImport.length,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tmoved += diff;\n\t\t\ti += oldImport.length;\n\t\t}\n\t}\n\n\tmap.unshift(...newMaps);\n\n\treturn content;\n}\n","import fs from \"node:fs\";\nimport loadVts from \"./loadVts\";\nimport transformDocument from \"./transformDocument\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ntype LoadResult =\n\t| { ok: false; errors: Diagnostic[] }\n\t| {\n\t\t\tok: true;\n\t\t\tfilename: string;\n\t\t\tkey: string;\n\t\t\ttext: string;\n\t\t\tcontent: string;\n\t\t\tmap: SourceMap[];\n\t\t\tvts: VirtualTypeScript;\n\t };\n\nexport function loadDocument(filename: string): LoadResult {\n\tconst key = filename.replace(/\\.torp$/, \".ts\");\n\n\tconst vts = loadVts(filename);\n\tif (vts === undefined) {\n\t\treturn { ok: false, errors: [] };\n\t}\n\n\tconst text = fs.readFileSync(filename, \"utf-8\");\n\tif (filename.endsWith(\".torp\")) {\n\t\tconst transformed = transformDocument(vts, filename, text);\n\t\tif (!transformed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: transformed.errors,\n\t\t\t};\n\t\t}\n\t\tconst { content, map } = transformed;\n\t\tupdateVirtualFile(vts, key, content, filename, map);\n\t\treturn { ok: true, filename, key, text, content, map, vts: vts };\n\t} else {\n\t\tupdateVirtualFile(vts, key, text, filename, []);\n\t\treturn { ok: true, filename, key, text, content: text, map: [], vts: vts };\n\t}\n}\n\nfunction updateVirtualFile(\n\tvts: VirtualTypeScript,\n\tkey: string,\n\tcontent: string,\n\tsourceFile: string,\n\tmap: SourceMap[],\n) {\n\tif (!vts.virtualFiles.has(key)) {\n\t\tvts.env.createFile(key, content);\n\t} else {\n\t\tvts.env.updateFile(key, content);\n\t}\n\tvts.virtualFiles.set(key, content);\n\tvts.virtualFileMaps.set(key, { sourceFile, map });\n}\n","import fs from \"node:fs\";\nimport type ts from \"typescript\";\nimport type { DiagnosticMessageChain } from \"typescript\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nexport default function processErrors(\n\tvts: VirtualTypeScript,\n\terrors: ts.Diagnostic[],\n): Diagnostic[] {\n\treturn errors\n\t\t.map((d: ts.Diagnostic) => {\n\t\t\tlet message = getMessageText(d);\n\n\t\t\tif (d.file === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: \"\",\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet filename = d.file.fileName;\n\t\t\tlet map: SourceMap[] = [];\n\t\t\tif (vts.virtualFileMaps.has(filename)) {\n\t\t\t\tlet transformed = vts.virtualFileMaps.get(filename)!;\n\t\t\t\tfilename = transformed.sourceFile;\n\t\t\t\tmap = transformed.map;\n\t\t\t}\n\t\t\tconst source = fs.readFileSync(filename, \"utf-8\");\n\t\t\tlet lineText: string | undefined;\n\t\t\tif (!filename.endsWith(\".torp\")) {\n\t\t\t\tlet start = { line: 0, character: 0 };\n\t\t\t\tlet end = { line: 0, character: 0 };\n\t\t\t\tif (d.start !== undefined) {\n\t\t\t\t\t// @ts-ignore we know this exists\n\t\t\t\t\tlet lineMap: number[] = d.file.lineMap;\n\t\t\t\t\tif (lineMap === undefined) {\n\t\t\t\t\t\tlineMap = [0];\n\t\t\t\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\t\t\t\tif (source[i] === \"\\n\") lineMap.push(i);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// TODO: These need to be indexes\n\t\t\t\t\tstart.line = (lineMap.findIndex((l: number) => l > d.start!) ?? 1) - 1;\n\t\t\t\t\tstart.character = d.start - lineMap[start.line] - 1;\n\t\t\t\t\tlet endx = d.start! + (d.length ?? 0);\n\t\t\t\t\tend.line = (lineMap.findIndex((l: number) => l >= endx) ?? 1) - 1;\n\t\t\t\t\tend.character = endx - lineMap[end.line] - 1;\n\t\t\t\t\tlet lineStart = lineMap[start.line] + 1;\n\t\t\t\t\tlet lineEnd = lineMap[start.line + 1];\n\t\t\t\t\tlineText = source.substring(lineStart, lineEnd);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: { start, end },\n\t\t\t\t\tlineText,\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// Find the mapping between source and compiled, if it exists. If it\n\t\t\t// doesn't exist, the error must be in non-user code. Not great, but\n\t\t\t// the user doesn't need to know about it\n\t\t\tlet start = d.start ?? 0;\n\t\t\tlet end = (d.start ?? 0) + (d.length ?? 0);\n\t\t\tlet mapped = map.find((m: any) => start >= m.compiled.start && end <= m.compiled.end);\n\n\t\t\t// HACK: We don't care about these? Maybe there's a better way to\n\t\t\t// ignore/fix them\n\t\t\tif (\n\t\t\t\tmessage.startsWith(\"This import uses a '.ts' extension to resolve\") ||\n\t\t\t\t/Cannot find module '(.+?)\\?raw'/.test(message)\n\t\t\t) {\n\t\t\t\tmapped = undefined;\n\t\t\t\t// This special message will be filtered out\n\t\t\t\tmessage = \"!\";\n\t\t\t}\n\n\t\t\t//if (!mapped && message !== \"!\") {\n\t\t\t//\t// Log it for diagnostics\n\t\t\t//\tconsole.log(`Error${!mapped ? \" (unmapped)\" : \"\"}:`, message);\n\t\t\t//\t// @ts-ignore we know this exists\n\t\t\t//\tconst lineMap: number[] = d.file?.lineMap;\n\t\t\t//\tif (lineMap) {\n\t\t\t//\t\tconst line = (lineMap.findIndex((l: number) => l > start) ?? 1) - 1;\n\t\t\t//\t\tconst char = start - lineMap[line];\n\t\t\t//\t\tconsole.log(`(${line + 1}, ${char + 1}):`, content.split(\"\\n\")[line]);\n\t\t\t//\t}\n\t\t\t//}\n\n\t\t\t// HACK: Couldn't map back to the source, so just display it at the\n\t\t\t// first character\n\t\t\tif (!mapped) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// We have the mapping, so we know roughly where in the\n\t\t\t// source the error occurs, but now we need to narrow it\n\t\t\t// down to the exact location\n\t\t\tlet sourceStart = mapped.source.start + start - mapped.compiled.start;\n\t\t\tlet sourceEnd = mapped.source.start + end - mapped.compiled.start;\n\t\t\t// HACK: If the translated mapping is outside of the source mapping,\n\t\t\t// just highlight the source mapping. It won't be 100% accurate, but\n\t\t\t// better than showing it way off in the middle of nowhere. This\n\t\t\t// happens e.g. when the $props are bad (as `<Component>` maps to\n\t\t\t// something like `Component($parent, $anchor, $props)`\n\t\t\tif (sourceStart > mapped.source.end) {\n\t\t\t\tsourceStart = mapped.source.start;\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\t\t\t// Same thing for if the error extends too far\n\t\t\tif (sourceEnd > mapped.source.end) {\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\n\t\t\t// TODO: Store this, so we don't need to start from 0 every time\n\t\t\tlet lastLineStart = 0;\n\t\t\tlet startLine = 0;\n\t\t\tfor (let i = 0; i < sourceStart; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i + 1;\n\t\t\t\t\tstartLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet startChar = sourceStart - lastLineStart; /*- 1*/\n\n\t\t\tlet lastLineEnd: number | undefined = source.indexOf(\"\\n\", lastLineStart + 1);\n\t\t\tif (lastLineEnd === -1) lastLineEnd = undefined;\n\t\t\tlineText = source.substring(lastLineStart, lastLineEnd);\n\n\t\t\tlet endLine = startLine;\n\t\t\tfor (let i = sourceStart; i < sourceEnd; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i;\n\t\t\t\t\tendLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet endChar = sourceEnd - lastLineStart; // - 1;\n\n\t\t\treturn {\n\t\t\t\tpath: filename,\n\t\t\t\tmessage,\n\t\t\t\tcode: d.code,\n\t\t\t\trange: {\n\t\t\t\t\tstart: {\n\t\t\t\t\t\tline: startLine,\n\t\t\t\t\t\tcharacter: startChar,\n\t\t\t\t\t},\n\t\t\t\t\tend: {\n\t\t\t\t\t\tline: endLine,\n\t\t\t\t\t\tcharacter: endChar,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlineText,\n\t\t\t} satisfies Diagnostic;\n\t\t})\n\t\t.filter((d) => d.message !== \"!\");\n}\n\nfunction getMessageText(d: ts.Diagnostic): string {\n\tif (typeof d.messageText === \"string\") {\n\t\treturn d.messageText;\n\t} else {\n\t\tlet messages: string[] = [];\n\t\tgetMessages(d.messageText, messages);\n\t\treturn messages.map((m, i) => \" \".repeat(i * 2) + m).join(\"\\n\");\n\t}\n}\n\nfunction getMessages(chain: DiagnosticMessageChain, messages: string[]) {\n\tmessages.push(chain.messageText);\n\tif (chain.next !== undefined) {\n\t\tfor (let next of chain.next) {\n\t\t\tgetMessages(next, messages);\n\t\t}\n\t}\n}\n","import tsvfs from \"@typescript/vfs\";\nimport chalk from \"chalk\";\nimport fg from \"fast-glob\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { loadDocument } from \"./loadDocument\";\nimport loadVts from \"./loadVts\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function check(folder: string): Diagnostic[] {\n\tif (!fs.existsSync(folder)) {\n\t\tfolder = path.join(process.cwd(), folder);\n\t}\n\tconsole.log(\"Checking files in\", folder);\n\n\tconst vts = loadVts(folder);\n\tif (vts === undefined) {\n\t\treturn [];\n\t}\n\n\t// The compiler module the project is checked with (already loaded by\n\t// loadVts)\n\tconst ts = vts.ts;\n\n\t// Convert tsconfig includes and excludes to globs\n\tlet pathToGlob = (f: string) => {\n\t\tf = fg.convertPathToPattern(f).replaceAll(\"\\\\*\", \"*\");\n\t\tif (!f.includes(\"*\")) {\n\t\t\tif (!f.endsWith(\"/\")) f += \"/\";\n\t\t\tf += \"**\";\n\t\t}\n\t\treturn f;\n\t};\n\tlet include = vts.config.include.map(pathToGlob);\n\tif (include.length === 0) {\n\t\tinclude.push(\"**\");\n\t}\n\tconst ignore = vts.config.exclude.map(pathToGlob);\n\n\t// Get the included files with supported extensions\n\tlet files: string[] = fg\n\t\t.globSync(include, { cwd: folder, ignore })\n\t\t.filter((f) => f.endsWith(\".js\") || f.endsWith(\".ts\") || f.endsWith(\".torp\"));\n\tconsole.log(`Found ${chalk.green(files.length)} file${files.length === 1 ? \"\" : \"s\"} to check`);\n\n\tlet errors: Diagnostic[] = [];\n\n\t// Transform files and gather transform errors\n\tfor (let file of files) {\n\t\tfile = path.join(folder, file);\n\t\tconst loaded = loadDocument(file);\n\t\tif (!loaded.ok) {\n\t\t\terrors.push(...loaded.errors);\n\t\t}\n\t}\n\n\t// Build the typescript program with all compiling files\n\tconst host = tsvfs.createVirtualCompilerHost(vts.env.sys, vts.config.options, ts);\n\tconst program = ts.createProgram({\n\t\trootNames: [...vts.virtualFiles.keys()],\n\t\toptions: vts.config.options,\n\t\thost: host.compilerHost,\n\t});\n\n\t// Get typescript to check the compiled files\n\tconst compileErrors = program\n\t\t.getSemanticDiagnostics()\n\t\t.concat(program.getDeclarationDiagnostics())\n\t\t.concat(program.getConfigFileParsingDiagnostics())\n\t\t.concat(program.getGlobalDiagnostics())\n\t\t.concat(program.getOptionsDiagnostics())\n\t\t.concat(program.getSyntacticDiagnostics());\n\terrors.push(...processErrors(vts, compileErrors));\n\n\treturn errors;\n}\n","import { loadDocument } from \"./loadDocument\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function validateScript(filename: string): Diagnostic[] {\n\ttry {\n\t\tconst transformed = loadDocument(filename);\n\t\tif (!transformed.ok) {\n\t\t\t// If there were parse or build errors, return them immediately\n\t\t\t// TODO: Do we want to clear the virtual file??\n\t\t\tif (!transformed.ok) {\n\t\t\t\treturn transformed.errors;\n\t\t\t}\n\t\t}\n\n\t\tconst { key, vts } = transformed;\n\n\t\t// HACK: Is this ok to do every check? We're doing it because otherwise\n\t\t// changes to linked files (e.g. adding or removing a field in an interface)\n\t\t// don't get picked up. But doing it here also means that it only happens\n\t\t// when the file is edited...\n\t\tvts.lang.cleanupSemanticCache();\n\n\t\tconst diagnostics = processErrors(vts, [\n\t\t\t...vts.lang.getSyntacticDiagnostics(key),\n\t\t\t...vts.lang.getSemanticDiagnostics(key),\n\t\t]);\n\n\t\treturn diagnostics;\n\t} catch (ex) {\n\t\tconsole.log(\"VALIDATE ERROR:\", ex);\n\t\treturn [];\n\t}\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport validateScript from \"./validateScript\";\n\nexport default function check(file: string): Diagnostic[] {\n\tif (!fs.existsSync(file)) {\n\t\tfile = path.join(process.cwd(), file);\n\t}\n\tconsole.log(\"Checking file\", file);\n\n\treturn validateScript(file);\n}\n","import chalk from \"chalk\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function printErrors(folder: string, errors: Diagnostic[]): void {\n\terrors.sort((a, b) => a.path.localeCompare(b.path));\n\n\tfor (let error of errors) {\n\t\tconsole.log(\n\t\t\t`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red(\"error\")}${error.code ? chalk.gray(` TS${error.code}`) : \"\"}: ${error.message}`,\n\t\t);\n\t\tif (error.lineText) {\n\t\t\t// HACK: If I were less lazy I'd replace tabs with 4 spaces and adjust positions\n\t\t\terror.lineText = error.lineText.replaceAll(\"\\t\", \" \");\n\t\t\tconsole.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);\n\t\t\tlet numberLength = error.range.start.line.toString().length;\n\t\t\tlet spacerLength = error.range.start.character;\n\t\t\tlet squiggleLength =\n\t\t\t\terror.range.start.line === error.range.end.line\n\t\t\t\t\t? error.range.end.character - error.range.start.character\n\t\t\t\t\t: error.lineText.length - error.range.start.character;\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.black.bgWhite(\" \".repeat(numberLength))} ${\" \".repeat(spacerLength)}${chalk.red(\"~\").repeat(squiggleLength)}`,\n\t\t\t);\n\t\t}\n\t\tconsole.log();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAS,aAAa,IAA+B;CACpD,MAAM,MAAM;CACZ,OACC,CAAC,CAAC,OACF,OA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