Skip to content

Commit

Permalink
[transpiler] Fix new length for raw template contents (oven-sh#3215)
Browse files Browse the repository at this point in the history
* use correct length for raw template contents

* tests for raw template contents
  • Loading branch information
dylan-conway authored Jun 5, 2023
1 parent c87d658 commit 568f170
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js_lexer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,7 @@ fn NewLexer_(
end += 1;
}

return bytes.toOwnedSliceLength(end + 1);
return bytes.toOwnedSliceLength(end);
}

fn parseNumericLiteralOrDot(lexer: *LexerType) !void {
Expand Down
41 changes: 41 additions & 0 deletions test/transpiler/transpiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,47 @@ console.log(foo, array);
});
});

it("raw template literal contents", () => {
expectPrinted("String.raw`\r`", "String.raw`\n`");
expectPrinted("String.raw`\r\n`", "String.raw`\n`");
expectPrinted("String.raw`\n`", "String.raw`\n`");
expectPrinted("String.raw`\r\r\r\r\r\n\r`", "String.raw`\n\n\n\n\n\n`");
expectPrinted("String.raw`\n\r`", "String.raw`\n\n`");
var code = `String.raw\`
<head>
<meta charset="UTF-8" />
<title>${"meow123"}</title>
<link rel="stylesheet" href="/css/style.css" />
</head>
\``;
var result = code;
expectPrinted(code, code);

code = `String.raw\`
<head>\r\n\n\r\r\r
<meta charset="UTF-8" />\r
<title>${"meow123"}</title>\n
\r
\r
\n\r
<link rel="stylesheet" href="/css/style.css" />
</head>
\``;
result = `String.raw\`
<head>\n\n\n\n
<meta charset="UTF-8" />
<title>${"meow123"}</title>\n
\n
<link rel="stylesheet" href="/css/style.css" />
</head>
\``;
expectPrinted(code, result);
});

describe("scan", () => {
it("reports all export names", () => {
const { imports, exports } = transpiler.scan(code);
Expand Down

0 comments on commit 568f170

Please sign in to comment.