Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stop mangling tagged templates and backquoted strings#7841

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tsnobip merged 1 commit intomasterfromcompile-to-js-template-literals
Sep 4, 2025

Conversation

@tsnobip
Copy link
Member

@tsnobiptsnobip commentedSep 4, 2025
edited
Loading

Fixes#7777,#7196.

With this PR

letquery=sql`" SELECT * FROM ${table} WHERE id = ${id}`

generates

letquery=Tagged_template_libJs.sql`" SELECT * FROM${table} WHERE id =${id}`;

It used to generate

letquery=Tagged_template_libJs.sql`\"\nSELECT * FROM${table} WHERE id =${id}`;

Backquoted strings are now compiled as backquoted strings in JS, but they are still concatenated with+ when there are interpolations, this could be improved in a subsequent PR (for v12.1?).

hackwaly reacted with thumbs up emoji
@tsnobiptsnobipforce-pushed thecompile-to-js-template-literals branch from8459260 to89cb764CompareSeptember 4, 2025 12:20
@tsnobiptsnobipforce-pushed thecompile-to-js-template-literals branch from89cb764 toa16c424CompareSeptember 4, 2025 12:30
@pkg-pr-new
Copy link

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7841

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7841

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7841

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7841

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7841

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7841

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7841

commit:a16c424

Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the compilation of tagged templates and backquoted strings in ReScript to preserve their original formatting in the generated JavaScript output. Previously, these were being mangled with unnecessary escape sequences.

  • Adds support forDBackQuotes delimiter type to preserve template literal syntax
  • Updates the string constant representation to track delimiter information instead of just unicode flag
  • Modifies the compiler pipeline to properly handle backquoted strings and tagged templates

Reviewed Changes

Copilot reviewed 46 out of 46 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
tests/tests/src/*.mjsTest output files showing proper backquote preservation in generated JS
compiler/frontend/external_arg_spec.ml*Adds DBackQuotes delimiter type
compiler/frontend/ast_utf8_string_interp.mlUpdates string interpolation handling for template literals
compiler/frontend/lam_constant.ml*Changes Const_string to use delim field instead of unicode boolean
compiler/core/*.mlUpdates constant handling throughout compiler pipeline
compiler/core/js_dump.mlAdds backquote output support in JS generation

Tip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.

Comment on lines +297 to +301
let is_template=
Ext_list.exists e.pexp_attributes (fun ({txt},_) ->
match txtwith
|"res.template"|"res.taggedTemplate" ->true
|_ ->false)
Copy link

CopilotAISep 4, 2025

Choose a reason for hiding this comment

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

The template detection logic is duplicated in thetransform_exp function but not intransform_pat. This inconsistency could lead to different behavior between expressions and patterns. Consider extracting this logic into a helper function or ensuring consistent template detection across both functions.

Copilot uses AI. Check for mistakes.
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

this is because you can't have string interpolation in pattern matching.

Ext_string.equal optDelim.escaped_j_delimiter
||Ext_string.equal optDelim.escaped_back_quote_delimiter

letis_unescapeds=Ext_string.equal sDelim.unescaped_js_delimiter
Copy link

CopilotAISep 4, 2025

Choose a reason for hiding this comment

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

Theis_unescaped function only checks for theunescaped_js_delimiter but doesn't account for the new backquote delimiter. This could lead to inconsistent behavior when processing unescaped strings with different delimiters.

Suggested change
letis_unescapeds=Ext_string.equal sDelim.unescaped_js_delimiter
letis_unescapeds=
Ext_string.equal sDelim.unescaped_js_delimiter
||Ext_string.equal sDelim.escaped_back_quote_delimiter

Copilot uses AI. Check for mistakes.
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

wrong suggestion

Copy link
Member

@cknittcknitt left a comment

Choose a reason for hiding this comment

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

Tested against a large real-world project and worked fine.

tsnobip reacted with rocket emoji
@tsnobiptsnobip merged commitedf2724 intomasterSep 4, 2025
25 checks passed
@cknittcknitt deleted the compile-to-js-template-literals branchSeptember 12, 2025 15:07
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@cknittcknittcknitt approved these changes

@cristianoccristianoccristianoc approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

" compiles to\" which prevent using npm:regex library

4 participants

@tsnobip@cknitt@cristianoc

[8]ページ先頭

©2009-2025 Movatter.jp