Skip to content

TypeScript language service parsing error in Svelte files and breaks variable declaration recognition #2791

@burpheart

Description

@burpheart

Describe the bug

When using certain regular expressions (specifically pattern) in Svelte TypeScript files, the TypeScript language service encounters a parsing error that completely breaks variable declaration recognition throughout the entire file. This causes all variables and functions in the template to be marked as "Cannot find name" even though the code compiles and runs correctly.

Reproduction

Create a Svelte file with TypeScript
Add a regular expression containing

 function testFunction(content: string) {
     if (/<!DOCTYPE html>/i.test(content)) { // ❌ This line triggers the bug
       return "html";// ❌ IDE reports : "Expression expected."
     }
     return "json";
   }

Add variables and use them in template:
let testVariable = "hello"; // ✅ This should work
<div>{testVariable}</div> <!-- ❌ IDE reports "Cannot find name 'testVariable'" -->

Expected behaviour

No TypeScript parsing errors
All variables should be properly recognized in the template

System Info

OS: Windows 11
IDE: VS Code / Cursor 1.2.1
Svelte for VS Code 109.9.0

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions