Open hax opened 1 year ago
I don't think the question of how to handle caching is significant enough to warrant revisiting syntax. It's really only relevant in an edge case which most people will never encounter.
With MySQL, the following situations are common.
const query = `
select *
from \`users\`
where \`name\` = ?
`
If implemented via String.dedent
, this problem is repeated.
In the "In other languages" section of the README, the grammar(heredoc) is implemented separately from the default string(""
) for other languages because it also includes these escape issues.
If we are to introduce new syntax, we should make it worthwhile by including more features and solving as many problems as possible, otherwise the features proposed too late will become breaking changes in the future.
Here is my proposal of adding raw string literal to ECMAScript/JavaScript to solve multiple problems together:
(Mentioned in #40 as well)
Does this feature compose with other tagged template literals? e.g.:
const mySql = sql`
SELECT *
FROM myTable...
`;
If not please reconsider a syntax-based solution that will work with existing tagged-template literals.
Does this feature compose with other tagged template literals?
Yes:
const mySql = String.dedent(sql)`
SELECT *
FROM myTable...
`;
@sken130 I really like your proposal, but you need a champion (TC39 delegate) to bring it to the committee. 😉
@bakkot What if we want compose more? For example, also compose String.raw
?
@hax You already can't compose String.raw
with another template tag. This won't change that either way. (Besides, there's no reason to - template tags can look at the raw
component themselves, if they want to, so there's no need to use String.raw
if you're using another template tag already.)
Hi everyone, I plan to write a raw string syntax proposal (maybe based on @sken130 work) and present to the committee for stage 1, if I can catch the deadline of next meeting.
Besides the use cases this issue or @sken130 's discourse post already mentioned, the main reason I decide to champion it myself is because I feel really pain when writing LLM code in JS --- if you want to write prompt in markdown or contains JS code directly in the prompts.
I will update this issue when the proposal repo ready.
Please check the repo: https://github.com/hax/proposal-raw-string-literals
@sken130 Feel free to add your real name to authors if you wish.
I suggest we reconsider syntax option because with syntax, we just solve #75.
There are also other reasons, copy from original issue:
One problem of current template literal is, you can't have unescaped
`
in the literal (it always end the literal). This is very inconvenient for text contains backticks, eg. markdown.This issue is not directly relate to dedent, but consider the main use cases of dedent is long text, I really hope we can revisit the syntax options which could allow unescaped backticks.
Syntax also make
String.dedent(tag)
unnecessary. I feelString.dedent(tag)
is a little bit hard to understand for average programmers, andString.dedent(obj.foo)
may not work. (needString.dedent(obj.foo.bind(obj))
.)Originally posted by @hax in https://github.com/tc39/proposal-string-dedent/issues/40#issuecomment-1188570725