typescript-svelte-plugin 0.3.39 → 0.3.41

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 CHANGED
@@ -98,7 +98,8 @@ function init(modules) {
98
98
  // don't clear semantic cache here
99
99
  // typescript now expected the program updates to be completely in their control
100
100
  // doing so will result in a crash
101
- info.project.markAsDirty();
101
+ // @ts-expect-error internal API since TS 5.5
102
+ info.project.markAsDirty?.();
102
103
  // updateGraph checks for new root files
103
104
  // if there's no tsconfig there isn't root files to check
104
105
  if (projectSvelteFilesManager) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateCallHierarchy = void 0;
3
+ exports.decorateCallHierarchy = decorateCallHierarchy;
4
4
  const utils_1 = require("../utils");
5
5
  const ENSURE_COMPONENT_HELPER = '__sveltets_2_ensureComponent';
6
6
  function decorateCallHierarchy(ls, snapshotManager, typescript) {
@@ -60,7 +60,7 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
60
60
  const snapshot = snapshotManager.get(fileName);
61
61
  return provideCallHierarchyOutgoingCalls(fileName, offset)
62
62
  .concat(program && sourceFile && isComponentModulePosition(fileName, position)
63
- ? getOutgoingCallsForComponent(program, sourceFile) ?? []
63
+ ? (getOutgoingCallsForComponent(program, sourceFile) ?? [])
64
64
  : [])
65
65
  .map((item) => {
66
66
  const to = convertSvelteCallHierarchyItem(item.to, program);
@@ -223,5 +223,4 @@ function decorateCallHierarchy(ls, snapshotManager, typescript) {
223
223
  }) ?? null);
224
224
  }
225
225
  }
226
- exports.decorateCallHierarchy = decorateCallHierarchy;
227
226
  //# sourceMappingURL=call-hierarchy.js.map
