Skip to content

Add support for tagged template literals #2

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

Closed
wants to merge 9 commits into from

Conversation

kevinbarabash
Copy link
Owner

@kevinbarabash kevinbarabash commented Dec 26, 2021

This PR is a replacement for rescript-lang/syntax#471. In addition to updating the parser to treat tagged templates as apply nodes, it also updates the frontend to convert those apply nodes (with ap_tagged_template set to true) to tagged template literals in the JS output.

NOTE: This PR depends on rescript-lang#5347.

TODO:

  • update ES6 output to use tagged templates
  • do the TODOs that were added by this PR
  • update ocamlStrings.res to use "" in place of {js| strings and rename it to resStrings.res or something like that and bring back the original ocamlStrings.ml just without the sql test case.

let x = j`/* https://www.apple.com */`
let x = `/* https://www.apple.com*/`
let x = `/*https://www.apple.com*/`
let x = `/*https://www.apple.com*/`
let x = sql`/*https://www.apple.com*/`

let x = `\`https://\${appleWebsite}\``
Copy link
Owner Author

@kevinbarabash kevinbarabash Dec 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsnobip I'm not sure what the ReScript equivalent of

{js|`https://${appleWebsite}`|js}

should be. I tried

`\`https://${appleWebsite}\``

but now the $ isn't escaped in the output anymore. I'm not really sure what the original test case was trying to test.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinbarabash {js| is just a unicode string with no string-interpolation, in rescript master, you can just use regular double quotes " for that

"https://${appleWebsite}"

should do it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original had backticks between between the {js| and |js}. Wouldn't that make it

"`https://${appleWebsite}`"

of does {js| does something special with backticks?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops sorry my bad, it is indeed

"`https://${appleWebsite}`"

Comment on lines +8 to +13
function sql(prim0, prim1) {
return Caml_splice_call.spliceApply(Tagged_template_libJs.sql, [
prim0,
prim1
]);
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't appear in the output since it isn't used.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a test file that calls the tagged template function as a function call to make sure that this helper is still included in that situation.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this a bit more and it is actually being used because sql is exported.

@kevinbarabash kevinbarabash changed the title Add support for tagged template literals Add support for tagged template literals [WIP] Dec 27, 2021
@kevinbarabash kevinbarabash marked this pull request as draft December 27, 2021 04:37
@kevinbarabash kevinbarabash changed the title Add support for tagged template literals [WIP] Add support for tagged template literals Dec 28, 2021
@kevinbarabash kevinbarabash marked this pull request as ready for review December 28, 2021 00:40
@zth
Copy link

zth commented Jun 29, 2022

I know this is closed, but @kevinbarabash @tsnobip is this something you'd be interested in taking up work on again? Support for tagged template literals would be a great addition to the compiler, and there's currently good chances to get this reviewed in a timely manner given that the activity in the compiler development has increased significantly the last month.

tsnobip added a commit to rescript-lang/rescript that referenced this pull request May 9, 2023
tsnobip added a commit to rescript-lang/rescript that referenced this pull request Jan 15, 2024
tsnobip added a commit to rescript-lang/rescript that referenced this pull request Jan 25, 2024
tsnobip added a commit to rescript-lang/rescript that referenced this pull request Jan 25, 2024
* support tagged template in rescript and allow to bind to JS
tagged templates using @taggedTemplate annotation

* Set version to 11.1.0

* add tagged templates to changelog

This work was originally based on kevinbarabash#2
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

Successfully merging this pull request may close these issues.

3 participants