Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Nov 9, 2025

In this PR:

  • Port missing checkJs logic.
  • Set ObjectFlagsJSLiteral on object literals in .js files (this allows accessing unknown properties).

Fixes #2037.

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

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 GetFirstConstructorWithBody utility function from declarations transformer to the shared AST utilities package for broader reuse
  • Implements isUncheckedJSSuggestion to 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

Comment on lines +1863 to +1867
}

func nodeIsDecorated(node *ast.Node, parent *ast.Node, grandparent *ast.Node) bool {
return ast.HasDecorators(node) && nodeCanBeDecorated(false, node, parent, grandparent)
}
Copy link

Copilot AI Nov 9, 2025

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.

Copilot uses AI. Check for mistakes.
@ahejlsberg ahejlsberg added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit 7c19676 Nov 10, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the fix-2037 branch November 10, 2025 01:29
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.

Differing JavaScript suggestion diagnostics in editor

3 participants