Skip to content

Commit

Permalink
fix: adjust ambient module snipping logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dummdidumm committed Jun 17, 2024
1 parent 730090f commit 0261112
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export namespace DocumentSnapshot {

if (normalizedPath.endsWith('node_modules/svelte/types/index.d.ts')) {
const startIdx = originalText.indexOf(`declare module '*.svelte' {`);
const endIdx = originalText.indexOf(`}`, originalText.indexOf(';', startIdx)) + 1;
const endIdx = originalText.indexOf(`\n}`, startIdx + 1) + 2;
originalText =
originalText.substring(0, startIdx) +
' '.repeat(endIdx - startIdx) +
Expand Down
3 changes: 1 addition & 2 deletions packages/typescript-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ function init(modules: { typescript: typeof ts }): ts.server.PluginModule {
if (snapshot) {
const originalText = snapshot.getText(0, snapshot.getLength());
const startIdx = originalText.indexOf(`declare module '*.svelte' {`);
const endIdx =
originalText.indexOf(`}`, originalText.indexOf(';', startIdx)) + 1;
const endIdx = originalText.indexOf(`\n}`, startIdx + 1) + 2;
return modules.typescript.ScriptSnapshot.fromString(
originalText.substring(0, startIdx) +
' '.repeat(endIdx - startIdx) +
Expand Down

0 comments on commit 0261112

Please sign in to comment.