Fix nlb property for template strings tokens starting with nlb

Also add .gitattributes to checkout lf eol style
This commit is contained in:
Anthony Van de Gejuchte
2016-10-28 23:47:03 +02:00
committed by Richard van Velzen
parent 0aa526e72c
commit 1b2c02c944
4 changed files with 247 additions and 210 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.js text eol=lf

View File

@@ -497,10 +497,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
S.template_braces.push(S.brace_counter);
}
var content = "", raw = "", ch, tok;
next();
while ((ch = next(true)) !== "`") {
next(true, true);
while ((ch = next(true, true)) !== "`") {
if (ch === "$" && peek() === "{") {
next();
next(true, true);
S.brace_counter++;
tok = token(begin ? "template_head" : "template_substitution", content);
tok.begin = begin;

View File

@@ -341,3 +341,39 @@ escape_dollar_curly: {
}
expect_exact: "console.log(`\\${ beep }`);console.log(`1\\${2-0}\\${3-0}4`);console.log(`\\${not an expression}`);"
}
template_starting_with_newline: {
options = {
dead_code: true
}
input: {
function foo(e) {
return `
this is a template string!`;
};
} expect_exact: "function foo(e){return`\nthis is a template string!`}"
}
template_with_newline: {
options = {
dead_code: true
}
input: {
function foo(e) {
return `yep,
this is a template string!`;
};
} expect_exact: "function foo(e){return`yep,\nthis is a template string!`}"
}
template_ending_with_newline: {
options = {
dead_code: true
}
input: {
function foo(e) {
return `this is a template string!
`;
};
} expect_exact: "function foo(e){return`this is a template string!\n`}"
}