Commits

Mathias Panzenböck committed b2cf379

opt++

  • Participants
  • Parent commits 86000a4

Comments (0)

Files changed (1)

File lib/optimizingvisitor.js

 				case 'typeof': return new nodes.Literal(typeof arg.value);
 			}
 		}
+		else if (arg.type === "UnaryExpression") {
+			if (op === '+' && (arg.operator === '+' || arg.operator === '-')) {
+				return arg;
+			}
+			else if (op === '-') {
+				if (arg.operator === '-') {
+					return new nodes.UnaryExpression('+', arg.argument, loc);
+				}
+				else if (arg.operator === '+') {
+					return new nodes.UnaryExpression('-', arg.argument, loc);
+				}
+			}
+			else if (op === '!' && arg.operator === '!' &&
+				arg.argument.type === "UnaryExpression" &&
+				arg.argument.operator === '!') {
+				return arg.argument;
+			}
+			else if (op === '~' && arg.operator === '~' &&
+				arg.argument.type === "UnaryExpression" &&
+				arg.argument.operator === '~') {
+				return arg.argument;
+			}
+		}
 		return new nodes.UnaryExpression(op, arg, loc);
 	},
 	logicalExpression: function (op, left, right, loc) {