@directive is dropped on @this functions
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 55/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, ocaml
- 領域
- compilers
研究方向
Start with the Pjs_fn_method case in compiler/core/lam_compile.ml, then follow how E.method_ builds functions in compiler/core/js_exp_make.ml and how the method branch prints them in Js_dump.pp_function. Check the frontend @this rewrite to confirm the directive stays on the inner function; printlambda does not show directives. Done means @directive appears first in the generated method body, before let self = this, for both examples while preserving async.
由索引模型根據 Issue 內容生成。
描述
A @this function loses its @directive. Nothing is reported, and async on the same function is kept.
let plain = @this @directive("'use cache'") (self, x) => self + x
let action = @this @directive("'use server'") async (self, x) => self + x
compiles to
function plain(x) {
let self = this ;
return self + x | 0;
}
async function action(x) {
let self = this ;
return self + x | 0;
}
Neither directive appears in the output. Without @this, the directive is kept (function d(n) { 'use cache'; … }).
Cause
@this compiles through %unsafe_to_method to Pjs_fn_method, and that path drops the directive:
compiler/core/lam_compile.ml: thePjs_fn_methodcase matchesattr = {return_unit; async}and never readsdirective.compiler/core/js_exp_make.ml:E.method_has nodirectiveparameter and builds the function withdirective = None.
Fixing it
Passing the directive through is not enough. In Js_dump.pp_function, the method branch prints let self = this before function_body ?directive. The directive would then not be the first statement in the body, so JavaScript would treat it as a plain string expression. The method branch has to print the directive before let self = this.
printlambda does not show directives, so check that the @this rewrite in the frontend keeps the attribute on the inner function.
Found while reviewing #9176, which fixes the related #9174 (forwarding async/directive functions reduced away). This bug was there before that PR.
- 主要語言
- OCaml
- 星號
- 7.5k
- 分支
- 485
- 平均合併
- 16 小時 51 分鐘
- 30 天內合併 PR
- 268
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rescript-lang/rescript 的其他 Issue
-
Exception analysis does not know the Temporal `fromStringOrThrow` functions可能已有人在做 @cknitt 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
rescript-lang/rescript#9182 ·
維護者通常 1 天內回覆
-
Build system: make output wording and labels consistent可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 4/5 3-5 天 新手友好度 48/100
rescript-lang/rescript#9244 ·
維護者通常 1 天內回覆
-
rescript format: aborts on a syntax error, unstable output, raw compiler errors可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 4/5 3-5 天 新手友好度 56/100
rescript-lang/rescript#9243 ·
維護者通常 1 天內回覆
-
Build system CLI: behavior that disagrees with the help text可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 4/5 3-5 天 新手友好度 43/100
rescript-lang/rescript#9242 ·
維護者通常 1 天內回覆
-
Build system: a failed first build forces full rebuilds, and clean breaks a running watch可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 4/5 3-5 天 新手友好度 52/100
rescript-lang/rescript#9241 ·
維護者通常 1 天內回覆
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
GaloisInc/llvm-pretty#211 ·
-
crash mlir
難度 2/5 1-3 小時 新手友好度 74/100
llvm/llvm-project#239604 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug good first issue self-hosted compiler
難度 2/5 1-3 小時 新手友好度 85/100
AeroForger/AeroFyl#1 ·
-
難度 2/5 1-3 小時 新手友好度 63/100
KhronosGroup/SPIRV-LLVM-Translator#4151 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
anthropics/claudes-c-compiler#322 ·