Skip to content

fix: re-introduce JSDoc type casts without wrapping binding identifiers - #167

Merged
elliott-with-the-longest-name-on-github merged 3 commits into
mainfrom
fix-jsdoc-binding-casts
Aug 17, 2026
Merged

fix: re-introduce JSDoc type casts without wrapping binding identifiers#167
elliott-with-the-longest-name-on-github merged 3 commits into
mainfrom
fix-jsdoc-binding-casts

Conversation

@elliott-with-the-longest-name-on-github

Copy link
Copy Markdown
Contributor

Fixes #164.

This un-reverts #165 (re-introducing the JSDoc type cast support from #162) and fixes the regression that prompted the revert.

Problem

#162 detected JSDoc type casts with the guard node.type in EXPRESSIONS_PRECEDENCE, but Identifier (and patterns) are in that table even when they appear in binding positions. A /** @type {...} */ comment attached to the id of a VariableDeclarator — as emitted by the svelte compiler for hoisted let declarations in server output — was wrapped in parens, producing invalid output like:

let /** @type {number | undefined} */ (
computed);

Fix

Track nodes in binding positions (variable declarator ids, function/method/arrow/TS-signature params, catch clause params) in a WeakSet and exclude them from type cast detection. Genuine casts (const foo = /** @type {number} */ (1);) still keep their parentheses.

Tests

New comment-jsdoc-type-annotation sample covering declarator ids, multiple declarators, function/arrow params, catch params, alongside a genuine cast.

Fixes #164 by tracking nodes in binding positions (variable declarator
ids, function/method/arrow params, catch clause params) and excluding
them from JSDoc type cast detection, so `let /** @type {T} */ x;`
prints valid output while `/** @type {T} */ (expr)` casts keep their
parentheses.
@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 14, 2026

Copy link
Copy Markdown

Install the latest version of esrap from 93d797e:

pnpm add https://pkg.svelte.dev/esrap/c/93d797ed676a4d9fa4a83089b2f0f18bb29396b9

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/esrap/pr/167

@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 93d797e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
esrap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

2.3.3 regression: JSDoc @type comments on hoisted let declarations produce invalid output like let (foo);

2 participants