Skip to content

Add this/satisfies tag #1157

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

Merged
merged 9 commits into from
Jun 12, 2025
Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Jun 10, 2025

These are the last hosted tags!

I'm not sure about the name makeNewCast; copilot originally suggested two separate functions, which felt a little repetitive to me.

sandersn added 2 commits June 10, 2025 12:48
This is the last hosted tag. Just callback is left.
@Copilot Copilot AI review requested due to automatic review settings June 10, 2025 21:46
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

Adds support for JSDoc’s @satisfies and @this tags by introducing a unified cast helper and extending the parser’s reparse logic

  • Refactor existing type-assertion helper into makeNewCast with an isAssertion flag
  • Extend reparseHosted to handle @satisfies tags on parenthesized expressions
  • Add logic in reparseHosted to inject a this parameter for functions annotated with @this

Reviewed Changes

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

File Description
internal/parser/reparser.go Replace makeNewTypeAssertion calls with makeNewCast, add cases for JSDoc @satisfies and @this
testdata/baselines/** Update expected types, symbols, and errors to reflect new @satisfies/@this behavior

@@ -7,8 +7,9 @@
->p : { isEven: (n: number) => boolean; isOdd: (n: number) => boolean; }
->({ isEven: n => n % 2 === 0, isOdd: n => n % 2 === 1}) : { isEven: (n: number) => boolean; isOdd: (n: number) => boolean; }
->{ isEven: n => n % 2 === 0, isOdd: n => n % 2 === 1} : { isEven: (n: number) => boolean; isOdd: (n: number) => boolean; }
+>p : { isEven: (n: any) => boolean; isOdd: (n: any) => boolean; }
+>({ isEven: n => n % 2 === 0, isOdd: n => n % 2 === 1}) : { isEven: (n: any) => boolean; isOdd: (n: any) => boolean; }
+>p : any
Copy link
Member Author

Choose a reason for hiding this comment

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

this is now any because Corsa no longer supports index signature syntax like Object.<string, T>

@@ -7,8 +7,9 @@
->x : { m: true; s: string; }
->({ m: true, s: "false"}) : { m: true; s: string; }
->{ m: true, s: "false"} : { m: true; s: string; }
+>x : { m: boolean; s: string; }
+>({ m: true, s: "false"}) : { m: boolean; s: string; }
+>x : any
Copy link
Member Author

Choose a reason for hiding this comment

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

same; more unsupported syntax

sandersn added 2 commits June 12, 2025 06:56
print their children but not the nodes themselves. This makes the
baselines basically identical to the Strada ones.
@sandersn sandersn requested a review from jakebailey June 12, 2025 14:05
Comment on lines 11 to +12
->this : Symbol(this)
+>this : Symbol(C, Decl(a.js, 0, 0))
+>this : Symbol((Missing), Decl(a.js, 3, 8))
Copy link
Member

Choose a reason for hiding this comment

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

I am curious what the deal is with (Missing) here, hopefully not a problem.

Copy link
Member

Choose a reason for hiding this comment

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

iirc, it means the Name node of the symbol is missing/undefined, (and this isn't a class (it's the class static side), so it isn't (anonymous class)). Probably a bug somewhere, since this is jsdoc assigned to type T, so it really aughta be T, if not the generic unresolved this symbol. Perhaps lookup of the names of jsdoc template type params is broken?

Copy link
Member

Choose a reason for hiding this comment

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

#731 potentially

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, lookup of template types isbroken. I'm working on a fix right now as part of adding @callback and refactoring @typedef support.

@@ -266,6 +271,31 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node)
}
}
}
case ast.KindJSDocThisTag:
if fun, ok := getFunctionLikeHost(parent); ok {
Copy link
Member

Choose a reason for hiding this comment

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

What's this supposed to do for function-like-expressions that don't have a this, like arrow functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

@sandersn sandersn added this pull request to the merge queue Jun 12, 2025
Merged via the queue into microsoft:main with commit 429d093 Jun 12, 2025
22 checks passed
@sandersn sandersn deleted the add-this/satisfies-tag branch June 12, 2025 20:25
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.

4 participants