A JS import named like a prelude function (`fetch`, `map`, `filter`, `len`, `str`, `sum`, `every`, `indexOf`, `fail`, `log`) is bound to `__B.<name>`, not to the import

Aperta Adatta ai principianti
#74 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript

Direzione di ricerca

Leggi compiler/src/emit.rs nei due punti indicati nell’issue: la riga 361 filtra i nomi dall’import JavaScript generato e la riga 679 seleziona il binding. Controlla come vengono gestiti in entrambi i punti i nomi importati che corrispondono a funzioni del prelude, quindi verifica che il modulo generato importi e associ fetch da lib.js come previsto. L’issue è risolta quando i nomi elencati vengono associati ai rispettivi import JavaScript; gli import .rx non sono stati testati esplicitamente.

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

Descrizione

Found while building a component library on ReactiveScript. Written with Claude Fable 5.2 (in Claude Code), which also ran the reproductions; all of them were rerun before posting.

@reactivescript/compiler 0.3.1, through @solidjs/vite-plugin 3.0.0-next.57 (vite dev server, plugins: [solid()]),
mounted with createApp from @reactivescript/runtime 0.3.1, in Chromium.

lib.js:

export const fetch = (key) => "lib.js got " + key;

a.rx:

import { fetch } from "./lib.js"

export default component App() {
  source out := "-"
  <div>
    <button onClick={() => { out := fetch("x") }}>go</button>
    <p>{out}</p>
  </div>
}

It compiles with no diagnostic. After a click the paragraph shows

{"key":"x","first":{},"queue":[],"waiters":[],"started":false}

Expected: lib.js got x. guide/language.md, "Imperative code": "anything else from JS comes in through an
import from a .js module." CP-4c (spec/11-compiler.md) lists B.fetch and B.fail as the scenario prelude:
"Compiled code calls them only in a conformance build".

The generated module has no import from lib.js. It binds the name to the prelude:

const v$fetch = __B.fetch;

The same happens with:

  • an alias: import { fetch as get } from "./lib.js" emits const v$get = __B.fetch;
  • a declaration beside the module: lib.d.rx containing export fn fetch(key: string): string is accepted and
    changes nothing;
  • each of the other nine names: the generated code binds every one to __B.<name>. Of those I ran only fail,
    where the call throws the prelude's panic.

In compiler/src/emit.rs on main (eab7356, read, not built) two places exclude these names for a JS import: line
361 filters them out of the emitted import list (!builtin(&n.name) && n.name != "log"), and line 679 chooses
the binding (self.js_import(from) && !builtin(name) && name != "log"), which falls through to the __B branch.

Not tested: an import of one of these names from another .rx module.

Lingua principale
TypeScript
Stelle
127
Fork
7
Merge medio
15h 42m
PR unite (30g)
63

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 solidjs/reactivescript

Tutte le issue di solidjs/reactivescript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.