From f7b26ebe2803931dc59285af1571cf6c6883d53f Mon Sep 17 00:00:00 2001 From: osyrisrblx Date: Fri, 21 Jun 2024 23:49:03 -0400 Subject: [PATCH 1/4] Fix #458 --- src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts index f98a486..c29d9de 100644 --- a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts +++ b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts @@ -5,5 +5,5 @@ export function renderInterpolatedStringPart(state: RenderState, node: luau.Inte // braces and newlines are escaped to be valid in luau // () captures result, [] to search for any of: {} // $1 fills in capture from original search - return node.text.replace(/([{}])/g, "\\$1").replace(/\n/g, "\\\n"); + return node.text.replace(/([{}])/g, "\\$1").replace(/(\r\n?|\n)/g, "\\$1"); } From a5af3f62e1ea346e1ea476bc8d2901d6a7434053 Mon Sep 17 00:00:00 2001 From: osyrisrblx Date: Sat, 22 Jun 2024 00:32:26 -0400 Subject: [PATCH 2/4] Fix #484 --- .../nodes/fields/renderInterpolatedStringPart.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts index c29d9de..b1ec006 100644 --- a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts +++ b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts @@ -2,8 +2,11 @@ import luau from "LuauAST"; import { RenderState } from "LuauRenderer"; export function renderInterpolatedStringPart(state: RenderState, node: luau.InterpolatedStringPart) { - // braces and newlines are escaped to be valid in luau - // () captures result, [] to search for any of: {} - // $1 fills in capture from original search - return node.text.replace(/([{}])/g, "\\$1").replace(/(\r\n?|\n)/g, "\\$1"); + // escape braces and newlines, but do not touch braces within unicode escape codes + return node.text + .replace( + /(\\u\{[0-9A-Fa-f]+\})|([{}])/g, + (_, unicodeEscape: string | undefined, brace: string | undefined) => unicodeEscape ?? "\\" + brace, + ) + .replace(/(\r\n?|\n)/g, "\\$1"); } From 9593ab4c0f1450790bc53f07007ab807f0f60173 Mon Sep 17 00:00:00 2001 From: osyrisrblx Date: Sat, 22 Jun 2024 22:17:07 -0400 Subject: [PATCH 3/4] Add comments --- .../nodes/fields/renderInterpolatedStringPart.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts index b1ec006..b44aade 100644 --- a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts +++ b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts @@ -3,10 +3,14 @@ import { RenderState } from "LuauRenderer"; export function renderInterpolatedStringPart(state: RenderState, node: luau.InterpolatedStringPart) { // escape braces and newlines, but do not touch braces within unicode escape codes - return node.text - .replace( - /(\\u\{[0-9A-Fa-f]+\})|([{}])/g, - (_, unicodeEscape: string | undefined, brace: string | undefined) => unicodeEscape ?? "\\" + brace, - ) - .replace(/(\r\n?|\n)/g, "\\$1"); + return ( + node.text + .replace( + /(\\u{[0-9A-Fa-f]+})|([{}])/g, + (_, unicodeEscape: string | undefined, brace: string | undefined) => unicodeEscape ?? "\\" + brace, + ) + // captures a CR with optionally an LF after it + // or just an LF on its own + .replace(/(\r\n?|\n)/g, "\\$1") + ); } From d59d519f2b3810708359dd775b0c9100b70f9a52 Mon Sep 17 00:00:00 2001 From: osyrisrblx Date: Sun, 23 Jun 2024 21:40:59 -0400 Subject: [PATCH 4/4] Refactor to make things a little cleaner --- .../nodes/fields/renderInterpolatedStringPart.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts index b44aade..f246820 100644 --- a/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts +++ b/src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts @@ -2,15 +2,11 @@ import luau from "LuauAST"; import { RenderState } from "LuauRenderer"; export function renderInterpolatedStringPart(state: RenderState, node: luau.InterpolatedStringPart) { - // escape braces and newlines, but do not touch braces within unicode escape codes return ( node.text - .replace( - /(\\u{[0-9A-Fa-f]+})|([{}])/g, - (_, unicodeEscape: string | undefined, brace: string | undefined) => unicodeEscape ?? "\\" + brace, - ) - // captures a CR with optionally an LF after it - // or just an LF on its own + // escape braces, but do not touch braces within unicode escape codes + .replace(/(\\u{[a-fA-F0-9]+})|([{}])/g, (_, unicodeEscape, brace) => unicodeEscape ?? "\\" + brace) + // escape newlines, captures a CR with optionally an LF after it or just an LF on its own .replace(/(\r\n?|\n)/g, "\\$1") ); }