fix: wrap module script content in block scope to prevent false redeclaration errors - #308027
Conversation
…icrosoft#229357) When multiple <script> tags exist in an HTML file, the HTML language server concatenates their content into a single virtual JavaScript document for validation. This causes false "Cannot redeclare block-scoped variable" errors when <script type="module"> tags declare variables with the same name as regular <script> tags, since module scripts should have their own scope per the HTML spec. Fix by wrapping <script type="module"> content in block scope delimiters ({ ... }) in the virtual document, preventing variable name collisions between module scripts and regular scripts.
6fe875b to
b5972f7
Compare
There was a problem hiding this comment.
Pull request overview
Attempts to isolate HTML module scripts in embedded JavaScript validation.
Changes:
- Tracks module script regions.
- Wraps module contents in braces.
- Adds embedded-document tests.
Show a summary per file
| File | Description |
|---|---|
embeddedSupport.ts |
Detects and wraps module scripts. |
embedded.test.ts |
Tests module detection and generated content. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Medium
81a4f47
|
Addressed the review feedback in 81a4f47. The brace-based approach has been replaced with validation-specific embedded documents: classic scripts are validated together, while each The tests now exercise diagnostic behavior instead of only checking generated braces. Coverage includes classic/module and module/module duplicate names, Validation: HTML language server compilation succeeded, all 70 server tests passed, and hygiene passed. |
|
Added two focused regression checks in 9920ae5: classic |
Summary
<script type="module">case-insensitively and validates classic scripts together while validating each module script as a separate ES module source document.vardeclarations, classic-script redeclarations, module syntax, top-levelawait, and diagnostic range mapping.Test plan
var, without a false redeclaration error.import.meta,export) and top-levelawaitvalidate without syntax errors.