@@ -0,0 +1,5 @@
1
+ import type ts from 'typescript';
2
+ import { SvelteSnapshotManager } from '../svelte-snapshots';
3
+ type _ts = typeof ts;
4
+ export declare function decorateQuickFixAndRefactor(ls: ts.LanguageService, ts: _ts, snapshotManager: SvelteSnapshotManager): void;
5
+ export {};
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decorateQuickFixAndRefactor = decorateQuickFixAndRefactor;
4
+ const utils_1 = require("../utils");
5
+ function decorateQuickFixAndRefactor(ls, ts, snapshotManager) {
6
+ const getEditsForRefactor = ls.getEditsForRefactor;
7
+ const getCodeFixesAtPosition = ls.getCodeFixesAtPosition;
8
+ ls.getEditsForRefactor = (...args) => {
9
+ const result = getEditsForRefactor(...args);
10
+ if (!result) {
11
+ return;
12
+ }
13
+ const edits = result.edits.map(mapFileTextChanges).filter(utils_1.isNotNullOrUndefined);
14
+ if (edits.length === 0) {
15
+ return;
16
+ }
17
+ return {
18
+ ...result,
19
+ edits
20
+ };
21
+ };
22
+ ls.getCodeFixesAtPosition = (...args) => {
23
+ const result = getCodeFixesAtPosition(...args);
24
+ return result
25
+ .map((fix) => {
26
+ return {
27
+ ...fix,
28
+ changes: fix.changes.map(mapFileTextChanges).filter(utils_1.isNotNullOrUndefined)
29
+ };
30
+ })
31
+ .filter((fix) => fix.changes.length > 0);
32
+ };
33
+ function mapFileTextChanges(change) {
34
+ const snapshot = snapshotManager.get(change.fileName);
35
+ if (!(0, utils_1.isSvelteFilePath)(change.fileName) || !snapshot) {
36
+ return change;
37
+ }
38
+ let baseIndent;
39
+ const getBaseIndent = () => {
40
+ if (baseIndent !== undefined) {
41
+ return baseIndent;
42
+ }
43
+ baseIndent = getIndentOfFirstStatement(ts, ls, change.fileName, snapshot);
44
+ return baseIndent;
45
+ };
46
+ const textChanges = change.textChanges
47
+ .map((textChange) => mapEdit(textChange, snapshot, getBaseIndent))
48
+ .filter(utils_1.isNotNullOrUndefined);
49
+ // If part of the text changes are invalid, filter out the whole change
50
+ if (textChanges.length === 0 || textChanges.length !== change.textChanges.length) {
51
+ return null;
52
+ }
53
+ return {
54
+ ...change,
55
+ textChanges
56
+ };
57
+ }
58
+ }
59
+ function mapEdit(change, snapshot, getBaseIndent) {
60
+ const isNewImportStatement = change.newText.trimStart().startsWith('import');
61
+ if (isNewImportStatement) {
62
+ return mapNewImport(change, snapshot, getBaseIndent);
63
+ }
64
+ const span = snapshot.getOriginalTextSpan(change.span);
65
+ if (!span) {
66
+ return null;
67
+ }
68
+ return {
69
+ span,
70
+ newText: change.newText
71
+ };
72
+ }
73
+ function mapNewImport(change, snapshot, getBaseIndent) {
74
+ const previousLineEnds = getPreviousLineEnds(snapshot.getText(), change.span.start);
75
+ if (previousLineEnds === -1) {
76
+ return null;
77
+ }
78
+ const mappable = snapshot.getOriginalTextSpan({
79
+ start: previousLineEnds,
80
+ length: 0
81
+ });
82
+ if (!mappable) {
83
+ // There might not be any import at all but this is rare enough so ignore for now
84
+ return null;
85
+ }
86
+ const originalText = snapshot.getOriginalText();
87
+ const span = {
88
+ start: originalText.indexOf('\n', mappable.start) + 1,
89
+ length: change.span.length
90
+ };
91
+ const baseIndent = getBaseIndent();
92
+ let newText = baseIndent
93
+ ? change.newText
94
+ .split('\n')
95
+ .map((line) => (line ? baseIndent + line : line))
96
+ .join('\n')
97
+ : change.newText;
98
+ return { span, newText };
99
+ }
100
+ function getPreviousLineEnds(text, start) {
101
+ const index = text.lastIndexOf('\n', start);
102
+ if (index === -1) {
103
+ return index;
104
+ }
105
+ if (text[index - 1] === '\r') {
106
+ return index - 1;
107
+ }
108
+ return index;
109
+ }
110
+ function getIndentOfFirstStatement(ts, ls, fileName, snapshot) {
111
+ const firstExportOrImport = ls
112
+ .getProgram()
113
+ ?.getSourceFile(fileName)
114
+ ?.statements.find((node) => ts.isExportDeclaration(node) || ts.isImportDeclaration(node));
115
+ const originalPosition = firstExportOrImport
116
+ ? snapshot.getOriginalOffset(firstExportOrImport.getStart())
117
+ : -1;
118
+ if (originalPosition === -1) {
119
+ return '';
120
+ }
121
+ const source = snapshot.getOriginalText();
122
+ const start = source.lastIndexOf('\n', originalPosition) + 1;
123
+ let index = start;
124
+ while (index < originalPosition) {
125
+ const char = source[index];
126
+ if (char.trim()) {
127
+ break;
128
+ }
129
+ index++;
130
+ }
131
+ return source.substring(start, index);
132
+ }
133
+ //# sourceMappingURL=code-action.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateCompletions = void 0;
3
+ exports.decorateCompletions = decorateCompletions;
4
4
  const path_1 = require("path");
5
5
  const utils_1 = require("../utils");
6
6
  const sveltekit_1 = require("./sveltekit");
@@ -199,7 +199,6 @@ function decorateCompletions(ls, info, ts, logger) {
199
199
  return getSignatureHelpItems(fileName, position, options);
200
200
  };
201
201
  }
