Skip to content

Add %raw syntax for fixed external arguments - #8609

Draft
cknitt wants to merge 3 commits into
rescript-lang:masterfrom
cknitt:codex/raw-external-arguments
Draft

Add %raw syntax for fixed external arguments#8609
cknitt wants to merge 3 commits into
rescript-lang:masterfrom
cknitt:codex/raw-external-arguments

Conversation

@cknitt

@cknitt cknitt commented Sep 3, 2026

Copy link
Copy Markdown
Member

Summary

Introduce a dedicated parsetree representation and new syntax for fixed external arguments.

Previously, fixed values were expressed using an @as attribute on a wildcard type:

@val
external unsafeAddStyle: (@as(json`{}`) _, t, {..}) => t = "Object.assign"

They can now be written using the familiar %raw extension syntax:

@val
external unsafeAddStyle: (%raw("{}"), t, {..}) => t = "Object.assign"

The %raw payload must be a string containing a JavaScript literal. Non-interpolated template strings are also supported, which is convenient for JavaScript string values:

external createElement: (%raw(`"img"`), document) => element = "createElement"

Compatibility

Existing fixed-value forms continue to parse:

@as(json`{}`) _
@as("img") _
@as(1) _

They now:

  • emit a deprecation warning;
  • normalize to the dedicated fixed-argument parsetree node;
  • format automatically to the corresponding %raw(...) syntax.

The json tag no longer has a special string-literal representation in the AST. Outside this compatibility path, json templates behave like ordinary tagged template strings.

Implementation

Fixed external arguments are represented explicitly as Parg_fixed, containing the raw JavaScript source and argument metadata. The representation is handled across AST traversal, mapping, analysis, type checking, external processing, and printing.

The frozen v0 parsetree remains unchanged. The existing AST mapping bridge converts fixed arguments to and from a compatible v0 representation.

Testing

Added and updated coverage for:

  • parser and formatter behavior;
  • legacy syntax migration and deprecation warnings;
  • %raw string and template-string payloads;
  • invalid payloads and invalid positions;
  • v0 parsetree round trips;
  • analysis features;
  • generated JavaScript and runtime behavior.

make test, syntax tests, and syntax round-trip tests pass.

Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.93464% with 92 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.25%. Comparing base (bc382a4) to head (29d80dd).

Files with missing lines Patch % Lines
compiler/ml/ast_payload.ml 20.00% 32 Missing ⚠️
compiler/frontend/ast_attributes.ml 15.38% 11 Missing ⚠️
compiler/syntax/src/res_core.ml 81.13% 10 Missing ⚠️
compiler/frontend/ast_external_process.ml 73.33% 8 Missing ⚠️
compiler/ml/printast.ml 0.00% 6 Missing ⚠️
compiler/syntax/src/res_comments_table.ml 64.28% 5 Missing ⚠️
compiler/core/js_dump.ml 33.33% 2 Missing ⚠️
compiler/ml/ast_mapper_from0.ml 87.50% 2 Missing ⚠️
compiler/ml/pprintast.ml 83.33% 2 Missing ⚠️
compiler/ml/typecore.ml 50.00% 2 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8609      +/-   ##
==========================================
- Coverage   77.32%   77.25%   -0.08%     
==========================================
  Files         467      467              
  Lines       63342    63459     +117     
==========================================
+ Hits        48982    49024      +42     
- Misses      14360    14435      +75     
Files with missing lines Coverage Δ
analysis/src/dump_ast.ml 33.17% <ø> (+0.15%) ⬆️
compiler/core/j.ml 100.00% <ø> (ø)
compiler/core/js_record_fold.ml 88.81% <100.00%> (ø)
compiler/core/js_record_iter.ml 95.49% <100.00%> (ø)
compiler/core/js_record_map.ml 95.75% <100.00%> (ø)
compiler/core/lam_compile_const.ml 93.54% <100.00%> (-0.40%) ⬇️
compiler/frontend/ast_config.ml 87.09% <ø> (-0.41%) ⬇️
compiler/frontend/ast_derive_abstract.ml 92.98% <100.00%> (ø)
compiler/frontend/ast_derive_js_mapper.ml 84.78% <100.00%> (ø)
compiler/frontend/ast_derive_projector.ml 90.62% <100.00%> (ø)
... and 36 more

... and 1 file with indirect coverage changes

🚀 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.

Signed-off-by: Christoph Knittel <ck@cca.io>
@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8609

@rescript/belt

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/belt@8609

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@8609

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8609

@rescript/win32-x64

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

commit: 29d80dd

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.

1 participant