-
Notifications
You must be signed in to change notification settings - Fork 734
Port missing checkJs logic
#2046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements improved error handling for unchecked JavaScript files by distinguishing between hard errors and suggestions. The changes enable TypeScript to provide more helpful "Did you mean?" suggestions in plain JS files without checkJS enabled, while maintaining strict error reporting in TypeScript and checked JS files.
Key Changes:
- Moves
GetFirstConstructorWithBodyutility function from declarations transformer to the shared AST utilities package for broader reuse - Implements
isUncheckedJSSuggestionto detect when errors should be downgraded to suggestions in unchecked JS files - Updates error reporting to use suggestions instead of errors for "Did you mean?" messages in unchecked JS contexts
- Fixes private field grammar error reporting in plain JS files
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
testdata/baselines/reference/submodule/conformance/plainJSGrammarErrors4.errors.txt.diff |
Removed diff file indicating convergence with TypeScript reference implementation |
testdata/baselines/reference/submodule/conformance/plainJSGrammarErrors4.errors.txt |
Baseline now correctly shows private field error in plain JS file |
internal/transformers/declarations/util.go |
Removed local utility function (moved to ast package) |
internal/transformers/declarations/transform.go |
Updated to use the moved utility function from ast package |
internal/checker/utilities.go |
Added JS-specific suggestion detection logic, decorator checking, and JSLiteral type checking |
internal/checker/checker.go |
Updated error reporting to use suggestions for unchecked JS files and enabled private field grammar checking |
internal/ast/utilities.go |
Added shared GetFirstConstructorWithBody utility function |
| } | ||
|
|
||
| func nodeIsDecorated(node *ast.Node, parent *ast.Node, grandparent *ast.Node) bool { | ||
| return ast.HasDecorators(node) && nodeCanBeDecorated(false, node, parent, grandparent) | ||
| } |
Copilot
AI
Nov 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for suggestionHasNoExtendsOrDecorators is incorrect. This variable should be true when the suggestion is not a class OR when it is a class with neither extends nor decorators. However, lines 1866-1867 incorrectly use OR and check for the presence (not absence) of extends/decorators.
The current logic returns true when the class HAS extends OR HAS decorators, which is the opposite of what the variable name indicates.
The correct logic should be:
suggestionHasNoExtendsOrDecorators := suggestion == nil ||
suggestion.ValueDeclaration == nil ||
!ast.IsClassLike(suggestion.ValueDeclaration) ||
(len(ast.GetExtendsHeritageClauseElements(suggestion.ValueDeclaration)) == 0 &&
!classOrConstructorParameterIsDecorated(suggestion.ValueDeclaration))Note: The last condition uses AND (not OR) and checks for the absence (== 0 and !) of extends/decorators.
In this PR:
checkJslogic.ObjectFlagsJSLiteralon object literals in .js files (this allows accessing unknown properties).Fixes #2037.