fix: add isModule property to Node for script type=module detection#243
Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: add isModule property to Node for script type=module detection#243maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #133
Bug: Module scripts (
<script type="module">) were not distinguishable from classic scripts, causing consumers to incorrectly report "Cannot redeclare block-scoped variable" errors when multiple module scripts each declare the same variable.Root Cause: The
Nodeclass and interface had no way to indicate whether a<script>tag usestype="module", so all scripts were treated as sharing a single global scope.Fix: Added an
isModulecomputed property to theNodeclass and interface that returnstruewhen the node is a<script>tag withtype="module", allowing consumers to treat each module script as having its own isolated scope per the HTML specification.Changes
src/htmlLanguageTypes.ts: Addedreadonly isModule: booleanto theNodeinterface with JSDoc documentation.src/parser/htmlParser.ts: ImplementedisModuleas a getter on theNodeclass that checks the tag isscriptand thetypeattribute value (unquoted) equalsmodule.src/test/parser.test.ts: Added 7 regression tests covering double-quoted, single-quoted, classic scripts, non-script tags, multiple module scripts, and mixed module/classic scripts.Testing
src/test/parser.test.tsthat verifyisModulereturns the correct value for all relevant scenarios.