Skip to content

Commit

Permalink
JS: don't trim escapes in tagged template expression, fixes #701
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 15, 2024
1 parent 19a374b commit 35ef965
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,10 +1133,18 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
parentInFor := m.inFor
m.inFor = false
for _, item := range expr.List {
m.write(replaceEscapes(item.Value, '`', 1, 2))
if expr.Tag == nil {
m.write(replaceEscapes(item.Value, '`', 1, 2))
} else {
m.write(item.Value)
}
m.minifyExpr(item.Expr, js.OpExpr)
}
m.write(replaceEscapes(expr.Tail, '`', 1, 1))
if expr.Tag == nil {
m.write(replaceEscapes(expr.Tail, '`', 1, 1))
} else {
m.write(expr.Tail)
}
m.inFor = parentInFor
case *js.NewExpr:
if expr.Args == nil && js.OpLHS < prec && prec != js.OpNew {
Expand Down
1 change: 1 addition & 0 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ func TestJS(t *testing.T) {
{`for(!a;b;c);`, "for(!a;b;c);"}, // #656
{"var a = /*! comment */ b;", "/*! comment */var a=b"}, // #664
{`var c="";for(let i=0;;);var d="";for(let i=0;;);`, `var d,c="";for(let i=0;;);d="";for(let i=0;;);`}, // #687
{"String.raw`\\b`", "String.raw`\\b`"}, // #701
}

m := minify.New()
Expand Down

0 comments on commit 35ef965

Please sign in to comment.