Commits

Joey Smith committed ef1046d

When we see a Number, look-ahead one token; if we find a DOT, wrap
the number in () so that the token after the DOT gets evaulated correctly

  • Participants
  • Parent commits ae7ca5d

Comments (0)

Files changed (3)

File src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java

             token = consumeToken();
             symbol = token.getValue();
             currentScope = getCurrentScope();
-
             switch (token.getType()) {
                 case Token.GET:
                 case Token.SET:
                     break;
 
                 case Token.REGEXP:
-                case Token.NUMBER:
                 case Token.STRING:
                     result.append(symbol);
                     break;
 
+                case Token.NUMBER:
+                    if (getToken(0).getType() == Token.DOT) {
+                        // calling methods on int requires a leading dot so JS doesn't
+                        // treat the method as the decimal component of a float
+                        result.append('(');
+                        result.append(symbol);
+                        result.append(')');
+                    } else {
+                        result.append(symbol);
+                    }
+                    break;
+
                 case Token.ADD:
                 case Token.SUB:
                     result.append((String) literals.get(new Integer(token.getType())));

File tests/issue86.js

+.0.toString()
+1.3.toString()

File tests/issue86.js.min

+(0).toString();(1.3).toString();