Skip to content

Commit

Permalink
Backtickify source instead of JSON.stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed Jan 3, 2024
1 parent aabdde2 commit 289d668
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/rose/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
toplevel,
} from "./parse.js";

const backtick = (s: string) => `\`${s.replace(/[`\$\\]/g, (x) => `\\${x}`)}\``;

const infixes: ToplevelKind[] = ["infix", "infixl", "infixr"];

const parse = (
Expand Down Expand Up @@ -69,7 +71,7 @@ const transform = (lex: moo.Lexer, source: string): string => {
)}, prec: [${prec.map((x) => `${x}`).join(", ")}] },`,
),
"};",
`export const source = ${JSON.stringify(source)};`,
`export const source = ${backtick(source)};`,
"",
].join("\n");
};
Expand Down

0 comments on commit 289d668

Please sign in to comment.