202
- exports.decorateCompletions = decorateCompletions;
203
202
  function adjustPath(path) {
204
203
  return path.replace(/(['"])(.+?)['"]/,
205
204
  // .js logic for node16 module resolution
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateGetDefinition = void 0;
3
+ exports.decorateGetDefinition = decorateGetDefinition;
4
4
  const utils_1 = require("../utils");
5
5
  const sveltekit_1 = require("./sveltekit");
6
6
  function decorateGetDefinition(ls, info, ts, snapshotManager, logger) {
@@ -38,7 +38,6 @@ function decorateGetDefinition(ls, info, ts, snapshotManager, logger) {
38
38
  };
39
39
  };
40
40
  }
41
- exports.decorateGetDefinition = decorateGetDefinition;
42
41
  function getKitDefinitions(ts, info, fileName, position) {
43
42
  const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
44
43
  if (!result)
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.decorateDiagnostics = void 0;
6
+ exports.decorateDiagnostics = decorateDiagnostics;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const svelte2tsx_1 = require("svelte2tsx");
9
9
  const utils_1 = require("../utils");
@@ -13,7 +13,6 @@ function decorateDiagnostics(ls, info, typescript, logger) {
13
13
  decorateSemanticDiagnostics(ls, info, typescript, logger);
14
14
  decorateSuggestionDiagnostics(ls, info, typescript, logger);
15
15
  }
16
- exports.decorateDiagnostics = decorateDiagnostics;
17
16
  function decorateSyntacticDiagnostics(ls, info, typescript, logger) {
18
17
  const getSyntacticDiagnostics = ls.getSyntacticDiagnostics;
19
18
  ls.getSyntacticDiagnostics = (fileName) => {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateFileReferences = void 0;
3
+ exports.decorateFileReferences = decorateFileReferences;
4
4
  const utils_1 = require("../utils");
5
5
  function decorateFileReferences(ls, snapshotManager) {
6
6
  const getFileReferences = ls.getFileReferences;
@@ -23,5 +23,4 @@ function decorateFileReferences(ls, snapshotManager) {
23
23
  .filter(utils_1.isNotNullOrUndefined);
24
24
  };
25
25
  }
26
- exports.decorateFileReferences = decorateFileReferences;
27
26
  //# sourceMappingURL=file-references.js.map
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateFindReferences = void 0;
3
+ exports.decorateFindReferences = decorateFindReferences;
4
4
  const utils_1 = require("../utils");
5
5
  function decorateFindReferences(ls, snapshotManager, logger) {
6
6
  decorateGetReferencesAtPosition(ls, snapshotManager, logger);
7
7
  _decorateFindReferences(ls, snapshotManager, logger);
8
8
  }
9
- exports.decorateFindReferences = decorateFindReferences;
10
9
  function _decorateFindReferences(ls, snapshotManager, logger) {
11
10
  const findReferences = ls.findReferences;
12
11
  const getReferences = (fileName, position) => findReferences(fileName, position)?.reduce((acc, curr) => acc.concat(curr.references), []);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateLanguageServiceHost = void 0;
3
+ exports.decorateLanguageServiceHost = decorateLanguageServiceHost;
4
4
  function decorateLanguageServiceHost(host) {
5
5
  const originalReadDirectory = host.readDirectory?.bind(host);
6
6
  host.readDirectory = originalReadDirectory
@@ -10,5 +10,4 @@ function decorateLanguageServiceHost(host) {
10
10
  }
11
11
  : undefined;
12
12
  }
13
- exports.decorateLanguageServiceHost = decorateLanguageServiceHost;
14
13
  //# sourceMappingURL=host.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateHover = void 0;
3
+ exports.decorateHover = decorateHover;
4
4
  const utils_1 = require("../utils");
5
5
  const sveltekit_1 = require("./sveltekit");
6
6
  function decorateHover(ls, info, ts, logger) {
@@ -28,5 +28,4 @@ function decorateHover(ls, info, ts, logger) {
28
28
  };
29
29
  };
30
30
  }
31
- exports.decorateHover = decorateHover;
32
31
  //# sourceMappingURL=hover.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateGetImplementation = void 0;
3
+ exports.decorateGetImplementation = decorateGetImplementation;
4
4
  const utils_1 = require("../utils");
5
5
  function decorateGetImplementation(ls, snapshotManager, logger) {
6
6
  const getImplementationAtPosition = ls.getImplementationAtPosition;
@@ -29,5 +29,4 @@ function decorateGetImplementation(ls, snapshotManager, logger) {
29
29
  .filter(utils_1.isNotNullOrUndefined);
30
30
  };
31
31
  }
32
- exports.decorateGetImplementation = decorateGetImplementation;
33
32
  //# sourceMappingURL=implementation.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateLanguageService = exports.isPatched = void 0;
3
+ exports.isPatched = isPatched;
4
+ exports.decorateLanguageService = decorateLanguageService;
4
5
  const utils_1 = require("../utils");
5
6
  const call_hierarchy_1 = require("./call-hierarchy");
6
7
  const completions_1 = require("./completions");
@@ -16,11 +17,11 @@ const host_1 = require("./host");
16
17
  const navigate_to_items_1 = require("./navigate-to-items");
17
18
  const file_references_1 = require("./file-references");
18
19
  const move_to_file_1 = require("./move-to-file");
20
+ const code_action_1 = require("./code-action");
19
21
  const patchedProject = new Set();
20
22
  function isPatched(project) {
21
23
  return patchedProject.has(project.getProjectName());
22
24
  }
23
- exports.isPatched = isPatched;
24
25
  function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript, onDispose) {
25
26
  patchedProject.add(info.project.getProjectName());
26
27
  // Decorate using a proxy so we can dynamically enable/disable method
@@ -30,7 +31,6 @@ function decorateLanguageService(ls, snapshotManager, logger, configManager, inf
30
31
  decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript, onDispose);
31
32
  return proxy;
32
33
  }
33
- exports.decorateLanguageService = decorateLanguageService;
34
34
  function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript, onDispose) {
35
35
  patchLineColumnOffset(ls, snapshotManager);
36
36
  (0, rename_1.decorateRename)(ls, snapshotManager, logger);
@@ -46,6 +46,7 @@ function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescr
46
46
  (0, navigate_to_items_1.decorateNavigateToItems)(ls, snapshotManager);
47
47
  (0, file_references_1.decorateFileReferences)(ls, snapshotManager);
48
48
  (0, move_to_file_1.decorateMoveToRefactoringFileSuggestions)(ls);
49
+ (0, code_action_1.decorateQuickFixAndRefactor)(ls, typescript, snapshotManager);
49
50
  decorateDispose(ls, info.project, onDispose);
50
51
  return ls;
51
52
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateInlayHints = void 0;
3
+ exports.decorateInlayHints = decorateInlayHints;
4
4
  const sveltekit_1 = require("./sveltekit");
5
5
  function decorateInlayHints(ls, info, ts, logger) {
6
6
  const provideInlayHints = ls.provideInlayHints;
@@ -22,5 +22,4 @@ function decorateInlayHints(ls, info, ts, logger) {
22
22
  }));
23
23
  };
24
24
  }
25
- exports.decorateInlayHints = decorateInlayHints;
26
25
  //# sourceMappingURL=inlay-hints.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateMoveToRefactoringFileSuggestions = void 0;
3
+ exports.decorateMoveToRefactoringFileSuggestions = decorateMoveToRefactoringFileSuggestions;
4
4
  function decorateMoveToRefactoringFileSuggestions(ls) {
5
5
  const getMoveToRefactoringFileSuggestions = ls.getMoveToRefactoringFileSuggestions;
6
6
  ls.getMoveToRefactoringFileSuggestions = (fileName, positionOrRange, preferences, triggerReason, kind) => {
@@ -20,5 +20,4 @@ function decorateMoveToRefactoringFileSuggestions(ls) {
20
20
  }
21
21
  };
22
22
  }
23
- exports.decorateMoveToRefactoringFileSuggestions = decorateMoveToRefactoringFileSuggestions;
24
23
  //# sourceMappingURL=move-to-file.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateNavigateToItems = void 0;
3
+ exports.decorateNavigateToItems = decorateNavigateToItems;
4
4
  const utils_1 = require("../utils");
5
5
  function decorateNavigateToItems(ls, snapshotManager) {
6
6
  const getNavigateToItems = ls.getNavigateToItems;
@@ -34,5 +34,4 @@ function decorateNavigateToItems(ls, snapshotManager) {
34
34
  .filter(utils_1.isNotNullOrUndefined);
35
35
  };
36
36
  }
37
- exports.decorateNavigateToItems = decorateNavigateToItems;
38
37
  //# sourceMappingURL=navigate-to-items.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateRename = void 0;
3
+ exports.decorateRename = decorateRename;
4
4
  const utils_1 = require("../utils");
5
5
  function decorateRename(ls, snapshotManager, logger) {
6
6
  const findRenameLocations = ls.findRenameLocations;
@@ -56,5 +56,4 @@ function decorateRename(ls, snapshotManager, logger) {
56
56
  return converted;
57
57
  }
58
58
  }
59
- exports.decorateRename = decorateRename;
60
59
  //# sourceMappingURL=rename.js.map
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVirtualLS = exports.isKitRouteExportAllowedIn = exports.kitExports = void 0;
3
+ exports.kitExports = void 0;
4
+ exports.isKitRouteExportAllowedIn = isKitRouteExportAllowedIn;
5
+ exports.getVirtualLS = getVirtualLS;
4
6
  const utils_1 = require("../utils");
5
7
  const svelte2tsx_1 = require("svelte2tsx");
6
8
  const cache = new WeakMap();
@@ -476,7 +478,6 @@ function isKitRouteExportAllowedIn(basename, kitExport) {
476
478
  ? allowedIn.includes('server')
477
479
  : allowedIn.includes('universal')));
478
480
  }
