@swiftuijs/twill 0.1.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/LICENSE +21 -0
- package/README.md +138 -0
- package/bin/twill.mjs +12 -0
- package/dist/branches.d.ts +12 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +128 -0
- package/dist/cli.js.map +1 -0
- package/dist/compiler-Bi9TNOhX.js +1127 -0
- package/dist/compiler-Bi9TNOhX.js.map +1 -0
- package/dist/compiler.d.ts +50 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +55 -0
- package/dist/config.js.map +1 -0
- package/dist/declarations.d.ts +14 -0
- package/dist/declarations.js +132 -0
- package/dist/declarations.js.map +1 -0
- package/dist/defer.d.ts +17 -0
- package/dist/doctor.d.ts +20 -0
- package/dist/doctor.js +198 -0
- package/dist/doctor.js.map +1 -0
- package/dist/editor.d.ts +53 -0
- package/dist/editor.js +261 -0
- package/dist/editor.js.map +1 -0
- package/dist/esbuild.d.ts +3 -0
- package/dist/esbuild.js +7 -0
- package/dist/esbuild.js.map +1 -0
- package/dist/files-D1mERoxc.js +46 -0
- package/dist/files-D1mERoxc.js.map +1 -0
- package/dist/files.d.ts +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/loader.d.ts +3 -0
- package/dist/loader.js +54 -0
- package/dist/loader.js.map +1 -0
- package/dist/parser.d.ts +9 -0
- package/dist/plugin-BGabvyT6.js +112 -0
- package/dist/plugin-BGabvyT6.js.map +1 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/project.d.ts +62 -0
- package/dist/project.js +416 -0
- package/dist/project.js.map +1 -0
- package/dist/recovery.d.ts +3 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +7 -0
- package/dist/register.js.map +1 -0
- package/dist/rollup.d.ts +3 -0
- package/dist/rollup.js +7 -0
- package/dist/rollup.js.map +1 -0
- package/dist/rspack.d.ts +3 -0
- package/dist/rspack.js +7 -0
- package/dist/rspack.js.map +1 -0
- package/dist/syntax.d.ts +11 -0
- package/dist/syntax.js +10 -0
- package/dist/syntax.js.map +1 -0
- package/dist/transpile-DwVekVFM.js +51 -0
- package/dist/transpile-DwVekVFM.js.map +1 -0
- package/dist/transpile.d.ts +11 -0
- package/dist/typescript-plugin.LICENSE.txt +375 -0
- package/dist/typescript-plugin.cjs +17741 -0
- package/dist/typescript-plugin.cjs.map +1 -0
- package/dist/typescript-plugin.d.ts +5 -0
- package/dist/vite-react.d.ts +10 -0
- package/dist/vite-react.js +22 -0
- package/dist/vite-react.js.map +1 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +7 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpack.d.ts +3 -0
- package/dist/webpack.js +7 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +180 -0
- package/schemas/twill.schema.json +16 -0
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { a as isTwillFile } from "./compiler-Bi9TNOhX.js";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
var package_default = {
|
|
4
|
+
name: "@swiftuijs/twill",
|
|
5
|
+
version: "0.1.0",
|
|
6
|
+
description: "Twill: a JS/TS syntax-sugar language with trailing closures, guards, block-scoped defer, build plugins, type checking, and editor support.",
|
|
7
|
+
main: "./dist/typescript-plugin.cjs",
|
|
8
|
+
repository: {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/swiftuijs/twill.git",
|
|
11
|
+
"directory": "packages/twill"
|
|
12
|
+
},
|
|
13
|
+
keywords: [
|
|
14
|
+
"javascript",
|
|
15
|
+
"typescript",
|
|
16
|
+
"trailing-closures",
|
|
17
|
+
"swift",
|
|
18
|
+
"vite",
|
|
19
|
+
"unplugin",
|
|
20
|
+
"react",
|
|
21
|
+
"vue",
|
|
22
|
+
"twill",
|
|
23
|
+
"guard",
|
|
24
|
+
"defer"
|
|
25
|
+
],
|
|
26
|
+
author: {
|
|
27
|
+
"name": "forth.ink",
|
|
28
|
+
"url": "https://forth.ink"
|
|
29
|
+
},
|
|
30
|
+
license: "MIT",
|
|
31
|
+
type: "module",
|
|
32
|
+
bugs: { "url": "https://github.com/swiftuijs/twill/issues" },
|
|
33
|
+
homepage: "https://swiftuijs.github.io/twill/",
|
|
34
|
+
dependencies: {
|
|
35
|
+
"@ampproject/remapping": "^2.3.0",
|
|
36
|
+
"@jridgewell/trace-mapping": "^0.3.31",
|
|
37
|
+
"acorn": "8.18.0",
|
|
38
|
+
"acorn-jsx": "^5.3.2",
|
|
39
|
+
"acorn-typescript": "1.4.13",
|
|
40
|
+
"magic-string": "^1.4.2",
|
|
41
|
+
"typescript": "catalog:",
|
|
42
|
+
"unplugin": "^3.4.0"
|
|
43
|
+
},
|
|
44
|
+
sideEffects: false,
|
|
45
|
+
engines: { "node": "^20.19.0 || >=22.12.0" },
|
|
46
|
+
files: [
|
|
47
|
+
"bin",
|
|
48
|
+
"dist/**/*.js",
|
|
49
|
+
"dist/**/*.js.map",
|
|
50
|
+
"dist/**/*.d.ts",
|
|
51
|
+
"schemas",
|
|
52
|
+
"README.md",
|
|
53
|
+
"LICENSE",
|
|
54
|
+
"dist/**/*.cjs",
|
|
55
|
+
"dist/**/*.cjs.map",
|
|
56
|
+
"dist/*.LICENSE.txt"
|
|
57
|
+
],
|
|
58
|
+
bin: { "twill": "./bin/twill.mjs" },
|
|
59
|
+
exports: {
|
|
60
|
+
".": {
|
|
61
|
+
"types": "./dist/index.d.ts",
|
|
62
|
+
"import": "./dist/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./vite": {
|
|
65
|
+
"types": "./dist/vite.d.ts",
|
|
66
|
+
"import": "./dist/vite.js"
|
|
67
|
+
},
|
|
68
|
+
"./rollup": {
|
|
69
|
+
"types": "./dist/rollup.d.ts",
|
|
70
|
+
"import": "./dist/rollup.js"
|
|
71
|
+
},
|
|
72
|
+
"./esbuild": {
|
|
73
|
+
"types": "./dist/esbuild.d.ts",
|
|
74
|
+
"import": "./dist/esbuild.js"
|
|
75
|
+
},
|
|
76
|
+
"./webpack": {
|
|
77
|
+
"types": "./dist/webpack.d.ts",
|
|
78
|
+
"import": "./dist/webpack.js"
|
|
79
|
+
},
|
|
80
|
+
"./rspack": {
|
|
81
|
+
"types": "./dist/rspack.d.ts",
|
|
82
|
+
"import": "./dist/rspack.js"
|
|
83
|
+
},
|
|
84
|
+
"./project": {
|
|
85
|
+
"types": "./dist/project.d.ts",
|
|
86
|
+
"import": "./dist/project.js"
|
|
87
|
+
},
|
|
88
|
+
"./editor": {
|
|
89
|
+
"types": "./dist/editor.d.ts",
|
|
90
|
+
"import": "./dist/editor.js"
|
|
91
|
+
},
|
|
92
|
+
"./register": {
|
|
93
|
+
"types": "./dist/register.d.ts",
|
|
94
|
+
"import": "./dist/register.js"
|
|
95
|
+
},
|
|
96
|
+
"./schema": "./schemas/twill.schema.json",
|
|
97
|
+
"./typescript-plugin": {
|
|
98
|
+
"types": "./dist/typescript-plugin.d.ts",
|
|
99
|
+
"require": "./dist/typescript-plugin.cjs",
|
|
100
|
+
"default": "./dist/typescript-plugin.cjs"
|
|
101
|
+
},
|
|
102
|
+
"./doctor": {
|
|
103
|
+
"types": "./dist/doctor.d.ts",
|
|
104
|
+
"import": "./dist/doctor.js"
|
|
105
|
+
},
|
|
106
|
+
"./syntax": {
|
|
107
|
+
"types": "./dist/syntax.d.ts",
|
|
108
|
+
"import": "./dist/syntax.js"
|
|
109
|
+
},
|
|
110
|
+
"./config": {
|
|
111
|
+
"types": "./dist/config.d.ts",
|
|
112
|
+
"import": "./dist/config.js"
|
|
113
|
+
},
|
|
114
|
+
"./declarations": {
|
|
115
|
+
"types": "./dist/declarations.d.ts",
|
|
116
|
+
"import": "./dist/declarations.js"
|
|
117
|
+
},
|
|
118
|
+
"./vite-react": {
|
|
119
|
+
"types": "./dist/vite-react.d.ts",
|
|
120
|
+
"import": "./dist/vite-react.js"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
peerDependencies: {
|
|
124
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
125
|
+
"vue": "^3.3.0",
|
|
126
|
+
"@vitejs/plugin-react": "^6.1.1"
|
|
127
|
+
},
|
|
128
|
+
peerDependenciesMeta: {
|
|
129
|
+
"react": { "optional": true },
|
|
130
|
+
"vue": { "optional": true },
|
|
131
|
+
"@vitejs/plugin-react": { "optional": true }
|
|
132
|
+
},
|
|
133
|
+
types: "./dist/index.d.ts",
|
|
134
|
+
publishConfig: { "access": "public" },
|
|
135
|
+
module: "./dist/index.js",
|
|
136
|
+
scripts: {
|
|
137
|
+
"build": "vite build && vite build --config vite.plugin.config.ts && node scripts/prepare-core.mjs",
|
|
138
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
139
|
+
"prepack": "pnpm run build",
|
|
140
|
+
"test:unit": "vitest run",
|
|
141
|
+
"test:watch": "vitest",
|
|
142
|
+
"test:coverage": "vitest run --coverage",
|
|
143
|
+
"test:package": "node tests/consumer.mjs",
|
|
144
|
+
"test:size": "node tests/bundle-size.mjs",
|
|
145
|
+
"test:browser": "playwright test",
|
|
146
|
+
"benchmark": "node benchmarks/compiler.mjs",
|
|
147
|
+
"test": "pnpm run test:unit",
|
|
148
|
+
"benchmark:branching": "node benchmarks/branching.mjs"
|
|
149
|
+
},
|
|
150
|
+
devDependencies: {
|
|
151
|
+
"vite": "catalog:",
|
|
152
|
+
"vite-plugin-dts": "^5.1.2",
|
|
153
|
+
"@types/node": "catalog:",
|
|
154
|
+
"@vitejs/plugin-react": "catalog:",
|
|
155
|
+
"vitest": "catalog:",
|
|
156
|
+
"@vitest/coverage-v8": "catalog:",
|
|
157
|
+
"@rspack/core": "catalog:",
|
|
158
|
+
"@types/react": "catalog:",
|
|
159
|
+
"@types/react-dom": "catalog:",
|
|
160
|
+
"@vue/server-renderer": "catalog:",
|
|
161
|
+
"esbuild": "catalog:",
|
|
162
|
+
"react": "catalog:",
|
|
163
|
+
"react-dom": "catalog:",
|
|
164
|
+
"rollup": "catalog:",
|
|
165
|
+
"vue": "catalog:",
|
|
166
|
+
"webpack": "catalog:",
|
|
167
|
+
"@playwright/test": "catalog:"
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/doctor.ts
|
|
172
|
+
/** Shareable diagnostics without source contents or environment-variable values. */
|
|
173
|
+
function inspectProject(project, filename) {
|
|
174
|
+
const started = performance.now();
|
|
175
|
+
const diagnostics = project.diagnostics(filename);
|
|
176
|
+
const files = project.sourceFiles();
|
|
177
|
+
return {
|
|
178
|
+
twillVersion: package_default.version,
|
|
179
|
+
typescriptVersion: ts.version,
|
|
180
|
+
nodeVersion: process.version,
|
|
181
|
+
root: project.root,
|
|
182
|
+
configFiles: project.configFiles,
|
|
183
|
+
compilerOptions: project.compilerOptions,
|
|
184
|
+
files: {
|
|
185
|
+
total: files.length,
|
|
186
|
+
twill: files.filter(isTwillFile).length,
|
|
187
|
+
native: files.filter((file) => !isTwillFile(file)).length
|
|
188
|
+
},
|
|
189
|
+
sourceFiles: files,
|
|
190
|
+
diagnostics,
|
|
191
|
+
diagnosticTimeMs: performance.now() - started,
|
|
192
|
+
ok: !diagnostics.some((diagnostic) => diagnostic.category === "error")
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
export { inspectProject };
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","names":["metadata"],"sources":["../package.json","../src/doctor.ts"],"sourcesContent":["{\n \"name\": \"@swiftuijs/twill\",\n \"version\": \"0.1.0\",\n \"description\": \"Twill: a JS/TS syntax-sugar language with trailing closures, guards, block-scoped defer, build plugins, type checking, and editor support.\",\n \"main\": \"./dist/typescript-plugin.cjs\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/swiftuijs/twill.git\",\n \"directory\": \"packages/twill\"\n },\n \"keywords\": [\n \"javascript\",\n \"typescript\",\n \"trailing-closures\",\n \"swift\",\n \"vite\",\n \"unplugin\",\n \"react\",\n \"vue\",\n \"twill\",\n \"guard\",\n \"defer\"\n ],\n \"author\": {\n \"name\": \"forth.ink\",\n \"url\": \"https://forth.ink\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"bugs\": {\n \"url\": \"https://github.com/swiftuijs/twill/issues\"\n },\n \"homepage\": \"https://swiftuijs.github.io/twill/\",\n \"dependencies\": {\n \"@ampproject/remapping\": \"^2.3.0\",\n \"@jridgewell/trace-mapping\": \"^0.3.31\",\n \"acorn\": \"8.18.0\",\n \"acorn-jsx\": \"^5.3.2\",\n \"acorn-typescript\": \"1.4.13\",\n \"magic-string\": \"^1.4.2\",\n \"typescript\": \"catalog:\",\n \"unplugin\": \"^3.4.0\"\n },\n \"sideEffects\": false,\n \"engines\": {\n \"node\": \"^20.19.0 || >=22.12.0\"\n },\n \"files\": [\n \"bin\",\n \"dist/**/*.js\",\n \"dist/**/*.js.map\",\n \"dist/**/*.d.ts\",\n \"schemas\",\n \"README.md\",\n \"LICENSE\",\n \"dist/**/*.cjs\",\n \"dist/**/*.cjs.map\",\n \"dist/*.LICENSE.txt\"\n ],\n \"bin\": {\n \"twill\": \"./bin/twill.mjs\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./vite\": {\n \"types\": \"./dist/vite.d.ts\",\n \"import\": \"./dist/vite.js\"\n },\n \"./rollup\": {\n \"types\": \"./dist/rollup.d.ts\",\n \"import\": \"./dist/rollup.js\"\n },\n \"./esbuild\": {\n \"types\": \"./dist/esbuild.d.ts\",\n \"import\": \"./dist/esbuild.js\"\n },\n \"./webpack\": {\n \"types\": \"./dist/webpack.d.ts\",\n \"import\": \"./dist/webpack.js\"\n },\n \"./rspack\": {\n \"types\": \"./dist/rspack.d.ts\",\n \"import\": \"./dist/rspack.js\"\n },\n \"./project\": {\n \"types\": \"./dist/project.d.ts\",\n \"import\": \"./dist/project.js\"\n },\n \"./editor\": {\n \"types\": \"./dist/editor.d.ts\",\n \"import\": \"./dist/editor.js\"\n },\n \"./register\": {\n \"types\": \"./dist/register.d.ts\",\n \"import\": \"./dist/register.js\"\n },\n \"./schema\": \"./schemas/twill.schema.json\",\n \"./typescript-plugin\": {\n \"types\": \"./dist/typescript-plugin.d.ts\",\n \"require\": \"./dist/typescript-plugin.cjs\",\n \"default\": \"./dist/typescript-plugin.cjs\"\n },\n \"./doctor\": {\n \"types\": \"./dist/doctor.d.ts\",\n \"import\": \"./dist/doctor.js\"\n },\n \"./syntax\": {\n \"types\": \"./dist/syntax.d.ts\",\n \"import\": \"./dist/syntax.js\"\n },\n \"./config\": {\n \"types\": \"./dist/config.d.ts\",\n \"import\": \"./dist/config.js\"\n },\n \"./declarations\": {\n \"types\": \"./dist/declarations.d.ts\",\n \"import\": \"./dist/declarations.js\"\n },\n \"./vite-react\": {\n \"types\": \"./dist/vite-react.d.ts\",\n \"import\": \"./dist/vite-react.js\"\n }\n },\n \"peerDependencies\": {\n \"react\": \"^18.2.0 || ^19.0.0\",\n \"vue\": \"^3.3.0\",\n \"@vitejs/plugin-react\": \"^6.1.1\"\n },\n \"peerDependenciesMeta\": {\n \"react\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"@vitejs/plugin-react\": {\n \"optional\": true\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"module\": \"./dist/index.js\",\n \"scripts\": {\n \"build\": \"vite build && vite build --config vite.plugin.config.ts && node scripts/prepare-core.mjs\",\n \"typecheck\": \"tsc --noEmit -p tsconfig.json\",\n \"prepack\": \"pnpm run build\",\n \"test:unit\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"test:coverage\": \"vitest run --coverage\",\n \"test:package\": \"node tests/consumer.mjs\",\n \"test:size\": \"node tests/bundle-size.mjs\",\n \"test:browser\": \"playwright test\",\n \"benchmark\": \"node benchmarks/compiler.mjs\",\n \"test\": \"pnpm run test:unit\",\n \"benchmark:branching\": \"node benchmarks/branching.mjs\"\n },\n \"devDependencies\": {\n \"vite\": \"catalog:\",\n \"vite-plugin-dts\": \"^5.1.2\",\n \"@types/node\": \"catalog:\",\n \"@vitejs/plugin-react\": \"catalog:\",\n \"vitest\": \"catalog:\",\n \"@vitest/coverage-v8\": \"catalog:\",\n \"@rspack/core\": \"catalog:\",\n \"@types/react\": \"catalog:\",\n \"@types/react-dom\": \"catalog:\",\n \"@vue/server-renderer\": \"catalog:\",\n \"esbuild\": \"catalog:\",\n \"react\": \"catalog:\",\n \"react-dom\": \"catalog:\",\n \"rollup\": \"catalog:\",\n \"vue\": \"catalog:\",\n \"webpack\": \"catalog:\",\n \"@playwright/test\": \"catalog:\"\n }\n}\n","import ts from 'typescript';\nimport metadata from '../package.json';\nimport { TwillProject } from './project.js';\nimport { isTwillFile } from './compiler.js';\n\n/** Shareable diagnostics without source contents or environment-variable values. */\nexport function inspectProject(project: TwillProject, filename?: string) {\n const started = performance.now();\n const diagnostics = project.diagnostics(filename);\n const files = project.sourceFiles();\n return {\n twillVersion: metadata.version,\n typescriptVersion: ts.version,\n nodeVersion: process.version,\n root: project.root,\n configFiles: project.configFiles,\n compilerOptions: project.compilerOptions,\n files: {\n total: files.length,\n twill: files.filter(isTwillFile).length,\n native: files.filter((file) => !isTwillFile(file)).length,\n },\n sourceFiles: files,\n diagnostics,\n diagnosticTimeMs: performance.now() - started,\n ok: !diagnostics.some((diagnostic) => diagnostic.category === 'error'),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACMA,SAAgB,eAAe,SAAuB,UAAmB;CACvE,MAAM,UAAU,YAAY,IAAI;CAChC,MAAM,cAAc,QAAQ,YAAY,QAAQ;CAChD,MAAM,QAAQ,QAAQ,YAAY;CAClC,OAAO;EACL,cAAcA,gBAAS;EACvB,mBAAmB,GAAG;EACtB,aAAa,QAAQ;EACrB,MAAM,QAAQ;EACd,aAAa,QAAQ;EACrB,iBAAiB,QAAQ;EACzB,OAAO;GACL,OAAO,MAAM;GACb,OAAO,MAAM,OAAO,WAAW,CAAC,CAAC;GACjC,QAAQ,MAAM,QAAQ,SAAS,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC;EACrD;EACA,aAAa;EACb;EACA,kBAAkB,YAAY,IAAI,IAAI;EACtC,IAAI,CAAC,YAAY,MAAM,eAAe,WAAW,aAAa,OAAO;CACvE;AACF"}
|
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { default as ts } from 'typescript';
|
|
2
|
+
import { TwillProject } from './project.js';
|
|
3
|
+
export interface SourceEdit {
|
|
4
|
+
filename: string;
|
|
5
|
+
span: ts.TextSpan;
|
|
6
|
+
newText: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CompletionRequest {
|
|
9
|
+
offset: number;
|
|
10
|
+
info: ts.CompletionInfo | undefined;
|
|
11
|
+
props?: {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Shared semantic requests and conservative source edits for both editor hosts. */
|
|
17
|
+
export declare class TwillEditor {
|
|
18
|
+
readonly project: TwillProject;
|
|
19
|
+
private attributeCache;
|
|
20
|
+
constructor(project: TwillProject);
|
|
21
|
+
private sourceFile;
|
|
22
|
+
private attributes;
|
|
23
|
+
completionLocation(filename: string, position: number): {
|
|
24
|
+
offset: number;
|
|
25
|
+
props: {
|
|
26
|
+
start: number;
|
|
27
|
+
end: number;
|
|
28
|
+
} | undefined;
|
|
29
|
+
};
|
|
30
|
+
completions(filename: string, position: number, preferences?: ts.UserPreferences): {
|
|
31
|
+
offset: number;
|
|
32
|
+
info: ts.WithMetadata<ts.CompletionInfo> | undefined;
|
|
33
|
+
props: {
|
|
34
|
+
start: number;
|
|
35
|
+
end: number;
|
|
36
|
+
} | undefined;
|
|
37
|
+
};
|
|
38
|
+
/** Never stretch a generated edit across lowered punctuation or helper code. */
|
|
39
|
+
mapSpan(filename: string, span: ts.TextSpan): ts.TextSpan | undefined;
|
|
40
|
+
mapChanges(changes: readonly ts.FileTextChanges[]): SourceEdit[] | undefined;
|
|
41
|
+
private importText;
|
|
42
|
+
organizeImports(filename: string, mode?: ts.OrganizeImportsMode): SourceEdit[] | undefined;
|
|
43
|
+
/** Read-only navigation must also exclude generated helpers and duplicate JSX tags. */
|
|
44
|
+
referenceGroups(filename: string, position: number): ts.ReferencedSymbol[] | undefined;
|
|
45
|
+
references(filename: string, position: number): ts.ReferencedSymbolEntry[] | undefined;
|
|
46
|
+
renameInfo(filename: string, position: number): ts.RenameInfo;
|
|
47
|
+
renameLocations(filename: string, position: number, preferences?: ts.UserPreferences | boolean): ts.RenameLocation[] | undefined;
|
|
48
|
+
rename(filename: string, position: number, name: string, preferences?: ts.UserPreferences | boolean): SourceEdit[] | undefined;
|
|
49
|
+
fixes(filename: string, start: number, end: number, codes: readonly number[]): {
|
|
50
|
+
description: string;
|
|
51
|
+
edits: SourceEdit[];
|
|
52
|
+
}[];
|
|
53
|
+
}
|
package/dist/editor.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { a as isTwillFile } from "./compiler-Bi9TNOhX.js";
|
|
2
|
+
import { sourceFilename, virtualFilename } from "./project.js";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
//#region src/editor.ts
|
|
5
|
+
/** Shared semantic requests and conservative source edits for both editor hosts. */
|
|
6
|
+
var TwillEditor = class {
|
|
7
|
+
project;
|
|
8
|
+
attributeCache = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
constructor(project) {
|
|
10
|
+
this.project = project;
|
|
11
|
+
}
|
|
12
|
+
sourceFile(filename) {
|
|
13
|
+
return this.project.service.getProgram()?.getSourceFile(virtualFilename(filename));
|
|
14
|
+
}
|
|
15
|
+
attributes(filename) {
|
|
16
|
+
const file = this.sourceFile(filename);
|
|
17
|
+
if (!file) return [];
|
|
18
|
+
const cached = this.attributeCache.get(file);
|
|
19
|
+
if (cached) return cached;
|
|
20
|
+
const result = [];
|
|
21
|
+
const visit = (node) => {
|
|
22
|
+
if (ts.isJsxAttribute(node)) result.push(node);
|
|
23
|
+
ts.forEachChild(node, visit);
|
|
24
|
+
};
|
|
25
|
+
visit(file);
|
|
26
|
+
this.attributeCache.set(file, result);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
completionLocation(filename, position) {
|
|
30
|
+
let offset = this.project.toGeneratedOffset(filename, position);
|
|
31
|
+
const prefix = this.project.text(filename)?.slice(0, position);
|
|
32
|
+
const member = prefix?.match(/\.([\p{ID_Continue}$\u200c\u200d]*)$/u);
|
|
33
|
+
const missingMember = prefix?.match(/\.\s*$/);
|
|
34
|
+
if (member) offset = this.project.toGeneratedOffset(filename, member.index) + member[0].length;
|
|
35
|
+
else if (missingMember) offset = this.project.toGeneratedOffset(filename, missingMember.index) + 1;
|
|
36
|
+
let props;
|
|
37
|
+
const metadata = this.project.transformed(filename)?.componentProps;
|
|
38
|
+
const property = metadata?.flatMap((object) => object.properties).find((item) => item.shorthand && position >= item.start && position <= item.end);
|
|
39
|
+
if (property) {
|
|
40
|
+
const attribute = this.attributes(filename).find((item) => item.name.getText() === property.name && item.initializer && ts.isJsxExpression(item.initializer) && item.initializer.expression && this.project.toOriginalOffset(filename, item.initializer.expression.getStart()) === property.start);
|
|
41
|
+
if (attribute) {
|
|
42
|
+
offset = attribute.name.getStart() + position - property.start;
|
|
43
|
+
props = {
|
|
44
|
+
start: property.start,
|
|
45
|
+
end: property.end
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
} else if (metadata?.some((object) => position > object.start && position < object.end) && !this.attributes(filename).some((attribute) => offset >= attribute.name.end && offset <= attribute.end)) props = {
|
|
49
|
+
start: position,
|
|
50
|
+
end: position
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
offset,
|
|
54
|
+
props
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
completions(filename, position, preferences = {}) {
|
|
58
|
+
let { offset, props } = this.completionLocation(filename, position);
|
|
59
|
+
const info = this.project.service.getCompletionsAtPosition(virtualFilename(filename), offset, {
|
|
60
|
+
includeCompletionsForModuleExports: true,
|
|
61
|
+
includeCompletionsWithInsertText: true,
|
|
62
|
+
...preferences
|
|
63
|
+
});
|
|
64
|
+
if (props && !info?.isMemberCompletion) props = void 0;
|
|
65
|
+
return {
|
|
66
|
+
offset,
|
|
67
|
+
info,
|
|
68
|
+
props
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Never stretch a generated edit across lowered punctuation or helper code. */
|
|
72
|
+
mapSpan(filename, span) {
|
|
73
|
+
filename = sourceFilename(filename);
|
|
74
|
+
const source = this.project.text(filename);
|
|
75
|
+
if (source === void 0) return void 0;
|
|
76
|
+
if (!isTwillFile(filename)) return span.start >= 0 && span.start + span.length <= source.length ? span : void 0;
|
|
77
|
+
const generated = this.project.transformed(filename)?.code;
|
|
78
|
+
if (generated === void 0) return void 0;
|
|
79
|
+
const start = this.project.toOriginalOffset(filename, span.start);
|
|
80
|
+
if (start < 0 || start + span.length > source.length || this.project.toGeneratedOffset(filename, start) !== span.start || source.slice(start, start + span.length) !== generated.slice(span.start, span.start + span.length)) return void 0;
|
|
81
|
+
return {
|
|
82
|
+
start,
|
|
83
|
+
length: span.length
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
mapChanges(changes) {
|
|
87
|
+
const edits = [];
|
|
88
|
+
for (const file of changes) {
|
|
89
|
+
if (file.isNewFile) return void 0;
|
|
90
|
+
const filename = sourceFilename(file.fileName);
|
|
91
|
+
for (const change of file.textChanges) {
|
|
92
|
+
let span = this.mapSpan(filename, change.span);
|
|
93
|
+
if (!span && change.span.length === 0 && /^\s*import\b/.test(change.newText)) {
|
|
94
|
+
const firstStatement = this.sourceFile(filename)?.statements[0];
|
|
95
|
+
if (change.span.start <= (firstStatement?.getStart() ?? 0)) span = {
|
|
96
|
+
start: 0,
|
|
97
|
+
length: 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (!span) return void 0;
|
|
101
|
+
edits.push({
|
|
102
|
+
filename,
|
|
103
|
+
span,
|
|
104
|
+
newText: this.importText(change.newText)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return edits;
|
|
109
|
+
}
|
|
110
|
+
importText(text) {
|
|
111
|
+
const file = ts.createSourceFile("edits.ts", text, ts.ScriptTarget.Latest, true);
|
|
112
|
+
const replacements = [];
|
|
113
|
+
for (const statement of file.statements) if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
114
|
+
const literal = statement.moduleSpecifier;
|
|
115
|
+
const value = sourceFilename(literal.text);
|
|
116
|
+
if (value !== literal.text) replacements.push({
|
|
117
|
+
start: literal.getStart() + 1,
|
|
118
|
+
end: literal.end - 1,
|
|
119
|
+
text: value
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
for (const replacement of replacements.reverse()) text = text.slice(0, replacement.start) + replacement.text + text.slice(replacement.end);
|
|
123
|
+
return text;
|
|
124
|
+
}
|
|
125
|
+
organizeImports(filename, mode = ts.OrganizeImportsMode.All) {
|
|
126
|
+
return this.mapChanges(this.project.service.organizeImports({
|
|
127
|
+
type: "file",
|
|
128
|
+
fileName: virtualFilename(filename),
|
|
129
|
+
mode
|
|
130
|
+
}, {}, {}));
|
|
131
|
+
}
|
|
132
|
+
/** Read-only navigation must also exclude generated helpers and duplicate JSX tags. */
|
|
133
|
+
referenceGroups(filename, position) {
|
|
134
|
+
const groups = this.project.service.findReferences(virtualFilename(filename), this.project.toGeneratedOffset(filename, position));
|
|
135
|
+
const mapped = (entry) => {
|
|
136
|
+
const fileName = sourceFilename(entry.fileName);
|
|
137
|
+
const textSpan = this.mapSpan(fileName, entry.textSpan);
|
|
138
|
+
if (!textSpan) return void 0;
|
|
139
|
+
const contextSpan = entry.contextSpan && this.mapSpan(fileName, entry.contextSpan);
|
|
140
|
+
return {
|
|
141
|
+
...entry,
|
|
142
|
+
fileName,
|
|
143
|
+
textSpan,
|
|
144
|
+
contextSpan
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
return groups?.flatMap((group) => {
|
|
148
|
+
const definition = mapped(group.definition);
|
|
149
|
+
if (!definition) return [];
|
|
150
|
+
const seen = /* @__PURE__ */ new Set();
|
|
151
|
+
return [{
|
|
152
|
+
definition,
|
|
153
|
+
references: group.references.flatMap((reference) => {
|
|
154
|
+
const entry = mapped(reference);
|
|
155
|
+
if (!entry) return [];
|
|
156
|
+
entry.isDefinition ??= entry.fileName === definition.fileName && entry.textSpan.start === definition.textSpan.start && entry.textSpan.length === definition.textSpan.length;
|
|
157
|
+
const key = `${entry.fileName}:${entry.textSpan.start}:${entry.textSpan.length}`;
|
|
158
|
+
if (seen.has(key)) return [];
|
|
159
|
+
seen.add(key);
|
|
160
|
+
return [entry];
|
|
161
|
+
})
|
|
162
|
+
}];
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
references(filename, position) {
|
|
166
|
+
return this.referenceGroups(filename, position)?.flatMap((group) => group.references);
|
|
167
|
+
}
|
|
168
|
+
renameInfo(filename, position) {
|
|
169
|
+
const info = this.project.service.getRenameInfo(virtualFilename(filename), this.project.toGeneratedOffset(filename, position), { allowRenameOfImportPath: false });
|
|
170
|
+
if (!info.canRename) return info;
|
|
171
|
+
const span = this.mapSpan(filename, info.triggerSpan);
|
|
172
|
+
return span ? {
|
|
173
|
+
...info,
|
|
174
|
+
triggerSpan: span
|
|
175
|
+
} : {
|
|
176
|
+
canRename: false,
|
|
177
|
+
localizedErrorMessage: "This generated symbol cannot be renamed in Twill source."
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
renameLocations(filename, position, preferences = true) {
|
|
181
|
+
if (!this.renameInfo(filename, position).canRename) return void 0;
|
|
182
|
+
const locations = this.project.service.findRenameLocations(virtualFilename(filename), this.project.toGeneratedOffset(filename, position), false, false, typeof preferences === "boolean" ? { providePrefixAndSuffixTextForRename: preferences } : preferences);
|
|
183
|
+
if (!locations) return void 0;
|
|
184
|
+
const result = [];
|
|
185
|
+
for (const location of locations) {
|
|
186
|
+
const file = sourceFilename(location.fileName);
|
|
187
|
+
let span = this.mapSpan(file, location.textSpan);
|
|
188
|
+
let prefixText = location.prefixText;
|
|
189
|
+
let suffixText = location.suffixText;
|
|
190
|
+
if (isTwillFile(file)) {
|
|
191
|
+
const attribute = this.attributes(file).find((item) => item.name.getStart() === location.textSpan.start && item.initializer && ts.isJsxExpression(item.initializer) && item.initializer.expression);
|
|
192
|
+
if (attribute && attribute.initializer && ts.isJsxExpression(attribute.initializer)) {
|
|
193
|
+
const original = this.project.toOriginalOffset(file, attribute.initializer.expression.getStart());
|
|
194
|
+
const property = this.project.transformed(file)?.componentProps.flatMap((object) => object.properties).find((item) => item.name === attribute.name.getText() && (item.shorthand ? item.start === original : item.start === this.project.toOriginalOffset(file, attribute.name.getStart())));
|
|
195
|
+
if (property) {
|
|
196
|
+
span = {
|
|
197
|
+
start: property.start,
|
|
198
|
+
length: property.end - property.start
|
|
199
|
+
};
|
|
200
|
+
if (property.shorthand) suffixText = `: ${property.name}`;
|
|
201
|
+
else {
|
|
202
|
+
const quote = this.project.text(file)?.[property.start];
|
|
203
|
+
if (quote === "\"" || quote === "'") {
|
|
204
|
+
prefixText = quote;
|
|
205
|
+
suffixText = quote;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} else if (span) {
|
|
210
|
+
const property = this.project.transformed(file)?.componentProps.flatMap((object) => object.properties).find((item) => item.shorthand && item.start === span.start);
|
|
211
|
+
if (property) prefixText = `${property.name}: `;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!span) {
|
|
215
|
+
const generated = this.project.transformed(file)?.code;
|
|
216
|
+
const start = this.project.toOriginalOffset(file, location.textSpan.start);
|
|
217
|
+
if (generated && this.project.text(file)?.slice(start, start + location.textSpan.length) !== generated.slice(location.textSpan.start, location.textSpan.start + location.textSpan.length)) continue;
|
|
218
|
+
const sf = this.sourceFile(file);
|
|
219
|
+
let closing = false;
|
|
220
|
+
const visit = (node) => {
|
|
221
|
+
if (ts.isJsxClosingElement(node) && location.textSpan.start >= node.tagName.getStart() && location.textSpan.start < node.tagName.end) closing = true;
|
|
222
|
+
else if (location.textSpan.start >= node.getFullStart() && location.textSpan.start < node.end) ts.forEachChild(node, visit);
|
|
223
|
+
};
|
|
224
|
+
if (sf) visit(sf);
|
|
225
|
+
if (closing) continue;
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
result.push({
|
|
229
|
+
...location,
|
|
230
|
+
fileName: file,
|
|
231
|
+
textSpan: span,
|
|
232
|
+
prefixText,
|
|
233
|
+
suffixText,
|
|
234
|
+
contextSpan: location.contextSpan ? this.mapSpan(file, location.contextSpan) : void 0
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return result.filter((item, index) => result.findIndex((other) => item.fileName === other.fileName && item.textSpan.start === other.textSpan.start && item.textSpan.length === other.textSpan.length) === index);
|
|
238
|
+
}
|
|
239
|
+
rename(filename, position, name, preferences = true) {
|
|
240
|
+
const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, ts.LanguageVariant.Standard, name);
|
|
241
|
+
if (scanner.scan() !== ts.SyntaxKind.Identifier || scanner.scan() !== ts.SyntaxKind.EndOfFileToken) return void 0;
|
|
242
|
+
return this.renameLocations(filename, position, preferences)?.map((location) => ({
|
|
243
|
+
filename: location.fileName,
|
|
244
|
+
span: location.textSpan,
|
|
245
|
+
newText: (location.prefixText ?? "") + name + (location.suffixText ?? "")
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
fixes(filename, start, end, codes) {
|
|
249
|
+
return this.project.service.getCodeFixesAtPosition(virtualFilename(filename), this.project.toGeneratedOffset(filename, start), this.project.toGeneratedOffset(filename, end), codes, {}, {}).flatMap((fix) => {
|
|
250
|
+
const edits = this.mapChanges(fix.changes);
|
|
251
|
+
return edits?.length && !fix.commands?.length ? [{
|
|
252
|
+
description: fix.description,
|
|
253
|
+
edits
|
|
254
|
+
}] : [];
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
//#endregion
|
|
259
|
+
export { TwillEditor };
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","names":[],"sources":["../src/editor.ts"],"sourcesContent":["import ts from 'typescript';\nimport { TwillProject, sourceFilename, virtualFilename } from './project.js';\nimport { isTwillFile } from './compiler.js';\n\nexport interface SourceEdit {\n filename: string;\n span: ts.TextSpan;\n newText: string;\n}\n\nexport interface CompletionRequest {\n offset: number;\n info: ts.CompletionInfo | undefined;\n props?: { start: number; end: number };\n}\n\n/** Shared semantic requests and conservative source edits for both editor hosts. */\nexport class TwillEditor {\n private attributeCache = new WeakMap<ts.SourceFile, ts.JsxAttribute[]>();\n constructor(readonly project: TwillProject) {}\n\n private sourceFile(filename: string) {\n return this.project.service.getProgram()?.getSourceFile(virtualFilename(filename));\n }\n\n private attributes(filename: string) {\n const file = this.sourceFile(filename);\n if (!file) return [];\n const cached = this.attributeCache.get(file);\n if (cached) return cached;\n const result: ts.JsxAttribute[] = [];\n const visit = (node: ts.Node) => {\n if (ts.isJsxAttribute(node)) result.push(node);\n ts.forEachChild(node, visit);\n };\n visit(file);\n this.attributeCache.set(file, result);\n return result;\n }\n\n completionLocation(filename: string, position: number) {\n let offset = this.project.toGeneratedOffset(filename, position);\n // A repaired member name and generated arm punctuation can share the same\n // original boundary. Anchor requests at the source-backed dot instead.\n const prefix = this.project.text(filename)?.slice(0, position);\n const member = prefix?.match(/\\.([\\p{ID_Continue}$\\u200c\\u200d]*)$/u);\n const missingMember = prefix?.match(/\\.\\s*$/);\n if (member) offset = this.project.toGeneratedOffset(filename, member.index!) + member[0].length;\n else if (missingMember)\n offset = this.project.toGeneratedOffset(filename, missingMember.index!) + 1;\n let props: CompletionRequest['props'];\n const metadata = this.project.transformed(filename)?.componentProps;\n const property = metadata\n ?.flatMap((object) => object.properties)\n .find((item) => item.shorthand && position >= item.start && position <= item.end);\n if (property) {\n const attribute = this.attributes(filename).find(\n (item) =>\n item.name.getText() === property.name &&\n item.initializer &&\n ts.isJsxExpression(item.initializer) &&\n item.initializer.expression &&\n this.project.toOriginalOffset(filename, item.initializer.expression.getStart()) ===\n property.start,\n );\n if (attribute) {\n offset = attribute.name.getStart() + position - property.start;\n props = { start: property.start, end: property.end };\n }\n } else if (\n metadata?.some((object) => position > object.start && position < object.end) &&\n !this.attributes(filename).some(\n (attribute) => offset >= attribute.name.end && offset <= attribute.end,\n )\n ) {\n // Empty objects and gaps between properties already map to JSX attribute\n // positions. Only classify requests that TS identifies as member lists.\n props = { start: position, end: position };\n }\n return { offset, props };\n }\n\n completions(filename: string, position: number, preferences: ts.UserPreferences = {}) {\n let { offset, props } = this.completionLocation(filename, position);\n const info = this.project.service.getCompletionsAtPosition(virtualFilename(filename), offset, {\n includeCompletionsForModuleExports: true,\n includeCompletionsWithInsertText: true,\n ...preferences,\n });\n if (props && !info?.isMemberCompletion) props = undefined;\n return { offset, info, props } satisfies CompletionRequest;\n }\n\n /** Never stretch a generated edit across lowered punctuation or helper code. */\n mapSpan(filename: string, span: ts.TextSpan): ts.TextSpan | undefined {\n filename = sourceFilename(filename);\n const source = this.project.text(filename);\n if (source === undefined) return undefined;\n if (!isTwillFile(filename))\n return span.start >= 0 && span.start + span.length <= source.length ? span : undefined;\n const generated = this.project.transformed(filename)?.code;\n if (generated === undefined) return undefined;\n const start = this.project.toOriginalOffset(filename, span.start);\n if (\n start < 0 ||\n start + span.length > source.length ||\n this.project.toGeneratedOffset(filename, start) !== span.start ||\n source.slice(start, start + span.length) !==\n generated.slice(span.start, span.start + span.length)\n )\n return undefined;\n return { start, length: span.length };\n }\n\n mapChanges(changes: readonly ts.FileTextChanges[]): SourceEdit[] | undefined {\n const edits: SourceEdit[] = [];\n for (const file of changes) {\n if (file.isNewFile) return undefined;\n const filename = sourceFilename(file.fileName);\n for (const change of file.textChanges) {\n let span = this.mapSpan(filename, change.span);\n // Inferred JSX runtime pragmas can precede the first source token.\n // A fresh import can safely be inserted before the original module.\n if (!span && change.span.length === 0 && /^\\s*import\\b/.test(change.newText)) {\n const firstStatement = this.sourceFile(filename)?.statements[0];\n if (change.span.start <= (firstStatement?.getStart() ?? 0))\n span = { start: 0, length: 0 };\n }\n if (!span) return undefined;\n edits.push({ filename, span, newText: this.importText(change.newText) });\n }\n }\n return edits;\n }\n\n private importText(text: string) {\n // Edit only module literals, never user strings in an unrelated code fix.\n const file = ts.createSourceFile('edits.ts', text, ts.ScriptTarget.Latest, true);\n const replacements: { start: number; end: number; text: string }[] = [];\n for (const statement of file.statements) {\n if (\n (ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) &&\n statement.moduleSpecifier &&\n ts.isStringLiteral(statement.moduleSpecifier)\n ) {\n const literal = statement.moduleSpecifier;\n const value = sourceFilename(literal.text);\n if (value !== literal.text)\n replacements.push({ start: literal.getStart() + 1, end: literal.end - 1, text: value });\n }\n }\n for (const replacement of replacements.reverse())\n text = text.slice(0, replacement.start) + replacement.text + text.slice(replacement.end);\n return text;\n }\n\n organizeImports(filename: string, mode = ts.OrganizeImportsMode.All) {\n return this.mapChanges(\n this.project.service.organizeImports(\n { type: 'file', fileName: virtualFilename(filename), mode },\n {},\n {},\n ),\n );\n }\n\n /** Read-only navigation must also exclude generated helpers and duplicate JSX tags. */\n referenceGroups(filename: string, position: number): ts.ReferencedSymbol[] | undefined {\n const groups = this.project.service.findReferences(\n virtualFilename(filename),\n this.project.toGeneratedOffset(filename, position),\n );\n const mapped = <T extends ts.DocumentSpan>(entry: T): T | undefined => {\n const fileName = sourceFilename(entry.fileName);\n const textSpan = this.mapSpan(fileName, entry.textSpan);\n if (!textSpan) return undefined;\n const contextSpan = entry.contextSpan && this.mapSpan(fileName, entry.contextSpan);\n return { ...entry, fileName, textSpan, contextSpan };\n };\n return groups?.flatMap((group) => {\n const definition = mapped(group.definition);\n if (!definition) return [];\n const seen = new Set<string>();\n const references = group.references.flatMap((reference) => {\n const entry = mapped(reference);\n if (!entry) return [];\n // Some TS versions omit isDefinition from findReferences results.\n // Preserve supplied flags; otherwise compare the source-backed span\n // with this symbol group's definition for includeDeclaration requests.\n entry.isDefinition ??=\n entry.fileName === definition.fileName &&\n entry.textSpan.start === definition.textSpan.start &&\n entry.textSpan.length === definition.textSpan.length;\n const key = `${entry.fileName}:${entry.textSpan.start}:${entry.textSpan.length}`;\n if (seen.has(key)) return [];\n seen.add(key);\n return [entry];\n });\n return [{ definition, references }];\n });\n }\n\n references(filename: string, position: number) {\n return this.referenceGroups(filename, position)?.flatMap((group) => group.references);\n }\n\n renameInfo(filename: string, position: number): ts.RenameInfo {\n const info = this.project.service.getRenameInfo(\n virtualFilename(filename),\n this.project.toGeneratedOffset(filename, position),\n { allowRenameOfImportPath: false },\n );\n if (!info.canRename) return info;\n const span = this.mapSpan(filename, info.triggerSpan);\n return span\n ? { ...info, triggerSpan: span }\n : {\n canRename: false,\n localizedErrorMessage: 'This generated symbol cannot be renamed in Twill source.',\n };\n }\n\n renameLocations(\n filename: string,\n position: number,\n preferences: ts.UserPreferences | boolean = true,\n ) {\n const info = this.renameInfo(filename, position);\n if (!info.canRename) return undefined;\n const locations = this.project.service.findRenameLocations(\n virtualFilename(filename),\n this.project.toGeneratedOffset(filename, position),\n false,\n false,\n typeof preferences === 'boolean'\n ? { providePrefixAndSuffixTextForRename: preferences }\n : preferences,\n );\n if (!locations) return undefined;\n const result: ts.RenameLocation[] = [];\n for (const location of locations) {\n const file = sourceFilename(location.fileName);\n let span = this.mapSpan(file, location.textSpan);\n let prefixText = location.prefixText;\n let suffixText = location.suffixText;\n if (isTwillFile(file)) {\n const attribute = this.attributes(file).find(\n (item) =>\n item.name.getStart() === location.textSpan.start &&\n item.initializer &&\n ts.isJsxExpression(item.initializer) &&\n item.initializer.expression,\n );\n if (attribute && attribute.initializer && ts.isJsxExpression(attribute.initializer)) {\n const original = this.project.toOriginalOffset(\n file,\n attribute.initializer.expression!.getStart(),\n );\n const property = this.project\n .transformed(file)\n ?.componentProps.flatMap((object) => object.properties)\n .find(\n (item) =>\n item.name === attribute.name.getText() &&\n (item.shorthand\n ? item.start === original\n : item.start === this.project.toOriginalOffset(file, attribute.name.getStart())),\n );\n if (property) {\n span = { start: property.start, length: property.end - property.start };\n if (property.shorthand) suffixText = `: ${property.name}`;\n else {\n const quote = this.project.text(file)?.[property.start];\n if (quote === '\"' || quote === \"'\") {\n prefixText = quote;\n suffixText = quote;\n }\n }\n }\n } else if (span) {\n const property = this.project\n .transformed(file)\n ?.componentProps.flatMap((object) => object.properties)\n .find((item) => item.shorthand && item.start === span!.start);\n if (property) prefixText = `${property.name}: `;\n }\n }\n if (!span) {\n const generated = this.project.transformed(file)?.code;\n const start = this.project.toOriginalOffset(file, location.textSpan.start);\n if (\n generated &&\n this.project.text(file)?.slice(start, start + location.textSpan.length) !==\n generated.slice(\n location.textSpan.start,\n location.textSpan.start + location.textSpan.length,\n )\n )\n continue; // A compiler-inserted guard/defer reference is regenerated.\n // Generated closing JSX tags duplicate a source component reference;\n // they have no independent source occurrence to edit.\n const sf = this.sourceFile(file);\n let closing = false;\n const visit = (node: ts.Node) => {\n if (\n ts.isJsxClosingElement(node) &&\n location.textSpan.start >= node.tagName.getStart() &&\n location.textSpan.start < node.tagName.end\n )\n closing = true;\n else if (\n location.textSpan.start >= node.getFullStart() &&\n location.textSpan.start < node.end\n )\n ts.forEachChild(node, visit);\n };\n if (sf) visit(sf);\n if (closing) continue;\n return undefined;\n }\n result.push({\n ...location,\n fileName: file,\n textSpan: span,\n prefixText,\n suffixText,\n contextSpan: location.contextSpan ? this.mapSpan(file, location.contextSpan) : undefined,\n });\n }\n return result.filter(\n (item, index) =>\n result.findIndex(\n (other) =>\n item.fileName === other.fileName &&\n item.textSpan.start === other.textSpan.start &&\n item.textSpan.length === other.textSpan.length,\n ) === index,\n );\n }\n\n rename(\n filename: string,\n position: number,\n name: string,\n preferences: ts.UserPreferences | boolean = true,\n ): SourceEdit[] | undefined {\n const scanner = ts.createScanner(\n ts.ScriptTarget.Latest,\n false,\n ts.LanguageVariant.Standard,\n name,\n );\n if (\n scanner.scan() !== ts.SyntaxKind.Identifier ||\n scanner.scan() !== ts.SyntaxKind.EndOfFileToken\n )\n return undefined;\n return this.renameLocations(filename, position, preferences)?.map((location) => ({\n filename: location.fileName,\n span: location.textSpan,\n newText: (location.prefixText ?? '') + name + (location.suffixText ?? ''),\n }));\n }\n\n fixes(filename: string, start: number, end: number, codes: readonly number[]) {\n return this.project.service\n .getCodeFixesAtPosition(\n virtualFilename(filename),\n this.project.toGeneratedOffset(filename, start),\n this.project.toGeneratedOffset(filename, end),\n codes,\n {},\n {},\n )\n .flatMap((fix) => {\n const edits = this.mapChanges(fix.changes);\n return edits?.length && !fix.commands?.length\n ? [{ description: fix.description, edits }]\n : [];\n });\n }\n}\n"],"mappings":";;;;;AAiBA,IAAa,cAAb,MAAyB;CAEF;CADrB,iCAAyB,IAAI,QAA0C;CACvE,YAAY,SAAgC;EAAvB,KAAA,UAAA;CAAwB;CAE7C,WAAmB,UAAkB;EACnC,OAAO,KAAK,QAAQ,QAAQ,WAAW,CAAC,EAAE,cAAc,gBAAgB,QAAQ,CAAC;CACnF;CAEA,WAAmB,UAAkB;EACnC,MAAM,OAAO,KAAK,WAAW,QAAQ;EACrC,IAAI,CAAC,MAAM,OAAO,CAAC;EACnB,MAAM,SAAS,KAAK,eA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AM,CAAC,IACxC,CAAC;EACP,CAAC;CACL;AACF"}
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.js","names":[],"sources":["../src/esbuild.ts"],"sourcesContent":["import { twillPlugin } from './plugin.js';\nexport default twillPlugin.esbuild;\nexport type { PluginOptions } from './plugin.js';\n"],"mappings":";;AACA,IAAA,kBAAe,YAAY"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { n as extensions } from "./compiler-Bi9TNOhX.js";
|
|
2
|
+
import { statSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
//#region src/files.ts
|
|
5
|
+
var sourceExtensions = [
|
|
6
|
+
".mjs",
|
|
7
|
+
".js",
|
|
8
|
+
".mts",
|
|
9
|
+
".ts",
|
|
10
|
+
".jsx",
|
|
11
|
+
".tsx",
|
|
12
|
+
".cjs",
|
|
13
|
+
".cts",
|
|
14
|
+
".json",
|
|
15
|
+
...extensions
|
|
16
|
+
];
|
|
17
|
+
function isDependency(filename) {
|
|
18
|
+
return /(?:^|[\\/])node_modules[\\/]/.test(filename);
|
|
19
|
+
}
|
|
20
|
+
function needsTypeEmission(filename) {
|
|
21
|
+
return /\.(?:tsx?|mts|jsx)$/.test(filename) && !/\.d\.(?:ts|mts)$/.test(filename);
|
|
22
|
+
}
|
|
23
|
+
function splitId(id) {
|
|
24
|
+
const index = id.search(/[?#]/);
|
|
25
|
+
return index < 0 ? [id, ""] : [id.slice(0, index), id.slice(index)];
|
|
26
|
+
}
|
|
27
|
+
function resolveSourceFile(base) {
|
|
28
|
+
const file = (candidate) => {
|
|
29
|
+
try {
|
|
30
|
+
return statSync(candidate).isFile();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code ?? "")) return false;
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (file(base)) return base;
|
|
37
|
+
for (const extension of sourceExtensions) if (file(base + extension)) return base + extension;
|
|
38
|
+
for (const extension of sourceExtensions) {
|
|
39
|
+
const candidate = resolve(base, "index" + extension);
|
|
40
|
+
if (file(candidate)) return candidate;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { splitId as a, sourceExtensions as i, needsTypeEmission as n, resolveSourceFile as r, isDependency as t };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=files-D1mERoxc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-D1mERoxc.js","names":[],"sources":["../src/files.ts"],"sourcesContent":["import { statSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { extensions } from './compiler.js';\n\nexport const sourceExtensions = [\n '.mjs',\n '.js',\n '.mts',\n '.ts',\n '.jsx',\n '.tsx',\n '.cjs',\n '.cts',\n '.json',\n ...extensions,\n];\nexport function isDependency(filename: string) {\n return /(?:^|[\\\\/])node_modules[\\\\/]/.test(filename);\n}\nexport function needsTypeEmission(filename: string) {\n return /\\.(?:tsx?|mts|jsx)$/.test(filename) && !/\\.d\\.(?:ts|mts)$/.test(filename);\n}\nexport function splitId(id: string): [string, string] {\n const index = id.search(/[?#]/);\n return index < 0 ? [id, ''] : [id.slice(0, index), id.slice(index)];\n}\nexport function resolveSourceFile(base: string): string | undefined {\n const file = (candidate: string) => {\n try {\n return statSync(candidate).isFile();\n } catch (error) {\n if (['ENOENT', 'ENOTDIR'].includes((error as NodeJS.ErrnoException).code ?? '')) return false;\n throw error;\n }\n };\n if (file(base)) return base;\n // Match the native-first order of the Vite resolver. Explicit filenames\n // remain the way to select one of several same-stem source files.\n for (const extension of sourceExtensions) if (file(base + extension)) return base + extension;\n for (const extension of sourceExtensions) {\n const candidate = resolve(base, 'index' + extension);\n if (file(candidate)) return candidate;\n }\n}\n"],"mappings":";;;;AAIA,IAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;AACL;AACA,SAAgB,aAAa,UAAkB;CAC7C,OAAO,+BAA+B,KAAK,QAAQ;AACrD;AACA,SAAgB,kBAAkB,UAAkB;CAClD,OAAO,sBAAsB,KAAK,QAAQ,KAAK,CAAC,mBAAmB,KAAK,QAAQ;AAClF;AACA,SAAgB,QAAQ,IAA8B;CACpD,MAAM,QAAQ,GAAG,OAAO,MAAM;CAC9B,OAAO,QAAQ,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,MAAM,KAAK,CAAC;AACpE;AACA,SAAgB,kBAAkB,MAAkC;CAClE,MAAM,QAAQ,cAAsB;EAClC,IAAI;GACF,OAAO,SAAS,SAAS,CAAC,CAAC,OAAO;EACpC,SAAS,OAAO;GACd,IAAI,CAAC,UAAU,SAAS,CAAC,CAAC,SAAU,MAAgC,QAAQ,EAAE,GAAG,OAAO;GACxF,MAAM;EACR;CACF;CACA,IAAI,KAAK,IAAI,GAAG,OAAO;CAGvB,KAAK,MAAM,aAAa,kBAAkB,IAAI,KAAK,OAAO,SAAS,GAAG,OAAO,OAAO;CACpF,KAAK,MAAM,aAAa,kBAAkB;EACxC,MAAM,YAAY,QAAQ,MAAM,UAAU,SAAS;EACnD,IAAI,KAAK,SAAS,GAAG,OAAO;CAC9B;AACF"}
|