diff options
author | 2023-06-05 12:55:56 -0700 | |
---|---|---|
committer | 2023-06-05 12:55:56 -0700 | |
commit | 568f170e126dd32720e8d626e61b82b401c142e0 (patch) | |
tree | 02c158d4327bf5c3a5634f812dad1bc0cbf84f19 | |
parent | c87d65856c06a03a2470fdc1bd48bc4042dadaec (diff) | |
download | bun-568f170e126dd32720e8d626e61b82b401c142e0.tar.gz bun-568f170e126dd32720e8d626e61b82b401c142e0.tar.zst bun-568f170e126dd32720e8d626e61b82b401c142e0.zip |
[transpiler] Fix new length for raw template contents (#3215)
* use correct length for raw template contents
* tests for raw template contents
-rw-r--r-- | src/js_lexer.zig | 2 | ||||
-rw-r--r-- | test/transpiler/transpiler.test.js | 41 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig index c4ed7216c..753b80d95 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -2662,7 +2662,7 @@ fn NewLexer_( end += 1; } - return bytes.toOwnedSliceLength(end + 1); + return bytes.toOwnedSliceLength(end); } fn parseNumericLiteralOrDot(lexer: *LexerType) !void { diff --git a/test/transpiler/transpiler.test.js b/test/transpiler/transpiler.test.js index 81cb367c3..3040a9913 100644 --- a/test/transpiler/transpiler.test.js +++ b/test/transpiler/transpiler.test.js @@ -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); |