fix corner cases with template literals (#4903)

fixes #4902
This commit is contained in:
Alex Lam S.L
2021-05-03 15:26:20 +01:00
committed by GitHub
parent 45b6d23d36
commit 5d9224deb8
2 changed files with 36 additions and 0 deletions

View File

@@ -709,6 +709,8 @@ function OutputStream(options) {
// (x++)[y] // (x++)[y]
// (typeof x).y // (typeof x).y
if (p instanceof AST_PropAccess) return p.expression === this; if (p instanceof AST_PropAccess) return p.expression === this;
// (~x)`foo`
if (p instanceof AST_Template) return p.tag === this;
} }
PARENS(AST_Await, needs_parens_unary); PARENS(AST_Await, needs_parens_unary);
PARENS(AST_Unary, needs_parens_unary); PARENS(AST_Unary, needs_parens_unary);
@@ -782,6 +784,8 @@ function OutputStream(options) {
if (p instanceof AST_Class) return true; if (p instanceof AST_Class) return true;
// (foo && bar)["prop"], (foo && bar).prop // (foo && bar)["prop"], (foo && bar).prop
if (p instanceof AST_PropAccess) return p.expression === this; if (p instanceof AST_PropAccess) return p.expression === this;
// (foo && bar)``
if (p instanceof AST_Template) return p.tag === this;
// typeof (foo && bar) // typeof (foo && bar)
if (p instanceof AST_Unary) return true; if (p instanceof AST_Unary) return true;
}); });

View File

@@ -62,6 +62,23 @@ tag_parentheses_arrow: {
node_version: ">=4" node_version: ">=4"
} }
tag_parentheses_binary: {
options = {
collapse_vars: true,
toplevel: true,
unused: true,
}
input: {
var f = function() {
console.log("PASS");
} || console
f``;
}
expect_exact: '(function(){console.log("PASS")}||console)``;'
expect_stdout: "PASS"
node_version: ">=4"
}
tag_parentheses_new: { tag_parentheses_new: {
input: { input: {
(new function() { (new function() {
@@ -87,6 +104,21 @@ tag_parentheses_sequence: {
node_version: ">=4" node_version: ">=4"
} }
tag_parentheses_unary: {
input: {
var a;
try {
(~a)``;
(a++)``;
} catch (e) {
console.log("PASS");
}
}
expect_exact: 'var a;try{(~a)``;(a++)``}catch(e){console.log("PASS")}'
expect_stdout: "PASS"
node_version: ">=4"
}
malformed_escape: { malformed_escape: {
input: { input: {
(function(s) { (function(s) {