479
- exports.isKitRouteExportAllowedIn = isKitRouteExportAllowedIn;
480
481
  const kitFilesSettings = {
481
482
  paramsPath: 'src/params',
482
483
  clientHooksPath: 'src/hooks.client',
@@ -746,5 +747,4 @@ function getVirtualLS(fileName, info, ts, logger) {
746
747
  };
747
748
  }
748
749
  }
749
- exports.getVirtualLS = getVirtualLS;
750
750
  //# sourceMappingURL=sveltekit.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.decorateUpdateImports = void 0;
6
+ exports.decorateUpdateImports = decorateUpdateImports;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const utils_1 = require("../utils");
9
9
  function decorateUpdateImports(ls, snapshotManager, logger) {
@@ -33,5 +33,4 @@ function decorateUpdateImports(ls, snapshotManager, logger) {
33
33
  });
34
34
  };
35
35
  }
36
- exports.decorateUpdateImports = decorateUpdateImports;
37
36
  //# sourceMappingURL=update-imports.js.map
@@ -2,13 +2,6 @@ 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
- }
12
5
  /**
13
6
  * Creates a module loader than can also resolve `.svelte` files.
14
7
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patchModuleLoader = void 0;
3
+ exports.patchModuleLoader = patchModuleLoader;
4
4
  const svelte_sys_1 = require("./svelte-sys");
5
5
  const utils_1 = require("./utils");
6
6
  /**
@@ -65,6 +65,8 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
65
65
  lsHost.resolveModuleNameLiterals = resolveModuleNameLiterals;
66
66
  }
67
67
  else {
68
+ // TODO do we need to keep this around? We're requiring 5.0 now, so TS doesn't need it,
69
+ // but would this break when other TS plugins are used and we no longer provide it?
68
70
  lsHost.resolveModuleNames = resolveModuleNames;
69
71
  }
70
72
  const origRemoveFile = project.removeFile.bind(project);
@@ -95,11 +97,15 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
95
97
  }
96
98
  return resolved.map((tsResolvedModule, idx) => {
97
99
  const moduleName = moduleNames[idx];
98
- if (tsResolvedModule || !(0, utils_1.ensureRealSvelteFilePath)(moduleName).endsWith('.svelte')) {
100
+ if (!(0, utils_1.isSvelteFilePath)(moduleName) ||
101
+ // corresponding .d.ts files take precedence over .svelte files
102
+ tsResolvedModule?.resolvedFileName.endsWith('.d.ts') ||
103
+ tsResolvedModule?.resolvedFileName.endsWith('.d.svelte.ts')) {
99
104
  return tsResolvedModule;
100
105
  }
101
- return resolveSvelteModuleNameFromCache(moduleName, containingFile, compilerOptions)
102
- .resolvedModule;
106
+ const result = resolveSvelteModuleNameFromCache(moduleName, containingFile, compilerOptions).resolvedModule;
107
+ // .svelte takes precedence over .svelte.ts etc
108
+ return result ?? tsResolvedModule;
103
109
  });
104
110
  }
105
111
  function resolveSvelteModuleName(name, containingFile, compilerOptions) {
@@ -138,11 +144,16 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
138
144
  }
139
145
  return resolved.map((tsResolvedModule, idx) => {
140
146
  const moduleName = moduleLiterals[idx].text;
141
- if (tsResolvedModule.resolvedModule ||
142
- !(0, utils_1.ensureRealSvelteFilePath)(moduleName).endsWith('.svelte')) {
147
+ const resolvedModule = tsResolvedModule.resolvedModule;
148
+ if (!(0, utils_1.isSvelteFilePath)(moduleName) ||
149
+ // corresponding .d.ts files take precedence over .svelte files
150
+ resolvedModule?.resolvedFileName.endsWith('.d.ts') ||
151
+ resolvedModule?.resolvedFileName.endsWith('.d.svelte.ts')) {
143
152
  return tsResolvedModule;
144
153
  }
145
- return resolveSvelteModuleNameFromCache(moduleName, containingFile, options);
154
+ const result = resolveSvelteModuleNameFromCache(moduleName, containingFile, options);
155
+ // .svelte takes precedence over .svelte.ts etc
156
+ return result.resolvedModule ? result : tsResolvedModule;
146
157
  });
147
158
  }
148
159
  function resolveSvelteModuleNameFromCache(moduleName, containingFile, options) {
@@ -159,5 +170,4 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
159
170
  };
160
171
  }
161
172
  }
162
- exports.patchModuleLoader = patchModuleLoader;
163
173
  //# sourceMappingURL=module-loader.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSvelteSys = void 0;
3
+ exports.createSvelteSys = createSvelteSys;
4
4
  const utils_1 = require("./utils");
5
5
  /**
6
6
  * This should only be accessed by TS svelte module resolution.
@@ -26,12 +26,11 @@ function createSvelteSys(ts, logger) {
26
26
  const realpath = ts.sys.realpath;
27
27
  svelteSys.realpath = function (path) {
28
28
  if ((0, utils_1.isVirtualSvelteFilePath)(path)) {
29
- return realpath((0, utils_1.toRealSvelteFilePath)(path)) + '.ts';
29
+ return realpath((0, utils_1.toRealSvelteFilePath)(path));
30
30
  }
31
31
  return realpath(path);
32
32
  };
33
33
  }
34
34
  return svelteSys;
35
35
  }
36
- exports.createSvelteSys = createSvelteSys;
37
36
  //# sourceMappingURL=svelte-sys.js.map
@@ -4,6 +4,7 @@ type _ts = typeof ts;
4
4
  export declare function isSvelteFilePath(filePath: string): boolean;
5
5
  export declare function isVirtualSvelteFilePath(filePath: string): boolean;
6
6
  export declare function toRealSvelteFilePath(filePath: string): string;
7
+ export declare function toVirtualSvelteFilePath(svelteFilePath: string): string;
7
8
  export declare function ensureRealSvelteFilePath(filePath: string): string;
8
9
  export declare function isNotNullOrUndefined<T>(val: T | undefined | null): val is T;
9
10
  /**
package/dist/src/utils.js CHANGED
@@ -1,27 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.importSvelteCompiler = exports.isSvelteProject = exports.hasNodeModule = exports.getProjectDirectory = exports.findIdentifier = exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.isTopLevelExport = exports.findNodeAtPosition = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
3
+ exports.isSvelteFilePath = isSvelteFilePath;
4
+ exports.isVirtualSvelteFilePath = isVirtualSvelteFilePath;
5
+ exports.toRealSvelteFilePath = toRealSvelteFilePath;
6
+ exports.toVirtualSvelteFilePath = toVirtualSvelteFilePath;
7
+ exports.ensureRealSvelteFilePath = ensureRealSvelteFilePath;
8
+ exports.isNotNullOrUndefined = isNotNullOrUndefined;
9
+ exports.isInGeneratedCode = isInGeneratedCode;
10
+ exports.isNoTextSpanInGeneratedCode = isNoTextSpanInGeneratedCode;
11
+ exports.replaceDeep = replaceDeep;
12
+ exports.getConfigPathForProject = getConfigPathForProject;
13
+ exports.isStoreVariableIn$storeDeclaration = isStoreVariableIn$storeDeclaration;
14
+ exports.get$storeOffsetOf$storeDeclaration = get$storeOffsetOf$storeDeclaration;
15
+ exports.findNodeAtSpan = findNodeAtSpan;
16
+ exports.findNodeAtPosition = findNodeAtPosition;
17
+ exports.isTopLevelExport = isTopLevelExport;
18
+ exports.isGeneratedSvelteComponentName = isGeneratedSvelteComponentName;
19
+ exports.offsetOfGeneratedComponentExport = offsetOfGeneratedComponentExport;
20
+ exports.gatherDescendants = gatherDescendants;
21
+ exports.findIdentifier = findIdentifier;
22
+ exports.getProjectDirectory = getProjectDirectory;
23
+ exports.hasNodeModule = hasNodeModule;
24
+ exports.isSvelteProject = isSvelteProject;
25
+ exports.importSvelteCompiler = importSvelteCompiler;
4
26
  const path_1 = require("path");
5
27
  function isSvelteFilePath(filePath) {
6
28
  return filePath.endsWith('.svelte');
7
29
  }
8
- exports.isSvelteFilePath = isSvelteFilePath;
9
30
  function isVirtualSvelteFilePath(filePath) {
10
- return filePath.endsWith('.svelte.ts');
31
+ return filePath.endsWith('.d.svelte.ts');
11
32
  }
12
- exports.isVirtualSvelteFilePath = isVirtualSvelteFilePath;
13
33
  function toRealSvelteFilePath(filePath) {
14
- return filePath.slice(0, -'.ts'.length);
34
+ return filePath.slice(0, -11 /* 'd.svelte.ts'.length */) + 'svelte';
35
+ }
36
+ function toVirtualSvelteFilePath(svelteFilePath) {
37
+ return isVirtualSvelteFilePath(svelteFilePath)
38
+ ? svelteFilePath
39
+ : svelteFilePath.slice(0, -6 /* 'svelte'.length */) + 'd.svelte.ts';
15
40
  }
