terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
385 stars 32 forks source link

[Bug]: bug with ejs template engine #162

Closed sintret closed 2 weeks ago

sintret commented 1 year ago

What happened?

i have a code in ejs template like following

<script>
    submitForm('form-group', '', '/<%- routeName %>');
    $(window).keydown(function(event){
        if((event.keyCode == 13)) {
            var eltarget = $(event.target);
            if(eltarget.attr("type") == "input") {
                event.preventDefault();
                return false;
            }
        }
    });
    $(".divlayout_id ").hide();
    $("#layouts").on("change", function(){
        if($(this).val() == 4) {
           $(".divlayout_id ").show();
        } else {
           $(".divlayout_id ").hide();
        }
    })
    <% var layout =  data.layouts == "4" ? `$(".divlayout_id ").show();` : `$(".divlayout_id ").hide();` %>
    <%- layout%>
</script>

Error in console log image

Version

v7.2.0

What browsers are you seeing the problem on?

Chrome

Link to reproduce

https://github.com/terser/html-minifier-terser

Relevant log output

<script>submitForm("form-group","","/<%- routeName %>"),$(window).keydown((function(t){if(13==t.keyCode&&"input"==$(t.target).attr("type"))return t.preventDefault(),!1})),$(".divlayout_id ").hide(),$("#layouts").on("change",(function(){4==$(this).val()?$(".divlayout_id ").show():$(".divlayout_id ").hide()}))</script>
<% var layout =  data.layouts == "4" ? `$(".divlayout_id ").show();` : `$(".divlayout_id ").hide();` %>,<%- layout%>

Willing to submit a PR?

Yes

DanielRuf commented 3 weeks ago

See https://github.com/terser/html-minifier-terser/issues/161#issuecomment-2452955381