# Path: pj/transformations/obvious.py
# def Expr_default(t, x):
#     return JSExpressionStatement(x.value)
# 
# Path: pj/transformations/obvious.py
# def BinOp_default(t, x):
#     return JSBinOp(x.left, x.op, x.right)
# 
# Path: pj/transformations/obvious.py
# def Name_default(t, x):
#     cls = {
#         'True': JSTrue,
#         'False': JSFalse,
#         'None': JSNull,
#     }.get(x.id)
#     if cls:
#         return cls()
#     else:
#         return JSName(x.id)
# 
# Path: pj/transformations/classes.py
# def Call_super(t, x):
#     if (
#             isinstance(x.func, ast.Name) and
#             x.func.id == 'super'):
#         
#         # Are we in a FuncDef and is it a method?
#         METHOD = t.firstAncestorSubclassing(x, ast.FunctionDef)
#         if METHOD and isinstance(t.parentOf(METHOD), ast.ClassDef):
#             
#             cls = t.parentOf(METHOD)
#             assert len(cls.bases) == 1
#             assert isinstance(cls.bases[0], ast.Name)
#             SUPERCLASS_STRING = cls.bases[0].id
#             CLASS_STRING = cls.name
#             
#             # <code>super(...)</code> &rarr; <code>SUPERCLASS.call(this, ...)</code>
#             if METHOD.name == '__init__':
#                 return JSCall(
#                             JSAttribute(
#                                 JSName(SUPERCLASS_STRING),
#                                 'call'),
#                             [JSThis()] + x.args)
#             
#             # <code>super(...)</code> &rarr; <code>CLASSNAME.__super__.METHODNAME.call(this, ...)</code>
#             else:
#                 return JSCall(
#                             JSAttribute(
#                                 JSAttribute(
#                                     JSAttribute(
#                                         JSName(CLASS_STRING),
#                                         '__super__'),
#                                     METHOD.name),
#                                 'call'),
#                             [JSThis()] + x.args)
# 
# Path: pj/transformations/obvious.py
# def Call_default(t, x):
#     assert not any([x.keywords, x.starargs, x.kwargs])
#     return JSCall(x.func, x.args)


import ast, re
from pj.js_ast import *
from pj.transformations.obvious import Expr_default
from pj.transformations.obvious import BinOp_default
from pj.transformations.obvious import Name_default
from pj.transformations.classes import Call_super
from pj.transformations.obvious import Call_default

Name = [Name_self, Name_default]

#### Call

# <code>typeof(x)</code> &rarr; <code>(typeof x)</code>
def Call_typeof(t, x):
    if (
            isinstance(x.func, ast.Name) and
            x.func.id == 'typeof'):
        assert len(x.args) == 1
        return JSUnaryOp(
                    JSOpTypeof(),
                    x.args[0])


# <code>isinstance(x, y)</code> &rarr; <code>(x instanceof y)</code>
def Call_isinstance(t, x):
    if (
            isinstance(x.func, ast.Name) and
            x.func.id == 'isinstance'):
        assert len(x.args) == 2
        return JSBinOp(
                    x.args[0],
                    JSOpInstanceof(),
                    x.args[1])



# <code>print(...)</code> &rarr; <code>console.log(...)</code>

# Path: pj/transformations/obvious.py
# def Expr_default(t, x):
#     return JSExpressionStatement(x.value)
# 
# Path: pj/transformations/obvious.py
# def BinOp_default(t, x):
#     return JSBinOp(x.left, x.op, x.right)
# 
# Path: pj/transformations/obvious.py
# def Name_default(t, x):
#     cls = {
#         'True': JSTrue,
#         'False': JSFalse,
#         'None': JSNull,
#     }.get(x.id)
#     if cls:
#         return cls()
#     else:
#         return JSName(x.id)
# 
# Path: pj/transformations/classes.py
# def Call_super(t, x):
#     if (
#             isinstance(x.func, ast.Name) and
#             x.func.id == 'super'):
#         
#         # Are we in a FuncDef and is it a method?
#         METHOD = t.firstAncestorSubclassing(x, ast.FunctionDef)
#         if METHOD and isinstance(t.parentOf(METHOD), ast.ClassDef):
#             
#             cls = t.parentOf(METHOD)
#             assert len(cls.bases) == 1
#             assert isinstance(cls.bases[0], ast.Name)
#             SUPERCLASS_STRING = cls.bases[0].id
#             CLASS_STRING = cls.name
#             
#             # <code>super(...)</code> &rarr; <code>SUPERCLASS.call(this, ...)</code>
#             if METHOD.name == '__init__':
#                 return JSCall(
#                             JSAttribute(
#                                 JSName(SUPERCLASS_STRING),
#                                 'call'),
#                             [JSThis()] + x.args)
#             
#             # <code>super(...)</code> &rarr; <code>CLASSNAME.__super__.METHODNAME.call(this, ...)</code>
#             else:
#                 return JSCall(
#                             JSAttribute(
#                                 JSAttribute(
#                                     JSAttribute(
#                                         JSName(CLASS_STRING),
#                                         '__super__'),
#                                     METHOD.name),
#                                 'call'),
#                             [JSThis()] + x.args)
# 
# Path: pj/transformations/obvious.py
# def Call_default(t, x):
#     assert not any([x.keywords, x.starargs, x.kwargs])
#     return JSCall(x.func, x.args)


# Path: pj/transformations/special.py
import ast, re
from pj.js_ast import *
from pj.transformations.obvious import Expr_default
from pj.transformations.obvious import BinOp_default
from pj.transformations.obvious import Name_default
from pj.transformations.classes import Call_super
from pj.transformations.obvious import Call_default


Name = [Name_self, Name_default]

#### Call

# <code>typeof(x)</code> &rarr; <code>(typeof x)</code>
def Call_typeof(t, x):
    if (
            isinstance(x.func, ast.Name) and
            x.func.id == 'typeof'):
        assert len(x.args) == 1
        return JSUnaryOp(
                    JSOpTypeof(),
                    x.args[0])


# <code>isinstance(x, y)</code> &rarr; <code>(x instanceof y)</code>
def Call_isinstance(t, x):
    if (
            isinstance(x.func, ast.Name) and
            x.func.id == 'isinstance'):
        assert len(x.args) == 2
        return JSBinOp(
                    x.args[0],
                    JSOpInstanceof(),
                    x.args[1])



# <code>print(...)</code> &rarr; <code>console.log(...)</code>

def Call_print(t, x):