Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JasoonS opened this issue May 2, 2023 · 3 comments
Open

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

JasoonS opened this issue May 2, 2023 · 3 comments
Milestone

Comments

@JasoonS
Copy link

JasoonS commented May 2, 2023

Please see more details here: https://forum.rescript-lang.org/t/string-interpolations-in-raw/871/8?u=jasoons

Example:

%%raw(`
// look ma, regular JavaScript!
var message = \`\${"hello"}\`;
function greet(m) {
  console.log(m)
}
`)

In rescript 9 this produces:

// look ma, regular JavaScript!
var message = `${"hello"}`;
function greet(m) {
  console.log(m)
}

But in rescript >= 10 it produces:

// look ma, regular JavaScript!
var message = \`\${"hello"}\`;
function greet(m) {
  console.log(m)
}

You can reproduce this by adjusting the rescript version in the playground settings: https://rescript-lang.org/try?code=KTBOEMHcAoAMCgD0iAEAbA9hg1igtuADQqgCmA5gK5rigoBS4AbuAMoDGoAlgA4AuAQngs6eUgGdx4cqRQBeFAB1YigCQBvAEQALUmkyaAvsoDc8AGaUAduz5cMVlOTKk+0PAEoU6+ChTsHcQw0UgA6THJ3D3hDeFgPIA

@cknitt
Copy link
Member

cknitt commented May 2, 2023

Hi! As the README says, the syntax repo is deprecated and new issues should be created in the compiler repo. I'll transfer your issue there.

@cknitt cknitt transferred this issue from rescript-lang/syntax May 2, 2023
@brettcannon
Copy link

brettcannon commented May 7, 2024

I ran into this myself when trying to convert some JS code that had string interpolation via backticks. I had to unwind the string interpolation to proceed with the conversion to ReScript which was unfortunate (I added back once that chunk of code was ready to be rewritten in ReScript).

I also think the title of this issue meant to say \ and not /.

@cknitt cknitt added this to the v12 milestone Sep 1, 2024
@joshgillies
Copy link

I'd say this issue needs to be called out in the following docs:

I hit this immediately when trying to convert some existing code to ReScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants