Skip to content

Keep @directive on @this functions - #9262

Open
cknitt wants to merge 2 commits into
masterfrom
this-directive-9197
Open

cknitt wants to merge 2 commits into
masterfrom
this-directive-9197

Conversation

@cknitt

@cknitt cknitt commented Nov 7, 2026

Copy link
Copy Markdown
Member

Fixes #9197.

@this functions dropped their @directive. There were two causes:

  • bs_builtin_ppx left the attribute on the unsafe_to_method call instead of the function, which is where translcore reads it. The PPX now moves @directive onto the inner function.
  • Pjs_fn_method ignored directive, and E.method_ had no parameter for it. lam_compile now passes it through.

A directive has to be the first statement of the body, so Js_dump prints it before let self = this. This also works for async functions and when self is unused.

New test: tests/tests/src/this_directive.res, a JS snapshot covering the plain, async and unused-self cases.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJuq6rWZULJVY3ATmY

Why:
    The @this rewrite left @directive on the unsafe_to_method call
    instead of the function, and the Pjs_fn_method path built the JS
    function without a directive, so it was dropped without a report.
    The PPX now moves @directive onto the inner function, E.method_
    takes it, and the printer puts it before `let self = this`, since a
    directive must be the first statement of the body.

JS modified (@this function with a directive):
Example:
    let plain = @this @directive("'use cache'") (self, x) => self + x
Before (js):
    function plain(x) {
      let self = this ;
      return self + x | 0;
    }
After (js):
    function plain(x) {
      'use cache';
      let self = this ;
      return self + x | 0;
    }

Fixes #9197

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJuq6rWZULJVY3ATmY
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Keep @directive on @this functions.

Semantic Diff

2 commits · Full page

Keep @directive on @this functions

66d6998 · cknitt + Claude · Nov 07, 2026, 15:28 UTC

Why

The @this rewrite left @directive on the unsafe_to_method call instead of the function, and the Pjs_fn_method path built the JS function without a directive, so it was dropped without a report. The PPX now moves @directive onto the inner function, E.method_ takes it, and the printer puts it before let self = this, since a directive must be the first statement of the body.

JS modified (@this function with a directive)

let plain = @this @directive("'use cache'") (self, x) => self + x

js

 function plain(x) {
+  'use cache';
   let self = this ;
   return self + x | 0;
 }

Fixes #9197

✨ Print the this binding of a method without a space before the semicolon

ac091ee · cknitt + Claude · Nov 07, 2026, 15:41 UTC · new

The space was left over from when the printer spelled out let self = by hand; no other statement puts a space before its semicolon.

JS modified (@this function)

let even = @this (o, x) => x + o

js

-let o = this ;
+let o = this;

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.74%. Comparing base (827be16) to head (ac091ee).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9262   +/-   ##
=======================================
  Coverage   81.74%   81.74%           
=======================================
  Files         457      457           
  Lines       65713    65717    +4     
=======================================
+ Hits        53715    53719    +4     
  Misses      11998    11998           
Files with missing lines Coverage Δ
compiler/core/js_dump.ml 93.94% <100.00%> (+0.01%) ⬆️
compiler/core/js_exp_make.ml 66.28% <ø> (ø)
compiler/core/lam_compile.ml 89.92% <100.00%> (ø)
compiler/frontend/ast_uncurry_gen.ml 95.23% <100.00%> (ø)
compiler/frontend/bs_builtin_ppx.ml 90.67% <100.00%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9262

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9262

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9262

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9262

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9262

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9262

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9262

commit: ac091ee

The space was left over from when the printer spelled out `let self =`
by hand; no other statement puts a space before its semicolon.

JS modified (@this function):
Example:
    let even = @this (o, x) => x + o
Before (js):
    let o = this ;
After (js):
    let o = this;

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJuq6rWZULJVY3ATmY
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T15:58:30.782163Z ac091ee Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac091eec07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread compiler/core/lam_compile.ml Resolved
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

@cknitt

cknitt commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: ac091eec07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt marked this pull request as ready for review November 7, 2026 16:01
@cknitt
cknitt requested a review from cristianoc November 7, 2026 16:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@directive is dropped on @this functions

1 participant