Skip to content

Commit 0819c3a

Browse files
authored
(fix) use ts only through injection (#1902)
There were two ts usages through imports, one of them using an import that is no longer available which broke the plugin. Guard against that by only using the ts version that is passed to the plugin, which is more correct anyway #1897
1 parent f43f3ad commit 0819c3a

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

packages/typescript-plugin/src/language-service/completions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { basename, dirname, extname } from 'path';
2-
import ts from 'typescript/lib/tsserverlibrary';
2+
import type ts from 'typescript';
33
import { Logger } from '../logger';
44
import { isSvelteFilePath, replaceDeep } from '../utils';
55

6+
type _ts = typeof ts;
7+
68
const componentPostfix = '__SvelteComponent_';
79

8-
export function decorateCompletions(ls: ts.LanguageService, logger: Logger): void {
10+
export function decorateCompletions(ls: ts.LanguageService, ts: _ts, logger: Logger): void {
911
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
1012
ls.getCompletionsAtPosition = (fileName, position, options) => {
1113
const completions = getCompletionsAtPosition(fileName, position, options);

packages/typescript-plugin/src/language-service/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function decorateLanguageServiceInner(
4242
decorateRename(ls, snapshotManager, logger);
4343
decorateDiagnostics(ls, logger);
4444
decorateFindReferences(ls, snapshotManager, logger);
45-
decorateCompletions(ls, logger);
45+
decorateCompletions(ls, typescript, logger);
4646
decorateGetDefinition(ls, snapshotManager, logger);
4747
decorateGetImplementation(ls, snapshotManager, logger);
4848
decorateUpdateImports(ls, snapshotManager, logger);

packages/typescript-plugin/src/module-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function patchModuleLoader(
102102
project: ts.server.Project,
103103
configManager: ConfigManager
104104
): void {
105-
const svelteSys = createSvelteSys(logger);
105+
const svelteSys = createSvelteSys(typescript, logger);
106106
const moduleCache = new ModuleResolutionCache(project.projectService);
107107
const origResolveModuleNames = lsHost.resolveModuleNames?.bind(lsHost);
108108
const origResolveModuleNamLiterals = lsHost.resolveModuleNameLiterals?.bind(lsHost);

packages/typescript-plugin/src/svelte-sys.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import ts from 'typescript';
1+
import type ts from 'typescript';
22
import { Logger } from './logger';
33
import { ensureRealSvelteFilePath, isVirtualSvelteFilePath, toRealSvelteFilePath } from './utils';
44

5+
type _ts = typeof ts;
6+
57
/**
68
* This should only be accessed by TS svelte module resolution.
79
*/
8-
export function createSvelteSys(logger: Logger) {
10+
export function createSvelteSys(ts: _ts, logger: Logger) {
911
const svelteSys: ts.System = {
1012
...ts.sys,
1113
fileExists(path: string) {

0 commit comments

Comments
 (0)