@swiftuijs/twill 0.2.0 → 0.3.0
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/dist/cli.js +3 -3
- 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-CbNSBUI2.js} +54 -15
- package/dist/compiler-CbNSBUI2.js.map +1 -0
- package/dist/config.js +1 -1
- package/dist/{configuration-CTJjSu_h.js → configuration-BVMf6Q_j.js} +17 -7
- package/dist/configuration-BVMf6Q_j.js.map +1 -0
- package/dist/defer.d.ts +1 -1
- package/dist/doctor.js +1 -1
- package/dist/doctor.js.map +1 -1
- package/dist/esbuild.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{loader-compiler-DIw9aw5n.js → loader-compiler-D1teTrXw.js} +3 -3
- package/dist/{loader-compiler-DIw9aw5n.js.map → loader-compiler-D1teTrXw.js.map} +1 -1
- package/dist/loader.js +2 -2
- package/dist/{plugin-Bks2hxCJ.js → plugin-BHfiQ2L-.js} +3 -3
- package/dist/{plugin-Bks2hxCJ.js.map → plugin-BHfiQ2L-.js.map} +1 -1
- package/dist/project.js +14 -10
- package/dist/project.js.map +1 -1
- package/dist/recovery.d.ts +2 -2
- package/dist/rollup.js +1 -1
- package/dist/rspack.js +1 -1
- package/dist/syntax.js +1 -1
- package/dist/{transpile-DG81yfVs.js → transpile-D8P8Lsbx.js} +2 -2
- package/dist/{transpile-DG81yfVs.js.map → transpile-D8P8Lsbx.js.map} +1 -1
- package/dist/typescript-plugin.cjs +65 -22
- package/dist/typescript-plugin.cjs.map +1 -1
- package/dist/vite.js +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-Bks2hxCJ.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { dirname, isAbsolute, resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { createUnplugin } from 'unplugin';\nimport { isTwillFile, type TransformOptions } from './compiler.js';\nimport { loadConfig, configurationFiles } from './config.js';\nimport { transpile, transpileNative } from './transpile.js';\nimport {\n isDependency,\n needsTypeEmission,\n splitId,\n resolveSourceFile,\n sourceExtensions,\n} from './files.js';\n\nexport interface PluginOptions extends Omit<TransformOptions, 'filename' | 'language'> {\n root?: string;\n /** Resolve relative extensionless native/Twill sources. Defaults to true. */\n resolveExtensions?: boolean;\n /** Native TS/JSX emission: defaults off for Vite/esbuild, on for Rollup/webpack/rspack. */\n nativeSources?: boolean;\n}\n\nexport const twillPlugin = createUnplugin<PluginOptions | undefined, false>(\n (options = {}, meta) => {\n let root = options.root ?? process.cwd();\n let config = { ...loadConfig(root), ...options };\n let configFiles = configurationFiles(root);\n let configError: unknown;\n let servingVite = false;\n // Reuse native host emission where it already exists.\n const nativeSources = options.nativeSources ?? !['vite', 'esbuild'].includes(meta.framework);\n return {\n name: 'twill',\n enforce: 'pre',\n buildStart() {\n // Refresh once per build, including incremental contexts. Vite dev\n // uses its server watcher to report errors and invalidate the graph.\n if (!servingVite) {\n configError = undefined;\n try {\n config = { ...loadConfig(root), ...options };\n configFiles = configurationFiles(root);\n } catch (cause) {\n // Report through transformed modules, retaining their watch\n // dependencies. A fatal make/start error can stop host watching.\n configError = cause;\n }\n }\n },\n webpack(compiler) {\n if (nativeSources)\n compiler.options.module.rules.push({\n include: (file) => !isDependency(file) && needsTypeEmission(file),\n // Twill already emits JS. Webpack's automatic TS stripper rejects\n // .tsx by extension even when a loader has lowered all JSX.\n parser: { typescript: false },\n });\n },\n esbuild: {\n setup(build) {\n // unplugin tags its resolved files with a custom namespace. Native\n // dependencies of those files must re-enter esbuild's normal resolver.\n build.onResolve({ filter: /.*/, namespace: 'twill' }, (args) =>\n build.resolve(args.path, {\n resolveDir: dirname(args.importer),\n kind: args.kind,\n }),\n );\n },\n },\n vite: {\n configResolved(viteConfig) {\n root = options.root ?? viteConfig.root;\n config = { ...loadConfig(root), ...options };\n servingVite = viteConfig.command === 'serve';\n },\n config() {\n return {\n resolve: {\n extensions: sourceExtensions,\n },\n };\n },\n configureServer(server) {\n let files = new Set(configurationFiles(root).map((file) => resolve(file)));\n // Watch the parent of an absent file. Registering a missing path\n // directly can narrow Chokidar's directory filter and lose additions.\n const watch = () =>\n server.watcher.add([...files].map((file) => (existsSync(file) ? file : dirname(file))));\n watch();\n let update: ReturnType<typeof setTimeout> | undefined;\n const changed = (filename: string) => {\n if (files.has(resolve(filename))) {\n clearTimeout(update);\n // Chokidar throttles rapid changes for 50 ms. Read after that\n // window so consecutive saves use the final contents, and a\n // correction after an error overlay produces another event.\n update = setTimeout(() => {\n try {\n config = { ...loadConfig(root), ...options };\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n server.config.logger.error(error.message);\n server.ws.send({\n type: 'error',\n err: { message: error.message, stack: error.stack ?? '', plugin: 'twill' },\n });\n return;\n }\n files = new Set(configurationFiles(root).map((file) => resolve(file)));\n watch();\n if (server.environments)\n for (const environment of Object.values(server.environments))\n environment.moduleGraph.invalidateAll();\n else server.moduleGraph.invalidateAll();\n server.ws.send({ type: 'full-reload' });\n }, 75);\n }\n };\n server.watcher.on('change', changed).on('add', changed).on('unlink', changed);\n server.httpServer?.once('close', () => clearTimeout(update));\n // Chokidar removes listeners when the watcher closes. HTTP can close\n // and reopen independently of the watcher during server setup.\n },\n },\n resolveId(id, importer) {\n if (options.resolveExtensions === false || (!id.startsWith('.') && !isAbsolute(id)))\n return null;\n const [path, query] = splitId(id);\n const base = isAbsolute(path!)\n ? path!\n : resolve(importer ? dirname(splitId(importer)[0]) : root, path!);\n const candidate = resolveSourceFile(base);\n if (!candidate || candidate === base) return null;\n if (meta.framework === 'esbuild' && !isTwillFile(candidate)) return null;\n return candidate + query;\n },\n transformInclude(id) {\n const filename = splitId(id)[0];\n return (\n !isDependency(filename) &&\n (isTwillFile(filename) || (nativeSources && needsTypeEmission(filename)))\n );\n },\n transform(source, id) {\n const filename = splitId(id)[0];\n if (isDependency(filename)) return null;\n const dialect = isTwillFile(filename);\n if (!dialect && !(nativeSources && needsTypeEmission(filename))) return null;\n // Vite's dev import analysis treats addWatchFile as a browser import.\n // Watch config with the server instead; a missing optional config\n // must never become an unresolved browser module.\n if (!servingVite) for (const file of configFiles) this.addWatchFile(file);\n try {\n if (configError !== undefined) throw configError;\n return dialect\n ? transpile(source, { ...config, filename })\n : transpileNative(source, filename, undefined, undefined, config.jsxImportSource);\n } catch (cause) {\n if (meta.framework !== 'esbuild') throw cause;\n // Throwing from esbuild's onLoad discards its watchFiles. Report a\n // failed build while returning dependency metadata for recovery.\n this.error(cause instanceof Error ? cause : String(cause));\n return { code: ';', map: null };\n }\n },\n };\n },\n);\n"],"mappings":";;;;;;;;AAsBA,IAAa,cAAc,gBACxB,UAAU,CAAC,GAAG,SAAS;CACtB,IAAI,OAAO,QAAQ,QAAQ,QAAQ,IAAI;CACvC,IAAI,SAAS;EAAE,GAAG,WAAW,IAAI;EAAG,GAAG;CAAQ;CAC/C,IAAI,cAAc,mBAAmB,IAAI;CACzC,IAAI;CACJ,IAAI,cAAc;CAElB,MAAM,gBAAgB,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,SAAS,CAAC,CAAC,SAAS,KAAK,SAAS;CAC3F,OAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;GAGX,IAAI,CAAC,aAAa;IAChB,cAAc,KAAA;IACd,IAAI;KACF,SAAS;MAAE,GAAG,WAAW,IAAI;MAAG,GAAG;KAAQ;KAC3C,cAAc,mBAAmB,IAAI;IACvC,SAAS,OAAO;KAGd,cAAc;IAChB;GACF;EACF;EACA,QAAQ,UAAU;GAChB,IAAI,eACF,SAAS,QAAQ,OAAO,MAAM,KAAK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AAC,aAAa,KAAK,MAAM,QAAQ,aAAa,KAAK,aAAa,IAAI;GACxE,IAAI;IACF,IAAI,gBAAgB,KAAA,GAAW,MAAM;IACrC,OAAO,UACH,UAAU,QAAQ;KAAE,GAAG;KAAQ;IAAS,CAAC,IACzC,gBAAgB,QAAQ,UAAU,KAAA,GAAW,KAAA,GAAW,OAAO,eAAe;GACpF,SAAS,OAAO;IACd,IAAI,KAAK,cAAc,WAAW,MAAM;IAGxC,KAAK,MAAM,iBAAiB,QAAQ,QAAQ,OAAO,KAAK,CAAC;IACzD,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;EACF;CACF;AACF,CACF"}
|
|
1
|
+
{"version":3,"file":"plugin-BHfiQ2L-.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { dirname, isAbsolute, resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { createUnplugin } from 'unplugin';\nimport { isTwillFile, type TransformOptions } from './compiler.js';\nimport { loadConfig, configurationFiles } from './config.js';\nimport { transpile, transpileNative } from './transpile.js';\nimport {\n isDependency,\n needsTypeEmission,\n splitId,\n resolveSourceFile,\n sourceExtensions,\n} from './files.js';\n\nexport interface PluginOptions extends Omit<TransformOptions, 'filename' | 'language'> {\n root?: string;\n /** Resolve relative extensionless native/Twill sources. Defaults to true. */\n resolveExtensions?: boolean;\n /** Native TS/JSX emission: defaults off for Vite/esbuild, on for Rollup/webpack/rspack. */\n nativeSources?: boolean;\n}\n\nexport const twillPlugin = createUnplugin<PluginOptions | undefined, false>(\n (options = {}, meta) => {\n let root = options.root ?? process.cwd();\n let config = { ...loadConfig(root), ...options };\n let configFiles = configurationFiles(root);\n let configError: unknown;\n let servingVite = false;\n // Reuse native host emission where it already exists.\n const nativeSources = options.nativeSources ?? !['vite', 'esbuild'].includes(meta.framework);\n return {\n name: 'twill',\n enforce: 'pre',\n buildStart() {\n // Refresh once per build, including incremental contexts. Vite dev\n // uses its server watcher to report errors and invalidate the graph.\n if (!servingVite) {\n configError = undefined;\n try {\n config = { ...loadConfig(root), ...options };\n configFiles = configurationFiles(root);\n } catch (cause) {\n // Report through transformed modules, retaining their watch\n // dependencies. A fatal make/start error can stop host watching.\n configError = cause;\n }\n }\n },\n webpack(compiler) {\n if (nativeSources)\n compiler.options.module.rules.push({\n include: (file) => !isDependency(file) && needsTypeEmission(file),\n // Twill already emits JS. Webpack's automatic TS stripper rejects\n // .tsx by extension even when a loader has lowered all JSX.\n parser: { typescript: false },\n });\n },\n esbuild: {\n setup(build) {\n // unplugin tags its resolved files with a custom namespace. Native\n // dependencies of those files must re-enter esbuild's normal resolver.\n build.onResolve({ filter: /.*/, namespace: 'twill' }, (args) =>\n build.resolve(args.path, {\n resolveDir: dirname(args.importer),\n kind: args.kind,\n }),\n );\n },\n },\n vite: {\n configResolved(viteConfig) {\n root = options.root ?? viteConfig.root;\n config = { ...loadConfig(root), ...options };\n servingVite = viteConfig.command === 'serve';\n },\n config() {\n return {\n resolve: {\n extensions: sourceExtensions,\n },\n };\n },\n configureServer(server) {\n let files = new Set(configurationFiles(root).map((file) => resolve(file)));\n // Watch the parent of an absent file. Registering a missing path\n // directly can narrow Chokidar's directory filter and lose additions.\n const watch = () =>\n server.watcher.add([...files].map((file) => (existsSync(file) ? file : dirname(file))));\n watch();\n let update: ReturnType<typeof setTimeout> | undefined;\n const changed = (filename: string) => {\n if (files.has(resolve(filename))) {\n clearTimeout(update);\n // Chokidar throttles rapid changes for 50 ms. Read after that\n // window so consecutive saves use the final contents, and a\n // correction after an error overlay produces another event.\n update = setTimeout(() => {\n try {\n config = { ...loadConfig(root), ...options };\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n server.config.logger.error(error.message);\n server.ws.send({\n type: 'error',\n err: { message: error.message, stack: error.stack ?? '', plugin: 'twill' },\n });\n return;\n }\n files = new Set(configurationFiles(root).map((file) => resolve(file)));\n watch();\n if (server.environments)\n for (const environment of Object.values(server.environments))\n environment.moduleGraph.invalidateAll();\n else server.moduleGraph.invalidateAll();\n server.ws.send({ type: 'full-reload' });\n }, 75);\n }\n };\n server.watcher.on('change', changed).on('add', changed).on('unlink', changed);\n server.httpServer?.once('close', () => clearTimeout(update));\n // Chokidar removes listeners when the watcher closes. HTTP can close\n // and reopen independently of the watcher during server setup.\n },\n },\n resolveId(id, importer) {\n if (options.resolveExtensions === false || (!id.startsWith('.') && !isAbsolute(id)))\n return null;\n const [path, query] = splitId(id);\n const base = isAbsolute(path!)\n ? path!\n : resolve(importer ? dirname(splitId(importer)[0]) : root, path!);\n const candidate = resolveSourceFile(base);\n if (!candidate || candidate === base) return null;\n if (meta.framework === 'esbuild' && !isTwillFile(candidate)) return null;\n return candidate + query;\n },\n transformInclude(id) {\n const filename = splitId(id)[0];\n return (\n !isDependency(filename) &&\n (isTwillFile(filename) || (nativeSources && needsTypeEmission(filename)))\n );\n },\n transform(source, id) {\n const filename = splitId(id)[0];\n if (isDependency(filename)) return null;\n const dialect = isTwillFile(filename);\n if (!dialect && !(nativeSources && needsTypeEmission(filename))) return null;\n // Vite's dev import analysis treats addWatchFile as a browser import.\n // Watch config with the server instead; a missing optional config\n // must never become an unresolved browser module.\n if (!servingVite) for (const file of configFiles) this.addWatchFile(file);\n try {\n if (configError !== undefined) throw configError;\n return dialect\n ? transpile(source, { ...config, filename })\n : transpileNative(source, filename, undefined, undefined, config.jsxImportSource);\n } catch (cause) {\n if (meta.framework !== 'esbuild') throw cause;\n // Throwing from esbuild's onLoad discards its watchFiles. Report a\n // failed build while returning dependency metadata for recovery.\n this.error(cause instanceof Error ? cause : String(cause));\n return { code: ';', map: null };\n }\n },\n };\n },\n);\n"],"mappings":";;;;;;;;AAsBA,IAAa,cAAc,gBACxB,UAAU,CAAC,GAAG,SAAS;CACtB,IAAI,OAAO,QAAQ,QAAQ,QAAQ,IAAI;CACvC,IAAI,SAAS;EAAE,GAAG,WAAW,IAAI;EAAG,GAAG;CAAQ;CAC/C,IAAI,cAAc,mBAAmB,IAAI;CACzC,IAAI;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G,OAAO;GACpE,OAAO,YAAY;EACrB;EACA,iBAAiB,IAAI;GACnB,MAAM,WAAW,QAAQ,EAAE,CAAC,CAAC;GAC7B,OACE,CAAC,aAAa,QAAQ,MACrB,YAAY,QAAQ,KAAM,iBAAiB,kBAAkB,QAAQ;EAE1E;EACA,UAAU,QAAQ,IAAI;GACpB,MAAM,WAAW,QAAQ,EAAE,CAAC,CAAC;GAC7B,IAAI,aAAa,QAAQ,GAAG,OAAO;GACnC,MAAM,UAAU,YAAY,QAAQ;GACpC,IAAI,CAAC,WAAW,EAAE,iBAAiB,kBAAkB,QAAQ,IAAI,OAAO;GAIxE,IAAI,CAAC,aAAa,KAAK,MAAM,QAAQ,aAAa,KAAK,aAAa,IAAI;GACxE,IAAI;IACF,IAAI,gBAAgB,KAAA,GAAW,MAAM;IACrC,OAAO,UACH,UAAU,QAAQ;KAAE,GAAG;KAAQ;IAAS,CAAC,IACzC,gBAAgB,QAAQ,UAAU,KAAA,GAAW,KAAA,GAAW,OAAO,eAAe;GACpF,SAAS,OAAO;IACd,IAAI,KAAK,cAAc,WAAW,MAAM;IAGxC,KAAK,MAAM,iBAAiB,QAAQ,QAAQ,OAAO,KAAK,CAAC;IACzD,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;EACF;CACF;AACF,CACF"}
|
package/dist/project.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as transform, i as originalPosition, n as generatedPosition, r as inferLanguage, t as TwillSyntaxError } from "./compiler-
|
|
1
|
+
import { a as transform, i as originalPosition, n as generatedPosition, r as inferLanguage, t as TwillSyntaxError } from "./compiler-CbNSBUI2.js";
|
|
2
2
|
import { n as isTwillFile, t as extensions } from "./extensions-B1xTkoYP.js";
|
|
3
|
-
import { n as loadConfig } from "./configuration-
|
|
3
|
+
import { n as loadConfig } from "./configuration-BVMf6Q_j.js";
|
|
4
4
|
import { t as isDependency } from "./files-BW9geU0_.js";
|
|
5
5
|
import MagicString from "magic-string";
|
|
6
6
|
import { dirname, resolve } from "node:path";
|
|
@@ -8,7 +8,7 @@ import ts from "typescript";
|
|
|
8
8
|
import remapping from "@ampproject/remapping";
|
|
9
9
|
//#region src/recovery.ts
|
|
10
10
|
/** Editor-only recovery; build and CLI compilation always use strict parsing. */
|
|
11
|
-
function recoverTransform(source, options) {
|
|
11
|
+
function recoverTransform(source, options, onSyntaxError) {
|
|
12
12
|
const repaired = new MagicString(source);
|
|
13
13
|
let text = source;
|
|
14
14
|
for (let attempt = 0; attempt < 8; attempt++) try {
|
|
@@ -49,6 +49,7 @@ function recoverTransform(source, options) {
|
|
|
49
49
|
};
|
|
50
50
|
} catch (error) {
|
|
51
51
|
if (!(error instanceof TwillSyntaxError)) throw error;
|
|
52
|
+
if (attempt === 0) onSyntaxError?.(error);
|
|
52
53
|
const before = text.slice(0, error.offset);
|
|
53
54
|
let insertion;
|
|
54
55
|
let offset = error.offset;
|
|
@@ -309,13 +310,18 @@ var TwillProject = class {
|
|
|
309
310
|
result(filename, source) {
|
|
310
311
|
const cached = this.results.get(filename);
|
|
311
312
|
if (cached?.source === source) return cached.result;
|
|
312
|
-
const
|
|
313
|
+
const options = {
|
|
313
314
|
...this.options,
|
|
314
315
|
filename
|
|
315
|
-
}
|
|
316
|
+
};
|
|
317
|
+
let syntaxError;
|
|
318
|
+
const result = this.recover ? recoverTransform(source, options, (error) => {
|
|
319
|
+
syntaxError = error;
|
|
320
|
+
}) : transform(source, options);
|
|
316
321
|
this.results.set(filename, {
|
|
317
322
|
source,
|
|
318
|
-
result
|
|
323
|
+
result,
|
|
324
|
+
syntaxError
|
|
319
325
|
});
|
|
320
326
|
return result;
|
|
321
327
|
}
|
|
@@ -409,11 +415,9 @@ var TwillProject = class {
|
|
|
409
415
|
for (const file of files) {
|
|
410
416
|
if (/\.d\.[cm]?ts$/.test(file)) continue;
|
|
411
417
|
try {
|
|
412
|
-
if (this.recover && isTwillFile(sourceFilename(file))) transform(this.text(file) ?? "", {
|
|
413
|
-
...this.options,
|
|
414
|
-
filename: sourceFilename(file)
|
|
415
|
-
});
|
|
416
418
|
this.transformed(file);
|
|
419
|
+
const syntaxError = this.results.get(sourceFilename(file))?.syntaxError;
|
|
420
|
+
if (syntaxError) throw syntaxError;
|
|
417
421
|
result.push(...[...this.service.getSyntacticDiagnostics(file), ...this.service.getSemanticDiagnostics(file)].map((error) => this.diagnostic(error)));
|
|
418
422
|
} catch (error) {
|
|
419
423
|
const syntax = error;
|
package/dist/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","names":[],"sources":["../src/recovery.ts","../src/project.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport remapping from '@ampproject/remapping';\nimport {\n transform,\n TwillSyntaxError,\n originalPosition,\n type TransformOptions,\n type TransformResult,\n} from './compiler.js';\n\n/** Editor-only recovery; build and CLI compilation always use strict parsing. */\nexport function recoverTransform(source: string, options: TransformOptions): TransformResult {\n const repaired = new MagicString(source);\n let text = source;\n // Complete a missing member name or a few unfinished delimiters. Limit repair\n // attempts so malformed documents cannot lock up the extension host.\n for (let attempt = 0; attempt < 8; attempt++) {\n try {\n const result = transform(text, options);\n if (text === source) return result;\n const repairMap = repaired.generateMap({\n source: options.filename,\n includeContent: true,\n hires: true,\n });\n // Descriptor offsets belong to repaired parser input. Restore their\n // source positions before the editor composes generated mappings;\n // otherwise an earlier inserted token can bypass linked-tag rename checks.\n const repairedResult = { ...result, map: repairMap };\n const starts = [0];\n for (const match of source.matchAll(/\\n/g)) starts.push(match.index! + 1);\n const sourceOffset = (offset: number) => {\n const prefix = text.slice(0, offset).split('\\n');\n const point = originalPosition(repairedResult, prefix.length, prefix.at(-1)!.length);\n return starts[point.line! - 1]! + point.column!;\n };\n const enumPatterns = result.enumPatterns.map((pattern) => ({\n ...pattern,\n reference: {\n ...pattern.reference,\n property: {\n ...pattern.reference.property,\n start: sourceOffset(pattern.reference.property.start),\n end: sourceOffset(pattern.reference.property.end),\n },\n },\n }));\n const map = remapping(\n [JSON.parse(result.map.toString()), JSON.parse(repairMap.toString())],\n () => null,\n );\n return { ...result, enumPatterns, map: map as unknown as TransformResult['map'] };\n } catch (error) {\n if (!(error instanceof TwillSyntaxError)) throw error;\n const before = text.slice(0, error.offset);\n let insertion: string;\n let offset = error.offset;\n if (/\\.\\s*$/.test(before)) insertion = '__twillIncomplete';\n else if (offset >= text.length) {\n // Match lexical delimiters via the original source. This path only\n // handles suffix completion; it never makes build output valid.\n const stack: string[] = [];\n const scanner =\n /(?:\"(?:\\\\.|[^\"\\\\])*\"|'(?:\\\\.|[^'\\\\])*'|`(?:\\\\.|[^`\\\\])*`|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n]*|[()[\\]{}])/g;\n for (const token of text.matchAll(scanner)) {\n if ('([{'.includes(token[0])) stack.push(token[0]);\n else if (')]}'.includes(token[0])) stack.pop();\n }\n const opening = stack.at(-1);\n if (!opening) throw error;\n insertion = ({ '(': ')', '[': ']', '{': '}' } as Record<string, string>)[opening]!;\n } else throw error;\n // Later parser errors refer to the repaired text. Map interior offsets\n // back before inserting again; suffix repairs always anchor at source EOF.\n if (offset >= text.length) offset = source.length;\n else if (text !== source) {\n const prefix = text.slice(0, offset).split('\\n');\n const point = originalPosition(\n {\n code: text,\n map: repaired.generateMap({ source: options.filename, hires: true }),\n } as TransformResult,\n prefix.length,\n prefix.at(-1)!.length,\n );\n const starts = [0];\n for (const match of source.matchAll(/\\n/g)) starts.push(match.index! + 1);\n offset =\n point.line == null || point.column == null\n ? source.length\n : starts[point.line - 1]! + point.column;\n }\n repaired.appendLeft(offset, insertion);\n text = repaired.toString();\n }\n }\n return transform(source, options);\n}\n","import ts from 'typescript';\nimport { resolve, dirname } from 'node:path';\nimport {\n transform,\n extensions,\n isTwillFile,\n inferLanguage,\n originalPosition,\n generatedPosition,\n type TransformOptions,\n type TransformResult,\n} from './compiler.js';\nimport { loadConfig } from './config.js';\nimport { recoverTransform } from './recovery.js';\nimport { isDependency } from './files.js';\nexport { isDependency } from './files.js';\n\nfunction lineStarts(text: string): number[] {\n const starts = [0];\n // MagicString maps count LF-delimited lines. TS language-service APIs here\n // take absolute offsets, so keep the map's coordinates at this boundary.\n const breaks = /\\n/g;\n while (breaks.exec(text)) starts.push(breaks.lastIndex);\n return starts;\n}\nfunction positionAt(starts: number[], offset: number) {\n let low = 0;\n let high = starts.length;\n while (low + 1 < high) {\n const mid = (low + high) >>> 1;\n if (starts[mid]! <= offset) low = mid;\n else high = mid;\n }\n return { line: low + 1, column: offset - starts[low]! };\n}\n\n// TypeScript's config discovery accepts custom TS extensions only as Deferred;\n// each virtual filename below supplies the actual script kind to the service.\nconst extraExtensions = extensions.map((extension) => ({\n extension,\n isMixedContent: false,\n scriptKind: ts.ScriptKind.Deferred,\n}));\nexport function virtualFilename(filename: string): string {\n filename = filename.replaceAll('\\\\', '/');\n return isTwillFile(filename)\n ? filename + { ts: '.ts', tsx: '.tsx', js: '.js', jsx: '.jsx' }[inferLanguage(filename)]\n : filename;\n}\nexport function sourceFilename(filename: string): string {\n filename = filename.replaceAll('\\\\', '/');\n if (isTwillFile(filename)) return filename;\n return filename.replace(/(\\.twill)\\.ts$/, '$1').replace(/(\\.twillx)\\.tsx$/, '$1');\n}\n\nexport interface ProjectDiagnostic {\n filename?: string;\n line: number;\n column: number;\n length: number;\n code: number;\n category: 'error' | 'warning' | 'message';\n message: string;\n}\n\n/** A virtual-source TypeScript project shared by the CLI and VS Code extension. */\nexport class TwillProject {\n readonly root: string;\n readonly service: ts.LanguageService;\n readonly compilerOptions: ts.CompilerOptions;\n readonly configFiles: readonly string[];\n private files: string[];\n private overlays = new Map<string, string>();\n private results = new Map<string, { source: string; result: TransformResult }>();\n private lineMaps = new WeakMap<TransformResult, { original: number[]; generated: number[] }>();\n private version = 0;\n private invalidation = 0;\n private fileVersions = new Map<string, number>();\n private configurationErrors: readonly ts.Diagnostic[];\n private options: TransformOptions;\n private readonly host: ts.LanguageServiceHost;\n private recover: boolean;\n private discoverFiles: () => string[];\n\n constructor(\n tsconfig: string,\n options: TransformOptions = {},\n projectOptions: {\n inferred?: boolean;\n recover?: boolean;\n defaultLibFileName?: (options: ts.CompilerOptions) => string;\n declarationRedirects?: ReadonlyMap<string, string>;\n } = {},\n ) {\n const configFile = sourceFilename(resolve(tsconfig));\n this.root = dirname(configFile);\n this.recover = projectOptions.recover ?? false;\n this.options = { ...loadConfig(this.root, configFile), ...options };\n const configReads = new Set([\n configFile,\n sourceFilename(resolve(this.root, 'twill.config.json')),\n ]);\n const configHost = {\n ...ts.sys,\n readFile: (filename: string) => {\n configReads.add(sourceFilename(filename));\n return ts.sys.readFile(filename);\n },\n };\n const raw =\n projectOptions.inferred && !ts.sys.fileExists(configFile)\n ? {\n config: {\n compilerOptions: {\n strict: true,\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'Bundler',\n jsx: 'react-jsx',\n },\n },\n }\n : ts.readConfigFile(configFile, configHost.readFile);\n const parsed = ts.parseJsonConfigFileContent(\n raw.config ?? {},\n configHost,\n this.root,\n { allowJs: true, allowImportingTsExtensions: true, noEmit: true },\n configFile,\n undefined,\n extraExtensions,\n );\n this.configurationErrors = [...(raw.error ? [raw.error] : []), ...parsed.errors];\n if (parsed.projectReferences?.length && !projectOptions.declarationRedirects)\n this.configurationErrors = [\n ...this.configurationErrors,\n {\n category: ts.DiagnosticCategory.Error,\n code: 90002,\n file: undefined,\n start: undefined,\n length: undefined,\n messageText:\n 'TypeScript project references are not supported by twill check. Check each referenced project separately.',\n },\n ];\n this.compilerOptions = parsed.options;\n this.configFiles = [...configReads];\n this.options.jsxImportSource ??= parsed.options.jsxImportSource;\n this.files = parsed.fileNames.map(virtualFilename);\n this.discoverFiles = () =>\n ts\n .parseJsonConfigFileContent(\n raw.config ?? {},\n configHost,\n this.root,\n { allowJs: true, allowImportingTsExtensions: true, noEmit: true },\n configFile,\n undefined,\n extraExtensions,\n )\n .fileNames.map(virtualFilename);\n const readFile = (name: string) => {\n const original = sourceFilename(name);\n const source = this.overlays.get(original) ?? ts.sys.readFile(original);\n if (source === undefined) return undefined;\n if (!isTwillFile(original)) return source;\n // Syntax failures are reported separately, with original source positions.\n // Keep the service alive so other open documents still work.\n try {\n return this.result(original, source).code;\n } catch {\n return '';\n }\n };\n const fileExists = (name: string) =>\n this.overlays.has(sourceFilename(name)) || ts.sys.fileExists(sourceFilename(name));\n const resolutionHost: ts.ModuleResolutionHost = { ...ts.sys, readFile, fileExists };\n this.host = {\n ...ts.sys,\n getScriptFileNames: () => this.files,\n useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,\n getScriptVersion: (name) =>\n `${this.invalidation}:${this.fileVersions.get(sourceFilename(name)) ?? 0}`,\n getProjectVersion: () => String(this.version),\n getScriptSnapshot: (name) => {\n const text = readFile(name);\n return text === undefined ? undefined : ts.ScriptSnapshot.fromString(text);\n },\n getCurrentDirectory: () => this.root,\n getCompilationSettings: () => this.compilerOptions,\n getDefaultLibFileName:\n projectOptions.defaultLibFileName ?? ((opts) => ts.getDefaultLibFilePath(opts)),\n readFile,\n fileExists,\n resolveModuleNames: (names, importer) =>\n names.map((name) => {\n const resolved = ts.resolveModuleName(\n name,\n importer,\n this.compilerOptions,\n resolutionHost,\n ).resolvedModule;\n if (resolved) {\n const redirect = projectOptions.declarationRedirects?.get(\n sourceFilename(resolved.resolvedFileName),\n );\n return redirect\n ? { ...resolved, resolvedFileName: redirect, extension: ts.Extension.Dts }\n : { ...resolved, resolvedFileName: virtualFilename(resolved.resolvedFileName) };\n }\n if (name.startsWith('.') || name.startsWith('/')) {\n const base = resolve(dirname(sourceFilename(importer)), name);\n const candidates = isTwillFile(base)\n ? [base]\n : extensions.flatMap((extension) => [\n base + extension,\n resolve(base, 'index' + extension),\n ]);\n for (const candidate of candidates) {\n if (fileExists(candidate)) {\n const redirect = projectOptions.declarationRedirects?.get(\n sourceFilename(candidate),\n );\n if (redirect)\n return {\n resolvedFileName: redirect,\n extension: ts.Extension.Dts,\n isExternalLibraryImport: false,\n };\n const file = virtualFilename(candidate);\n // Fallback candidates are exclusively .twill/.twillx; native\n // JS/TS extensions are resolved by TypeScript above.\n const extension = file.endsWith('.tsx') ? ts.Extension.Tsx : ts.Extension.Ts;\n return { resolvedFileName: file, extension, isExternalLibraryImport: false };\n }\n }\n }\n return undefined;\n }),\n };\n this.service = ts.createLanguageService(this.host);\n }\n\n /** Declaration-only native TypeScript emit from the checked virtual program. */\n declarationOutput(outDir: string, declarationMap = true) {\n const diagnostics = this.diagnostics();\n if (diagnostics.some((item) => item.category === 'error')) return { diagnostics, files: [] };\n const previous = this.service.getProgram();\n if (!previous) return { diagnostics, files: [] };\n const options: ts.CompilerOptions = {\n ...this.compilerOptions,\n noEmit: false,\n declaration: true,\n emitDeclarationOnly: true,\n declarationMap,\n noEmitOnError: true,\n incremental: false,\n composite: false,\n rootDir: this.compilerOptions.rootDir ?? this.root,\n outDir,\n declarationDir: outDir,\n allowImportingTsExtensions: true,\n };\n const host = ts.createCompilerHost(options);\n host.readFile = this.host.readFile!;\n host.fileExists = this.host.fileExists!;\n host.getCurrentDirectory = () => this.root;\n host.resolveModuleNames = this.host.resolveModuleNames;\n host.getSourceFile = (filename, languageVersion) =>\n previous.getSourceFile(filename) ??\n (host.readFile(filename) === undefined\n ? undefined\n : ts.createSourceFile(filename, host.readFile(filename)!, languageVersion, true));\n const program = ts.createProgram(previous.getRootFileNames(), options, host);\n const errors = ts.getPreEmitDiagnostics(program).map((item) => this.diagnostic(item));\n if (errors.some((item) => item.category === 'error')) return { diagnostics: errors, files: [] };\n const files: { filename: string; text: string; sources: string[] }[] = [];\n const emitted = program.emit(\n undefined,\n (filename, text, _bom, _error, sources) => {\n files.push({\n filename: sourceFilename(filename),\n text,\n sources: sources?.map((source) => sourceFilename(source.fileName)) ?? [],\n });\n },\n undefined,\n true,\n );\n return {\n diagnostics: [...diagnostics, ...emitted.diagnostics.map((item) => this.diagnostic(item))],\n files: emitted.emitSkipped ? [] : files,\n };\n }\n\n private result(filename: string, source: string): TransformResult {\n const cached = this.results.get(filename);\n if (cached?.source === source) return cached.result;\n const result = (this.recover ? recoverTransform : transform)(source, {\n ...this.options,\n filename,\n });\n this.results.set(filename, { source, result });\n return result;\n }\n\n update(filename: string, text?: string) {\n filename = sourceFilename(resolve(filename));\n // Hover and completion often submit the same open document. An unchanged\n // overlay must retain compiler results and TypeScript's semantic caches.\n if (\n text !== undefined &&\n text === this.overlays.get(filename) &&\n this.files.includes(virtualFilename(filename))\n )\n return;\n if (text === undefined) this.overlays.delete(filename);\n else this.overlays.set(filename, text);\n this.fileVersions.set(filename, (this.fileVersions.get(filename) ?? 0) + 1);\n if (!this.files.includes(virtualFilename(filename))) this.files.push(virtualFilename(filename));\n this.results.delete(filename);\n this.version++;\n }\n\n invalidate() {\n this.invalidation++;\n this.version++;\n this.results.clear();\n }\n\n /** Refresh a disk version without discarding unsaved overlays or other transforms. */\n refresh(filename: string, discover = false) {\n filename = sourceFilename(resolve(filename));\n if (discover)\n this.files = [\n ...new Set([...this.discoverFiles(), ...[...this.overlays.keys()].map(virtualFilename)]),\n ];\n if (!this.overlays.has(filename)) {\n this.results.delete(filename);\n this.fileVersions.set(filename, (this.fileVersions.get(filename) ?? 0) + 1);\n }\n this.version++;\n }\n\n text(filename: string): string | undefined {\n filename = sourceFilename(resolve(filename));\n return this.overlays.get(filename) ?? ts.sys.readFile(filename);\n }\n\n transformed(filename: string): TransformResult | undefined {\n filename = sourceFilename(resolve(filename));\n const source = this.text(filename);\n return source !== undefined && isTwillFile(filename)\n ? this.result(filename, source)\n : undefined;\n }\n\n sourceFiles(): string[] {\n const dependencies =\n this.service\n .getProgram()\n ?.getSourceFiles()\n .filter((file) => !file.isDeclarationFile && !isDependency(file.fileName))\n .map((file) => file.fileName) ?? [];\n return [...new Set([...this.files, ...dependencies].map(sourceFilename))];\n }\n\n private lines(filename: string, result: TransformResult) {\n let lines = this.lineMaps.get(result);\n if (!lines) {\n lines = { original: lineStarts(this.text(filename)!), generated: lineStarts(result.code) };\n this.lineMaps.set(result, lines);\n }\n return lines;\n }\n\n toGeneratedOffset(filename: string, offset: number): number {\n const result = this.transformed(filename);\n if (!result) return offset;\n const lines = this.lines(filename, result);\n const sourcePosition = positionAt(lines.original, offset);\n const position = generatedPosition(result, sourcePosition.line, sourcePosition.column);\n if (position.line === null || position.column === null) return offset;\n return (lines.generated[position.line - 1] ?? 0) + position.column;\n }\n\n toOriginalOffset(filename: string, offset: number): number {\n const result = this.transformed(filename);\n if (!result) return offset;\n const lines = this.lines(filename, result);\n const sourcePosition = positionAt(lines.generated, offset);\n const position = originalPosition(result, sourcePosition.line, sourcePosition.column);\n if (position.line === null || position.column === null) return 0;\n return (lines.original[position.line - 1] ?? 0) + position.column;\n }\n\n private diagnostic(diagnostic: ts.Diagnostic): ProjectDiagnostic {\n const filename = diagnostic.file ? sourceFilename(diagnostic.file.fileName) : undefined;\n const source = filename ? (this.text(filename) ?? '') : '';\n const start = filename ? this.toOriginalOffset(filename, diagnostic.start ?? 0) : 0;\n const end = filename\n ? this.toOriginalOffset(filename, (diagnostic.start ?? 0) + (diagnostic.length ?? 1))\n : start + 1;\n const before = source.slice(0, start).split(/\\r\\n|[\\r\\n\\u2028\\u2029]/);\n return {\n filename,\n line: before.length,\n column: before.at(-1)!.length,\n length: Math.max(1, end - start),\n code: diagnostic.code,\n category:\n diagnostic.category === ts.DiagnosticCategory.Error\n ? 'error'\n : diagnostic.category === ts.DiagnosticCategory.Warning\n ? 'warning'\n : 'message',\n message: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\\n'),\n };\n }\n\n diagnostics(filename?: string): ProjectDiagnostic[] {\n const result = this.configurationErrors.map((error) => this.diagnostic(error));\n if (!filename)\n result.push(\n ...this.service.getCompilerOptionsDiagnostics().map((error) => this.diagnostic(error)),\n );\n const files = filename\n ? [virtualFilename(resolve(filename))]\n : this.sourceFiles().map(virtualFilename);\n for (const file of files) {\n if (/\\.d\\.[cm]?ts$/.test(file)) continue;\n try {\n if (this.recover && isTwillFile(sourceFilename(file)))\n transform(this.text(file) ?? '', { ...this.options, filename: sourceFilename(file) });\n this.transformed(file);\n result.push(\n ...[\n ...this.service.getSyntacticDiagnostics(file),\n ...this.service.getSemanticDiagnostics(file),\n ].map((error) => this.diagnostic(error)),\n );\n } catch (error) {\n const syntax = error as { message: string; line?: number; column?: number };\n result.push({\n filename: sourceFilename(file),\n line: syntax.line ?? 1,\n column: syntax.column ?? 0,\n length: 1,\n code: 90001,\n category: 'error',\n message: syntax.message,\n });\n }\n }\n return result;\n }\n\n dispose() {\n this.service.dispose();\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,iBAAiB,QAAgB,SAA4C;CAC3F,MAAM,WAAW,IAAI,YAAY,MAAM;CACvC,IAAI,OAAO;CAGX,KAAK,IAAI,UAAU,GAAG,UAAU,GAAG,WACjC,IAAI;EACF,MAAM,SAAS,UAAU,MAAM,OAAO;EACtC,IAAI,SAAS,QAAQ,OAAO;EAC5B,MAAM,YAAY,SAAS,YAAY;GACrC,QAAQ,QAAQ;GAChB,gBAAgB;GAChB,OAAO;EACT,CAAC;EAID,MAAM,iBAAiB;GAAE,GAAG;GAAQ,KAAK;EAAU;EACnD,MAAM,SAAS,CAAC,CAAC;EACjB,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG,OAAO,KAAK,MAAM,QAAS,CAAC;EACxE,MAAM,gBAAgB,WAAmB;GACvC,MAAM,SAAS,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC,MAAM,IAAI;GAC/C,MAAM,QAAQ,iBAAiB,gBAAgB,OAAO,QAAQ,OAAO,GAAG,EAAE,CAAC,CAAE,MAAM;GACnF,OAAO,OAAO,MAAM,OAAQ,KAAM,MAAM;EAC1C;EACA,MAAM,eAAe,OAAO,aAAa,KAAK,aAAa;GACzD,GAAG;GACH,WAAW;IACT,GAAG,QAAQ;IACX,UAAU;KACR,GAAG,QAAQ,UAAU;KACrB,OAAO,aAAa,QAAQ,UAAU,SAAS,KA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OAAO;GACxB,IAAI,gBAAgB,KAAK,IAAI,GAAG;GAChC,IAAI;IACF,IAAI,KAAK,WAAW,YAAY,eAAe,IAAI,CAAC,GAClD,UAAU,KAAK,KAAK,IAAI,KAAK,IAAI;KAAE,GAAG,KAAK;KAAS,UAAU,eAAe,IAAI;IAAE,CAAC;IACtF,KAAK,YAAY,IAAI;IACrB,OAAO,KACL,GAAG,CACD,GAAG,KAAK,QAAQ,wBAAwB,IAAI,GAC5C,GAAG,KAAK,QAAQ,uBAAuB,IAAI,CAC7C,CAAC,CAAC,KAAK,UAAU,KAAK,WAAW,KAAK,CAAC,CACzC;GACF,SAAS,OAAO;IACd,MAAM,SAAS;IACf,OAAO,KAAK;KACV,UAAU,eAAe,IAAI;KAC7B,MAAM,OAAO,QAAQ;KACrB,QAAQ,OAAO,UAAU;KACzB,QAAQ;KACR,MAAM;KACN,UAAU;KACV,SAAS,OAAO;IAClB,CAAC;GACH;EACF;EACA,OAAO;CACT;CAEA,UAAU;EACR,KAAK,QAAQ,QAAQ;CACvB;AACF"}
|
|
1
|
+
{"version":3,"file":"project.js","names":[],"sources":["../src/recovery.ts","../src/project.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport remapping from '@ampproject/remapping';\nimport {\n transform,\n TwillSyntaxError,\n originalPosition,\n type TransformOptions,\n type TransformResult,\n} from './compiler.js';\n\n/** Editor-only recovery; build and CLI compilation always use strict parsing. */\nexport function recoverTransform(\n source: string,\n options: TransformOptions,\n onSyntaxError?: (error: TwillSyntaxError) => void,\n): TransformResult {\n const repaired = new MagicString(source);\n let text = source;\n // Complete a missing member name or a few unfinished delimiters. Limit repair\n // attempts so malformed documents cannot lock up the extension host.\n for (let attempt = 0; attempt < 8; attempt++) {\n try {\n const result = transform(text, options);\n if (text === source) return result;\n const repairMap = repaired.generateMap({\n source: options.filename,\n includeContent: true,\n hires: true,\n });\n // Descriptor offsets belong to repaired parser input. Restore their\n // source positions before the editor composes generated mappings;\n // otherwise an earlier inserted token can bypass linked-tag rename checks.\n const repairedResult = { ...result, map: repairMap };\n const starts = [0];\n for (const match of source.matchAll(/\\n/g)) starts.push(match.index! + 1);\n const sourceOffset = (offset: number) => {\n const prefix = text.slice(0, offset).split('\\n');\n const point = originalPosition(repairedResult, prefix.length, prefix.at(-1)!.length);\n return starts[point.line! - 1]! + point.column!;\n };\n const enumPatterns = result.enumPatterns.map((pattern) => ({\n ...pattern,\n reference: {\n ...pattern.reference,\n property: {\n ...pattern.reference.property,\n start: sourceOffset(pattern.reference.property.start),\n end: sourceOffset(pattern.reference.property.end),\n },\n },\n }));\n const map = remapping(\n [JSON.parse(result.map.toString()), JSON.parse(repairMap.toString())],\n () => null,\n );\n return { ...result, enumPatterns, map: map as unknown as TransformResult['map'] };\n } catch (error) {\n if (!(error instanceof TwillSyntaxError)) throw error;\n if (attempt === 0) onSyntaxError?.(error);\n const before = text.slice(0, error.offset);\n let insertion: string;\n let offset = error.offset;\n if (/\\.\\s*$/.test(before)) insertion = '__twillIncomplete';\n else if (offset >= text.length) {\n // Match lexical delimiters via the original source. This path only\n // handles suffix completion; it never makes build output valid.\n const stack: string[] = [];\n const scanner =\n /(?:\"(?:\\\\.|[^\"\\\\])*\"|'(?:\\\\.|[^'\\\\])*'|`(?:\\\\.|[^`\\\\])*`|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n]*|[()[\\]{}])/g;\n for (const token of text.matchAll(scanner)) {\n if ('([{'.includes(token[0])) stack.push(token[0]);\n else if (')]}'.includes(token[0])) stack.pop();\n }\n const opening = stack.at(-1);\n if (!opening) throw error;\n insertion = ({ '(': ')', '[': ']', '{': '}' } as Record<string, string>)[opening]!;\n } else throw error;\n // Later parser errors refer to the repaired text. Map interior offsets\n // back before inserting again; suffix repairs always anchor at source EOF.\n if (offset >= text.length) offset = source.length;\n else if (text !== source) {\n const prefix = text.slice(0, offset).split('\\n');\n const point = originalPosition(\n {\n code: text,\n map: repaired.generateMap({ source: options.filename, hires: true }),\n } as TransformResult,\n prefix.length,\n prefix.at(-1)!.length,\n );\n const starts = [0];\n for (const match of source.matchAll(/\\n/g)) starts.push(match.index! + 1);\n offset =\n point.line == null || point.column == null\n ? source.length\n : starts[point.line - 1]! + point.column;\n }\n repaired.appendLeft(offset, insertion);\n text = repaired.toString();\n }\n }\n return transform(source, options);\n}\n","import ts from 'typescript';\nimport { resolve, dirname } from 'node:path';\nimport {\n transform,\n extensions,\n isTwillFile,\n inferLanguage,\n originalPosition,\n generatedPosition,\n type TransformOptions,\n type TransformResult,\n} from './compiler.js';\nimport { loadConfig } from './config.js';\nimport { recoverTransform } from './recovery.js';\nimport { isDependency } from './files.js';\nexport { isDependency } from './files.js';\n\nfunction lineStarts(text: string): number[] {\n const starts = [0];\n // MagicString maps count LF-delimited lines. TS language-service APIs here\n // take absolute offsets, so keep the map's coordinates at this boundary.\n const breaks = /\\n/g;\n while (breaks.exec(text)) starts.push(breaks.lastIndex);\n return starts;\n}\nfunction positionAt(starts: number[], offset: number) {\n let low = 0;\n let high = starts.length;\n while (low + 1 < high) {\n const mid = (low + high) >>> 1;\n if (starts[mid]! <= offset) low = mid;\n else high = mid;\n }\n return { line: low + 1, column: offset - starts[low]! };\n}\n\n// TypeScript's config discovery accepts custom TS extensions only as Deferred;\n// each virtual filename below supplies the actual script kind to the service.\nconst extraExtensions = extensions.map((extension) => ({\n extension,\n isMixedContent: false,\n scriptKind: ts.ScriptKind.Deferred,\n}));\nexport function virtualFilename(filename: string): string {\n filename = filename.replaceAll('\\\\', '/');\n return isTwillFile(filename)\n ? filename + { ts: '.ts', tsx: '.tsx', js: '.js', jsx: '.jsx' }[inferLanguage(filename)]\n : filename;\n}\nexport function sourceFilename(filename: string): string {\n filename = filename.replaceAll('\\\\', '/');\n if (isTwillFile(filename)) return filename;\n return filename.replace(/(\\.twill)\\.ts$/, '$1').replace(/(\\.twillx)\\.tsx$/, '$1');\n}\n\nexport interface ProjectDiagnostic {\n filename?: string;\n line: number;\n column: number;\n length: number;\n code: number;\n category: 'error' | 'warning' | 'message';\n message: string;\n}\n\n/** A virtual-source TypeScript project shared by the CLI and VS Code extension. */\nexport class TwillProject {\n readonly root: string;\n readonly service: ts.LanguageService;\n readonly compilerOptions: ts.CompilerOptions;\n readonly configFiles: readonly string[];\n private files: string[];\n private overlays = new Map<string, string>();\n private results = new Map<\n string,\n { source: string; result: TransformResult; syntaxError?: Error }\n >();\n private lineMaps = new WeakMap<TransformResult, { original: number[]; generated: number[] }>();\n private version = 0;\n private invalidation = 0;\n private fileVersions = new Map<string, number>();\n private configurationErrors: readonly ts.Diagnostic[];\n private options: TransformOptions;\n private readonly host: ts.LanguageServiceHost;\n private recover: boolean;\n private discoverFiles: () => string[];\n\n constructor(\n tsconfig: string,\n options: TransformOptions = {},\n projectOptions: {\n inferred?: boolean;\n recover?: boolean;\n defaultLibFileName?: (options: ts.CompilerOptions) => string;\n declarationRedirects?: ReadonlyMap<string, string>;\n } = {},\n ) {\n const configFile = sourceFilename(resolve(tsconfig));\n this.root = dirname(configFile);\n this.recover = projectOptions.recover ?? false;\n this.options = { ...loadConfig(this.root, configFile), ...options };\n const configReads = new Set([\n configFile,\n sourceFilename(resolve(this.root, 'twill.config.json')),\n ]);\n const configHost = {\n ...ts.sys,\n readFile: (filename: string) => {\n configReads.add(sourceFilename(filename));\n return ts.sys.readFile(filename);\n },\n };\n const raw =\n projectOptions.inferred && !ts.sys.fileExists(configFile)\n ? {\n config: {\n compilerOptions: {\n strict: true,\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'Bundler',\n jsx: 'react-jsx',\n },\n },\n }\n : ts.readConfigFile(configFile, configHost.readFile);\n const parsed = ts.parseJsonConfigFileContent(\n raw.config ?? {},\n configHost,\n this.root,\n { allowJs: true, allowImportingTsExtensions: true, noEmit: true },\n configFile,\n undefined,\n extraExtensions,\n );\n this.configurationErrors = [...(raw.error ? [raw.error] : []), ...parsed.errors];\n if (parsed.projectReferences?.length && !projectOptions.declarationRedirects)\n this.configurationErrors = [\n ...this.configurationErrors,\n {\n category: ts.DiagnosticCategory.Error,\n code: 90002,\n file: undefined,\n start: undefined,\n length: undefined,\n messageText:\n 'TypeScript project references are not supported by twill check. Check each referenced project separately.',\n },\n ];\n this.compilerOptions = parsed.options;\n this.configFiles = [...configReads];\n this.options.jsxImportSource ??= parsed.options.jsxImportSource;\n this.files = parsed.fileNames.map(virtualFilename);\n this.discoverFiles = () =>\n ts\n .parseJsonConfigFileContent(\n raw.config ?? {},\n configHost,\n this.root,\n { allowJs: true, allowImportingTsExtensions: true, noEmit: true },\n configFile,\n undefined,\n extraExtensions,\n )\n .fileNames.map(virtualFilename);\n const readFile = (name: string) => {\n const original = sourceFilename(name);\n const source = this.overlays.get(original) ?? ts.sys.readFile(original);\n if (source === undefined) return undefined;\n if (!isTwillFile(original)) return source;\n // Syntax failures are reported separately, with original source positions.\n // Keep the service alive so other open documents still work.\n try {\n return this.result(original, source).code;\n } catch {\n return '';\n }\n };\n const fileExists = (name: string) =>\n this.overlays.has(sourceFilename(name)) || ts.sys.fileExists(sourceFilename(name));\n const resolutionHost: ts.ModuleResolutionHost = { ...ts.sys, readFile, fileExists };\n this.host = {\n ...ts.sys,\n getScriptFileNames: () => this.files,\n useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,\n getScriptVersion: (name) =>\n `${this.invalidation}:${this.fileVersions.get(sourceFilename(name)) ?? 0}`,\n getProjectVersion: () => String(this.version),\n getScriptSnapshot: (name) => {\n const text = readFile(name);\n return text === undefined ? undefined : ts.ScriptSnapshot.fromString(text);\n },\n getCurrentDirectory: () => this.root,\n getCompilationSettings: () => this.compilerOptions,\n getDefaultLibFileName:\n projectOptions.defaultLibFileName ?? ((opts) => ts.getDefaultLibFilePath(opts)),\n readFile,\n fileExists,\n resolveModuleNames: (names, importer) =>\n names.map((name) => {\n const resolved = ts.resolveModuleName(\n name,\n importer,\n this.compilerOptions,\n resolutionHost,\n ).resolvedModule;\n if (resolved) {\n const redirect = projectOptions.declarationRedirects?.get(\n sourceFilename(resolved.resolvedFileName),\n );\n return redirect\n ? { ...resolved, resolvedFileName: redirect, extension: ts.Extension.Dts }\n : { ...resolved, resolvedFileName: virtualFilename(resolved.resolvedFileName) };\n }\n if (name.startsWith('.') || name.startsWith('/')) {\n const base = resolve(dirname(sourceFilename(importer)), name);\n const candidates = isTwillFile(base)\n ? [base]\n : extensions.flatMap((extension) => [\n base + extension,\n resolve(base, 'index' + extension),\n ]);\n for (const candidate of candidates) {\n if (fileExists(candidate)) {\n const redirect = projectOptions.declarationRedirects?.get(\n sourceFilename(candidate),\n );\n if (redirect)\n return {\n resolvedFileName: redirect,\n extension: ts.Extension.Dts,\n isExternalLibraryImport: false,\n };\n const file = virtualFilename(candidate);\n // Fallback candidates are exclusively .twill/.twillx; native\n // JS/TS extensions are resolved by TypeScript above.\n const extension = file.endsWith('.tsx') ? ts.Extension.Tsx : ts.Extension.Ts;\n return { resolvedFileName: file, extension, isExternalLibraryImport: false };\n }\n }\n }\n return undefined;\n }),\n };\n this.service = ts.createLanguageService(this.host);\n }\n\n /** Declaration-only native TypeScript emit from the checked virtual program. */\n declarationOutput(outDir: string, declarationMap = true) {\n const diagnostics = this.diagnostics();\n if (diagnostics.some((item) => item.category === 'error')) return { diagnostics, files: [] };\n const previous = this.service.getProgram();\n if (!previous) return { diagnostics, files: [] };\n const options: ts.CompilerOptions = {\n ...this.compilerOptions,\n noEmit: false,\n declaration: true,\n emitDeclarationOnly: true,\n declarationMap,\n noEmitOnError: true,\n incremental: false,\n composite: false,\n rootDir: this.compilerOptions.rootDir ?? this.root,\n outDir,\n declarationDir: outDir,\n allowImportingTsExtensions: true,\n };\n const host = ts.createCompilerHost(options);\n host.readFile = this.host.readFile!;\n host.fileExists = this.host.fileExists!;\n host.getCurrentDirectory = () => this.root;\n host.resolveModuleNames = this.host.resolveModuleNames;\n host.getSourceFile = (filename, languageVersion) =>\n previous.getSourceFile(filename) ??\n (host.readFile(filename) === undefined\n ? undefined\n : ts.createSourceFile(filename, host.readFile(filename)!, languageVersion, true));\n const program = ts.createProgram(previous.getRootFileNames(), options, host);\n const errors = ts.getPreEmitDiagnostics(program).map((item) => this.diagnostic(item));\n if (errors.some((item) => item.category === 'error')) return { diagnostics: errors, files: [] };\n const files: { filename: string; text: string; sources: string[] }[] = [];\n const emitted = program.emit(\n undefined,\n (filename, text, _bom, _error, sources) => {\n files.push({\n filename: sourceFilename(filename),\n text,\n sources: sources?.map((source) => sourceFilename(source.fileName)) ?? [],\n });\n },\n undefined,\n true,\n );\n return {\n diagnostics: [...diagnostics, ...emitted.diagnostics.map((item) => this.diagnostic(item))],\n files: emitted.emitSkipped ? [] : files,\n };\n }\n\n private result(filename: string, source: string): TransformResult {\n const cached = this.results.get(filename);\n if (cached?.source === source) return cached.result;\n const options = { ...this.options, filename };\n let syntaxError: Error | undefined;\n const result = this.recover\n ? recoverTransform(source, options, (error) => {\n syntaxError = error;\n })\n : transform(source, options);\n this.results.set(filename, { source, result, syntaxError });\n return result;\n }\n\n update(filename: string, text?: string) {\n filename = sourceFilename(resolve(filename));\n // Hover and completion often submit the same open document. An unchanged\n // overlay must retain compiler results and TypeScript's semantic caches.\n if (\n text !== undefined &&\n text === this.overlays.get(filename) &&\n this.files.includes(virtualFilename(filename))\n )\n return;\n if (text === undefined) this.overlays.delete(filename);\n else this.overlays.set(filename, text);\n this.fileVersions.set(filename, (this.fileVersions.get(filename) ?? 0) + 1);\n if (!this.files.includes(virtualFilename(filename))) this.files.push(virtualFilename(filename));\n this.results.delete(filename);\n this.version++;\n }\n\n invalidate() {\n this.invalidation++;\n this.version++;\n this.results.clear();\n }\n\n /** Refresh a disk version without discarding unsaved overlays or other transforms. */\n refresh(filename: string, discover = false) {\n filename = sourceFilename(resolve(filename));\n if (discover)\n this.files = [\n ...new Set([...this.discoverFiles(), ...[...this.overlays.keys()].map(virtualFilename)]),\n ];\n if (!this.overlays.has(filename)) {\n this.results.delete(filename);\n this.fileVersions.set(filename, (this.fileVersions.get(filename) ?? 0) + 1);\n }\n this.version++;\n }\n\n text(filename: string): string | undefined {\n filename = sourceFilename(resolve(filename));\n return this.overlays.get(filename) ?? ts.sys.readFile(filename);\n }\n\n transformed(filename: string): TransformResult | undefined {\n filename = sourceFilename(resolve(filename));\n const source = this.text(filename);\n return source !== undefined && isTwillFile(filename)\n ? this.result(filename, source)\n : undefined;\n }\n\n sourceFiles(): string[] {\n const dependencies =\n this.service\n .getProgram()\n ?.getSourceFiles()\n .filter((file) => !file.isDeclarationFile && !isDependency(file.fileName))\n .map((file) => file.fileName) ?? [];\n return [...new Set([...this.files, ...dependencies].map(sourceFilename))];\n }\n\n private lines(filename: string, result: TransformResult) {\n let lines = this.lineMaps.get(result);\n if (!lines) {\n lines = { original: lineStarts(this.text(filename)!), generated: lineStarts(result.code) };\n this.lineMaps.set(result, lines);\n }\n return lines;\n }\n\n toGeneratedOffset(filename: string, offset: number): number {\n const result = this.transformed(filename);\n if (!result) return offset;\n const lines = this.lines(filename, result);\n const sourcePosition = positionAt(lines.original, offset);\n const position = generatedPosition(result, sourcePosition.line, sourcePosition.column);\n if (position.line === null || position.column === null) return offset;\n return (lines.generated[position.line - 1] ?? 0) + position.column;\n }\n\n toOriginalOffset(filename: string, offset: number): number {\n const result = this.transformed(filename);\n if (!result) return offset;\n const lines = this.lines(filename, result);\n const sourcePosition = positionAt(lines.generated, offset);\n const position = originalPosition(result, sourcePosition.line, sourcePosition.column);\n if (position.line === null || position.column === null) return 0;\n return (lines.original[position.line - 1] ?? 0) + position.column;\n }\n\n private diagnostic(diagnostic: ts.Diagnostic): ProjectDiagnostic {\n const filename = diagnostic.file ? sourceFilename(diagnostic.file.fileName) : undefined;\n const source = filename ? (this.text(filename) ?? '') : '';\n const start = filename ? this.toOriginalOffset(filename, diagnostic.start ?? 0) : 0;\n const end = filename\n ? this.toOriginalOffset(filename, (diagnostic.start ?? 0) + (diagnostic.length ?? 1))\n : start + 1;\n const before = source.slice(0, start).split(/\\r\\n|[\\r\\n\\u2028\\u2029]/);\n return {\n filename,\n line: before.length,\n column: before.at(-1)!.length,\n length: Math.max(1, end - start),\n code: diagnostic.code,\n category:\n diagnostic.category === ts.DiagnosticCategory.Error\n ? 'error'\n : diagnostic.category === ts.DiagnosticCategory.Warning\n ? 'warning'\n : 'message',\n message: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\\n'),\n };\n }\n\n diagnostics(filename?: string): ProjectDiagnostic[] {\n const result = this.configurationErrors.map((error) => this.diagnostic(error));\n if (!filename)\n result.push(\n ...this.service.getCompilerOptionsDiagnostics().map((error) => this.diagnostic(error)),\n );\n const files = filename\n ? [virtualFilename(resolve(filename))]\n : this.sourceFiles().map(virtualFilename);\n for (const file of files) {\n if (/\\.d\\.[cm]?ts$/.test(file)) continue;\n try {\n this.transformed(file);\n const syntaxError = this.results.get(sourceFilename(file))?.syntaxError;\n if (syntaxError) throw syntaxError;\n result.push(\n ...[\n ...this.service.getSyntacticDiagnostics(file),\n ...this.service.getSemanticDiagnostics(file),\n ].map((error) => this.diagnostic(error)),\n );\n } catch (error) {\n const syntax = error as { message: string; line?: number; column?: number };\n result.push({\n filename: sourceFilename(file),\n line: syntax.line ?? 1,\n column: syntax.column ?? 0,\n length: 1,\n code: 90001,\n category: 'error',\n message: syntax.message,\n });\n }\n }\n return result;\n }\n\n dispose() {\n this.service.dispose();\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,iBACd,QACA,SACA,eACiB;CACjB,MAAM,WAAW,IAAI,YAAY,MAAM;CACvC,IAAI,OAAO;CAGX,KAAK,IAAI,UAAU,GAAG,UAAU,GAAG,WACjC,IAAI;EACF,MAAM,SAAS,UAAU,MAAM,OAAO;EACtC,IAAI,SAAS,QAAQ,OAAO;EAC5B,MAAM,YAAY,SAAS,YAAY;GACrC,QAAQ,QAAQ;GAChB,gBAAgB;GAChB,OAAO;EACT,CAAC;EAID,MAAM,iBAAiB;GAAE,GAAG;GAAQ,KAAK;EAAU;EACnD,MAAM,SAAS,CAAC,CAAC;EACjB,KAA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
|
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/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-CbNSBUI2.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-CbNSBUI2.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-D8P8Lsbx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpile-
|
|
1
|
+
{"version":3,"file":"transpile-D8P8Lsbx.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"}
|
|
@@ -15159,6 +15159,15 @@ function parserFor(language) {
|
|
|
15159
15159
|
if (parsers.has(language)) return parsers.get(language);
|
|
15160
15160
|
const Base = bases[language];
|
|
15161
15161
|
class TwillParser extends Base {
|
|
15162
|
+
declareName(name, bindingType, position) {
|
|
15163
|
+
if (bindingType === 6 || bindingType === 7) {
|
|
15164
|
+
const scope = this.currentScope();
|
|
15165
|
+
(scope.types ??= []).push(name);
|
|
15166
|
+
if (this.inModule && scope.flags & 1) delete this.undefinedExports[name];
|
|
15167
|
+
return;
|
|
15168
|
+
}
|
|
15169
|
+
super.declareName(name, bindingType, position);
|
|
15170
|
+
}
|
|
15162
15171
|
skipHeader = null;
|
|
15163
15172
|
closures = [];
|
|
15164
15173
|
lineStarts = null;
|
|
@@ -15632,9 +15641,10 @@ function parse$1(source, language = "ts", sourceType = "module") {
|
|
|
15632
15641
|
if (node.type === "DeferStatement") defers.push(node);
|
|
15633
15642
|
if (node.type === "TwillSwitchExpression") switches.push(node);
|
|
15634
15643
|
if (node.type === "TwillEnumDeclaration") enums.push(node);
|
|
15635
|
-
for (const
|
|
15644
|
+
for (const key of Object.keys(node)) {
|
|
15636
15645
|
if (key === "trailing" || key === "loc") continue;
|
|
15637
|
-
|
|
15646
|
+
const value = node[key];
|
|
15647
|
+
if (Array.isArray(value)) for (const child of value) visit(child);
|
|
15638
15648
|
else if (value?.type) visit(value);
|
|
15639
15649
|
}
|
|
15640
15650
|
};
|
|
@@ -15667,15 +15677,15 @@ var functions = /* @__PURE__ */ new Set([
|
|
|
15667
15677
|
"ArrowFunctionExpression"
|
|
15668
15678
|
]);
|
|
15669
15679
|
function children(node, visit) {
|
|
15670
|
-
for (const
|
|
15680
|
+
for (const key of Object.keys(node)) {
|
|
15671
15681
|
if (key === "loc" || key === "trailing") continue;
|
|
15672
|
-
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
else if (value?.type) visit(value);
|
|
15682
|
+
const value = node[key];
|
|
15683
|
+
if (Array.isArray(value)) {
|
|
15684
|
+
for (const child of value) if (child?.type) visit(child);
|
|
15685
|
+
} else if (value?.type) visit(value);
|
|
15676
15686
|
}
|
|
15677
15687
|
}
|
|
15678
|
-
/**
|
|
15688
|
+
/** Native finally where scope permits; callbacks retain dynamic registration semantics. */
|
|
15679
15689
|
function lowerDefers(source, ast, code, language, usedNames, contentStarts, comments, runtime, sourceType, fail) {
|
|
15680
15690
|
const scopes = [];
|
|
15681
15691
|
const visit = (node, scope, parent) => {
|
|
@@ -15730,6 +15740,35 @@ function lowerDefers(source, ast, code, language, usedNames, contentStarts, comm
|
|
|
15730
15740
|
if (!scope.defers.length) continue;
|
|
15731
15741
|
const { block } = scope;
|
|
15732
15742
|
const statements = block.body;
|
|
15743
|
+
const first = statements.indexOf(scope.defers[0]);
|
|
15744
|
+
let native = first >= 0 && scope.defers.every((node) => !node.awaited && statements.includes(node));
|
|
15745
|
+
if (native) {
|
|
15746
|
+
native = !statements.some((node, index) => node.type === "FunctionDeclaration" || node.type === "TSDeclareFunction" || node.type === "VariableDeclaration" && node.kind.endsWith("using") || index > first && (node.type === "VariableDeclaration" && node.kind !== "var" || node.type.endsWith("Declaration") && node.type !== "VariableDeclaration" || node.type === "GuardStatement" && node.binding));
|
|
15747
|
+
const check = (node) => {
|
|
15748
|
+
if (node.type === "WithStatement" || node.type === "ThisExpression" || node.type === "VariableDeclarator" && !node.init || node.type === "VariableDeclaration" && node.kind === "var" && (!statements.includes(node) || node.start > scope.defers[0].start) || node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "eval") native = false;
|
|
15749
|
+
children(node, check);
|
|
15750
|
+
};
|
|
15751
|
+
if (native) check(block);
|
|
15752
|
+
const cleanupScope = (node) => {
|
|
15753
|
+
if (node.type === "FunctionDeclaration" || node.directive || node.type === "VariableDeclaration" && node.kind === "var") native = false;
|
|
15754
|
+
if (!functions.has(node.type)) children(node, cleanupScope);
|
|
15755
|
+
};
|
|
15756
|
+
if (native) for (const node of scope.defers) cleanupScope(node.cleanup.body);
|
|
15757
|
+
}
|
|
15758
|
+
if (native) {
|
|
15759
|
+
for (const node of [...scope.defers].reverse()) {
|
|
15760
|
+
code.overwrite(node.start, node.cleanup.body.start, ";try {");
|
|
15761
|
+
if (!node.cleanup.body.body.length) {
|
|
15762
|
+
code.remove(node.cleanup.body.start, node.cleanup.body.end);
|
|
15763
|
+
code.appendLeft(block.end - 1, "\n} finally " + source.slice(node.cleanup.body.start, node.cleanup.body.end) + "\n");
|
|
15764
|
+
continue;
|
|
15765
|
+
}
|
|
15766
|
+
code.prependRight(node.cleanup.body.start, "\n} finally ");
|
|
15767
|
+
code.appendLeft(node.cleanup.body.end, "\n");
|
|
15768
|
+
if (node.cleanup.body.end !== block.end - 1) code.move(node.cleanup.body.start, node.cleanup.body.end, block.end - 1);
|
|
15769
|
+
}
|
|
15770
|
+
continue;
|
|
15771
|
+
}
|
|
15733
15772
|
const single = scope.defers.length === 1 && statements.includes(scope.defers[0]);
|
|
15734
15773
|
const stack = fresh(single ? "Cleanup" : "Defers");
|
|
15735
15774
|
const failure = single ? "" : fresh("Failure");
|
|
@@ -16610,12 +16649,12 @@ var TwillSyntaxError = class extends SyntaxError {
|
|
|
16610
16649
|
};
|
|
16611
16650
|
function walk(node, visit) {
|
|
16612
16651
|
visit(node);
|
|
16613
|
-
for (const
|
|
16614
|
-
if (
|
|
16615
|
-
|
|
16616
|
-
|
|
16617
|
-
|
|
16618
|
-
else if (value?.type) walk(value, visit);
|
|
16652
|
+
for (const key of Object.keys(node)) {
|
|
16653
|
+
if (key === "loc" || key === "trailing") continue;
|
|
16654
|
+
const value = node[key];
|
|
16655
|
+
if (Array.isArray(value)) {
|
|
16656
|
+
for (const child of value) if (child?.type) walk(child, visit);
|
|
16657
|
+
} else if (value?.type) walk(value, visit);
|
|
16619
16658
|
}
|
|
16620
16659
|
}
|
|
16621
16660
|
function calleeName(node) {
|
|
@@ -17392,7 +17431,7 @@ function remapping(input, loader, options) {
|
|
|
17392
17431
|
//#endregion
|
|
17393
17432
|
//#region src/recovery.ts
|
|
17394
17433
|
/** Editor-only recovery; build and CLI compilation always use strict parsing. */
|
|
17395
|
-
function recoverTransform(source, options) {
|
|
17434
|
+
function recoverTransform(source, options, onSyntaxError) {
|
|
17396
17435
|
const repaired = new MagicString(source);
|
|
17397
17436
|
let text = source;
|
|
17398
17437
|
for (let attempt = 0; attempt < 8; attempt++) try {
|
|
@@ -17433,6 +17472,7 @@ function recoverTransform(source, options) {
|
|
|
17433
17472
|
};
|
|
17434
17473
|
} catch (error) {
|
|
17435
17474
|
if (!(error instanceof TwillSyntaxError)) throw error;
|
|
17475
|
+
if (attempt === 0) onSyntaxError?.(error);
|
|
17436
17476
|
const before = text.slice(0, error.offset);
|
|
17437
17477
|
let insertion;
|
|
17438
17478
|
let offset = error.offset;
|
|
@@ -17697,13 +17737,18 @@ var TwillProject = class {
|
|
|
17697
17737
|
result(filename, source) {
|
|
17698
17738
|
const cached = this.results.get(filename);
|
|
17699
17739
|
if (cached?.source === source) return cached.result;
|
|
17700
|
-
const
|
|
17740
|
+
const options = {
|
|
17701
17741
|
...this.options,
|
|
17702
17742
|
filename
|
|
17703
|
-
}
|
|
17743
|
+
};
|
|
17744
|
+
let syntaxError;
|
|
17745
|
+
const result = this.recover ? recoverTransform(source, options, (error) => {
|
|
17746
|
+
syntaxError = error;
|
|
17747
|
+
}) : transform(source, options);
|
|
17704
17748
|
this.results.set(filename, {
|
|
17705
17749
|
source,
|
|
17706
|
-
result
|
|
17750
|
+
result,
|
|
17751
|
+
syntaxError
|
|
17707
17752
|
});
|
|
17708
17753
|
return result;
|
|
17709
17754
|
}
|
|
@@ -17797,11 +17842,9 @@ var TwillProject = class {
|
|
|
17797
17842
|
for (const file of files) {
|
|
17798
17843
|
if (/\.d\.[cm]?ts$/.test(file)) continue;
|
|
17799
17844
|
try {
|
|
17800
|
-
if (this.recover && isTwillFile(sourceFilename(file))) transform(this.text(file) ?? "", {
|
|
17801
|
-
...this.options,
|
|
17802
|
-
filename: sourceFilename(file)
|
|
17803
|
-
});
|
|
17804
17845
|
this.transformed(file);
|
|
17846
|
+
const syntaxError = this.results.get(sourceFilename(file))?.syntaxError;
|
|
17847
|
+
if (syntaxError) throw syntaxError;
|
|
17805
17848
|
result.push(...[...this.service.getSyntacticDiagnostics(file), ...this.service.getSemanticDiagnostics(file)].map((error) => this.diagnostic(error)));
|
|
17806
17849
|
} catch (error) {
|
|
17807
17850
|
const syntax = error;
|