typescript-svelte-plugin 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.js +36 -3
- package/dist/src/language-service/completions.d.ts +4 -2
- package/dist/src/language-service/completions.js +99 -29
- package/dist/src/language-service/definition.d.ts +3 -1
- package/dist/src/language-service/definition.js +20 -2
- package/dist/src/language-service/diagnostics.d.ts +1 -1
- package/dist/src/language-service/diagnostics.js +53 -10
- package/dist/src/language-service/hover.d.ts +5 -0
- package/dist/src/language-service/hover.js +35 -0
- package/dist/src/language-service/index.d.ts +1 -1
- package/dist/src/language-service/index.js +8 -6
- package/dist/src/language-service/sveltekit.d.ts +135 -0
- package/dist/src/language-service/sveltekit.js +567 -0
- package/dist/src/module-loader.js +3 -3
- package/dist/src/source-mapper.js +1 -1
- package/dist/src/svelte-sys.d.ts +4 -2
- package/dist/src/svelte-sys.js +6 -10
- package/dist/src/utils.d.ts +9 -0
- package/dist/src/utils.js +43 -1
- package/package.json +1 -1
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toOriginalPos = exports.toVirtualPos = exports.getVirtualLS = exports.getProxiedLanguageService = exports.kitExports = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const cache = new WeakMap();
|
|
9
|
+
exports.kitExports = {
|
|
10
|
+
prerender: {
|
|
11
|
+
displayParts: [
|
|
12
|
+
{
|
|
13
|
+
text: 'const',
|
|
14
|
+
kind: 'keyword'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
text: ' ',
|
|
18
|
+
kind: 'space'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
text: 'prerender',
|
|
22
|
+
kind: 'localName'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
text: ': ',
|
|
26
|
+
kind: 'punctuation'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
text: 'boolean',
|
|
30
|
+
kind: 'keyword'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
text: ' | ',
|
|
34
|
+
kind: 'punctuation'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
text: "'auto'",
|
|
38
|
+
kind: 'stringLiteral'
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
documentation: [
|
|
42
|
+
{
|
|
43
|
+
text: 'Control whether or not this page is prerendered. More info: https://kit.svelte.dev/docs/page-options#prerender',
|
|
44
|
+
kind: 'text'
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
ssr: {
|
|
49
|
+
displayParts: [
|
|
50
|
+
{
|
|
51
|
+
text: 'const',
|
|
52
|
+
kind: 'keyword'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
text: ' ',
|
|
56
|
+
kind: 'space'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
text: 'ssr',
|
|
60
|
+
kind: 'localName'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
text: ': ',
|
|
64
|
+
kind: 'punctuation'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: 'boolean',
|
|
68
|
+
kind: 'keyword'
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
documentation: [
|
|
72
|
+
{
|
|
73
|
+
text: 'Control whether or not this page is server-side rendered. More info: https://kit.svelte.dev/docs/page-options#ssr',
|
|
74
|
+
kind: 'text'
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
csr: {
|
|
79
|
+
displayParts: [
|
|
80
|
+
{
|
|
81
|
+
text: 'const',
|
|
82
|
+
kind: 'keyword'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
text: ' ',
|
|
86
|
+
kind: 'space'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
text: 'csr',
|
|
90
|
+
kind: 'localName'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
text: ': ',
|
|
94
|
+
kind: 'punctuation'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
text: 'boolean',
|
|
98
|
+
kind: 'keyword'
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
documentation: [
|
|
102
|
+
{
|
|
103
|
+
text: 'Control whether or not this page is hydrated (i.e. if JS is delivered to the client). More info: https://kit.svelte.dev/docs/page-options#csr',
|
|
104
|
+
kind: 'text'
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
trailingSlash: {
|
|
109
|
+
displayParts: [
|
|
110
|
+
{
|
|
111
|
+
text: 'const',
|
|
112
|
+
kind: 'keyword'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
text: ' ',
|
|
116
|
+
kind: 'space'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
text: 'trailingSlash',
|
|
120
|
+
kind: 'localName'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
text: ': ',
|
|
124
|
+
kind: 'punctuation'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
text: "'auto' | 'always' | 'never'",
|
|
128
|
+
kind: 'stringLiteral'
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
documentation: [
|
|
132
|
+
{
|
|
133
|
+
text: 'Control how SvelteKit should handle (missing) trailing slashes in the URL. More info: https://kit.svelte.dev/docs/page-options#trailingslash',
|
|
134
|
+
kind: 'text'
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
config: {
|
|
139
|
+
displayParts: [
|
|
140
|
+
{
|
|
141
|
+
text: 'const',
|
|
142
|
+
kind: 'keyword'
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
text: ' ',
|
|
146
|
+
kind: 'space'
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
text: 'config',
|
|
150
|
+
kind: 'localName'
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
text: ': ',
|
|
154
|
+
kind: 'punctuation'
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
text: 'Config',
|
|
158
|
+
kind: 'interfaceName'
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
documentation: [
|
|
162
|
+
{
|
|
163
|
+
text: `With the concept of adapters, SvelteKit is able to run on a variety of platforms. ` +
|
|
164
|
+
`Each of these might have specific configuration to further tweak the deployment, which you can configure here. ` +
|
|
165
|
+
`More info: https://kit.svelte.dev/docs/page-options#config`,
|
|
166
|
+
kind: 'text'
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
actions: {
|
|
171
|
+
displayParts: [
|
|
172
|
+
{
|
|
173
|
+
text: 'const',
|
|
174
|
+
kind: 'keyword'
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
text: ' ',
|
|
178
|
+
kind: 'space'
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
text: 'actions',
|
|
182
|
+
kind: 'localName'
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
text: ': ',
|
|
186
|
+
kind: 'punctuation'
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
text: 'Actions',
|
|
190
|
+
kind: 'interfaceName'
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
documentation: [
|
|
194
|
+
{
|
|
195
|
+
text: `An object of methods which handle form POST requests. ` +
|
|
196
|
+
`More info: https://kit.svelte.dev/docs/form-actions`,
|
|
197
|
+
kind: 'text'
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
},
|
|
201
|
+
load: {
|
|
202
|
+
displayParts: [
|
|
203
|
+
{
|
|
204
|
+
text: 'export',
|
|
205
|
+
kind: 'keyword'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
text: ' ',
|
|
209
|
+
kind: 'space'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
text: 'function',
|
|
213
|
+
kind: 'keyword'
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
text: ' ',
|
|
217
|
+
kind: 'space'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
text: 'load',
|
|
221
|
+
kind: 'localName'
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
text: '(',
|
|
225
|
+
kind: 'punctuation'
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
text: 'event',
|
|
229
|
+
kind: 'parameterName'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
text: ': ',
|
|
233
|
+
kind: 'punctuation'
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
text: 'LoadEvent',
|
|
237
|
+
kind: 'interfaceName'
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
text: ')',
|
|
241
|
+
kind: 'punctuation'
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
text: ': ',
|
|
245
|
+
kind: 'punctuation'
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
text: 'Promise',
|
|
249
|
+
kind: 'keyword'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
text: '<',
|
|
253
|
+
kind: 'punctuation'
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
text: 'LoadOutput',
|
|
257
|
+
kind: 'interfaceName'
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
text: '>',
|
|
261
|
+
kind: 'punctuation'
|
|
262
|
+
}
|
|
263
|
+
],
|
|
264
|
+
documentation: [
|
|
265
|
+
{
|
|
266
|
+
text: 'Loads data for the given page or layout. More info: https://kit.svelte.dev/docs/load',
|
|
267
|
+
kind: 'text'
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
function getProxiedLanguageService(info, ts, logger) {
|
|
273
|
+
const cachedProxiedLanguageService = cache.get(info);
|
|
274
|
+
if (cachedProxiedLanguageService) {
|
|
275
|
+
return cachedProxiedLanguageService;
|
|
276
|
+
}
|
|
277
|
+
const originalLanguageServiceHost = info.languageServiceHost;
|
|
278
|
+
class ProxiedLanguageServiceHost {
|
|
279
|
+
constructor() {
|
|
280
|
+
this.files = {};
|
|
281
|
+
this.resolveModuleNames = originalLanguageServiceHost.resolveModuleNames
|
|
282
|
+
? (...args) => {
|
|
283
|
+
return originalLanguageServiceHost.resolveModuleNames(
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
...args);
|
|
286
|
+
}
|
|
287
|
+
: undefined;
|
|
288
|
+
this.resolveModuleNameLiterals = originalLanguageServiceHost.resolveModuleNameLiterals
|
|
289
|
+
? (...args) => {
|
|
290
|
+
return originalLanguageServiceHost.resolveModuleNameLiterals(
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
...args);
|
|
293
|
+
}
|
|
294
|
+
: undefined;
|
|
295
|
+
}
|
|
296
|
+
log() { }
|
|
297
|
+
trace() { }
|
|
298
|
+
error() { }
|
|
299
|
+
getCompilationSettings() {
|
|
300
|
+
return originalLanguageServiceHost.getCompilationSettings();
|
|
301
|
+
}
|
|
302
|
+
getScriptIsOpen() {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
getCurrentDirectory() {
|
|
306
|
+
return originalLanguageServiceHost.getCurrentDirectory();
|
|
307
|
+
}
|
|
308
|
+
getDefaultLibFileName(o) {
|
|
309
|
+
return originalLanguageServiceHost.getDefaultLibFileName(o);
|
|
310
|
+
}
|
|
311
|
+
getScriptVersion(fileName) {
|
|
312
|
+
const file = this.files[fileName];
|
|
313
|
+
if (!file)
|
|
314
|
+
return originalLanguageServiceHost.getScriptVersion(fileName);
|
|
315
|
+
return file.version.toString();
|
|
316
|
+
}
|
|
317
|
+
getScriptSnapshot(fileName) {
|
|
318
|
+
const file = this.files[fileName];
|
|
319
|
+
if (!file)
|
|
320
|
+
return originalLanguageServiceHost.getScriptSnapshot(fileName);
|
|
321
|
+
return file.file;
|
|
322
|
+
}
|
|
323
|
+
getScriptFileNames() {
|
|
324
|
+
const names = new Set(Object.keys(this.files));
|
|
325
|
+
const files = originalLanguageServiceHost.getScriptFileNames();
|
|
326
|
+
for (const file of files) {
|
|
327
|
+
names.add(file);
|
|
328
|
+
}
|
|
329
|
+
return [...names];
|
|
330
|
+
}
|
|
331
|
+
getKitScriptSnapshotIfUpToDate(fileName) {
|
|
332
|
+
if (!this.files[fileName] ||
|
|
333
|
+
this.getScriptVersion(fileName) !==
|
|
334
|
+
originalLanguageServiceHost.getScriptVersion(fileName)) {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
return this.files[fileName];
|
|
338
|
+
}
|
|
339
|
+
upsertKitFile(fileName) {
|
|
340
|
+
var _a;
|
|
341
|
+
const basename = path_1.default.basename(fileName);
|
|
342
|
+
if (!kitPageFiles.has(basename))
|
|
343
|
+
return;
|
|
344
|
+
const source = (_a = info.languageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
345
|
+
if (!source)
|
|
346
|
+
return;
|
|
347
|
+
const addedCode = [];
|
|
348
|
+
const insert = (pos, inserted) => {
|
|
349
|
+
var _a, _b, _c, _d;
|
|
350
|
+
const insertionIdx = addedCode.findIndex((c) => c.generatedPos > pos);
|
|
351
|
+
if (insertionIdx >= 0) {
|
|
352
|
+
for (let i = insertionIdx; i < addedCode.length; i++) {
|
|
353
|
+
addedCode[i].generatedPos += inserted.length;
|
|
354
|
+
addedCode[i].total += inserted.length;
|
|
355
|
+
}
|
|
356
|
+
const prevTotal = (_b = (_a = addedCode[insertionIdx - 1]) === null || _a === void 0 ? void 0 : _a.total) !== null && _b !== void 0 ? _b : 0;
|
|
357
|
+
addedCode.splice(insertionIdx, 0, {
|
|
358
|
+
generatedPos: pos + prevTotal,
|
|
359
|
+
originalPos: pos,
|
|
360
|
+
length: inserted.length,
|
|
361
|
+
inserted,
|
|
362
|
+
total: prevTotal + inserted.length
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
const prevTotal = (_d = (_c = addedCode[addedCode.length - 1]) === null || _c === void 0 ? void 0 : _c.total) !== null && _d !== void 0 ? _d : 0;
|
|
367
|
+
addedCode.push({
|
|
368
|
+
generatedPos: pos + prevTotal,
|
|
369
|
+
originalPos: pos,
|
|
370
|
+
length: inserted.length,
|
|
371
|
+
inserted,
|
|
372
|
+
total: prevTotal + inserted.length
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const isTsFile = basename.endsWith('.ts');
|
|
377
|
+
const exports = findExports(ts, source, isTsFile);
|
|
378
|
+
// add type to load function if not explicitly typed
|
|
379
|
+
const load = exports.get('load');
|
|
380
|
+
if ((load === null || load === void 0 ? void 0 : load.type) === 'function' &&
|
|
381
|
+
load.node.parameters.length === 1 &&
|
|
382
|
+
!load.hasTypeDefinition) {
|
|
383
|
+
const pos = load.node.parameters[0].getEnd();
|
|
384
|
+
const inserted = `: import('./$types').${basename.includes('layout') ? 'Layout' : 'Page'}${basename.includes('server') ? 'Server' : ''}LoadEvent`;
|
|
385
|
+
insert(pos, inserted);
|
|
386
|
+
}
|
|
387
|
+
// add type to actions variable if not explicitly typed
|
|
388
|
+
const actions = exports.get('actions');
|
|
389
|
+
if ((actions === null || actions === void 0 ? void 0 : actions.type) === 'var' && !actions.hasTypeDefinition && actions.node.initializer) {
|
|
390
|
+
const pos = actions.node.initializer.getEnd();
|
|
391
|
+
const inserted = ` satisfies import('./$types').Actions`;
|
|
392
|
+
insert(pos, inserted);
|
|
393
|
+
}
|
|
394
|
+
// add type to prerender variable if not explicitly typed
|
|
395
|
+
const prerender = exports.get('prerender');
|
|
396
|
+
if ((prerender === null || prerender === void 0 ? void 0 : prerender.type) === 'var' &&
|
|
397
|
+
!prerender.hasTypeDefinition &&
|
|
398
|
+
prerender.node.initializer) {
|
|
399
|
+
const pos = prerender.node.name.getEnd();
|
|
400
|
+
const inserted = ` : import('@sveltejs/kit').PrerenderOption`;
|
|
401
|
+
insert(pos, inserted);
|
|
402
|
+
}
|
|
403
|
+
// add type to trailingSlash variable if not explicitly typed
|
|
404
|
+
const trailingSlash = exports.get('trailingSlash');
|
|
405
|
+
if ((trailingSlash === null || trailingSlash === void 0 ? void 0 : trailingSlash.type) === 'var' &&
|
|
406
|
+
!trailingSlash.hasTypeDefinition &&
|
|
407
|
+
trailingSlash.node.initializer) {
|
|
408
|
+
const pos = trailingSlash.node.name.getEnd();
|
|
409
|
+
const inserted = ` : 'never' | 'always' | 'ignore'`; // TODO this should be exported from kit
|
|
410
|
+
insert(pos, inserted);
|
|
411
|
+
}
|
|
412
|
+
// add type to ssr variable if not explicitly typed
|
|
413
|
+
const ssr = exports.get('ssr');
|
|
414
|
+
if ((ssr === null || ssr === void 0 ? void 0 : ssr.type) === 'var' && !ssr.hasTypeDefinition && ssr.node.initializer) {
|
|
415
|
+
const pos = ssr.node.name.getEnd();
|
|
416
|
+
const inserted = ` : boolean`;
|
|
417
|
+
insert(pos, inserted);
|
|
418
|
+
}
|
|
419
|
+
// add type to csr variable if not explicitly typed
|
|
420
|
+
const csr = exports.get('csr');
|
|
421
|
+
if ((csr === null || csr === void 0 ? void 0 : csr.type) === 'var' && !csr.hasTypeDefinition && csr.node.initializer) {
|
|
422
|
+
const pos = csr.node.name.getEnd();
|
|
423
|
+
const inserted = ` : boolean`;
|
|
424
|
+
insert(pos, inserted);
|
|
425
|
+
}
|
|
426
|
+
// construct generated text from internal text and addedCode array
|
|
427
|
+
const originalText = source.getFullText();
|
|
428
|
+
let pos = 0;
|
|
429
|
+
let text = '';
|
|
430
|
+
for (const added of addedCode) {
|
|
431
|
+
text += originalText.slice(pos, added.originalPos) + added.inserted;
|
|
432
|
+
pos = added.originalPos;
|
|
433
|
+
}
|
|
434
|
+
text += originalText.slice(pos);
|
|
435
|
+
const snap = ts.ScriptSnapshot.fromString(text);
|
|
436
|
+
snap.getChangeRange = (_) => undefined;
|
|
437
|
+
this.files[fileName] = {
|
|
438
|
+
version: originalLanguageServiceHost.getScriptVersion(fileName),
|
|
439
|
+
file: snap,
|
|
440
|
+
addedCode
|
|
441
|
+
};
|
|
442
|
+
return this.files[fileName];
|
|
443
|
+
}
|
|
444
|
+
readFile(fileName) {
|
|
445
|
+
const file = this.files[fileName];
|
|
446
|
+
return file
|
|
447
|
+
? file.file.getText(0, file.file.getLength())
|
|
448
|
+
: originalLanguageServiceHost.readFile(fileName);
|
|
449
|
+
}
|
|
450
|
+
fileExists(fileName) {
|
|
451
|
+
return (this.files[fileName] !== undefined ||
|
|
452
|
+
originalLanguageServiceHost.fileExists(fileName));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const languageServiceHost = new ProxiedLanguageServiceHost();
|
|
456
|
+
const languageService = ts.createLanguageService(languageServiceHost, ts.createDocumentRegistry());
|
|
457
|
+
cache.set(info, { languageService, languageServiceHost });
|
|
458
|
+
return {
|
|
459
|
+
languageService,
|
|
460
|
+
languageServiceHost
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
exports.getProxiedLanguageService = getProxiedLanguageService;
|
|
464
|
+
const kitPageFiles = new Set([
|
|
465
|
+
'+page.ts',
|
|
466
|
+
'+page.js',
|
|
467
|
+
'+layout.ts',
|
|
468
|
+
'+layout.js',
|
|
469
|
+
'+page.server.ts',
|
|
470
|
+
'+page.server.js',
|
|
471
|
+
'+layout.server.ts',
|
|
472
|
+
'+layout.server.js'
|
|
473
|
+
]);
|
|
474
|
+
function getVirtualLS(fileName, info, ts, logger) {
|
|
475
|
+
var _a;
|
|
476
|
+
const proxy = getProxiedLanguageService(info, ts, logger);
|
|
477
|
+
const result = (_a = proxy.languageServiceHost.getKitScriptSnapshotIfUpToDate(fileName)) !== null && _a !== void 0 ? _a : proxy.languageServiceHost.upsertKitFile(fileName);
|
|
478
|
+
if (result) {
|
|
479
|
+
return {
|
|
480
|
+
languageService: proxy.languageService,
|
|
481
|
+
addedCode: result.addedCode,
|
|
482
|
+
toVirtualPos: (pos) => toVirtualPos(pos, result.addedCode),
|
|
483
|
+
toOriginalPos: (pos) => toOriginalPos(pos, result.addedCode)
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
exports.getVirtualLS = getVirtualLS;
|
|
488
|
+
function toVirtualPos(pos, addedCode) {
|
|
489
|
+
let total = 0;
|
|
490
|
+
for (const added of addedCode) {
|
|
491
|
+
if (pos < added.originalPos)
|
|
492
|
+
break;
|
|
493
|
+
total += added.length;
|
|
494
|
+
}
|
|
495
|
+
return pos + total;
|
|
496
|
+
}
|
|
497
|
+
exports.toVirtualPos = toVirtualPos;
|
|
498
|
+
function toOriginalPos(pos, addedCode) {
|
|
499
|
+
let total = 0;
|
|
500
|
+
let idx = 0;
|
|
501
|
+
for (; idx < addedCode.length; idx++) {
|
|
502
|
+
const added = addedCode[idx];
|
|
503
|
+
if (pos < added.generatedPos)
|
|
504
|
+
break;
|
|
505
|
+
total += added.length;
|
|
506
|
+
}
|
|
507
|
+
if (idx > 0) {
|
|
508
|
+
const prev = addedCode[idx - 1];
|
|
509
|
+
// If pos is in the middle of an added range, return the start of the addition
|
|
510
|
+
if (pos > prev.generatedPos && pos < prev.generatedPos + prev.length) {
|
|
511
|
+
return { pos: prev.originalPos, inGenerated: true };
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return { pos: pos - total, inGenerated: false };
|
|
515
|
+
}
|
|
516
|
+
exports.toOriginalPos = toOriginalPos;
|
|
517
|
+
/**
|
|
518
|
+
* Finds the top level const/let/function exports of a source file.
|
|
519
|
+
*/
|
|
520
|
+
function findExports(ts, source, isTsFile) {
|
|
521
|
+
var _a, _b, _c, _d, _e;
|
|
522
|
+
const exports = new Map();
|
|
523
|
+
// TODO handle indirect exports?
|
|
524
|
+
for (const statement of source.statements) {
|
|
525
|
+
if (ts.isFunctionDeclaration(statement) &&
|
|
526
|
+
statement.name &&
|
|
527
|
+
((_b = (_a = ts.getModifiers(statement)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.ExportKeyword) {
|
|
528
|
+
// export function x ...
|
|
529
|
+
exports.set(statement.name.text, {
|
|
530
|
+
type: 'function',
|
|
531
|
+
node: statement,
|
|
532
|
+
hasTypeDefinition: !!((_c = statement.parameters[0]) === null || _c === void 0 ? void 0 : _c.type) ||
|
|
533
|
+
(!isTsFile &&
|
|
534
|
+
(!!ts.getJSDocType(statement) ||
|
|
535
|
+
(statement.parameters[0] &&
|
|
536
|
+
!!ts.getJSDocParameterTags(statement.parameters[0]).length)))
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
if (ts.isVariableStatement(statement) &&
|
|
540
|
+
statement.declarationList.declarations.length === 1 &&
|
|
541
|
+
((_e = (_d = ts.getModifiers(statement)) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.kind) === ts.SyntaxKind.ExportKeyword) {
|
|
542
|
+
// export const x = ...
|
|
543
|
+
const declaration = statement.declarationList.declarations[0];
|
|
544
|
+
const hasTypeDefinition = !!declaration.type ||
|
|
545
|
+
(!isTsFile && !!ts.getJSDocType(declaration)) ||
|
|
546
|
+
(!!declaration.initializer && ts.isSatisfiesExpression(declaration.initializer));
|
|
547
|
+
if (declaration.initializer &&
|
|
548
|
+
(ts.isFunctionExpression(declaration.initializer) ||
|
|
549
|
+
ts.isArrowFunction(declaration.initializer))) {
|
|
550
|
+
exports.set(declaration.name.getText(), {
|
|
551
|
+
type: 'function',
|
|
552
|
+
node: declaration.initializer,
|
|
553
|
+
hasTypeDefinition
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
exports.set(declaration.name.getText(), {
|
|
558
|
+
type: 'var',
|
|
559
|
+
node: declaration,
|
|
560
|
+
hasTypeDefinition
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return exports;
|
|
566
|
+
}
|
|
567
|
+
//# sourceMappingURL=sveltekit.js.map
|
|
@@ -58,7 +58,7 @@ class ModuleResolutionCache {
|
|
|
58
58
|
*/
|
|
59
59
|
function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project, configManager) {
|
|
60
60
|
var _a, _b;
|
|
61
|
-
const svelteSys = (0, svelte_sys_1.createSvelteSys)(logger);
|
|
61
|
+
const svelteSys = (0, svelte_sys_1.createSvelteSys)(typescript, logger);
|
|
62
62
|
const moduleCache = new ModuleResolutionCache(project.projectService);
|
|
63
63
|
const origResolveModuleNames = (_a = lsHost.resolveModuleNames) === null || _a === void 0 ? void 0 : _a.bind(lsHost);
|
|
64
64
|
const origResolveModuleNamLiterals = (_b = lsHost.resolveModuleNameLiterals) === null || _b === void 0 ? void 0 : _b.bind(lsHost);
|
|
@@ -78,7 +78,7 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
78
78
|
moduleCache.clear();
|
|
79
79
|
});
|
|
80
80
|
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) {
|
|
81
|
-
logger.
|
|
81
|
+
logger.debug('Resolving modules names for ' + containingFile);
|
|
82
82
|
// Try resolving all module names with the original method first.
|
|
83
83
|
// The ones that are undefined will be re-checked if they are a
|
|
84
84
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
@@ -119,7 +119,7 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
119
119
|
}
|
|
120
120
|
function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
|
|
121
121
|
var _a;
|
|
122
|
-
logger.
|
|
122
|
+
logger.debug('Resolving modules names for ' + containingFile);
|
|
123
123
|
// Try resolving all module names with the original method first.
|
|
124
124
|
// The ones that are undefined will be re-checked if they are a
|
|
125
125
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
@@ -24,7 +24,7 @@ function binarySearch(array, target, key) {
|
|
|
24
24
|
let high = array.length - 1;
|
|
25
25
|
while (low <= high) {
|
|
26
26
|
const i = low + ((high - low) >> 1);
|
|
27
|
-
const item = undefined === key ? array[i] : array[i][key];
|
|
27
|
+
const item = (undefined === key ? array[i] : array[i][key]);
|
|
28
28
|
if (item === target) {
|
|
29
29
|
return i;
|
|
30
30
|
}
|
package/dist/src/svelte-sys.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
1
|
+
import type ts from 'typescript';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
+
type _ts = typeof ts;
|
|
3
4
|
/**
|
|
4
5
|
* This should only be accessed by TS svelte module resolution.
|
|
5
6
|
*/
|
|
6
|
-
export declare function createSvelteSys(logger: Logger): ts.System;
|
|
7
|
+
export declare function createSvelteSys(ts: _ts, logger: Logger): ts.System;
|
|
8
|
+
export {};
|
package/dist/src/svelte-sys.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createSvelteSys = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
4
|
const utils_1 = require("./utils");
|
|
9
5
|
/**
|
|
10
6
|
* This should only be accessed by TS svelte module resolution.
|
|
11
7
|
*/
|
|
12
|
-
function createSvelteSys(logger) {
|
|
8
|
+
function createSvelteSys(ts, logger) {
|
|
13
9
|
const svelteSys = {
|
|
14
|
-
...
|
|
10
|
+
...ts.sys,
|
|
15
11
|
fileExists(path) {
|
|
16
|
-
return
|
|
12
|
+
return ts.sys.fileExists((0, utils_1.ensureRealSvelteFilePath)(path));
|
|
17
13
|
},
|
|
18
14
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
19
15
|
const extensionsWithSvelte = (extensions !== null && extensions !== void 0 ? extensions : []).concat('.svelte');
|
|
20
|
-
return
|
|
16
|
+
return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
|
|
21
17
|
}
|
|
22
18
|
};
|
|
23
|
-
if (
|
|
24
|
-
const realpath =
|
|
19
|
+
if (ts.sys.realpath) {
|
|
20
|
+
const realpath = ts.sys.realpath;
|
|
25
21
|
svelteSys.realpath = function (path) {
|
|
26
22
|
if ((0, utils_1.isVirtualSvelteFilePath)(path)) {
|
|
27
23
|
return realpath((0, utils_1.toRealSvelteFilePath)(path)) + '.ts';
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { SvelteSnapshot } from './svelte-snapshots';
|
|
3
|
+
type _ts = typeof ts;
|
|
3
4
|
export declare function isSvelteFilePath(filePath: string): boolean;
|
|
4
5
|
export declare function isVirtualSvelteFilePath(filePath: string): boolean;
|
|
5
6
|
export declare function toRealSvelteFilePath(filePath: string): string;
|
|
@@ -31,6 +32,14 @@ export declare function findNodeAtSpan<T extends ts.Node>(node: ts.Node, span: {
|
|
|
31
32
|
start: number;
|
|
32
33
|
length: number;
|
|
33
34
|
}, predicate?: NodeTypePredicate<T>): T | void;
|
|
35
|
+
/**
|
|
36
|
+
* Finds node somewhere at position.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findNodeAtPosition<T extends ts.Node>(node: ts.Node, pos: number, predicate?: NodeTypePredicate<T>): T | void;
|
|
39
|
+
/**
|
|
40
|
+
* True if is `export const/let/function`
|
|
41
|
+
*/
|
|
42
|
+
export declare function isTopLevelExport(ts: _ts, node: ts.Node, source: ts.SourceFile): boolean;
|
|
34
43
|
export declare function isGeneratedSvelteComponentName(className: string): boolean;
|
|
35
44
|
export declare function offsetOfGeneratedComponentExport(snapshot: SvelteSnapshot): number;
|
|
36
45
|
export declare function gatherDescendants<T extends ts.Node>(node: ts.Node, predicate: NodePredicate | NodeTypePredicate<T>, dest?: T[]): T[];
|