Skip to content

Error on modules-as-namespaces#2760

Open
Copilot wants to merge 3 commits intomainfrom
copilot/remove-module-declaration-parsing
Open

Error on modules-as-namespaces#2760
Copilot wants to merge 3 commits intomainfrom
copilot/remove-module-declaration-parsing

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

  • Parser: Emit parse error on identifier names when module keyword is used for namespace declarations
  • Parser: Dotted names get errors on each component (e.g., module A.B {} → errors on A and B)
  • Parser: AST uses KindNamespaceKeyword for error recovery
  • Checker: Remove now-unreachable suggestion diagnostic code
  • Checker: Remove unused getNonModifierTokenRangeOfNode utility
  • Printer tests: Remove module a{} and module a.b{} tests (now produce parse errors)
  • Baselines: Match TypeScript exactly (diff files deleted)
  • All tests pass

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Instead of issuing an error for `module X {}`, the parser now always
treats it as `namespace X {}`. Only `declare module "foo"` and
`namespace` syntax are distinguished.

Changes:
- Parser: Always use KindNamespaceKeyword for identifier-named module declarations
- Checker: Remove suggestion diagnostic for module keyword usage
- Checker: Remove unused getNonModifierTokenRangeOfNode utility
- Printer tests: Update expected output for module->namespace conversion

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove parser capability for module declarations as namespaces Remove parser's ability to produce module-keyword namespace declarations Feb 11, 2026
Copilot AI requested a review from jakebailey February 11, 2026 06:59
@jakebailey
Copy link
Member

@copilot the intent is that module is illegal and produces a parse error

- Parser emits parse error on each identifier name when `module`
  keyword is used for namespace declarations (matching TS behavior)
- Dotted names like `module A.B {}` get errors on both `A` and `B`
- AST still uses KindNamespaceKeyword for error recovery
- Baselines now match TypeScript exactly (diff files deleted)

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 11, 2026

@copilot the intent is that module is illegal and produces a parse error

Updated in e50c1d7. The parser now emits a parse error (TS1540) on each identifier name when module is used for namespace declarations, including on each component of dotted names (e.g., module A.B {} errors on both A and B). The AST still uses KindNamespaceKeyword for error recovery. Baselines now match TypeScript exactly — both diff files were deleted.

@jakebailey jakebailey marked this pull request as ready for review February 11, 2026 16:32
Copilot AI review requested due to automatic review settings February 11, 2026 16:32
@jakebailey
Copy link
Member

I guess this is fine, though I think I was hoping to hard remove it and not even have this diagnostic, as though module foo { were entirely illegal.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes support for module-keyword namespace declarations by turning them into parser errors, aligning behavior and baselines with upstream TypeScript.

Changes:

  • Parser now errors on module X {} (and per-component on dotted names) and uses KindNamespaceKeyword for recovery.
  • Checker cleanup: removes now-unreachable suggestion diagnostics and a related utility.
  • Updates/removes printer tests and baseline diff artifacts to match TypeScript outputs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/parser/parser.go Emits parse errors for module-keyword namespace declarations; normalizes AST keyword to namespace for recovery.
internal/checker/checker.go Removes unreachable suggestion diagnostic for module-keyword namespace declarations.
internal/checker/utilities.go Removes unused helper previously used for the suggestion diagnostic span.
internal/printer/printer_test.go Drops printer cases that now fail to parse (module a{}, module a.b{}).
testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff Deletes baseline diff artifact.
testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt Adds/updates baseline error output in the non-diff format.
testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt.diff Deletes baseline diff artifact.
testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt Updates baseline to include the newly parser-emitted TS1540 error.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 11, 2026

I guess this is fine, though I think I was hoping to hard remove it and not even have this diagnostic

It's better to just gracefully parse it for as long as we can and issue a parse error.

@jakebailey jakebailey changed the title Remove parser's ability to produce module-keyword namespace declarations Error on modules-as-namespaces Feb 12, 2026
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.

3 participants