Skip to content

Commit 0261112

Browse files
committed
fix: adjust ambient module snipping logic
Since sveltejs/svelte#12061 the `declare module "*.svelte" {..}` declaration contains more closing braces and the logic to snip it out is now outdated. This updates the logic to instead look for the first bracket that comes directly after one line.
1 parent 730090f commit 0261112

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

packages/language-server/src/plugins/typescript/DocumentSnapshot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export namespace DocumentSnapshot {
136136

137137
if (normalizedPath.endsWith('node_modules/svelte/types/index.d.ts')) {
138138
const startIdx = originalText.indexOf(`declare module '*.svelte' {`);
139-
const endIdx = originalText.indexOf(`}`, originalText.indexOf(';', startIdx)) + 1;
139+
const endIdx = originalText.indexOf(`\n}`, startIdx + 1) + 2;
140140
originalText =
141141
originalText.substring(0, startIdx) +
142142
' '.repeat(endIdx - startIdx) +

packages/typescript-plugin/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ function init(modules: { typescript: typeof ts }): ts.server.PluginModule {
6767
if (snapshot) {
6868
const originalText = snapshot.getText(0, snapshot.getLength());
6969
const startIdx = originalText.indexOf(`declare module '*.svelte' {`);
70-
const endIdx =
71-
originalText.indexOf(`}`, originalText.indexOf(';', startIdx)) + 1;
70+
const endIdx = originalText.indexOf(`\n}`, startIdx + 1) + 2;
7271
return modules.typescript.ScriptSnapshot.fromString(
7372
originalText.substring(0, startIdx) +
7473
' '.repeat(endIdx - startIdx) +

0 commit comments

Comments
 (0)