Port "Disallow type and interface declarations in statements with blockless bodies"#1037
Merged
jakebailey merged 2 commits intoJun 4, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Ports the TypeScript check to forbid type/interface declarations in statements without block bodies and updates error baselines accordingly
- Adds grammar errors in the Go checker when a
typeorinterfaceappears in a blockless context - Updates/removes test baselines to reflect the new TS1156 errors
- Cleans up obsolete
.errors.txt.difffiles
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/checker/checker.go | Added containerAllowsBlockScopedVariable checks for type/interface |
| testdata/baselines/reference/submodule/compiler/typeInterfaceDeclarationsInBlockStatements1.errors.txt | Expanded expected errors to include the new interface-blockless error |
| testdata/baselines/reference/submodule/compiler/typeAliasDeclarationEmit3.errors.txt | Added expected errors for type-alias-blockless contexts |
| testdata/baselines/reference/submodule/compiler/*.errors.txt.diff | Removed outdated diff artifacts |
Comments suppressed due to low confidence (2)
testdata/baselines/reference/submodule/compiler/typeAliasDeclarationEmit3.errors.txt.diff:1
- [nitpick] This
.errors.txt.difffile is now empty; consider removing it entirely to avoid cluttering the testbaseline directory.
<no content>
internal/checker/checker.go:6426
- The blockless declaration check in
checkTypeAliasDeclarationisn’t guarded by the result ofc.checkGrammarModifiers, unlike theinterfaceversion; consider applying the same guard to maintain consistent early-exit behavior.
if !c.containerAllowsBlockScopedVariable(node.Parent) {
| if !c.checkGrammarModifiers(node) { | ||
| c.checkGrammarInterfaceDeclaration(node.AsInterfaceDeclaration()) | ||
| } | ||
| if !c.containerAllowsBlockScopedVariable(node.Parent) { |
There was a problem hiding this comment.
[nitpick] The logic for disallowing blockless type and interface declarations is duplicated; consider extracting a helper to reduce code duplication.
jakebailey
approved these changes
Jun 4, 2025
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.
ports microsoft/TypeScript#60183