Skip to content

Commit

Permalink
Refactor to make things a little cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
osyrisrblx committed Jun 24, 2024
1 parent 9593ab4 commit d59d519
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/LuauRenderer/nodes/fields/renderInterpolatedStringPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}

0 comments on commit d59d519

Please sign in to comment.