typescript-svelte-plugin 0.3.17 → 0.3.19
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 +37 -12
- package/dist/src/language-service/completions.d.ts +2 -2
- package/dist/src/language-service/completions.js +101 -25
- 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 +103 -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 +10 -6
- package/dist/src/language-service/inlay-hints.d.ts +5 -0
- package/dist/src/language-service/inlay-hints.js +25 -0
- package/dist/src/language-service/sveltekit.d.ts +20 -0
- package/dist/src/language-service/sveltekit.js +634 -0
- package/dist/src/module-loader.js +2 -2
- package/dist/src/source-mapper.js +1 -1
- package/dist/src/utils.d.ts +11 -0
- package/dist/src/utils.js +74 -1
- package/package.json +2 -2
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getVirtualLS = exports.isKitRouteExportAllowedIn = exports.kitExports = void 0;
|
|
27
|
+
const utils_1 = require("../utils");
|
|
28
|
+
const svelte2tsx_1 = require("svelte2tsx");
|
|
29
|
+
const cache = new WeakMap();
|
|
30
|
+
function createApiExport(name) {
|
|
31
|
+
return {
|
|
32
|
+
allowedIn: ['api', 'server'],
|
|
33
|
+
displayParts: [
|
|
34
|
+
{
|
|
35
|
+
text: 'export',
|
|
36
|
+
kind: 'keyword'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
text: ' ',
|
|
40
|
+
kind: 'space'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
text: 'async',
|
|
44
|
+
kind: 'keyword'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
text: ' ',
|
|
48
|
+
kind: 'space'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
text: 'function',
|
|
52
|
+
kind: 'keyword'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
text: ' ',
|
|
56
|
+
kind: 'space'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
text: name,
|
|
60
|
+
kind: 'localName'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
text: '(',
|
|
64
|
+
kind: 'punctuation'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: 'event',
|
|
68
|
+
kind: 'parameterName'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
text: ': ',
|
|
72
|
+
kind: 'punctuation'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
text: 'RequestEvent',
|
|
76
|
+
kind: 'interfaceName'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
text: ')',
|
|
80
|
+
kind: 'punctuation'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
text: ': ',
|
|
84
|
+
kind: 'punctuation'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
text: 'Promise',
|
|
88
|
+
kind: 'keyword'
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
text: '<',
|
|
92
|
+
kind: 'punctuation'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
text: 'Response',
|
|
96
|
+
kind: 'interfaceName'
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
text: '>',
|
|
100
|
+
kind: 'punctuation'
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
documentation: [
|
|
104
|
+
{
|
|
105
|
+
text: `Handles ${name} requests. More info: https://kit.svelte.dev/docs/routing#server`,
|
|
106
|
+
kind: 'text'
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
exports.kitExports = {
|
|
112
|
+
prerender: {
|
|
113
|
+
allowedIn: ['layout', 'page', 'api', 'server', 'universal'],
|
|
114
|
+
displayParts: [
|
|
115
|
+
{
|
|
116
|
+
text: 'const',
|
|
117
|
+
kind: 'keyword'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
text: ' ',
|
|
121
|
+
kind: 'space'
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
text: 'prerender',
|
|
125
|
+
kind: 'localName'
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
text: ': ',
|
|
129
|
+
kind: 'punctuation'
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
text: 'boolean',
|
|
133
|
+
kind: 'keyword'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
text: ' | ',
|
|
137
|
+
kind: 'punctuation'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
text: "'auto'",
|
|
141
|
+
kind: 'stringLiteral'
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
documentation: [
|
|
145
|
+
{
|
|
146
|
+
text: 'Control whether or not this page is prerendered. More info: https://kit.svelte.dev/docs/page-options#prerender',
|
|
147
|
+
kind: 'text'
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
ssr: {
|
|
152
|
+
allowedIn: ['layout', 'page', 'server', 'universal'],
|
|
153
|
+
displayParts: [
|
|
154
|
+
{
|
|
155
|
+
text: 'const',
|
|
156
|
+
kind: 'keyword'
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
text: ' ',
|
|
160
|
+
kind: 'space'
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
text: 'ssr',
|
|
164
|
+
kind: 'localName'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
text: ': ',
|
|
168
|
+
kind: 'punctuation'
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
text: 'boolean',
|
|
172
|
+
kind: 'keyword'
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
documentation: [
|
|
176
|
+
{
|
|
177
|
+
text: 'Control whether or not this page is server-side rendered. More info: https://kit.svelte.dev/docs/page-options#ssr',
|
|
178
|
+
kind: 'text'
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
csr: {
|
|
183
|
+
allowedIn: ['layout', 'page', 'server', 'universal'],
|
|
184
|
+
displayParts: [
|
|
185
|
+
{
|
|
186
|
+
text: 'const',
|
|
187
|
+
kind: 'keyword'
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
text: ' ',
|
|
191
|
+
kind: 'space'
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
text: 'csr',
|
|
195
|
+
kind: 'localName'
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
text: ': ',
|
|
199
|
+
kind: 'punctuation'
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
text: 'boolean',
|
|
203
|
+
kind: 'keyword'
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
documentation: [
|
|
207
|
+
{
|
|
208
|
+
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',
|
|
209
|
+
kind: 'text'
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
trailingSlash: {
|
|
214
|
+
allowedIn: ['layout', 'page', 'api', 'server', 'universal'],
|
|
215
|
+
displayParts: [
|
|
216
|
+
{
|
|
217
|
+
text: 'const',
|
|
218
|
+
kind: 'keyword'
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
text: ' ',
|
|
222
|
+
kind: 'space'
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
text: 'trailingSlash',
|
|
226
|
+
kind: 'localName'
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
text: ': ',
|
|
230
|
+
kind: 'punctuation'
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
text: "'auto' | 'always' | 'never'",
|
|
234
|
+
kind: 'stringLiteral'
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
documentation: [
|
|
238
|
+
{
|
|
239
|
+
text: 'Control how SvelteKit should handle (missing) trailing slashes in the URL. More info: https://kit.svelte.dev/docs/page-options#trailingslash',
|
|
240
|
+
kind: 'text'
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
},
|
|
244
|
+
config: {
|
|
245
|
+
allowedIn: ['layout', 'page', 'api', 'server', 'universal'],
|
|
246
|
+
displayParts: [
|
|
247
|
+
{
|
|
248
|
+
text: 'const',
|
|
249
|
+
kind: 'keyword'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
text: ' ',
|
|
253
|
+
kind: 'space'
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
text: 'config',
|
|
257
|
+
kind: 'localName'
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
text: ': ',
|
|
261
|
+
kind: 'punctuation'
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
text: 'Config',
|
|
265
|
+
kind: 'interfaceName'
|
|
266
|
+
}
|
|
267
|
+
],
|
|
268
|
+
documentation: [
|
|
269
|
+
{
|
|
270
|
+
text: `With the concept of adapters, SvelteKit is able to run on a variety of platforms. ` +
|
|
271
|
+
`Each of these might have specific configuration to further tweak the deployment, which you can configure here. ` +
|
|
272
|
+
`More info: https://kit.svelte.dev/docs/page-options#config`,
|
|
273
|
+
kind: 'text'
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
},
|
|
277
|
+
actions: {
|
|
278
|
+
allowedIn: ['page', 'server'],
|
|
279
|
+
displayParts: [
|
|
280
|
+
{
|
|
281
|
+
text: 'const',
|
|
282
|
+
kind: 'keyword'
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
text: ' ',
|
|
286
|
+
kind: 'space'
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
text: 'actions',
|
|
290
|
+
kind: 'localName'
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
text: ': ',
|
|
294
|
+
kind: 'punctuation'
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
text: 'Actions',
|
|
298
|
+
kind: 'interfaceName'
|
|
299
|
+
}
|
|
300
|
+
],
|
|
301
|
+
documentation: [
|
|
302
|
+
{
|
|
303
|
+
text: `An object of methods which handle form POST requests. ` +
|
|
304
|
+
`More info: https://kit.svelte.dev/docs/form-actions`,
|
|
305
|
+
kind: 'text'
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
load: {
|
|
310
|
+
allowedIn: ['layout', 'page', 'server', 'universal'],
|
|
311
|
+
displayParts: [
|
|
312
|
+
{
|
|
313
|
+
text: 'export',
|
|
314
|
+
kind: 'keyword'
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
text: ' ',
|
|
318
|
+
kind: 'space'
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
text: 'function',
|
|
322
|
+
kind: 'keyword'
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
text: ' ',
|
|
326
|
+
kind: 'space'
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
text: 'load',
|
|
330
|
+
kind: 'localName'
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
text: '(',
|
|
334
|
+
kind: 'punctuation'
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
text: 'event',
|
|
338
|
+
kind: 'parameterName'
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
text: ': ',
|
|
342
|
+
kind: 'punctuation'
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
text: 'LoadEvent',
|
|
346
|
+
kind: 'interfaceName'
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
text: ')',
|
|
350
|
+
kind: 'punctuation'
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
text: ': ',
|
|
354
|
+
kind: 'punctuation'
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
text: 'Promise',
|
|
358
|
+
kind: 'keyword'
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
text: '<',
|
|
362
|
+
kind: 'punctuation'
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
text: 'LoadOutput',
|
|
366
|
+
kind: 'interfaceName'
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
text: '>',
|
|
370
|
+
kind: 'punctuation'
|
|
371
|
+
}
|
|
372
|
+
],
|
|
373
|
+
documentation: [
|
|
374
|
+
{
|
|
375
|
+
text: 'Loads data for the given page or layout. More info: https://kit.svelte.dev/docs/load',
|
|
376
|
+
kind: 'text'
|
|
377
|
+
}
|
|
378
|
+
]
|
|
379
|
+
},
|
|
380
|
+
GET: createApiExport('GET'),
|
|
381
|
+
POST: createApiExport('POST'),
|
|
382
|
+
PUT: createApiExport('PUT'),
|
|
383
|
+
PATCH: createApiExport('PATCH'),
|
|
384
|
+
DELETE: createApiExport('DELETE'),
|
|
385
|
+
OPTIONS: createApiExport('OPTIONS'),
|
|
386
|
+
// param matching
|
|
387
|
+
match: {
|
|
388
|
+
allowedIn: [],
|
|
389
|
+
displayParts: [],
|
|
390
|
+
documentation: [
|
|
391
|
+
{
|
|
392
|
+
text: `A parameter matcher. ` +
|
|
393
|
+
`More info: https://kit.svelte.dev/docs/advanced-routing#matching`,
|
|
394
|
+
kind: 'text'
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
},
|
|
398
|
+
// hooks
|
|
399
|
+
handle: {
|
|
400
|
+
allowedIn: [],
|
|
401
|
+
displayParts: [],
|
|
402
|
+
documentation: [
|
|
403
|
+
{
|
|
404
|
+
text: `The handle hook runs every time the SvelteKit server receives a request and determines the response. ` +
|
|
405
|
+
`It receives an 'event' object representing the request and a function called 'resolve', which renders the route and generates a Response. ` +
|
|
406
|
+
`This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example). ` +
|
|
407
|
+
`More info: https://kit.svelte.dev/docs/hooks#server-hooks-handle`,
|
|
408
|
+
kind: 'text'
|
|
409
|
+
}
|
|
410
|
+
]
|
|
411
|
+
},
|
|
412
|
+
handleFetch: {
|
|
413
|
+
allowedIn: [],
|
|
414
|
+
displayParts: [],
|
|
415
|
+
documentation: [
|
|
416
|
+
{
|
|
417
|
+
text: `The handleFetch hook allows you to modify (or replace) a 'fetch' request that happens inside a 'load' function that runs on the server (or during pre-rendering). ` +
|
|
418
|
+
`More info: https://kit.svelte.dev/docs/hooks#server-hooks-handlefetch`,
|
|
419
|
+
kind: 'text'
|
|
420
|
+
}
|
|
421
|
+
]
|
|
422
|
+
},
|
|
423
|
+
handleError: {
|
|
424
|
+
allowedIn: [],
|
|
425
|
+
displayParts: [],
|
|
426
|
+
documentation: [
|
|
427
|
+
{
|
|
428
|
+
text: `The handleError hook runs when an unexpected error is thrown while responding to a request. ` +
|
|
429
|
+
`If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event. ` +
|
|
430
|
+
`Make sure that this function _never_ throws an error. ` +
|
|
431
|
+
`More info: https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror`,
|
|
432
|
+
kind: 'text'
|
|
433
|
+
}
|
|
434
|
+
]
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
function isKitRouteExportAllowedIn(basename, kitExport) {
|
|
438
|
+
if (!basename.startsWith('+')) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
const allowedIn = kitExport.allowedIn;
|
|
442
|
+
return ((basename.includes('layout')
|
|
443
|
+
? allowedIn.includes('layout')
|
|
444
|
+
: basename.includes('+server')
|
|
445
|
+
? allowedIn.includes('api')
|
|
446
|
+
: allowedIn.includes('page')) &&
|
|
447
|
+
(basename.includes('server')
|
|
448
|
+
? allowedIn.includes('server')
|
|
449
|
+
: allowedIn.includes('universal')));
|
|
450
|
+
}
|
|
451
|
+
exports.isKitRouteExportAllowedIn = isKitRouteExportAllowedIn;
|
|
452
|
+
function getProxiedLanguageService(info, ts, logger) {
|
|
453
|
+
const cachedProxiedLanguageService = cache.get(info);
|
|
454
|
+
if (cachedProxiedLanguageService !== undefined) {
|
|
455
|
+
return cachedProxiedLanguageService !== null && cachedProxiedLanguageService !== void 0 ? cachedProxiedLanguageService : undefined;
|
|
456
|
+
}
|
|
457
|
+
if (!(0, utils_1.hasNodeModule)(info.project.getCompilerOptions(), '@sveltejs/kit')) {
|
|
458
|
+
// Not a SvelteKit project, do nothing
|
|
459
|
+
cache.set(info, null);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const originalLanguageServiceHost = info.languageServiceHost;
|
|
463
|
+
class ProxiedLanguageServiceHost {
|
|
464
|
+
constructor() {
|
|
465
|
+
var _a;
|
|
466
|
+
this.files = {};
|
|
467
|
+
this.paramsPath = 'src/params';
|
|
468
|
+
this.serverHooksPath = 'src/hooks.server';
|
|
469
|
+
this.clientHooksPath = 'src/hooks.client';
|
|
470
|
+
this.resolveModuleNames = originalLanguageServiceHost.resolveModuleNames
|
|
471
|
+
? (...args) => {
|
|
472
|
+
return originalLanguageServiceHost.resolveModuleNames(
|
|
473
|
+
// @ts-ignore
|
|
474
|
+
...args);
|
|
475
|
+
}
|
|
476
|
+
: undefined;
|
|
477
|
+
this.resolveModuleNameLiterals = originalLanguageServiceHost.resolveModuleNameLiterals
|
|
478
|
+
? (...args) => {
|
|
479
|
+
return originalLanguageServiceHost.resolveModuleNameLiterals(
|
|
480
|
+
// @ts-ignore
|
|
481
|
+
...args);
|
|
482
|
+
}
|
|
483
|
+
: undefined;
|
|
484
|
+
// needed for path auto completions
|
|
485
|
+
this.readDirectory = originalLanguageServiceHost.readDirectory
|
|
486
|
+
? (...args) => {
|
|
487
|
+
return originalLanguageServiceHost.readDirectory(
|
|
488
|
+
// @ts-ignore
|
|
489
|
+
...args);
|
|
490
|
+
}
|
|
491
|
+
: undefined;
|
|
492
|
+
const configPath = info.project.getCurrentDirectory() + '/svelte.config.js';
|
|
493
|
+
(_a = configPath, Promise.resolve().then(() => __importStar(require(_a)))).then((module) => {
|
|
494
|
+
const config = module.default;
|
|
495
|
+
if (config.kit && config.kit.files) {
|
|
496
|
+
if (config.kit.files.params) {
|
|
497
|
+
this.paramsPath = config.kit.files.params;
|
|
498
|
+
}
|
|
499
|
+
if (config.kit.files.hooks) {
|
|
500
|
+
this.serverHooksPath || (this.serverHooksPath = config.kit.files.hooks.server);
|
|
501
|
+
this.clientHooksPath || (this.clientHooksPath = config.kit.files.hooks.client);
|
|
502
|
+
}
|
|
503
|
+
// We could be more sophisticated with only removing the files that are actually
|
|
504
|
+
// wrong but this is good enough given how rare it is that this setting is used
|
|
505
|
+
Object.keys(this.files)
|
|
506
|
+
.filter((name) => {
|
|
507
|
+
return !name.includes('src/hooks') && !name.includes('src/params');
|
|
508
|
+
})
|
|
509
|
+
.forEach((name) => {
|
|
510
|
+
delete this.files[name];
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
})
|
|
514
|
+
.catch(() => { });
|
|
515
|
+
}
|
|
516
|
+
log() { }
|
|
517
|
+
trace() { }
|
|
518
|
+
error() { }
|
|
519
|
+
getCompilationSettings() {
|
|
520
|
+
return originalLanguageServiceHost.getCompilationSettings();
|
|
521
|
+
}
|
|
522
|
+
getCurrentDirectory() {
|
|
523
|
+
return originalLanguageServiceHost.getCurrentDirectory();
|
|
524
|
+
}
|
|
525
|
+
getDefaultLibFileName(o) {
|
|
526
|
+
return originalLanguageServiceHost.getDefaultLibFileName(o);
|
|
527
|
+
}
|
|
528
|
+
getScriptVersion(fileName) {
|
|
529
|
+
const file = this.files[fileName];
|
|
530
|
+
if (!file)
|
|
531
|
+
return originalLanguageServiceHost.getScriptVersion(fileName);
|
|
532
|
+
return file.version.toString();
|
|
533
|
+
}
|
|
534
|
+
getScriptSnapshot(fileName) {
|
|
535
|
+
const file = this.files[fileName];
|
|
536
|
+
if (!file)
|
|
537
|
+
return originalLanguageServiceHost.getScriptSnapshot(fileName);
|
|
538
|
+
return file.file;
|
|
539
|
+
}
|
|
540
|
+
getScriptFileNames() {
|
|
541
|
+
const names = new Set(Object.keys(this.files));
|
|
542
|
+
const files = originalLanguageServiceHost.getScriptFileNames();
|
|
543
|
+
for (const file of files) {
|
|
544
|
+
names.add(file);
|
|
545
|
+
}
|
|
546
|
+
return [...names];
|
|
547
|
+
}
|
|
548
|
+
getKitScriptSnapshotIfUpToDate(fileName) {
|
|
549
|
+
if (!this.files[fileName] ||
|
|
550
|
+
this.getScriptVersion(fileName) !==
|
|
551
|
+
originalLanguageServiceHost.getScriptVersion(fileName)) {
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
554
|
+
return this.files[fileName];
|
|
555
|
+
}
|
|
556
|
+
upsertKitFile(fileName) {
|
|
557
|
+
const result = svelte2tsx_1.internalHelpers.upsertKitFile(fileName, {
|
|
558
|
+
clientHooksPath: this.clientHooksPath,
|
|
559
|
+
paramsPath: this.paramsPath,
|
|
560
|
+
serverHooksPath: this.serverHooksPath
|
|
561
|
+
}, () => { var _a; return (_a = info.languageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName); });
|
|
562
|
+
if (!result) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const { text, addedCode } = result;
|
|
566
|
+
const snap = ts.ScriptSnapshot.fromString(text);
|
|
567
|
+
snap.getChangeRange = (_) => undefined;
|
|
568
|
+
this.files[fileName] = {
|
|
569
|
+
version: originalLanguageServiceHost.getScriptVersion(fileName),
|
|
570
|
+
file: snap,
|
|
571
|
+
addedCode
|
|
572
|
+
};
|
|
573
|
+
return this.files[fileName];
|
|
574
|
+
}
|
|
575
|
+
readFile(fileName) {
|
|
576
|
+
const file = this.files[fileName];
|
|
577
|
+
return file
|
|
578
|
+
? file.file.getText(0, file.file.getLength())
|
|
579
|
+
: originalLanguageServiceHost.readFile(fileName);
|
|
580
|
+
}
|
|
581
|
+
fileExists(fileName) {
|
|
582
|
+
return (this.files[fileName] !== undefined ||
|
|
583
|
+
originalLanguageServiceHost.fileExists(fileName));
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
// Ideally we'd create a full Proxy of the language service, but that seems to have cache issues
|
|
587
|
+
// with diagnostics, which makes positions go out of sync.
|
|
588
|
+
const languageServiceHost = new ProxiedLanguageServiceHost();
|
|
589
|
+
const languageService = ts.createLanguageService(languageServiceHost, createProxyRegistry(ts, originalLanguageServiceHost, languageServiceHost));
|
|
590
|
+
cache.set(info, { languageService, languageServiceHost });
|
|
591
|
+
return {
|
|
592
|
+
languageService,
|
|
593
|
+
languageServiceHost
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function createProxyRegistry(ts, originalLanguageServiceHost, options) {
|
|
597
|
+
// Don't destructure options param, as the value may be mutated through a svelte.config.js later
|
|
598
|
+
const registry = ts.createDocumentRegistry();
|
|
599
|
+
const originalRegistry = originalLanguageServiceHost.documentRegistry;
|
|
600
|
+
const proxyRegistry = {
|
|
601
|
+
...originalRegistry,
|
|
602
|
+
acquireDocumentWithKey(fileName, tsPath, compilationSettingsOrHost, key, scriptSnapshot, version, scriptKind, sourceFileOptions) {
|
|
603
|
+
if (svelte2tsx_1.internalHelpers.isKitFile(fileName, options)) {
|
|
604
|
+
return registry.acquireDocumentWithKey(fileName, tsPath, compilationSettingsOrHost, key, scriptSnapshot, version, scriptKind, sourceFileOptions);
|
|
605
|
+
}
|
|
606
|
+
return originalRegistry.acquireDocumentWithKey(fileName, tsPath, compilationSettingsOrHost, key, scriptSnapshot, version, scriptKind, sourceFileOptions);
|
|
607
|
+
},
|
|
608
|
+
updateDocumentWithKey(fileName, tsPath, compilationSettingsOrHost, key, scriptSnapshot, version, scriptKind, sourceFileOptions) {
|
|
609
|
+
if (svelte2tsx_1.internalHelpers.isKitFile(fileName, options)) {
|
|
610
|
+
return registry.updateDocumentWithKey(fileName, tsPath, compilationSettingsOrHost, key, scriptSnapshot, version, scriptKind, sourceFileOptions);
|
|
611
|
+
}
|
|
612
|
+
return originalRegistry.updateDocumentWithKey(fileName, tsPath, compilationSettingsOrHost, key, scriptSnapshot, version, scriptKind, sourceFileOptions);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
return proxyRegistry;
|
|
616
|
+
}
|
|
617
|
+
function getVirtualLS(fileName, info, ts, logger) {
|
|
618
|
+
var _a;
|
|
619
|
+
const proxy = getProxiedLanguageService(info, ts, logger);
|
|
620
|
+
if (!proxy) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const result = (_a = proxy.languageServiceHost.getKitScriptSnapshotIfUpToDate(fileName)) !== null && _a !== void 0 ? _a : proxy.languageServiceHost.upsertKitFile(fileName);
|
|
624
|
+
if (result) {
|
|
625
|
+
return {
|
|
626
|
+
languageService: proxy.languageService,
|
|
627
|
+
addedCode: result.addedCode,
|
|
628
|
+
toVirtualPos: (pos) => svelte2tsx_1.internalHelpers.toVirtualPos(pos, result.addedCode),
|
|
629
|
+
toOriginalPos: (pos) => svelte2tsx_1.internalHelpers.toOriginalPos(pos, result.addedCode)
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
exports.getVirtualLS = getVirtualLS;
|
|
634
|
+
//# sourceMappingURL=sveltekit.js.map
|
|
@@ -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/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,7 +32,17 @@ 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[];
|
|
46
|
+
export declare function findIdentifier(ts: _ts, node: ts.Node): ts.Identifier | undefined;
|
|
47
|
+
export declare function hasNodeModule(compilerOptions: ts.CompilerOptions, module: string): string | boolean;
|
|
37
48
|
export {};
|