Permalink
Browse files

Update bundled jsmin

  • Loading branch information...
rraptorr committed Nov 3, 2013
1 parent 4845111 commit 34eff62a9064f817312b94355ad6717151becb6a
Showing with 76 additions and 44 deletions.
  1. +76 −44 utils/jsmin.c
View
@@ -1,5 +1,5 @@
/* jsmin.c
- 2007-05-22
+ 2013-03-29
Copyright (c) 2002 Douglas Crockford (www.crockford.com)
@@ -30,8 +30,19 @@ SOFTWARE.
static int theA;
static int theB;
static int theLookahead = EOF;
+static int theX = EOF;
+static int theY = EOF;
+static void
+error(char* s)
+{
+ fputs("JSMIN Error: ", stderr);
+ fputs(s, stderr);
+ fputc('\n', stderr);
+ exit(1);
+}
+
/* isAlphanum -- return true if the character is a letter, digit, underscore,
dollar sign, or non-ASCII character.
*/
@@ -93,28 +104,29 @@ next()
for (;;) {
c = get();
if (c <= '\n') {
- return c;
+ break;
}
}
+ break;
case '*':
get();
- for (;;) {
+ while (c != ' ') {
switch (get()) {
case '*':
if (peek() == '/') {
get();
- return ' ';
+ c = ' ';
}
break;
case EOF:
- fprintf(stderr, "Error: JSMIN Unterminated comment.\n");
- exit(1);
+ error("Unterminated comment.");
}
}
- default:
- return c;
+ break;
}
}
+ theY = theX;
+ theX = c;
return c;
}
@@ -133,46 +145,74 @@ action(int d)
switch (d) {
case 1:
putc(theA, stdout);
+ if (
+ (theY == '\n' || theY == ' ') &&
+ (theA == '+' || theA == '-' || theA == '*' || theA == '/') &&
+ (theB == '+' || theB == '-' || theB == '*' || theB == '/')
+ ) {
+ putc(theY, stdout);
+ }
case 2:
theA = theB;
- if (theA == '\'' || theA == '"') {
+ if (theA == '\'' || theA == '"' || theA == '`') {
for (;;) {
putc(theA, stdout);
theA = get();
if (theA == theB) {
break;
}
- if (theA <= '\n') {
- fprintf(stderr,
-"Error: JSMIN unterminated string literal: %c\n", theA);
- exit(1);
- }
if (theA == '\\') {
putc(theA, stdout);
theA = get();
}
+ if (theA == EOF) {
+ error("Unterminated string literal.");
+ }
}
}
case 3:
theB = next();
- if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' ||
- theA == ':' || theA == '[' || theA == '!' ||
- theA == '&' || theA == '|' || theA == '?' ||
- theA == '{' || theA == '}' || theA == ';' ||
- theA == '\n')) {
+ if (theB == '/' && (
+ theA == '(' || theA == ',' || theA == '=' || theA == ':' ||
+ theA == '[' || theA == '!' || theA == '&' || theA == '|' ||
+ theA == '?' || theA == '+' || theA == '-' || theA == '~' ||
+ theA == '*' || theA == '/' || theA == '{' || theA == '\n'
+ )) {
putc(theA, stdout);
+ if (theA == '/' || theA == '*') {
+ putc(' ', stdout);
+ }
putc(theB, stdout);
for (;;) {
theA = get();
- if (theA == '/') {
+ if (theA == '[') {
+ for (;;) {
+ putc(theA, stdout);
+ theA = get();
+ if (theA == ']') {
+ break;
+ }
+ if (theA == '\\') {
+ putc(theA, stdout);
+ theA = get();
+ }
+ if (theA == EOF) {
+ error("Unterminated set in Regular Expression literal.");
+ }
+ }
+ } else if (theA == '/') {
+ switch (peek()) {
+ case '/':
+ case '*':
+ error("Unterminated set in Regular Expression literal.");
+ }
break;
} else if (theA =='\\') {
putc(theA, stdout);
theA = get();
- } else if (theA <= '\n') {
- fprintf(stderr,
-"Error: JSMIN unterminated Regular Expression literal.\n", theA);
- exit(1);
+ }
+ if (theA == EOF) {
+ error("Unterminated Regular Expression literal.");
}
putc(theA, stdout);
}
@@ -191,16 +231,17 @@ action(int d)
static void
jsmin()
{
+ if (peek() == 0xEF) {
+ get();
+ get();
+ get();
+ }
theA = '\n';
action(3);
while (theA != EOF) {
switch (theA) {
case ' ':
- if (isAlphanum(theB)) {
- action(1);
- } else {
- action(2);
- }
+ action(isAlphanum(theB) ? 1 : 2);
break;
case '\n':
switch (theB) {
@@ -209,27 +250,21 @@ jsmin()
case '(':
case '+':
case '-':
+ case '!':
+ case '~':
action(1);
break;
case ' ':
action(3);
break;
default:
- if (isAlphanum(theB)) {
- action(1);
- } else {
- action(2);
- }
+ action(isAlphanum(theB) ? 1 : 2);
}
break;
default:
switch (theB) {
case ' ':
- if (isAlphanum(theA)) {
- action(1);
- break;
- }
- action(3);
+ action(isAlphanum(theA) ? 1 : 3);
break;
case '\n':
switch (theA) {
@@ -240,14 +275,11 @@ jsmin()
case '-':
case '"':
case '\'':
+ case '`':
action(1);
break;
default:
- if (isAlphanum(theA)) {
- action(1);
- } else {
- action(3);
- }
+ action(isAlphanum(theA) ? 1 : 3);
}
break;
default:

0 comments on commit 34eff62

Please sign in to comment.