Discarded negation of a void call rejects valid JavaScript

Aperta
#3,358 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.

  • #3362 di @MathurAditya724 — aperta

Valutazione

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

Direzione di ricerca

Start by locating the diagnostic that reports SC0001 for discarded negation of a void call, then trace how expression statements are lowered and compare them with consumed negations. Check the compiler tests for void expressions and add coverage for both !register() and an immediately invoked function expression, while preserving type-checking diagnostics. Done means discarded negation statements compile with their side effects intact, while consumed negations still require a runtime value; the issue notes that separate late-var require() restrictions remain.

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

Descrizione

When compiling a bundled CLI, the generated debug-ID banner starts an immediately invoked function with !. Its boolean result is discarded. Node runs the banner, but scriptc rejects it before lowering because the function returns void.

This also reproduces without the bundle:

function register() {
  console.log("registered");
}
!register();

Node prints registered and exits successfully. Current scriptc 0.4.9 reports SC0001: An expression of type 'void' cannot be tested for truthiness. The same problem affects !function () { console.log("registered"); }();.

For an expression statement, the result of the negation is unused. Evaluating the operand once and discarding its result preserves the side effects and any exception. The boolean conversion itself does not call user code.

This report is limited to discarded negation statements. A consumed negation, an if condition, or a short-circuit operand still needs a runtime value. Treating every void value as undefined would be unsafe: a callback typed as returning void can return a value at runtime. TypeScript and JavaScript projects that explicitly request type checking should retain their diagnostics.

In the current CLI application entry, five of seven diagnostic sites are this discarded-banner pattern. Removing that refusal exposes two separate late-var require() restrictions; it does not make the full CLI compile yet.

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.