@swiftuijs/twill 0.2.0 → 0.3.1
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/README.md +22 -7
- package/bin/run.mjs +2 -2
- package/dist/cli.js +6 -6
- package/dist/{compilation-cache-CuCGz02_.js → compilation-cache-7SugqJ4n.js} +2 -2
- package/dist/{compilation-cache-CuCGz02_.js.map → compilation-cache-7SugqJ4n.js.map} +1 -1
- package/dist/{compiler-DY1N07np.js → compiler-BdkU4Ruh.js} +85 -26
- package/dist/compiler-BdkU4Ruh.js.map +1 -0
- package/dist/config-la_KkjCS.js +1 -0
- package/dist/config.js +2 -1
- package/dist/{configuration-CTJjSu_h.js → configuration-BVMf6Q_j.js} +17 -7
- package/dist/configuration-BVMf6Q_j.js.map +1 -0
- package/dist/declarations-BTAS8Mb_.js +132 -0
- package/dist/declarations-BTAS8Mb_.js.map +1 -0
- package/dist/declarations.js +1 -131
- package/dist/defer.d.ts +1 -1
- package/dist/doctor-Co_pdZtt.js +202 -0
- package/dist/doctor-Co_pdZtt.js.map +1 -0
- package/dist/doctor.js +1 -201
- package/dist/editor.js +1 -1
- package/dist/esbuild.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{loader-compiler-DIw9aw5n.js → loader-compiler.js} +3 -3
- package/dist/loader-compiler.js.map +1 -0
- package/dist/loader-registration-B1ST9h1e.js +15 -0
- package/dist/loader-registration-B1ST9h1e.js.map +1 -0
- package/dist/loader-registration.d.ts +4 -0
- package/dist/loader-registration.js +2 -0
- package/dist/loader-state-DE2ArGYl.js +61 -0
- package/dist/loader-state-DE2ArGYl.js.map +1 -0
- package/dist/loader-state.d.ts +34 -0
- package/dist/loader-sync.d.ts +3 -0
- package/dist/loader-sync.js +28 -0
- package/dist/loader-sync.js.map +1 -0
- package/dist/loader.d.ts +2 -4
- package/dist/loader.js +9 -46
- package/dist/loader.js.map +1 -1
- package/dist/{plugin-Bks2hxCJ.js → plugin-DdTVagIU.js} +3 -3
- package/dist/{plugin-Bks2hxCJ.js.map → plugin-DdTVagIU.js.map} +1 -1
- package/dist/project-ZmlpFooa.js +444 -0
- package/dist/project-ZmlpFooa.js.map +1 -0
- package/dist/project.js +1 -438
- package/dist/recovery.d.ts +2 -2
- package/dist/register.js +2 -2
- package/dist/register.js.map +1 -1
- package/dist/rollup.js +1 -1
- package/dist/rspack.js +1 -1
- package/dist/syntax.js +1 -1
- package/dist/{transpile-DG81yfVs.js → transpile-CLNavDUr.js} +2 -2
- package/dist/{transpile-DG81yfVs.js.map → transpile-CLNavDUr.js.map} +1 -1
- package/dist/typescript-plugin.cjs +96 -33
- package/dist/typescript-plugin.cjs.map +1 -1
- package/dist/vite-BI-5KRgr.js +7 -0
- package/dist/vite-BI-5KRgr.js.map +1 -0
- package/dist/vite-react.js +1 -1
- package/dist/vite.js +1 -6
- package/dist/webpack.js +1 -1
- package/package.json +2 -2
- package/dist/compiler-DY1N07np.js.map +0 -1
- package/dist/configuration-CTJjSu_h.js.map +0 -1
- package/dist/declarations.js.map +0 -1
- package/dist/doctor.js.map +0 -1
- package/dist/loader-compiler-DIw9aw5n.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/vite.js.map +0 -1
package/dist/project.js
CHANGED
|
@@ -1,440 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as isTwillFile, t as extensions } from "./extensions-B1xTkoYP.js";
|
|
3
|
-
import { n as loadConfig } from "./configuration-CTJjSu_h.js";
|
|
1
|
+
import { n as sourceFilename, r as virtualFilename, t as TwillProject } from "./project-ZmlpFooa.js";
|
|
4
2
|
import { t as isDependency } from "./files-BW9geU0_.js";
|
|
5
|
-
import MagicString from "magic-string";
|
|
6
|
-
import { dirname, resolve } from "node:path";
|
|
7
|
-
import ts from "typescript";
|
|
8
|
-
import remapping from "@ampproject/remapping";
|
|
9
|
-
//#region src/recovery.ts
|
|
10
|
-
/** Editor-only recovery; build and CLI compilation always use strict parsing. */
|
|
11
|
-
function recoverTransform(source, options) {
|
|
12
|
-
const repaired = new MagicString(source);
|
|
13
|
-
let text = source;
|
|
14
|
-
for (let attempt = 0; attempt < 8; attempt++) try {
|
|
15
|
-
const result = transform(text, options);
|
|
16
|
-
if (text === source) return result;
|
|
17
|
-
const repairMap = repaired.generateMap({
|
|
18
|
-
source: options.filename,
|
|
19
|
-
includeContent: true,
|
|
20
|
-
hires: true
|
|
21
|
-
});
|
|
22
|
-
const repairedResult = {
|
|
23
|
-
...result,
|
|
24
|
-
map: repairMap
|
|
25
|
-
};
|
|
26
|
-
const starts = [0];
|
|
27
|
-
for (const match of source.matchAll(/\n/g)) starts.push(match.index + 1);
|
|
28
|
-
const sourceOffset = (offset) => {
|
|
29
|
-
const prefix = text.slice(0, offset).split("\n");
|
|
30
|
-
const point = originalPosition(repairedResult, prefix.length, prefix.at(-1).length);
|
|
31
|
-
return starts[point.line - 1] + point.column;
|
|
32
|
-
};
|
|
33
|
-
const enumPatterns = result.enumPatterns.map((pattern) => ({
|
|
34
|
-
...pattern,
|
|
35
|
-
reference: {
|
|
36
|
-
...pattern.reference,
|
|
37
|
-
property: {
|
|
38
|
-
...pattern.reference.property,
|
|
39
|
-
start: sourceOffset(pattern.reference.property.start),
|
|
40
|
-
end: sourceOffset(pattern.reference.property.end)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}));
|
|
44
|
-
const map = remapping([JSON.parse(result.map.toString()), JSON.parse(repairMap.toString())], () => null);
|
|
45
|
-
return {
|
|
46
|
-
...result,
|
|
47
|
-
enumPatterns,
|
|
48
|
-
map
|
|
49
|
-
};
|
|
50
|
-
} catch (error) {
|
|
51
|
-
if (!(error instanceof TwillSyntaxError)) throw error;
|
|
52
|
-
const before = text.slice(0, error.offset);
|
|
53
|
-
let insertion;
|
|
54
|
-
let offset = error.offset;
|
|
55
|
-
if (/\.\s*$/.test(before)) insertion = "__twillIncomplete";
|
|
56
|
-
else if (offset >= text.length) {
|
|
57
|
-
const stack = [];
|
|
58
|
-
for (const token of text.matchAll(/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|\/\*[\s\S]*?\*\/|\/\/[^\n]*|[()[\]{}])/g)) if ("([{".includes(token[0])) stack.push(token[0]);
|
|
59
|
-
else if (")]}".includes(token[0])) stack.pop();
|
|
60
|
-
const opening = stack.at(-1);
|
|
61
|
-
if (!opening) throw error;
|
|
62
|
-
insertion = {
|
|
63
|
-
"(": ")",
|
|
64
|
-
"[": "]",
|
|
65
|
-
"{": "}"
|
|
66
|
-
}[opening];
|
|
67
|
-
} else throw error;
|
|
68
|
-
if (offset >= text.length) offset = source.length;
|
|
69
|
-
else if (text !== source) {
|
|
70
|
-
const prefix = text.slice(0, offset).split("\n");
|
|
71
|
-
const point = originalPosition({
|
|
72
|
-
code: text,
|
|
73
|
-
map: repaired.generateMap({
|
|
74
|
-
source: options.filename,
|
|
75
|
-
hires: true
|
|
76
|
-
})
|
|
77
|
-
}, prefix.length, prefix.at(-1).length);
|
|
78
|
-
const starts = [0];
|
|
79
|
-
for (const match of source.matchAll(/\n/g)) starts.push(match.index + 1);
|
|
80
|
-
offset = point.line == null || point.column == null ? source.length : starts[point.line - 1] + point.column;
|
|
81
|
-
}
|
|
82
|
-
repaired.appendLeft(offset, insertion);
|
|
83
|
-
text = repaired.toString();
|
|
84
|
-
}
|
|
85
|
-
return transform(source, options);
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/project.ts
|
|
89
|
-
function lineStarts(text) {
|
|
90
|
-
const starts = [0];
|
|
91
|
-
const breaks = /\n/g;
|
|
92
|
-
while (breaks.exec(text)) starts.push(breaks.lastIndex);
|
|
93
|
-
return starts;
|
|
94
|
-
}
|
|
95
|
-
function positionAt(starts, offset) {
|
|
96
|
-
let low = 0;
|
|
97
|
-
let high = starts.length;
|
|
98
|
-
while (low + 1 < high) {
|
|
99
|
-
const mid = low + high >>> 1;
|
|
100
|
-
if (starts[mid] <= offset) low = mid;
|
|
101
|
-
else high = mid;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
line: low + 1,
|
|
105
|
-
column: offset - starts[low]
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
var extraExtensions = extensions.map((extension) => ({
|
|
109
|
-
extension,
|
|
110
|
-
isMixedContent: false,
|
|
111
|
-
scriptKind: ts.ScriptKind.Deferred
|
|
112
|
-
}));
|
|
113
|
-
function virtualFilename(filename) {
|
|
114
|
-
filename = filename.replaceAll("\\", "/");
|
|
115
|
-
return isTwillFile(filename) ? filename + {
|
|
116
|
-
ts: ".ts",
|
|
117
|
-
tsx: ".tsx",
|
|
118
|
-
js: ".js",
|
|
119
|
-
jsx: ".jsx"
|
|
120
|
-
}[inferLanguage(filename)] : filename;
|
|
121
|
-
}
|
|
122
|
-
function sourceFilename(filename) {
|
|
123
|
-
filename = filename.replaceAll("\\", "/");
|
|
124
|
-
if (isTwillFile(filename)) return filename;
|
|
125
|
-
return filename.replace(/(\.twill)\.ts$/, "$1").replace(/(\.twillx)\.tsx$/, "$1");
|
|
126
|
-
}
|
|
127
|
-
/** A virtual-source TypeScript project shared by the CLI and VS Code extension. */
|
|
128
|
-
var TwillProject = class {
|
|
129
|
-
root;
|
|
130
|
-
service;
|
|
131
|
-
compilerOptions;
|
|
132
|
-
configFiles;
|
|
133
|
-
files;
|
|
134
|
-
overlays = /* @__PURE__ */ new Map();
|
|
135
|
-
results = /* @__PURE__ */ new Map();
|
|
136
|
-
lineMaps = /* @__PURE__ */ new WeakMap();
|
|
137
|
-
version = 0;
|
|
138
|
-
invalidation = 0;
|
|
139
|
-
fileVersions = /* @__PURE__ */ new Map();
|
|
140
|
-
configurationErrors;
|
|
141
|
-
options;
|
|
142
|
-
host;
|
|
143
|
-
recover;
|
|
144
|
-
discoverFiles;
|
|
145
|
-
constructor(tsconfig, options = {}, projectOptions = {}) {
|
|
146
|
-
const configFile = sourceFilename(resolve(tsconfig));
|
|
147
|
-
this.root = dirname(configFile);
|
|
148
|
-
this.recover = projectOptions.recover ?? false;
|
|
149
|
-
this.options = {
|
|
150
|
-
...loadConfig(this.root, configFile),
|
|
151
|
-
...options
|
|
152
|
-
};
|
|
153
|
-
const configReads = /* @__PURE__ */ new Set([configFile, sourceFilename(resolve(this.root, "twill.config.json"))]);
|
|
154
|
-
const configHost = {
|
|
155
|
-
...ts.sys,
|
|
156
|
-
readFile: (filename) => {
|
|
157
|
-
configReads.add(sourceFilename(filename));
|
|
158
|
-
return ts.sys.readFile(filename);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const raw = projectOptions.inferred && !ts.sys.fileExists(configFile) ? { config: { compilerOptions: {
|
|
162
|
-
strict: true,
|
|
163
|
-
target: "ES2022",
|
|
164
|
-
module: "ESNext",
|
|
165
|
-
moduleResolution: "Bundler",
|
|
166
|
-
jsx: "react-jsx"
|
|
167
|
-
} } } : ts.readConfigFile(configFile, configHost.readFile);
|
|
168
|
-
const parsed = ts.parseJsonConfigFileContent(raw.config ?? {}, configHost, this.root, {
|
|
169
|
-
allowJs: true,
|
|
170
|
-
allowImportingTsExtensions: true,
|
|
171
|
-
noEmit: true
|
|
172
|
-
}, configFile, void 0, extraExtensions);
|
|
173
|
-
this.configurationErrors = [...raw.error ? [raw.error] : [], ...parsed.errors];
|
|
174
|
-
if (parsed.projectReferences?.length && !projectOptions.declarationRedirects) this.configurationErrors = [...this.configurationErrors, {
|
|
175
|
-
category: ts.DiagnosticCategory.Error,
|
|
176
|
-
code: 90002,
|
|
177
|
-
file: void 0,
|
|
178
|
-
start: void 0,
|
|
179
|
-
length: void 0,
|
|
180
|
-
messageText: "TypeScript project references are not supported by twill check. Check each referenced project separately."
|
|
181
|
-
}];
|
|
182
|
-
this.compilerOptions = parsed.options;
|
|
183
|
-
this.configFiles = [...configReads];
|
|
184
|
-
this.options.jsxImportSource ??= parsed.options.jsxImportSource;
|
|
185
|
-
this.files = parsed.fileNames.map(virtualFilename);
|
|
186
|
-
this.discoverFiles = () => ts.parseJsonConfigFileContent(raw.config ?? {}, configHost, this.root, {
|
|
187
|
-
allowJs: true,
|
|
188
|
-
allowImportingTsExtensions: true,
|
|
189
|
-
noEmit: true
|
|
190
|
-
}, configFile, void 0, extraExtensions).fileNames.map(virtualFilename);
|
|
191
|
-
const readFile = (name) => {
|
|
192
|
-
const original = sourceFilename(name);
|
|
193
|
-
const source = this.overlays.get(original) ?? ts.sys.readFile(original);
|
|
194
|
-
if (source === void 0) return void 0;
|
|
195
|
-
if (!isTwillFile(original)) return source;
|
|
196
|
-
try {
|
|
197
|
-
return this.result(original, source).code;
|
|
198
|
-
} catch {
|
|
199
|
-
return "";
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
const fileExists = (name) => this.overlays.has(sourceFilename(name)) || ts.sys.fileExists(sourceFilename(name));
|
|
203
|
-
const resolutionHost = {
|
|
204
|
-
...ts.sys,
|
|
205
|
-
readFile,
|
|
206
|
-
fileExists
|
|
207
|
-
};
|
|
208
|
-
this.host = {
|
|
209
|
-
...ts.sys,
|
|
210
|
-
getScriptFileNames: () => this.files,
|
|
211
|
-
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
212
|
-
getScriptVersion: (name) => `${this.invalidation}:${this.fileVersions.get(sourceFilename(name)) ?? 0}`,
|
|
213
|
-
getProjectVersion: () => String(this.version),
|
|
214
|
-
getScriptSnapshot: (name) => {
|
|
215
|
-
const text = readFile(name);
|
|
216
|
-
return text === void 0 ? void 0 : ts.ScriptSnapshot.fromString(text);
|
|
217
|
-
},
|
|
218
|
-
getCurrentDirectory: () => this.root,
|
|
219
|
-
getCompilationSettings: () => this.compilerOptions,
|
|
220
|
-
getDefaultLibFileName: projectOptions.defaultLibFileName ?? ((opts) => ts.getDefaultLibFilePath(opts)),
|
|
221
|
-
readFile,
|
|
222
|
-
fileExists,
|
|
223
|
-
resolveModuleNames: (names, importer) => names.map((name) => {
|
|
224
|
-
const resolved = ts.resolveModuleName(name, importer, this.compilerOptions, resolutionHost).resolvedModule;
|
|
225
|
-
if (resolved) {
|
|
226
|
-
const redirect = projectOptions.declarationRedirects?.get(sourceFilename(resolved.resolvedFileName));
|
|
227
|
-
return redirect ? {
|
|
228
|
-
...resolved,
|
|
229
|
-
resolvedFileName: redirect,
|
|
230
|
-
extension: ts.Extension.Dts
|
|
231
|
-
} : {
|
|
232
|
-
...resolved,
|
|
233
|
-
resolvedFileName: virtualFilename(resolved.resolvedFileName)
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
if (name.startsWith(".") || name.startsWith("/")) {
|
|
237
|
-
const base = resolve(dirname(sourceFilename(importer)), name);
|
|
238
|
-
const candidates = isTwillFile(base) ? [base] : extensions.flatMap((extension) => [base + extension, resolve(base, "index" + extension)]);
|
|
239
|
-
for (const candidate of candidates) if (fileExists(candidate)) {
|
|
240
|
-
const redirect = projectOptions.declarationRedirects?.get(sourceFilename(candidate));
|
|
241
|
-
if (redirect) return {
|
|
242
|
-
resolvedFileName: redirect,
|
|
243
|
-
extension: ts.Extension.Dts,
|
|
244
|
-
isExternalLibraryImport: false
|
|
245
|
-
};
|
|
246
|
-
const file = virtualFilename(candidate);
|
|
247
|
-
return {
|
|
248
|
-
resolvedFileName: file,
|
|
249
|
-
extension: file.endsWith(".tsx") ? ts.Extension.Tsx : ts.Extension.Ts,
|
|
250
|
-
isExternalLibraryImport: false
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
};
|
|
256
|
-
this.service = ts.createLanguageService(this.host);
|
|
257
|
-
}
|
|
258
|
-
/** Declaration-only native TypeScript emit from the checked virtual program. */
|
|
259
|
-
declarationOutput(outDir, declarationMap = true) {
|
|
260
|
-
const diagnostics = this.diagnostics();
|
|
261
|
-
if (diagnostics.some((item) => item.category === "error")) return {
|
|
262
|
-
diagnostics,
|
|
263
|
-
files: []
|
|
264
|
-
};
|
|
265
|
-
const previous = this.service.getProgram();
|
|
266
|
-
if (!previous) return {
|
|
267
|
-
diagnostics,
|
|
268
|
-
files: []
|
|
269
|
-
};
|
|
270
|
-
const options = {
|
|
271
|
-
...this.compilerOptions,
|
|
272
|
-
noEmit: false,
|
|
273
|
-
declaration: true,
|
|
274
|
-
emitDeclarationOnly: true,
|
|
275
|
-
declarationMap,
|
|
276
|
-
noEmitOnError: true,
|
|
277
|
-
incremental: false,
|
|
278
|
-
composite: false,
|
|
279
|
-
rootDir: this.compilerOptions.rootDir ?? this.root,
|
|
280
|
-
outDir,
|
|
281
|
-
declarationDir: outDir,
|
|
282
|
-
allowImportingTsExtensions: true
|
|
283
|
-
};
|
|
284
|
-
const host = ts.createCompilerHost(options);
|
|
285
|
-
host.readFile = this.host.readFile;
|
|
286
|
-
host.fileExists = this.host.fileExists;
|
|
287
|
-
host.getCurrentDirectory = () => this.root;
|
|
288
|
-
host.resolveModuleNames = this.host.resolveModuleNames;
|
|
289
|
-
host.getSourceFile = (filename, languageVersion) => previous.getSourceFile(filename) ?? (host.readFile(filename) === void 0 ? void 0 : ts.createSourceFile(filename, host.readFile(filename), languageVersion, true));
|
|
290
|
-
const program = ts.createProgram(previous.getRootFileNames(), options, host);
|
|
291
|
-
const errors = ts.getPreEmitDiagnostics(program).map((item) => this.diagnostic(item));
|
|
292
|
-
if (errors.some((item) => item.category === "error")) return {
|
|
293
|
-
diagnostics: errors,
|
|
294
|
-
files: []
|
|
295
|
-
};
|
|
296
|
-
const files = [];
|
|
297
|
-
const emitted = program.emit(void 0, (filename, text, _bom, _error, sources) => {
|
|
298
|
-
files.push({
|
|
299
|
-
filename: sourceFilename(filename),
|
|
300
|
-
text,
|
|
301
|
-
sources: sources?.map((source) => sourceFilename(source.fileName)) ?? []
|
|
302
|
-
});
|
|
303
|
-
}, void 0, true);
|
|
304
|
-
return {
|
|
305
|
-
diagnostics: [...diagnostics, ...emitted.diagnostics.map((item) => this.diagnostic(item))],
|
|
306
|
-
files: emitted.emitSkipped ? [] : files
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
result(filename, source) {
|
|
310
|
-
const cached = this.results.get(filename);
|
|
311
|
-
if (cached?.source === source) return cached.result;
|
|
312
|
-
const result = (this.recover ? recoverTransform : transform)(source, {
|
|
313
|
-
...this.options,
|
|
314
|
-
filename
|
|
315
|
-
});
|
|
316
|
-
this.results.set(filename, {
|
|
317
|
-
source,
|
|
318
|
-
result
|
|
319
|
-
});
|
|
320
|
-
return result;
|
|
321
|
-
}
|
|
322
|
-
update(filename, text) {
|
|
323
|
-
filename = sourceFilename(resolve(filename));
|
|
324
|
-
if (text !== void 0 && text === this.overlays.get(filename) && this.files.includes(virtualFilename(filename))) return;
|
|
325
|
-
if (text === void 0) this.overlays.delete(filename);
|
|
326
|
-
else this.overlays.set(filename, text);
|
|
327
|
-
this.fileVersions.set(filename, (this.fileVersions.get(filename) ?? 0) + 1);
|
|
328
|
-
if (!this.files.includes(virtualFilename(filename))) this.files.push(virtualFilename(filename));
|
|
329
|
-
this.results.delete(filename);
|
|
330
|
-
this.version++;
|
|
331
|
-
}
|
|
332
|
-
invalidate() {
|
|
333
|
-
this.invalidation++;
|
|
334
|
-
this.version++;
|
|
335
|
-
this.results.clear();
|
|
336
|
-
}
|
|
337
|
-
/** Refresh a disk version without discarding unsaved overlays or other transforms. */
|
|
338
|
-
refresh(filename, discover = false) {
|
|
339
|
-
filename = sourceFilename(resolve(filename));
|
|
340
|
-
if (discover) this.files = [.../* @__PURE__ */ new Set([...this.discoverFiles(), ...[...this.overlays.keys()].map(virtualFilename)])];
|
|
341
|
-
if (!this.overlays.has(filename)) {
|
|
342
|
-
this.results.delete(filename);
|
|
343
|
-
this.fileVersions.set(filename, (this.fileVersions.get(filename) ?? 0) + 1);
|
|
344
|
-
}
|
|
345
|
-
this.version++;
|
|
346
|
-
}
|
|
347
|
-
text(filename) {
|
|
348
|
-
filename = sourceFilename(resolve(filename));
|
|
349
|
-
return this.overlays.get(filename) ?? ts.sys.readFile(filename);
|
|
350
|
-
}
|
|
351
|
-
transformed(filename) {
|
|
352
|
-
filename = sourceFilename(resolve(filename));
|
|
353
|
-
const source = this.text(filename);
|
|
354
|
-
return source !== void 0 && isTwillFile(filename) ? this.result(filename, source) : void 0;
|
|
355
|
-
}
|
|
356
|
-
sourceFiles() {
|
|
357
|
-
const dependencies = this.service.getProgram()?.getSourceFiles().filter((file) => !file.isDeclarationFile && !isDependency(file.fileName)).map((file) => file.fileName) ?? [];
|
|
358
|
-
return [...new Set([...this.files, ...dependencies].map(sourceFilename))];
|
|
359
|
-
}
|
|
360
|
-
lines(filename, result) {
|
|
361
|
-
let lines = this.lineMaps.get(result);
|
|
362
|
-
if (!lines) {
|
|
363
|
-
lines = {
|
|
364
|
-
original: lineStarts(this.text(filename)),
|
|
365
|
-
generated: lineStarts(result.code)
|
|
366
|
-
};
|
|
367
|
-
this.lineMaps.set(result, lines);
|
|
368
|
-
}
|
|
369
|
-
return lines;
|
|
370
|
-
}
|
|
371
|
-
toGeneratedOffset(filename, offset) {
|
|
372
|
-
const result = this.transformed(filename);
|
|
373
|
-
if (!result) return offset;
|
|
374
|
-
const lines = this.lines(filename, result);
|
|
375
|
-
const sourcePosition = positionAt(lines.original, offset);
|
|
376
|
-
const position = generatedPosition(result, sourcePosition.line, sourcePosition.column);
|
|
377
|
-
if (position.line === null || position.column === null) return offset;
|
|
378
|
-
return (lines.generated[position.line - 1] ?? 0) + position.column;
|
|
379
|
-
}
|
|
380
|
-
toOriginalOffset(filename, offset) {
|
|
381
|
-
const result = this.transformed(filename);
|
|
382
|
-
if (!result) return offset;
|
|
383
|
-
const lines = this.lines(filename, result);
|
|
384
|
-
const sourcePosition = positionAt(lines.generated, offset);
|
|
385
|
-
const position = originalPosition(result, sourcePosition.line, sourcePosition.column);
|
|
386
|
-
if (position.line === null || position.column === null) return 0;
|
|
387
|
-
return (lines.original[position.line - 1] ?? 0) + position.column;
|
|
388
|
-
}
|
|
389
|
-
diagnostic(diagnostic) {
|
|
390
|
-
const filename = diagnostic.file ? sourceFilename(diagnostic.file.fileName) : void 0;
|
|
391
|
-
const source = filename ? this.text(filename) ?? "" : "";
|
|
392
|
-
const start = filename ? this.toOriginalOffset(filename, diagnostic.start ?? 0) : 0;
|
|
393
|
-
const end = filename ? this.toOriginalOffset(filename, (diagnostic.start ?? 0) + (diagnostic.length ?? 1)) : start + 1;
|
|
394
|
-
const before = source.slice(0, start).split(/\r\n|[\r\n\u2028\u2029]/);
|
|
395
|
-
return {
|
|
396
|
-
filename,
|
|
397
|
-
line: before.length,
|
|
398
|
-
column: before.at(-1).length,
|
|
399
|
-
length: Math.max(1, end - start),
|
|
400
|
-
code: diagnostic.code,
|
|
401
|
-
category: diagnostic.category === ts.DiagnosticCategory.Error ? "error" : diagnostic.category === ts.DiagnosticCategory.Warning ? "warning" : "message",
|
|
402
|
-
message: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
diagnostics(filename) {
|
|
406
|
-
const result = this.configurationErrors.map((error) => this.diagnostic(error));
|
|
407
|
-
if (!filename) result.push(...this.service.getCompilerOptionsDiagnostics().map((error) => this.diagnostic(error)));
|
|
408
|
-
const files = filename ? [virtualFilename(resolve(filename))] : this.sourceFiles().map(virtualFilename);
|
|
409
|
-
for (const file of files) {
|
|
410
|
-
if (/\.d\.[cm]?ts$/.test(file)) continue;
|
|
411
|
-
try {
|
|
412
|
-
if (this.recover && isTwillFile(sourceFilename(file))) transform(this.text(file) ?? "", {
|
|
413
|
-
...this.options,
|
|
414
|
-
filename: sourceFilename(file)
|
|
415
|
-
});
|
|
416
|
-
this.transformed(file);
|
|
417
|
-
result.push(...[...this.service.getSyntacticDiagnostics(file), ...this.service.getSemanticDiagnostics(file)].map((error) => this.diagnostic(error)));
|
|
418
|
-
} catch (error) {
|
|
419
|
-
const syntax = error;
|
|
420
|
-
result.push({
|
|
421
|
-
filename: sourceFilename(file),
|
|
422
|
-
line: syntax.line ?? 1,
|
|
423
|
-
column: syntax.column ?? 0,
|
|
424
|
-
length: 1,
|
|
425
|
-
code: 90001,
|
|
426
|
-
category: "error",
|
|
427
|
-
message: syntax.message
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return result;
|
|
432
|
-
}
|
|
433
|
-
dispose() {
|
|
434
|
-
this.service.dispose();
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
//#endregion
|
|
438
3
|
export { TwillProject, isDependency, sourceFilename, virtualFilename };
|
|
439
|
-
|
|
440
|
-
//# sourceMappingURL=project.js.map
|
package/dist/recovery.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TransformOptions, TransformResult } from './compiler.js';
|
|
1
|
+
import { TwillSyntaxError, TransformOptions, TransformResult } from './compiler.js';
|
|
2
2
|
/** Editor-only recovery; build and CLI compilation always use strict parsing. */
|
|
3
|
-
export declare function recoverTransform(source: string, options: TransformOptions): TransformResult;
|
|
3
|
+
export declare function recoverTransform(source: string, options: TransformOptions, onSyntaxError?: (error: TwillSyntaxError) => void): TransformResult;
|
package/dist/register.js
CHANGED
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","names":[],"sources":["../src/register.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"register.js","names":[],"sources":["../src/register.ts"],"sourcesContent":["import { registerLoader } from './loader-registration.js';\nawait registerLoader();\n"],"mappings":";;AACA,MAAM,eAAe"}
|
package/dist/rollup.js
CHANGED
package/dist/rspack.js
CHANGED
package/dist/syntax.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as parse, r as inferLanguage } from "./compiler-
|
|
1
|
+
import { o as parse, r as inferLanguage } from "./compiler-BdkU4Ruh.js";
|
|
2
2
|
//#region src/syntax.ts
|
|
3
3
|
/** Original ESTree and dialect metadata for source-aware tooling. */
|
|
4
4
|
function parseSyntax(source, options = {}) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as transform, r as inferLanguage } from "./compiler-
|
|
1
|
+
import { a as transform, r as inferLanguage } from "./compiler-BdkU4Ruh.js";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import remapping from "@ampproject/remapping";
|
|
@@ -48,4 +48,4 @@ function transpileNative(source, filename, language = inferLanguage(filename), s
|
|
|
48
48
|
//#endregion
|
|
49
49
|
export { transpileNative as n, transpile as t };
|
|
50
50
|
|
|
51
|
-
//# sourceMappingURL=transpile-
|
|
51
|
+
//# sourceMappingURL=transpile-CLNavDUr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpile-
|
|
1
|
+
{"version":3,"file":"transpile-CLNavDUr.js","names":[],"sources":["../src/transpile.ts"],"sourcesContent":["import ts from 'typescript';\nimport remapping from '@ampproject/remapping';\nimport MagicString from 'magic-string';\nimport { transform, inferLanguage, type TransformOptions } from './compiler.js';\n\nexport function transpile(\n source: string,\n options: TransformOptions = {},\n target = ts.ScriptTarget.ESNext,\n) {\n const filename = options.filename ?? 'input.twill';\n const result = transform(source, options);\n const language = options.language ?? inferLanguage(filename);\n return transpileNative(\n result.code,\n filename,\n language,\n result.map.toString(),\n options.jsxImportSource,\n target,\n );\n}\n\n/** Native source never goes through Twill's parser or implicit-return rules. */\nexport function transpileNative(\n source: string,\n filename: string,\n language = inferLanguage(filename),\n syntaxMap?: string,\n jsxImportSource?: string,\n target = ts.ScriptTarget.ESNext,\n) {\n // Plain JavaScript needs no type erasure or JSX transform. Leave modern JS\n // (including comments and import attributes) to the host's target pipeline.\n if (language === 'js')\n return {\n code: source,\n map:\n syntaxMap ??\n new MagicString(source)\n .generateMap({ source: filename, includeContent: true, hires: true })\n .toString(),\n };\n const output = ts.transpileModule(source, {\n fileName: syntaxMap ? filename + (language.endsWith('x') ? '.tsx' : '.ts') : filename,\n compilerOptions: {\n target,\n module: ts.ModuleKind.ESNext,\n jsx: ts.JsxEmit.ReactJSX,\n jsxImportSource,\n sourceMap: true,\n inlineSources: true,\n isolatedModules: true,\n verbatimModuleSyntax: true,\n },\n reportDiagnostics: true,\n });\n const errors = output.diagnostics?.filter(\n (diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error,\n );\n if (errors?.length)\n throw new Error(\n ts.formatDiagnostics(errors, {\n getCanonicalFileName: (name) => name,\n getCurrentDirectory: () => '',\n getNewLine: () => '\\n',\n }),\n );\n const map = syntaxMap\n ? remapping([JSON.parse(output.sourceMapText!), JSON.parse(syntaxMap)], () => null).toString()\n : output.sourceMapText!;\n return {\n code: output.outputText.replace(/^\\/\\/# sourceMappingURL=.*$/m, ''),\n map,\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,UACd,QACA,UAA4B,CAAC,GAC7B,SAAS,GAAG,aAAa,QACzB;CACA,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,SAAS,UAAU,QAAQ,OAAO;CACxC,MAAM,WAAW,QAAQ,YAAY,cAAc,QAAQ;CAC3D,OAAO,gBACL,OAAO,MACP,UACA,UACA,OAAO,IAAI,SAAS,GACpB,QAAQ,iBACR,MACF;AACF;;AAGA,SAAgB,gBACd,QACA,UACA,WAAW,cAAc,QAAQ,GACjC,WACA,iBACA,SAAS,GAAG,aAAa,QACzB;CAGA,IAAI,aAAa,MACf,OAAO;EACL,MAAM;EACN,KACE,aACA,IAAI,YAAY,MAAM,CAAC,CACpB,YAAY;GAAE,QAAQ;GAAU,gBAAgB;GAAM,OAAO;EAAK,CAAC,CAAC,CACpE,SAAS;CAChB;CACF,MAAM,SAAS,GAAG,gBAAgB,QAAQ;EACxC,UAAU,YAAY,YAAY,SAAS,SAAS,GAAG,IAAI,SAAS,SAAS;EAC7E,iBAAiB;GACf;GACA,QAAQ,GAAG,WAAW;GACtB,KAAK,GAAG,QAAQ;GAChB;GACA,WAAW;GACX,eAAe;GACf,iBAAiB;GACjB,sBAAsB;EACxB;EACA,mBAAmB;CACrB,CAAC;CACD,MAAM,SAAS,OAAO,aAAa,QAChC,eAAe,WAAW,aAAa,GAAG,mBAAmB,KAChE;CACA,IAAI,QAAQ,QACV,MAAM,IAAI,MACR,GAAG,kBAAkB,QAAQ;EAC3B,uBAAuB,SAAS;EAChC,2BAA2B;EAC3B,kBAAkB;CACpB,CAAC,CACH;CACF,MAAM,MAAM,YACR,UAAU,CAAC,KAAK,MAAM,OAAO,aAAc,GAAG,KAAK,MAAM,SAAS,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,IAC3F,OAAO;CACX,OAAO;EACL,MAAM,OAAO,WAAW,QAAQ,gCAAgC,EAAE;EAClE;CACF;AACF"}
|