microsoft / microsoft/TypeScript

'h' (Preact JSX factory) is not imported when '<>...</>' is used with no other JSX tags

Aperta
#40,210 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JSX/TSX
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

I'm using the new jsxFragmentFactory with preact.
It works almost well, but has a problem when no JSX tags other than <></> exist in a file:
An existing import of h (jsxFactory) is removed when transpiled.
This problem occurs with ES modules.

TypeScript Version: 4.0.2

Search Terms: jsx, jsxFactory, jsxFragmentFactory, preact

Code

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2015",
    "module": "ES2015",
    "jsx": "react",
    "jsxFactory": "h",
    "jsxFragmentFactory": "Fragment",

    "strict": true,

    "moduleResolution": "node",
    "esModuleInterop": true,

    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}

empty.tsx

import { Fragment, h } from 'preact';

export default <></>;

Expected behavior:
The import of h remains.

empty.js

import { Fragment, h } from 'preact';
export default h(Fragment, null);

Actual behavior:
The import of h is removed.

empty.js

import { Fragment } from 'preact';
export default h(Fragment, null);

This problem does not occur when any other tag exists.

empty.tsx

import { Fragment, h } from 'preact';

export default <><div /></>;

empty.js

import { Fragment, h } from 'preact';
export default h(Fragment, null,
    h("div", null));

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia transp ilando empty.tsx con il tsconfig.json fornito e confronta l’output di un file contenente solo un fragment con l’output quando viene incluso un div. Traccia la trasformazione del fragment JSX e la gestione degli import; è completato quando il modulo ES generato mantiene h emettendo h(Fragment, null).

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.