

Semicolon.js - MatthewPhillips
https://github.com/madrobby/semicolon.js

======
carbocation
If you made it this far, consider taking a look at palish's operational
response ( <http://news.ycombinator.com/item?id=3843339> ) to the
@DouglasCrockford/JSMin vs @fat/Bootstrap brouhaha (
<http://news.ycombinator.com/item?id=3842713> )

~~~
thezilch
I checked it out; it's as broken as these childish acts from "reputable"
javascript-library maintainers.

    
    
      cat foo.js; jsmin <foo.js
      "foo" &&
        !"foo"
      
      "foo"&&;!"foo"

~~~
palish
I have a simple fix. Standby.

EDIT: Fixed. Thanks for pointing that out. Let me know if you find anything
else.

~~~
thezilch
Sure thing; still some edges -- not limited to the following.

    
    
      cat foo.js; jsmin <foo.js
      var foo = "foo",
      is_foo = foo?
        !!foo:
        "bar";
      
      var foo="foo",is_foo=foo?;!!foo:"bar";

~~~
palish
Fixed. Thank you, keep 'em coming.

As of now, semicolon substitution isn't performed if the character before the
newline is any of: & | + - * ? :

~~~
thezilch
Like I said, not limited; surely you can see where these are going...

    
    
      cat foo.js; jsmin <foo.js
      foo = [
        !"foo",
        !"foo" %
          !!"bar",
        1 ==
          !"foo"
      ];
    
      foo=[;!"foo",;!"foo"%;!!"bar",1==;!"foo"];

~~~
palish
Fixed. Thanks so much! I added % and = to the blacklist.

I'm searching for a fundamentally elegant solution. My current one is more of
a kludge... though, if it fixes all cases and doesn't introduce problems, then
maybe it's worth a few extra lines.

~~~
thezilch
The last example demonstrated more than the % and = punctuators failing your
lexer, and then it doesn't demonstrate still more that would remain, including
but not limited to...

    
    
      cat foo.js; jsmin <foo.js
      while(
        !true){true;}
    
      while(;!true){true;}
    

You might look through the token(izing) section of the ECMA's spec,
specifically puctuators. [http://www.ecma-
international.org/publications/files/ECMA-ST...](http://www.ecma-
international.org/publications/files/ECMA-ST/Ecma-262.pdf)

~~~
palish
The "prior character blacklist" is now:

    
    
      & | + - * ? : % = ( [ { ,
    

Currently hunting for more problems, and a more elegant solution...

Offtopic, the reason I did this JSMin fork was just to challenge myself, not
to make a political statement or anything like that. My cat was just diagnosed
with feline lukemia. I know this project is a little silly, but it's been
fantastic for keeping my mind off of real-world stuff. You're awesome for
providing all of these examples; thank you.

More usefully, this serves to prove that Mr. Crockford was likely correct in
his assessment.

~~~
thezilch
Also, consider non-punctuator issues; such as those with exposed reserved-
keywords.

    
    
      cat foo.js; jsmin <foo.js
      do
        !!1 && 2
      while(0)
    
      do;!!1&&2
      while(0)

~~~
palish
Heh heh. You may have just found a fatal flaw.

On the other hand, is "do" the only reserved keyword which matters? Then it
might be okay to special case that _one_ instance as well.

There is no doubt that my approach is the wrong approach; I'm just curious
whether it's easier to handle each of the ~dozen special cases than to
fundamentally rewrite JSMin (as a full ECMAScript parser).

EDIT: Amusingly, I've special-cased the 'do' keyword in a fairly
straightforward way, so now the code handles every example thus far. I wonder
if these are the only special cases required, and whether they add any adverse
side-effects. Also, you're extremely talented and creative.

~~~
thezilch
Apart from some punctuators still missing, off the top of my head...

    
    
      ! ^ < >
    

A few keywords that could be left bare -- not limited to -- albeit unlikely
outside of do and else...

    
    
      case else instanceof typeof

------
chrisohara
No semicolon-min.js ?

~~~
nhebb
This one's getting milked for all it's worth:
<https://github.com/madrobby/semicolon.js/pull/6>

~~~
skrebbel
While the joke itself (hihi, we minified a semicolon!) is only slightly funny
at best, the accompanying text in the pull request makes it all worth it.

------
rimantas
Funny, but I came across the case when whil concatenating files the resulting
script was broken, becaus of the missing semicolon at the end of some library.
Dropping this script into the list would fix that ;)

------
facorreia
Uh wait, does that mean they GPL'd the semicolon?

------
rainboiboi
I looked at the code and..... ;

------
john2x
what the fuck

------
alpb
I see some hilarious animated GIF comments are removed from the issue. This is
censorship Twitter, how dare!

