Skip to content
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

Reconsider syntax proposal #76

Open
hax opened this issue Dec 1, 2022 · 10 comments
Open

Reconsider syntax proposal #76

hax opened this issue Dec 1, 2022 · 10 comments

Comments

@hax
Copy link
Member

hax commented Dec 1, 2022

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 feel String.dedent(tag) is a little bit hard to understand for average programmers, and String.dedent(obj.foo) may not work. (need String.dedent(obj.foo.bind(obj)).)

Originally posted by @hax in #40 (comment)

@bakkot
Copy link
Contributor

bakkot commented Dec 1, 2022

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.

@wan2land
Copy link

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.

@sken130
Copy link

sken130 commented Jul 24, 2023

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:

  • indentation/dedentation
  • string interpolation
  • multi-line string
  • containing arbitrary text without escaping

https://es.discourse.group/t/raw-string-literals-that-can-contain-any-arbitrary-text-without-the-need-for-special-escape-sequences/1757/3

(Mentioned in #40 as well)

@dimensia
Copy link

dimensia commented Aug 31, 2023

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.

@bakkot
Copy link
Contributor

bakkot commented Aug 31, 2023

Does this feature compose with other tagged template literals?

Yes:

const mySql = String.dedent(sql)`
  SELECT *
    FROM myTable...
`;  

@hax
Copy link
Member Author

hax commented Sep 4, 2023

@sken130 I really like your proposal, but you need a champion (TC39 delegate) to bring it to the committee. 😉

@hax
Copy link
Member Author

hax commented Sep 4, 2023

@bakkot What if we want compose more? For example, also compose String.raw?

@bakkot
Copy link
Contributor

bakkot commented Sep 4, 2023

@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.)

@hax
Copy link
Member Author

hax commented Jan 25, 2024

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.

@hax
Copy link
Member Author

hax commented Jan 26, 2024

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.

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

No branches or pull requests

5 participants