Hi Folks!
Looking at rescript for some components at work.
I have put my js code into a %%raw block as directed but the compiler seems to find the back ticks of my existing string interpolations as the end of the raw block and freaks out. Am I missing something?
Im sure you all Just went over this but a different escape character, at first thought?
To escape a backtick in a template literal, put a backslash \ before the backtick.
Otherwise if you use the ` inside, it would be picked up as “close this template string”.
Same situation for ${
I assume you meant to write:
%%raw(`
// look ma, regular JavaScript!
var message = \`\${"hello"}\`;
function greet(m) {
console.log(m)
}
`)
which compiles to the following JS
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
// look ma, regular JavaScript!
var message = `${"hello"}`;
function greet(m) {
console.log(m)
}
Yep fully aware of that workaround and I have done that.
But as the comment states [from the intro documentation] “regular JavaScript”. If i have go and escape the code every time I do this, I think that claim is unfounded. All common javascript will have single quotes and string interp quotes so think this experience will be quite common.
Anyways Im done with it now but for future I found this as a pain point in the tutorial path for rescript, and I think it can be better.
What’s the difference between backtick and double quotes?
I tried embedding js code in double quotes instead backticks. Seems it works.
But I had to change double quotes around ‘hello’ to single quotes.