typescript-svelte-plugin 0.3.15 → 0.3.16
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 -0
- package/dist/src/svelte-snapshots.js +1 -1
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -32,6 +32,42 @@ function init(modules) {
|
|
|
32
32
|
// This call the ConfiguredProject.getParsedCommandLine
|
|
33
33
|
// where it'll try to load the cached version of the parsedCommandLine
|
|
34
34
|
const parsedCommandLine = (_c = (_b = info.languageServiceHost).getParsedCommandLine) === null || _c === void 0 ? void 0 : _c.call(_b, (0, utils_1.getConfigPathForProject)(info.project));
|
|
35
|
+
// For some reason it's no longer enough to patch this at the projectService level, so we do it here, too
|
|
36
|
+
// TODO investigate if we can use the script snapshot for all Svelte files, too, enabling Svelte file
|
|
37
|
+
// updates getting picked up without a file save - move this logic into the snapshot manager then?
|
|
38
|
+
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
|
|
39
|
+
info.languageServiceHost.getScriptSnapshot = (fileName) => {
|
|
40
|
+
const normalizedPath = fileName.replace(/\\/g, '/');
|
|
41
|
+
if (normalizedPath.endsWith('node_modules/svelte/types/runtime/ambient.d.ts')) {
|
|
42
|
+
return modules.typescript.ScriptSnapshot.fromString('');
|
|
43
|
+
}
|
|
44
|
+
else if (normalizedPath.endsWith('svelte2tsx/svelte-jsx.d.ts')) {
|
|
45
|
+
// Remove the dom lib reference to not load these ambient types in case
|
|
46
|
+
// the user has a tsconfig.json with different lib settings like in
|
|
47
|
+
// https://github.com/sveltejs/language-tools/issues/1733
|
|
48
|
+
const snapshot = getScriptSnapshot(fileName);
|
|
49
|
+
if (snapshot) {
|
|
50
|
+
const originalText = snapshot.getText(0, snapshot.getLength());
|
|
51
|
+
return modules.typescript.ScriptSnapshot.fromString(originalText.replace('/// <reference lib="dom" />', ''));
|
|
52
|
+
}
|
|
53
|
+
return snapshot;
|
|
54
|
+
}
|
|
55
|
+
else if (normalizedPath.endsWith('svelte2tsx/svelte-shims.d.ts')) {
|
|
56
|
+
const snapshot = getScriptSnapshot(fileName);
|
|
57
|
+
if (snapshot) {
|
|
58
|
+
let originalText = snapshot.getText(0, snapshot.getLength());
|
|
59
|
+
if (!originalText.includes('// -- start svelte-ls-remove --')) {
|
|
60
|
+
return snapshot; // uses an older version of svelte2tsx or is already patched
|
|
61
|
+
}
|
|
62
|
+
originalText =
|
|
63
|
+
originalText.substring(0, originalText.indexOf('// -- start svelte-ls-remove --')) +
|
|
64
|
+
originalText.substring(originalText.indexOf('// -- end svelte-ls-remove --'));
|
|
65
|
+
return modules.typescript.ScriptSnapshot.fromString(originalText);
|
|
66
|
+
}
|
|
67
|
+
return snapshot;
|
|
68
|
+
}
|
|
69
|
+
return getScriptSnapshot(fileName);
|
|
70
|
+
};
|
|
35
71
|
const svelteOptions = ((_d = parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.raw) === null || _d === void 0 ? void 0 : _d.svelteOptions) || { namespace: 'svelteHTML' };
|
|
36
72
|
logger.log('svelteOptions:', svelteOptions);
|
|
37
73
|
logger.debug(parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.wildcardDirectories);
|
|
@@ -84,7 +84,7 @@ class SvelteSnapshot {
|
|
|
84
84
|
}
|
|
85
85
|
setAndPatchScriptInfo(scriptInfo) {
|
|
86
86
|
// @ts-expect-error
|
|
87
|
-
scriptInfo.scriptKind = this.typescript.ScriptKind.
|
|
87
|
+
scriptInfo.scriptKind = this.typescript.ScriptKind.TS;
|
|
88
88
|
const positionToLineOffset = scriptInfo.positionToLineOffset.bind(scriptInfo);
|
|
89
89
|
scriptInfo.positionToLineOffset = (position) => {
|
|
90
90
|
if (this.convertInternalCodePositions) {
|