Skip to content

fix: add isModule property to Node for script type=module detection#243

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-133-redeclare-block-scoped-module
Open

fix: add isModule property to Node for script type=module detection#243
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-133-redeclare-block-scoped-module

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

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 Node class and interface had no way to indicate whether a <script> tag uses type="module", so all scripts were treated as sharing a single global scope.

Fix: Added an isModule computed property to the Node class and interface that returns true when the node is a <script> tag with type="module", allowing consumers to treat each module script as having its own isolated scope per the HTML specification.

Changes

  • src/htmlLanguageTypes.ts: Added readonly isModule: boolean to the Node interface with JSDoc documentation.
  • src/parser/htmlParser.ts: Implemented isModule as a getter on the Node class that checks the tag is script and the type attribute value (unquoted) equals module.
  • 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

  • Added regression tests in src/test/parser.test.ts that verify isModule returns the correct value for all relevant scenarios.
  • All 156 existing tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid error message: "Cannot redeclare block-scoped variable"

1 participant