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

Offen Anfängerfreundlich
#74 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv

Rechercherichtung

Lies compiler/src/emit.rs an den beiden im Issue genannten Stellen: In Zeile 361 werden Namen aus dem ausgegebenen JavaScript-Import gefiltert, und in Zeile 679 wird die Bindung ausgewählt. Prüfe, wie importierte Namen, die mit Prelude-Funktionen übereinstimmen, an beiden Stellen behandelt werden, und verifiziere anschließend, dass das generierte Modul fetch wie erwartet aus lib.js importiert und bindet. Das Issue ist gelöst, wenn die aufgeführten Namen an ihre JavaScript-Imports gebunden werden; .rx-Imports wurden ausdrücklich nicht getestet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
127
Forks
7
Ø Merge
15 Std. 42 Min.
Gemergte PRs (30 T.)
63

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus solidjs/reactivescript

Alle Issues in solidjs/reactivescript

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.