Skip to content

Add %raw syntax for fixed external arguments - #8609

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

Add %raw syntax for fixed external arguments#8609
cknitt wants to merge 1 commit 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>
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