Optional JSDoc rejects mandatory JavaScript setter parameters

Aperta
#3,355 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@MathurAditya724 ci sta già lavorando.

Dal 7/11/2026.

  • #3359 di @MathurAditya724 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
javascript, node.js, typescript
Ambito
compilers, testing

Direzione di ricerca

Start at the setter-parameter preflight gate and the parser representation of optional JSDoc tokens; the issue does not name source files or test paths. Add regression coverage for class and object setters, checked JavaScript, syntax negatives, many setters, and same-filename JSX snapshots, then compare assignments, stored values, descriptors, and side effects with Node. Done means comment-only optional annotations pass while executable setter restrictions and caller checks remain intact.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The generated Symbolic bindings used by the full Sentry CLI document several JavaScript setter parameters as optional in JSDoc. The executable parameters themselves are mandatory. Node accepts these setters, but scriptc rejects them before lowering.

This follows up on #3036 and #3044. They were closed as fixed by #3112, but that merged diff contains the regex change; current main still rejects this example:

class Store {
  constructor() { this.stored = null; }
  /** @param {string | null} [next] */
  set value(next) { this.stored = next; }
}
const store = new Store();
store.value = "kept";
console.log(store.stored);

Node prints kept. scriptc reports SC0001: A 'set' accessor cannot have an optional parameter. The diagnostic points into the JSDoc comment, not an executable ? parameter. The same problem occurs for object-literal setters and with // @ts-check.

The parser represents the optional JSDoc annotation with a synthetic optional token, and the preflight gate treats it as executable setter syntax. The full CLI currently has five instances of this diagnostic in Symbolic's generated bindings.

The requested fix should admit this comment-only JavaScript case while preserving errors for real optional, default, rest, or multiple setter parameters and keeping caller type checks and reflective argument-count restrictions intact.

A dependency can contain many documented setters, so eligibility should not rescan the whole file for every diagnostic. A per-preflight index keyed by SourceFile identity can collect attached comment spans once and find a containing span with binary search. SourceFile identity matters because original and rewritten JSX snapshots can share a filename but have different offsets.

Regression coverage should include class and object setters, checked JavaScript, the real syntax negatives, many setters, and JSX snapshots sharing a filename. Native differential coverage should check assignments, stored values, descriptor behavior, and observable side effects against Node.

Reproduced with scriptc 0.4.9 built from current main and Node 24.22.1. The current-main positive setter tests fail with TS1051 before any production change. Related earlier work: #3036, #3044, #3112.

Lingua principale
TypeScript
Stelle
6.5k
Fork
212
Merge medio
13h 2m
PR unite (30g)
798

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.