Preserve tagged template in generated code
I've just tried out tagged template, and it would be great if they stayed as tagged templates instead of turning into arrays like here:
https://rescript-lang.org/try?version=v12.0.0-alpha.7&module=esmodule&code=KYDwLsBOB2CGA2ACAtgTwCqwOYDECu0AxmAJYD20iAXIgBSySSyoA8AzmJCdFgHwA0iBk1YByAA4NYyXgEpEAXl6JRZPGHHrFiAEQA3BDoBQRgFJsAdPDJZaaTLgLFy0AAYAzMmVeyjQA
I use the postgres package and it returns the following error:
You can add @taggedTemplate when it's an external to achieve what you want. What you can't do as of now is have a regular rescript function emitted as a proper tagged template. But I suppose that'd be possible to add too.
Cool, I didn't know about this. But in my case I have a returned type instead of an external: https://rescript-lang.org/try?version=v12.0.0-alpha.7&module=esmodule&code=AIFwhg5hCmAmAq0C2AHANmE0BQICeK0ABAM4COaRAvEQBRgBODYeAPCSAwJYB2EAfABoijZmw7c+-AJTV+RFAwD2SLiWisAUiQB02pTx0h+2XAWIolStAGEDAMy4RqRAN4BfU8CRLYAVzQcaAAPLAYeMEokMABraABlCgAuOgA-AGMHJxTLazseRwhZKnlyShoAIksOCAZoEgrTQJBSZNbyomi4xLRaDKyIKg9pU20dNCUIWjKAA3srGZGgA
I just want to add this would be a great feature for reading the compiled output. A tagged template could be formatted by Prettier and highlighted by VSCode extensions.
It would also be good for working with linting and AST transformation tools. As-is ReScript would need to do something weird like this:
let init = () => {
let sql = (_, _) => "example"
%raw(`globalThis`)["sql"] = sql
}
@taggedTemplate
external sql: (array<string>, array<string>) => string = "sql"
Cool, I didn't know about this. But in my case I have a returned type instead of an external: https://rescript-lang.org/try?version=v12.0.0-alpha.7&module=esmodule&code=AIFwhg5hCmAmAq0C2AHANmE0BQICeK0ABAM4COaRAvEQBRgBODYeAPCSAwJYB2EAfABoijZmw7c+-AJTV+RFAwD2SLiWisAUiQB02pTx0h+2XAWIolStAGEDAMy4RqRAN4BfU8CRLYAVzQcaAAPLAYeMEokMABraABlCgAuOgA-AGMHJxTLazseRwhZKnlyShoAIksOCAZoEgrTQJBSZNbyomi4xLRaDKyIKg9pU20dNCUIWjKAA3srGZGgA
@DZakh Have you solved this problem? I have encountered the same issue as well. https://forum.rescript-lang.org/t/how-to-use-taggedtemplate-generate-js-with-tagged-template-literals/6239
I started writing the queries by hand using sql.unsafe, this was actually better for me, since we have a perf critical application. So I'm not using tagged templates now.