Rewrote reference translation a bit. Added support for when call expression.
This commit is contained in:
@@ -289,4 +289,34 @@ public class AstUtil {
|
||||
public static JsBinaryOperation or(JsExpression op1, JsExpression op2) {
|
||||
return new JsBinaryOperation(JsBinaryOperator.OR, op1, op2);
|
||||
}
|
||||
|
||||
public static void setQualifier(JsExpression selector, JsExpression receiver) {
|
||||
if (selector instanceof JsInvocation) {
|
||||
setQualifier(((JsInvocation) selector).getQualifier(), receiver);
|
||||
return;
|
||||
}
|
||||
if (selector instanceof JsNameRef) {
|
||||
JsNameRef nameRef = (JsNameRef) selector;
|
||||
JsExpression qualifier = nameRef.getQualifier();
|
||||
if (qualifier == null) {
|
||||
nameRef.setQualifier(receiver);
|
||||
} else {
|
||||
setQualifier(qualifier, receiver);
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Set qualifier should be applied only to JsInvocation or JsNameRef instances");
|
||||
}
|
||||
|
||||
public static JsExpression equals(JsExpression arg1, JsExpression arg2) {
|
||||
return new JsBinaryOperation(JsBinaryOperator.REF_EQ, arg1, arg2);
|
||||
}
|
||||
|
||||
public static JsExpression equalsTrue(JsExpression expression, JsProgram program) {
|
||||
return equals(expression, program.getTrueLiteral());
|
||||
}
|
||||
|
||||
public static void thisQualify(JsExpression expression) {
|
||||
setQualifier(expression, new JsThisRef());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user