Repository navigation
fix(parser): JSDoc @template replaces an empty type parameter list - #114
Open
THEtheChad wants to merge 3 commits into
Open
THEtheChad wants to merge 3 commits into
THEtheChad wants to merge 3 commits into
Conversation
Go reparser.go:459 tests `fun.TypeParameters() == nil`, the Nodes of the list, which the Go parser leaves nil for an empty `<>` (Arena.Clone of an empty slice is nil). The port tested the list itself, so `/** @template T */ function f<>() {}` in a JS file kept the empty list: TS1098, TS2304 for the template names, and no type parameters in the declaration emit. The class branches test the list in Go too and are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ameters Go checker.go:10415 tests `node.TypeParameters() == nil`, which is also true for an empty `<>` list. The port tested the list, so inferFromAnnotatedParametersAndReturn did not run for `function <>(x: A)` and the inferred type could differ (`string` where Go gives `string | number`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frontend/parser/reparser.rs is a key source of lib_parse.bin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This branch has not been deployed
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.
In a JS file,
/** @template T */ function f<>() {}reports TS1098 "Type parameter list cannot be empty" in tsc-rs. Go tsc reports nothing, and withdeclarationit emitsdeclare function f<T>(): void;. A@returns {T}on the same function also gives TS2304 "Cannot find name 'T'" instead of Go's TS2355.Cause: Go's reparser (
reparser.go:459) checksfun.TypeParameters() == nil. That accessor returns the list's nodes, and Go's parser stores nil nodes for an empty<>(core/arena.go:55), so the@templateparameters replace the empty list. The port checked whether the list itself was nil, which it never is for<>.The checker made the same mistake at
checker.go:10415. A function expression with<>skipped the inference from its annotated parameters, sog(function <>(x: string | number) {}, "a")inferredstringinstead of Go'sstring | number.Fix: both sites use
type_parameters().is_empty(), the port of Go's accessor. The class branches really do check the list in Go and are unchanged. The lib parse blobs are regenerated becausereparser.rsis part of their key.Tests:
tsctests/empty_type_parameters.rs(4 tests, expected output from Go tsc at 3e9236361fa9). Output and exit code are byte-identical to Go for<>,< >,</* c */>, methods, function expressions, d.ts emit and the inference case. Found with a differential fuzzer run against the Go oracle at the pin.🤖 Generated with Claude Code