16
- exports.toRealSvelteFilePath = toRealSvelteFilePath;
17
41
  function ensureRealSvelteFilePath(filePath) {
18
42
  return isVirtualSvelteFilePath(filePath) ? toRealSvelteFilePath(filePath) : filePath;
19
43
  }
20
- exports.ensureRealSvelteFilePath = ensureRealSvelteFilePath;
21
44
  function isNotNullOrUndefined(val) {
22
45
  return val !== undefined && val !== null;
23
46
  }
24
- exports.isNotNullOrUndefined = isNotNullOrUndefined;
25
47
  /**
26
48
  * Checks if this a section that should be completely ignored
27
49
  * because it's purely generated.
@@ -33,7 +55,6 @@ function isInGeneratedCode(text, start, end) {
33
55
  const lastEnd = text.substring(lineStart, start).lastIndexOf('/*Ωignore_endΩ*/');
34
56
  return lastStart > lastEnd && text.substring(end, lineEnd).includes('/*Ωignore_endΩ*/');
35
57
  }
36
- exports.isInGeneratedCode = isInGeneratedCode;
37
58
  /**
38
59
  * Checks that this isn't a text span that should be completely ignored
39
60
  * because it's purely generated.
@@ -41,7 +62,6 @@ exports.isInGeneratedCode = isInGeneratedCode;
41
62
  function isNoTextSpanInGeneratedCode(text, span) {
42
63
  return !isInGeneratedCode(text, span.start, span.start + span.length);
43
64
  }
44
- exports.isNoTextSpanInGeneratedCode = isNoTextSpanInGeneratedCode;
45
65
  /**
46
66
  * Replace all occurrences of a string within an object with another string,
47
67
  */
