Hacker News new | ask | show | jobs
by palish 5171 days ago
I have a simple fix. Standby.

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

1 comments

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.