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 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, typescript

研究方向

閱讀 issue 指出的 compiler/src/emit.rs 中的兩個位置:第 361 行會從產生的 JavaScript import 中篩選名稱,第 679 行會選擇綁定。檢查與 prelude 函式同名的匯入名稱在這兩個位置分別如何處理,接著確認產生的模組是否如預期從 lib.js 匯入並綁定 fetch。列出的名稱綁定到各自的 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 分鐘
30 天內合併 PR
63

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

solidjs/reactivescript 的其他 Issue

查看 solidjs/reactivescript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。