Yes, I think we should work together with bobzhang to make it unicode compatible and drop the j
prefix
I also envisioned the following usecase:
sql`select * from myTable`
Yes, I think we should work together with bobzhang to make it unicode compatible and drop the j
prefix
I also envisioned the following usecase:
sql`select * from myTable`
Oh, tagged templates would be awesome, especially if you find a way to make them type safe.
AFAICT, PPXes in Reason play the about the same role as tagged templates in JS, but less syntax to learn is probably better.
@IwanKaramazow shall I file an issue regarding unicode in the new BuckleScript syntax repo?
I’m not sure what you mean by
Just without proper unicode support.
This code seems to do what I want:
let str = j`çóðè`;
Js.log(j`Üñî${str} interpolation works`);
It would be great if multi line strings would support indentation. So if the last backtick is on a new line, the indentation of the last backtick would be used for the multi line string.
@jdeisenberg I was referring to his j-less code snippet. It’d be nice to fuse the two but that’d mean even tighter integration with BuckleScript.
@Jfrolich we’re punting on this for now because there might actually be better multiline string solutions from e.g. Python and Swift IIRC that we can take.
@jfrolich Here is an analysis of choices to be made for multi-line strings: https://openjdk.java.net/jeps/326 (see the section titled “Margin Management.”) Their solution is to provide functions to do the alignment, but the things they had to think about are worth reading.
We made some changes to the current template literal syntax providing unicode support and typesafe string interpolation out of the box. Available in master and will be released soon.
let x = `Sehr schön, ${son.name} 🙌`
// parses as
let x = {js|Sehr schön, |js} ++ son.name ++ {js| 🙌|js}
Other variations are still available through use of a tag:
let sql = sql`select * from myTable`
let x = j`foo $bar`
Hi. What is the use case of other tags? Isn’t it better to leave that syntax for supporting real template literals at some point (functions that receive two arrays - text and interpolation values). That would be amazing for mapping to modern JS libraries.
That’s really great! Thanks a lot!
What about
"Sehr schön"
though? Will it be parsed as a Unicode string, too?
For now only template literals (between backticks) are supported. In the long term we should investigate if this is possible.
This is much better than JS. In JS it’s extremely confusing because sql
would be a function and you use it with the literal string. Here it’s a ppx or macro or whatever but the meta programming universe is completely separate from functions!
It would be nice thought to have better interop with the tagged template literals in js.
Let’s keep track of it in a separate issue. Changing “normal” strings as `“sehr schöne string” is going to be more complicated.
is there an easy way to update the syntax on a project to try this new String interpolation mechanism or should I better wait for a new release of BuckleScript?