Hacker News new | past | comments | ask | show | jobs | submit login
Semicolon.js (github.com/madrobby)
76 points by MatthewPhillips on April 15, 2012 | hide | past | favorite | 25 comments



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 )


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"


I have a simple fix. Standby.

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


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";


Fixed. Thank you, keep 'em coming.

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


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"];


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.


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...


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.


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)


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.


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


No semicolon-min.js ?


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


[deleted]


See: Satire.

Also in case you haven't noticed, semicolon.js is also Satire.


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.


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 ;)


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


[deleted]


Vapor.js is making fun of the trend of JavaScript frameworks. Most of the existing frameworks advertise their file size, since a small size is desirable for fast page loads. Vapor.js is an empty file.

Recently the authors of a popular JavaScript/CSS framework, Bootstrap, decided to remove the semicolons from their JavaScript (since they're technically optional).

Douglas Crockford is the author of a tool called JSMin that compresses JavaScript files. He is known ot have strong opinions on JavaScript coding style, as is evident in his book JavaScript: The Good Parts and his JavaScript formatting/checking tool, JSLint.

Someone pointed out that now that Bootstrap no longer has semicolons it no longer under JSMin. Douglas Crockford was pulled into the conversation, where he expressed his strong opinions on the use of semicolons in JavaScript

Semicolon.js is making fun of all of this by adding a semicolon to Vapor.js.

(Oh, darn. The person I was replying to deleted their post. Anyway, they said something along the lines of: "I know this is a joke, but I don't get it. Am I missing some subtle commentary?")


Thank you for the explanation. I guess a lot of people (like me) were confused by this multi-layer insider joke.


Just wanted to add one more point, same person who authored vapor.js did semicolon.js :-)


Thanks for explaining. I would have spent (too much time) figuring out that joke. It's funny, but not worth (too much time).


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


what the fuck


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: