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

Fix interpolated string rendering issues #483

Merged
merged 4 commits into from
Jun 24, 2024
Merged
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
11 changes: 7 additions & 4 deletions src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/\n/g, "\\\n");
return (
node.text
// 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")
);
}
Loading