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

オープン 初心者向け
#74 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, typescript

調査の方向性

issueで特定された2か所で compiler/src/emit.rs を読んでください。361行目では出力されるJavaScriptのimportから名前をフィルタリングし、679行目ではバインディングを選択します。prelude関数と一致するimportされた名前が両方の箇所でどのように扱われるかを確認し、生成されたモジュールが期待どおりに lib.js から fetch をimportしてバインドすることを検証してください。列挙された名前がそれぞれのJavaScript importにバインドされればissueは解決です。.rx importは明示的に未テストです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
127
フォーク
7
平均マージ
15時間 42分
マージ済み PR(30日)
63

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/reactivescript のほかの issue

solidjs/reactivescript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。