private Node transform(JsExpression x) {
   assert x != null;
   switch (x.getKind()) {
     case ARRAY:
       return transform((JsArrayLiteral) x);
     case ARRAY_ACCESS:
       return transform((JsArrayAccess) x);
     case BINARY_OP:
       return transform((JsBinaryOperation) x);
     case CONDITIONAL:
       return transform((JsConditional) x);
     case INVOKE:
       return transform((JsInvocation) x);
     case FUNCTION:
       return transform((JsFunction) x);
     case OBJECT:
       return transform((JsObjectLiteral) x);
     case BOOLEAN:
       return transform((JsBooleanLiteral) x);
     case NULL:
       return transform((JsNullLiteral) x);
     case NUMBER:
       if (x instanceof JsNumericEntry) {
         return transform((JsNumericEntry) x);
       }
       return transform((JsNumberLiteral) x);
     case REGEXP:
       return transform((JsRegExp) x);
     case STRING:
       return transform((JsStringLiteral) x);
     case THIS:
       return transform((JsThisRef) x);
     case NAME_OF:
       return transform((JsNameOf) x);
     case NAME_REF:
       return transform((JsNameRef) x);
     case NEW:
       return transform((JsNew) x);
     case POSTFIX_OP:
       return transform((JsPostfixOperation) x);
     case PREFIX_OP:
       return transform((JsPrefixOperation) x);
     default:
       throw new IllegalStateException(
           "Unexpected expression type: " + x.getClass().getSimpleName());
   }
 }
Example #2
0
 private void visitExpression(JsExpression x, JsContext ctx) {
   if (ctx.isLvalue()) {
     // Assignments to comma expressions aren't legal
     return;
   } else if (nodesInRefContext.contains(x)) {
     // Don't modify references into non-references
     return;
   } else if (!instrumentedFiles.contains(x.getSourceInfo().getFileName())) {
     return;
   } else if (x.getSourceInfo().getStartLine() == lastLine
       && (x.getSourceInfo().getFileName().equals(lastFile))) {
     return;
   }
   lastLine = x.getSourceInfo().getStartLine();
   lastFile = x.getSourceInfo().getFileName();
   endVisit(x, ctx);
 }