Skip to content

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Apr 9, 2025

This is needed to avoid a panic in a test once CommonJS import/exports are available.

I've guessed at the right thing to do here but I don't have a solid idea.

I haven't added tests because I'm not sure how:

  • Submodule tests only cover *
  • *, !T and ?T are testable outside JSDoc.
  • ...T and T= are only parsed in JSDoc.

This is needed to avoid a panic in a test once CommonJS import/exports are available.

I've guessed at the right thing to do here but I don't have a solid
idea.

I haven't added tests because I'm not sure how:
- Submodule tests only cover `*`
- `*`, `!T` and `?T` are testable outside JSDoc.
- `...T` and `T=` are only parsed in JSDoc.
@Copilot Copilot AI review requested due to automatic review settings April 9, 2025 15:47
Copy link
Contributor

@Copilot 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 updates the handling of JSDoc types in the printer and AST precedence modules to avoid panics and enable correct printing behaviors as CommonJS import/exports become available.

  • Implements dedicated printer functions for various JSDoc types.
  • Introduces a new precedence level for JSDoc optional and variadic types and updates the precedence grouping for additional JSDoc types.

Reviewed Changes

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

File Description
internal/printer/printer.go Added new functions for printing JSDoc types and updated type logic.
internal/ast/precedence.go Updated precedence rules for JSDoc types to support new printer logic.
Comments suppressed due to low confidence (1)

internal/printer/printer.go:2323

  • New JSDoc type printer functions are introduced without associated tests. Consider adding tests to verify correct punctuation and type emission to prevent regressions.
func (p *Printer) emitJSDocAllType(node *ast.Node) {

switch n.Kind {
case KindConditionalType:
return TypePrecedenceConditional
case KindJSDocOptionalType, KindJSDocVariadicType:
Copy link

Copilot AI Apr 9, 2025

Choose a reason for hiding this comment

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

The precedence grouping for JSDoc types appears inconsistent: some types use TypePrecedenceJSDoc while others fall into a different group. Review if all JSDoc types should share the same precedence level or if the differences are intentional and add clarifying comments.

Suggested change
case KindJSDocOptionalType, KindJSDocVariadicType:
case KindJSDocOptionalType, KindJSDocVariadicType,
KindJSDocAllType, KindJSDocNullableType, KindJSDocNonNullableType:
// All JSDoc-related types are grouped under TypePrecedenceJSDoc for consistency.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only Optional and Variadic are special-cased in parsing. The others are parsed just like any, unknown, etc. This is intentional.

@sandersn sandersn requested a review from rbuckton April 9, 2025 16:09
@sandersn sandersn added this pull request to the merge queue Apr 9, 2025
Merged via the queue into microsoft:main with commit 353bc12 Apr 9, 2025
23 checks passed
@sandersn sandersn deleted the precedence-for-jsdoc-types branch April 9, 2025 20:26
shinichy pushed a commit to shinichy/typescript-go that referenced this pull request Apr 12, 2025
zshannon pushed a commit to zshannon/typescript-go that referenced this pull request Oct 6, 2025
zshannon pushed a commit to zshannon/typescript-go that referenced this pull request Oct 6, 2025
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