Skip to content

Commit

Permalink
JS: support ECMAVersion < 2015 for template literals, fixes #621
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 27, 2023
1 parent b6acff4 commit 08752f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.write(notOneBytes)
}
} else if expr.TokenType == js.StringToken {
m.write(minifyString(expr.Data, true))
m.write(minifyString(expr.Data, m.o.minVersion(2015)))
} else if expr.TokenType == js.RegExpToken {
// </script>/ => < /script>/
if 0 < len(m.prev) && m.prev[len(m.prev)-1] == '<' && bytes.HasPrefix(expr.Data, regExpScriptBytes) {
Expand Down
3 changes: 2 additions & 1 deletion js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ func TestJSVarRenaming(t *testing.T) {
}

func TestJSVersion(t *testing.T) {
versions := []int{2022, 2020, 2019, 2018}
versions := []int{2022, 2020, 2019, 2018, 2014}

jsTests := []struct {
version int
Expand All @@ -901,6 +901,7 @@ func TestJSVersion(t *testing.T) {
}{
{2020, `a==null?b:a`, `a==null?b:a`, `a??b`},
{2019, `try{}catch(a){}`, `try{}catch(a){}`, `try{}catch{}`},
{2015, `"<div onclick=\"alert('test')\">"`, `"<div onclick=\"alert('test')\">"`, "`<div onclick=\"alert('test')\">`"},
}

m := minify.New()
Expand Down

0 comments on commit 08752f6

Please sign in to comment.