Skip to content

Fix escapes in raw template payloads - #8630

Merged
cknitt merged 2 commits into
masterfrom
codex/fix-raw-template-escapes
Sep 5, 2026
Merged

Fix escapes in raw template payloads#8630
cknitt merged 2 commits into
masterfrom
codex/fix-raw-template-escapes

Conversation

@cknitt

@cknitt cknitt commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

Fix a regression introduced in ReScript 10 where escapes used inside backquoted %raw, %ffi, and %re payloads leaked into the emitted JavaScript.

Escapes required by the surrounding ReScript template—such as escaped backticks, dollar signs, backslashes, and line continuations—are removed before parsing and emitting the embedded JavaScript. JavaScript-specific escapes such as \n and \x01 remain intact.

Add unit and end-to-end regression coverage for escaped JavaScript template literals.

For example:

%raw(`const message = \`Hello, \${name}\``)

is emitted as:

const message = `Hello, ${name}`;

The JavaScript template literal remains intact, while the ReScript-specific escaping is removed before emission.

Fixes #6236.

Signed-off-by: Christoph Knittel <ck@cca.io>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T18:34:06.821616Z 5e5f9b0 PR opened
ℹ️ 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.

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

@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: 5e5f9b0419

ℹ️ 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".

] ->
Some
(source.txt, Bs_flow_ast_utils.flow_deli_offset (Some "js"), expression)
let source = String_literal.decode_raw_template_source source.txt in

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve source offsets while decoding raw templates

When malformed embedded JavaScript occurs after a decoded escape, the Flow parser reports positions in the shortened source, but check_flow_errors later projects those positions onto the original ReScript text using only a constant delimiter offset. For example, an error following \`` or ${` is highlighted one or more columns early, while an error after a removed backslash-newline continuation can be reported on the wrong line. The decoder needs to retain an original-offset mapping for diagnostics, or error locations must otherwise be translated before reporting.

Useful? React with 👍 / 👎.

@cknitt cknitt Sep 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for catching this. I checked the ReScript 9.1.4 implementation: parseTemplateStringLiteral already decoded these escapes before the Flow parser ran, while check_flow_errors projected the resulting locations using only the same fixed delimiter offset. So diagnostic drift after a removed escape or line continuation is pre-existing behavior rather than something introduced by this change. Preserving exact positions would require carrying a source-offset map through decoding (including Unicode and removed line terminators), which is a substantially broader diagnostics change and outside the scope of this PR. I’d prefer to keep this PR focused on restoring the raw-template escape behavior.

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.38%. Comparing base (30c781c) to head (6d73272).

Files with missing lines Patch % Lines
compiler/ml/string_literal.ml 70.83% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8630      +/-   ##
==========================================
- Coverage   77.38%   77.38%   -0.01%     
==========================================
  Files         474      474              
  Lines       63524    63553      +29     
==========================================
+ Hits        49156    49178      +22     
- Misses      14368    14375       +7     
Files with missing lines Coverage Δ
compiler/ml/ast_payload.ml 81.19% <100.00%> (ø)
tests/ounit_tests/ounit_string_literal_tests.ml 90.90% <100.00%> (+0.11%) ⬆️
compiler/ml/string_literal.ml 93.39% <70.83%> (-2.67%) ⬇️
🚀 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 Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 6d73272

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

legit

@cknitt
cknitt enabled auto-merge (squash) September 5, 2026 18:55
@cknitt
cknitt merged commit 07e747b into master Sep 5, 2026
29 checks passed
@cknitt
cknitt deleted the codex/fix-raw-template-escapes branch September 5, 2026 18:58
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.

Escape character / doesn't work in rescript 10 in %raw templates

2 participants