Fix nlb property for template strings tokens starting with nlb
Also add .gitattributes to checkout lf eol style
This commit is contained in:
committed by
Richard van Velzen
parent
0aa526e72c
commit
1b2c02c944
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.js text eol=lf
|
||||||
@@ -497,10 +497,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
S.template_braces.push(S.brace_counter);
|
S.template_braces.push(S.brace_counter);
|
||||||
}
|
}
|
||||||
var content = "", raw = "", ch, tok;
|
var content = "", raw = "", ch, tok;
|
||||||
next();
|
next(true, true);
|
||||||
while ((ch = next(true)) !== "`") {
|
while ((ch = next(true, true)) !== "`") {
|
||||||
if (ch === "$" && peek() === "{") {
|
if (ch === "$" && peek() === "{") {
|
||||||
next();
|
next(true, true);
|
||||||
S.brace_counter++;
|
S.brace_counter++;
|
||||||
tok = token(begin ? "template_head" : "template_substitution", content);
|
tok = token(begin ? "template_head" : "template_substitution", content);
|
||||||
tok.begin = begin;
|
tok.begin = begin;
|
||||||
|
|||||||
@@ -1,94 +1,94 @@
|
|||||||
dead_code_1: {
|
dead_code_1: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true
|
dead_code: true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
a();
|
a();
|
||||||
b();
|
b();
|
||||||
x = 10;
|
x = 10;
|
||||||
return;
|
return;
|
||||||
if (x) {
|
if (x) {
|
||||||
y();
|
y();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
function f() {
|
||||||
a();
|
a();
|
||||||
b();
|
b();
|
||||||
x = 10;
|
x = 10;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_2_should_warn: {
|
dead_code_2_should_warn: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true
|
dead_code: true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
g();
|
g();
|
||||||
x = 10;
|
x = 10;
|
||||||
throw "foo";
|
throw "foo";
|
||||||
// completely discarding the `if` would introduce some
|
// completely discarding the `if` would introduce some
|
||||||
// bugs. UglifyJS v1 doesn't deal with this issue; in v2
|
// bugs. UglifyJS v1 doesn't deal with this issue; in v2
|
||||||
// we copy any declarations to the upper scope.
|
// we copy any declarations to the upper scope.
|
||||||
if (x) {
|
if (x) {
|
||||||
y();
|
y();
|
||||||
var x;
|
var x;
|
||||||
function g(){};
|
function g(){};
|
||||||
// but nested declarations should not be kept.
|
// but nested declarations should not be kept.
|
||||||
(function(){
|
(function(){
|
||||||
var q;
|
var q;
|
||||||
function y(){};
|
function y(){};
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
function f() {
|
||||||
g();
|
g();
|
||||||
x = 10;
|
x = 10;
|
||||||
throw "foo";
|
throw "foo";
|
||||||
var x;
|
var x;
|
||||||
function g(){};
|
function g(){};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_constant_boolean_should_warn_more: {
|
dead_code_constant_boolean_should_warn_more: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
loops : true,
|
loops : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true
|
evaluate : true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
while (!((foo && bar) || (x + "0"))) {
|
while (!((foo && bar) || (x + "0"))) {
|
||||||
console.log("unreachable");
|
console.log("unreachable");
|
||||||
var foo;
|
var foo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
|
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
|
||||||
asdf();
|
asdf();
|
||||||
foo();
|
foo();
|
||||||
var moo;
|
var moo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo;
|
var foo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
// nothing for the while
|
// nothing for the while
|
||||||
// as for the for, it should keep:
|
// as for the for, it should keep:
|
||||||
var x = 10, y;
|
var x = 10, y;
|
||||||
var moo;
|
var moo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_block_decls_die: {
|
dead_code_block_decls_die: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
@@ -110,119 +110,119 @@ dead_code_block_decls_die: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_declaration: {
|
dead_code_const_declaration: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
loops : true,
|
loops : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true
|
evaluate : true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
const CONST_FOO = false;
|
const CONST_FOO = false;
|
||||||
if (CONST_FOO) {
|
if (CONST_FOO) {
|
||||||
console.log("unreachable");
|
console.log("unreachable");
|
||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var unused;
|
var unused;
|
||||||
const CONST_FOO = !1;
|
const CONST_FOO = !1;
|
||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation: {
|
dead_code_const_annotation: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
loops : true,
|
loops : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true
|
evaluate : true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
/** @const */ var CONST_FOO_ANN = false;
|
/** @const */ var CONST_FOO_ANN = false;
|
||||||
if (CONST_FOO_ANN) {
|
if (CONST_FOO_ANN) {
|
||||||
console.log("unreachable");
|
console.log("unreachable");
|
||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var unused;
|
var unused;
|
||||||
var CONST_FOO_ANN = !1;
|
var CONST_FOO_ANN = !1;
|
||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
dead_code_const_annotation_regex: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
loops : true,
|
loops : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true
|
evaluate : true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
// @constraint this shouldn't be a constant
|
// @constraint this shouldn't be a constant
|
||||||
var CONST_FOO_ANN = false;
|
var CONST_FOO_ANN = false;
|
||||||
if (CONST_FOO_ANN) {
|
if (CONST_FOO_ANN) {
|
||||||
console.log("reachable");
|
console.log("reachable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var unused;
|
var unused;
|
||||||
var CONST_FOO_ANN = !1;
|
var CONST_FOO_ANN = !1;
|
||||||
CONST_FOO_ANN && console.log('reachable');
|
CONST_FOO_ANN && console.log('reachable');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_complex_scope: {
|
dead_code_const_annotation_complex_scope: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
loops : true,
|
loops : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true
|
evaluate : true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused_var;
|
var unused_var;
|
||||||
/** @const */ var test = 'test';
|
/** @const */ var test = 'test';
|
||||||
// @const
|
// @const
|
||||||
var CONST_FOO_ANN = false;
|
var CONST_FOO_ANN = false;
|
||||||
var unused_var_2;
|
var unused_var_2;
|
||||||
if (CONST_FOO_ANN) {
|
if (CONST_FOO_ANN) {
|
||||||
console.log("unreachable");
|
console.log("unreachable");
|
||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
if (test === 'test') {
|
if (test === 'test') {
|
||||||
var beef = 'good';
|
var beef = 'good';
|
||||||
/** @const */ var meat = 'beef';
|
/** @const */ var meat = 'beef';
|
||||||
var pork = 'bad';
|
var pork = 'bad';
|
||||||
if (meat === 'pork') {
|
if (meat === 'pork') {
|
||||||
console.log('also unreachable');
|
console.log('also unreachable');
|
||||||
} else if (pork === 'good') {
|
} else if (pork === 'good') {
|
||||||
console.log('reached, not const');
|
console.log('reached, not const');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var unused_var;
|
var unused_var;
|
||||||
var test = 'test';
|
var test = 'test';
|
||||||
var CONST_FOO_ANN = !1;
|
var CONST_FOO_ANN = !1;
|
||||||
var unused_var_2;
|
var unused_var_2;
|
||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
var beef = 'good';
|
var beef = 'good';
|
||||||
var meat = 'beef';
|
var meat = 'beef';
|
||||||
var pork = 'bad';
|
var pork = 'bad';
|
||||||
'good' === pork && console.log('reached, not const');
|
'good' === pork && console.log('reached, not const');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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}`);"
|
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`}"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user