Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

escape LineTerminator in escape sequences template literal characters #118

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .depend
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ src/res_comments_table.cmx : src/res_parsetree_viewer.cmx src/res_doc.cmx \
src/res_comment.cmx
src/res_core.cmx : src/res_token.cmx src/res_scanner.cmx src/res_printer.cmx \
src/res_parser.cmx src/res_js_ffi.cmx src/res_grammar.cmx src/res_doc.cmx \
src/res_diagnostics.cmx src/res_comments_table.cmx src/res_core.cmi
src/res_diagnostics.cmx src/res_comments_table.cmx \
src/res_character_codes.cmx src/res_core.cmi
src/res_core.cmi : src/res_parser.cmi
src/res_diagnostics.cmx : src/res_token.cmx src/res_grammar.cmx \
src/res_diagnostics_printing_utils.cmx src/res_diagnostics.cmi
Expand Down
2 changes: 1 addition & 1 deletion src/res_character_codes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ let digitValue ch =
else if Lower.a <= (lower ch) && (lower ch) <= Lower.f then
(lower ch) - Lower.a + 10
else
16 (* larger than any legal value *)
16 (* larger than any legal value *)
2 changes: 2 additions & 0 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ let parseTemplateStringLiteral s =
| '`' as c ->
Buffer.add_char b c;
loop (i + 2)
| c when Res_character_codes.isLineBreak (Char.code c) ->
loop (i + 2)
| c ->
Buffer.add_char b '\\';
Buffer.add_char b c;
Expand Down
1 change: 1 addition & 0 deletions src/res_scanner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ let scanTemplateLiteralToken scanner =
if scanner.ch == CharacterCodes.backtick
|| scanner.ch == CharacterCodes.backslash
|| scanner.ch == CharacterCodes.dollar
|| CharacterCodes.isLineBreak scanner.ch
then next scanner;
scan()
) else (
Expand Down
3 changes: 3 additions & 0 deletions tests/conversion/reason/__snapshots__/render.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,9 @@ let x = 1

exports[`string.re 1`] = `
"%%bs.raw(\\"define(x.y, 'userAgent', {value: 'USER_AGENT_STRING'})\\")

let x = \`This is a long string with a slash and line break \\\\\\\\
carriage return\`
"
`;

Expand Down
3 changes: 3 additions & 0 deletions tests/conversion/reason/string.re
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
%bs.raw
"define(x.y, 'userAgent', {value: 'USER_AGENT_STRING'})";

let x = {js|This is a long string with a slash and line break \
carriage return|js}