mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
[JS Printer] Fix bug with template literals
This commit is contained in:
@@ -22,5 +22,6 @@
|
||||
"/latin1-chars-in-regexp.js",
|
||||
"/jsx-spacing.jsx",
|
||||
"/jsx-entities.jsx",
|
||||
"/optional-chain-with-function.js"
|
||||
"/optional-chain-with-function.js",
|
||||
"/template-literal.js"
|
||||
]
|
||||
|
||||
37
integration/snippets/template-literal.js
Normal file
37
integration/snippets/template-literal.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const css = (templ) => templ.toString();
|
||||
|
||||
const fooNoBracesUTF8 = css`
|
||||
before
|
||||
/* */
|
||||
after
|
||||
`;
|
||||
|
||||
const fooNoBracesUT16 = css`
|
||||
before
|
||||
🙃
|
||||
after
|
||||
`;
|
||||
const fooUTF8 = css`
|
||||
before
|
||||
${true}
|
||||
after
|
||||
|
||||
`;
|
||||
|
||||
const fooUTF16 = css`
|
||||
before
|
||||
🙃 ${true}
|
||||
after
|
||||
|
||||
`;
|
||||
export function test() {
|
||||
for (let foo of [fooNoBracesUT16, fooNoBracesUTF8, fooUTF16, fooUTF8]) {
|
||||
console.assert(
|
||||
foo.includes("before"),
|
||||
`Expected ${foo} to include "before"`
|
||||
);
|
||||
console.assert(foo.includes("after"), `Expected ${foo} to include "after"`);
|
||||
}
|
||||
|
||||
return testDone(import.meta.url);
|
||||
}
|
||||
@@ -1473,11 +1473,7 @@ pub fn NewPrinter(
|
||||
|
||||
p.print("`");
|
||||
if (e.head.isPresent()) {
|
||||
if (e.tag != null) {
|
||||
p.print(e.head.utf8);
|
||||
} else {
|
||||
p.printStringContent(&e.head, '`');
|
||||
}
|
||||
p.printStringContent(&e.head, '`');
|
||||
}
|
||||
|
||||
for (e.parts) |part| {
|
||||
@@ -1485,11 +1481,7 @@ pub fn NewPrinter(
|
||||
p.printExpr(part.value, .lowest, ExprFlag.None());
|
||||
p.print("}");
|
||||
if (part.tail.isPresent()) {
|
||||
if (e.tag != null) {
|
||||
p.print(part.tail.utf8);
|
||||
} else {
|
||||
p.printStringContent(&part.tail, '`');
|
||||
}
|
||||
p.printStringContent(&part.tail, '`');
|
||||
}
|
||||
}
|
||||
p.print("`");
|
||||
|
||||
Reference in New Issue
Block a user