typescript-svelte-plugin 0.3.13 → 0.3.14
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.
|
@@ -2,6 +2,13 @@ import type ts from 'typescript/lib/tsserverlibrary';
|
|
|
2
2
|
import { ConfigManager } from './config-manager';
|
|
3
3
|
import { Logger } from './logger';
|
|
4
4
|
import { SvelteSnapshotManager } from './svelte-snapshots';
|
|
5
|
+
declare module 'typescript/lib/tsserverlibrary' {
|
|
6
|
+
interface LanguageServiceHost {
|
|
7
|
+
/** @deprecated supply resolveModuleNameLiterals instead for resolution that can handle newer resolution modes like nodenext */
|
|
8
|
+
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ts.ResolvedProjectReference | undefined, options: ts.CompilerOptions, containingSourceFile?: ts.SourceFile): (ts.ResolvedModule | undefined)[];
|
|
9
|
+
resolveModuleNameLiterals?(moduleLiterals: readonly ts.StringLiteralLike[], containingFile: string, redirectedReference: ts.ResolvedProjectReference | undefined, options: ts.CompilerOptions, containingSourceFile: ts.SourceFile, reusedNames: readonly ts.StringLiteralLike[] | undefined): readonly ts.ResolvedModuleWithFailedLookupLocations[];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* Creates a module loader than can also resolve `.svelte` files.
|
|
7
14
|
*
|
|
@@ -57,11 +57,17 @@ class ModuleResolutionCache {
|
|
|
57
57
|
* In order to fix this, we need to wrap typescript's module resolution and reroute all `.svelte.ts` file lookups to .svelte.
|
|
58
58
|
*/
|
|
59
59
|
function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project, configManager) {
|
|
60
|
-
var _a;
|
|
60
|
+
var _a, _b;
|
|
61
61
|
const svelteSys = (0, svelte_sys_1.createSvelteSys)(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
|
-
lsHost.
|
|
64
|
+
const origResolveModuleNamLiterals = (_b = lsHost.resolveModuleNameLiterals) === null || _b === void 0 ? void 0 : _b.bind(lsHost);
|
|
65
|
+
if (lsHost.resolveModuleNameLiterals) {
|
|
66
|
+
lsHost.resolveModuleNameLiterals = resolveModuleNameLiterals;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
lsHost.resolveModuleNames = resolveModuleNames;
|
|
70
|
+
}
|
|
65
71
|
const origRemoveFile = project.removeFile.bind(project);
|
|
66
72
|
project.removeFile = (info, fileExists, detachFromProject) => {
|
|
67
73
|
logger.log('File is being removed. Delete from cache: ', info.fileName);
|
|
@@ -81,18 +87,13 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
81
87
|
if (!configManager.getConfig().enable) {
|
|
82
88
|
return resolved;
|
|
83
89
|
}
|
|
84
|
-
return resolved.map((
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
const cachedModule = moduleCache.get(fileName, containingFile);
|
|
90
|
-
if (cachedModule) {
|
|
91
|
-
return cachedModule;
|
|
90
|
+
return resolved.map((tsResolvedModule, idx) => {
|
|
91
|
+
const moduleName = moduleNames[idx];
|
|
92
|
+
if (tsResolvedModule || !(0, utils_1.ensureRealSvelteFilePath)(moduleName).endsWith('.svelte')) {
|
|
93
|
+
return tsResolvedModule;
|
|
92
94
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return resolvedModule;
|
|
95
|
+
return resolveSvelteModuleNameFromCache(moduleName, containingFile, compilerOptions)
|
|
96
|
+
.resolvedModule;
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
function resolveSvelteModuleName(name, containingFile, compilerOptions) {
|
|
@@ -111,10 +112,46 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
111
112
|
}
|
|
112
113
|
const resolvedSvelteModule = {
|
|
113
114
|
extension: snapshot.isTsFile ? typescript.Extension.Ts : typescript.Extension.Js,
|
|
114
|
-
resolvedFileName
|
|
115
|
+
resolvedFileName,
|
|
116
|
+
isExternalLibraryImport: svelteResolvedModule.isExternalLibraryImport
|
|
115
117
|
};
|
|
116
118
|
return resolvedSvelteModule;
|
|
117
119
|
}
|
|
120
|
+
function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
|
|
121
|
+
var _a;
|
|
122
|
+
logger.log('Resolving modules names for ' + containingFile);
|
|
123
|
+
// Try resolving all module names with the original method first.
|
|
124
|
+
// The ones that are undefined will be re-checked if they are a
|
|
125
|
+
// Svelte file and if so, are resolved, too. This way we can defer
|
|
126
|
+
// all module resolving logic except for Svelte files to TypeScript.
|
|
127
|
+
const resolved = (_a = origResolveModuleNamLiterals === null || origResolveModuleNamLiterals === void 0 ? void 0 : origResolveModuleNamLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames)) !== null && _a !== void 0 ? _a : moduleLiterals.map(() => ({
|
|
128
|
+
resolvedModule: undefined
|
|
129
|
+
}));
|
|
130
|
+
if (!configManager.getConfig().enable) {
|
|
131
|
+
return resolved;
|
|
132
|
+
}
|
|
133
|
+
return resolved.map((tsResolvedModule, idx) => {
|
|
134
|
+
const moduleName = moduleLiterals[idx].text;
|
|
135
|
+
if (tsResolvedModule.resolvedModule ||
|
|
136
|
+
!(0, utils_1.ensureRealSvelteFilePath)(moduleName).endsWith('.svelte')) {
|
|
137
|
+
return tsResolvedModule;
|
|
138
|
+
}
|
|
139
|
+
return resolveSvelteModuleNameFromCache(moduleName, containingFile, options);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function resolveSvelteModuleNameFromCache(moduleName, containingFile, options) {
|
|
143
|
+
const cachedModule = moduleCache.get(moduleName, containingFile);
|
|
144
|
+
if (cachedModule) {
|
|
145
|
+
return {
|
|
146
|
+
resolvedModule: cachedModule
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const resolvedModule = resolveSvelteModuleName(moduleName, containingFile, options);
|
|
150
|
+
moduleCache.set(moduleName, containingFile, resolvedModule);
|
|
151
|
+
return {
|
|
152
|
+
resolvedModule: resolvedModule
|
|
153
|
+
};
|
|
154
|
+
}
|
|
118
155
|
}
|
|
119
156
|
exports.patchModuleLoader = patchModuleLoader;
|
|
120
157
|
//# sourceMappingURL=module-loader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SourceMapper = void 0;
|
|
4
|
-
const sourcemap_codec_1 = require("sourcemap-codec");
|
|
4
|
+
const sourcemap_codec_1 = require("@jridgewell/sourcemap-codec");
|
|
5
5
|
function binaryInsert(array, value, key) {
|
|
6
6
|
if (0 === key) {
|
|
7
7
|
key = '0';
|
|
@@ -248,6 +248,13 @@ class SvelteSnapshotManager {
|
|
|
248
248
|
if (normalizedPath.endsWith('node_modules/svelte/types/runtime/ambient.d.ts')) {
|
|
249
249
|
return '';
|
|
250
250
|
}
|
|
251
|
+
else if (normalizedPath.endsWith('svelte2tsx/svelte-jsx.d.ts')) {
|
|
252
|
+
// Remove the dom lib reference to not load these ambient types in case
|
|
253
|
+
// the user has a tsconfig.json with different lib settings like in
|
|
254
|
+
// https://github.com/sveltejs/language-tools/issues/1733
|
|
255
|
+
const originalText = readFile(path) || '';
|
|
256
|
+
return originalText.replace('/// <reference lib="dom" />', '');
|
|
257
|
+
}
|
|
251
258
|
else if (normalizedPath.endsWith('svelte2tsx/svelte-shims.d.ts')) {
|
|
252
259
|
let originalText = readFile(path) || '';
|
|
253
260
|
if (!originalText.includes('// -- start svelte-ls-remove --')) {
|
package/dist/src/utils.js
CHANGED
|
@@ -69,8 +69,8 @@ function getConfigPathForProject(project) {
|
|
|
69
69
|
}
|
|
70
70
|
exports.getConfigPathForProject = getConfigPathForProject;
|
|
71
71
|
function isStoreVariableIn$storeDeclaration(text, varStart) {
|
|
72
|
-
return (text.lastIndexOf('
|
|
73
|
-
varStart - '
|
|
72
|
+
return (text.lastIndexOf('__sveltets_2_store_get(', varStart) ===
|
|
73
|
+
varStart - '__sveltets_2_store_get('.length);
|
|
74
74
|
}
|
|
75
75
|
exports.isStoreVariableIn$storeDeclaration = isStoreVariableIn$storeDeclaration;
|
|
76
76
|
function get$storeOffsetOf$storeDeclaration(text, storePosition) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-svelte-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "A TypeScript Plugin providing Svelte intellisense",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"author": "The Svelte Community",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@tsconfig/
|
|
22
|
-
"@types/node": "^
|
|
21
|
+
"@tsconfig/node16": "^1.0.0",
|
|
22
|
+
"@types/node": "^16.0.0",
|
|
23
23
|
"typescript": "*"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"@jridgewell/sourcemap-codec": "^1.4.14",
|
|
27
|
+
"svelte2tsx": "~0.6.0"
|
|
28
28
|
}
|
|
29
29
|
}
|