rspivak / slimit

SlimIt - a JavaScript minifier/parser in Python
MIT License
550 stars 94 forks source link

Unexpected Token error -- script or slimit issue? #95

Open jshlbrd opened 7 years ago

jshlbrd commented 7 years ago

Slimit throws this error ...

SyntaxError: Unexpected token (LT, '<') at 1:0 between None and LexToken(NOT,'!',1,1)

... for this portion of the script ...

<!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->

Does this seem like an issue with the input script or a case that slimit should be able to handle?

ghost commented 7 years ago

That first line isn't commented out, this isnt an html parser, that's not valid javascript.

jshlbrd commented 7 years ago

This is an example from an HTML script block where the type is explicitly called as text/javascript. Here's another example: https://github.com/CartoDB/mobile-android-samples/blob/master/docs/deprecated-list.html

<script type="text/javascript"><!--
    try {
        if (location.href.indexOf('is-external=true') == -1) {
            parent.document.title="Deprecated List";
        }
    }
    catch(err) {
    }
//-->
</script>