@@ -63,21 +83,17 @@ function replaceDeep(obj, searchStr, replacementStr) {
63
83
  return _obj;
64
84
  }
65
85
  }
66
- exports.replaceDeep = replaceDeep;
67
86
  function getConfigPathForProject(project) {
68
87
  return (project.canonicalConfigFilePath ??
69
88
  project.getCompilerOptions().configFilePath);
70
89
  }
71
- exports.getConfigPathForProject = getConfigPathForProject;
72
90
  function isStoreVariableIn$storeDeclaration(text, varStart) {
73
91
  return (text.lastIndexOf('__sveltets_2_store_get(', varStart) ===
74
92
  varStart - '__sveltets_2_store_get('.length);
75
93
  }
76
- exports.isStoreVariableIn$storeDeclaration = isStoreVariableIn$storeDeclaration;
77
94
  function get$storeOffsetOf$storeDeclaration(text, storePosition) {
78
95
  return text.lastIndexOf(' =', storePosition) - 1;
79
96
  }
80
- exports.get$storeOffsetOf$storeDeclaration = get$storeOffsetOf$storeDeclaration;
81
97
  /**
82
98
  * Finds node exactly matching span {start, length}.
83
99
  */
@@ -107,7 +123,6 @@ function findNodeAtSpan(node, span, predicate) {
107
123
  }
108
124
  }
109
125
  }
110
- exports.findNodeAtSpan = findNodeAtSpan;
111
126
  /**
112
127
  * Finds node somewhere at position.
113
128
  */
@@ -133,7 +148,6 @@ function findNodeAtPosition(node, pos, predicate) {
133
148
  }
134
149
  }
135
150
  }
136
- exports.findNodeAtPosition = findNodeAtPosition;
137
151
  /**
138
152
  * True if is `export const/let/function`
139
153
  */
@@ -148,16 +162,13 @@ function isTopLevelExport(ts, node, source) {
148
162
  ts.isFunctionDeclaration(node.parent) &&
149
163
  source.statements.includes(node.parent)));
150
164
  }
151
- exports.isTopLevelExport = isTopLevelExport;
152
165
  const COMPONENT_SUFFIX = '__SvelteComponent_';
153
166
  function isGeneratedSvelteComponentName(className) {
154
167
  return className.endsWith(COMPONENT_SUFFIX);
155
168
  }
156
- exports.isGeneratedSvelteComponentName = isGeneratedSvelteComponentName;
157
169
  function offsetOfGeneratedComponentExport(snapshot) {
158
170
  return snapshot.getText().lastIndexOf(COMPONENT_SUFFIX);
159
171
  }
160
- exports.offsetOfGeneratedComponentExport = offsetOfGeneratedComponentExport;
161
172
  function gatherDescendants(node, predicate, dest = []) {
162
173
  if (predicate(node)) {
163
174
  dest.push(node);
@@ -169,7 +180,6 @@ function gatherDescendants(node, predicate, dest = []) {
169
180
  }
170
181
  return dest;
171
182
  }
172
- exports.gatherDescendants = gatherDescendants;
173
183
  function findIdentifier(ts, node) {
174
184
  if (ts.isIdentifier(node)) {
175
185
  return node;
@@ -187,7 +197,6 @@ function findIdentifier(ts, node) {
187
197
  node = node.parent;
188
198
  }
189
199
  }
190
- exports.findIdentifier = findIdentifier;
191
200
  function getProjectDirectory(project) {
192
201
  const compilerOptions = project.getCompilerOptions();
193
202
  if (typeof compilerOptions.configFilePath === 'string') {
@@ -196,7 +205,6 @@ function getProjectDirectory(project) {
196
205
  const packageJsonPath = (0, path_1.join)(project.getCurrentDirectory(), 'package.json');
197
206
  return project.fileExists(packageJsonPath) ? project.getCurrentDirectory() : undefined;
198
207
  }
199
- exports.getProjectDirectory = getProjectDirectory;
200
208
  function hasNodeModule(startPath, module) {
201
209
  try {
202
210
  const hasModule = require.resolve(module, { paths: [startPath] });
@@ -208,7 +216,6 @@ function hasNodeModule(startPath, module) {
208
216
  return e?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED';
209
217
  }
210
218
  }
211
- exports.hasNodeModule = hasNodeModule;
212
219
  function isSvelteProject(project) {
213
220
  const projectDirectory = getProjectDirectory(project);
214
221
  if (projectDirectory) {
@@ -222,7 +229,6 @@ function isSvelteProject(project) {
222
229
  .filter((file) => file.endsWith('package.json') && !hasConfigInConjunction(file, project));
223
230
  return packageJsons.some((packageJsonPath) => hasNodeModule((0, path_1.dirname)(packageJsonPath), 'svelte'));
224
231
  }
225
- exports.isSvelteProject = isSvelteProject;
226
232
  function hasConfigInConjunction(packageJsonPath, project) {
227
233
  const dir = (0, path_1.dirname)(packageJsonPath);
228
234
  return (project.fileExists((0, path_1.join)(dir, 'tsconfig.json')) ||
@@ -244,5 +250,4 @@ function importSvelteCompiler(fromPath) {
244
250
  // ignore
245
251
  }
246
252
  }
247
- exports.importSvelteCompiler = importSvelteCompiler;
248
253
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.39",
3
+ "version": "0.3.41",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "keywords": [
@@ -10,14 +10,19 @@
10
10
  "plugin"
11
11
  ],
12
12
  "author": "The Svelte Community",
13
+ "homepage": "https://github.com/sveltejs/language-tools/tree/master/packages/typescript-plugin",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/sveltejs/language-tools/tree/master/packages/typescript-plugin"
17
+ },
13
18
  "license": "MIT",
14
19
  "devDependencies": {
15
- "@types/node": "^16.0.0",
16
- "typescript": "^5.4.5",
17
- "svelte": "^3.57.0"
20
+ "@types/node": "^18.0.0",
21
+ "typescript": "^5.5.2",
22
+ "svelte": "^4.2.19"
18
23
  },
19
24
  "dependencies": {
20
- "@jridgewell/sourcemap-codec": "^1.4.14",
25
+ "@jridgewell/sourcemap-codec": "^1.5.0",
21
26
  "svelte2tsx": "~0.7.0"
22
27
  },
23
28
  "scripts": {