Esempio n. 1
0
def test_transform_module_with_exports():
    _assert_transform(
        cc.module([
            cc.declare("__all__"),
            cc.declare("x"),
            cc.assign(cc.ref("__all__"), cc.list_literal([cc.str_literal("x")])),
            cc.assign(cc.ref("x"), cc.none)
        ], exported_names=["x"]),
        """
            var __all__;
            var x;
            __all__ = ["x"];
            x = null;
            $exports.x = x;
        """
    )
Esempio n. 2
0
 def test_transform_compound_assignments(self):
     _assert_transform(
         nodes.assign(["x", "y"], nodes.ref("z")),
         cc.statements([
             cc.declare("__nope_u_tmp0", cc.ref("z")),
             cc.assign(cc.ref("x"), cc.ref("__nope_u_tmp0")),
             cc.assign(cc.ref("y"), cc.ref("__nope_u_tmp0")),
         ]),
     )
Esempio n. 3
0
 def test_function_definitions_in_body_are_stored_as_methods(self):
     _assert_transform(
         nodes.class_("Blah", [nodes.func("f", nodes.args([]), [], type=None)]),
         cc.class_(
             "Blah",
             methods=[cc.func("f", [], [cc.ret(cc.none)])],
             body=[cc.declare("f")],
         ),
     )
Esempio n. 4
0
 def test_variables_are_declared(self):
     _assert_transform(
         nodes.func("f", nodes.args([]), [
             nodes.assign([nodes.ref("x")], nodes.ref("y")),
             nodes.ret(nodes.ref("value")),
         ], type=None),
         cc.func("f", [], [
             cc.declare("x"),
             cc.assign(cc.ref("x"), cc.ref("y")),
             cc.ret(cc.ref("value")),
         ]),
     )
Esempio n. 5
0
 def test_assignments_in_body_are_transformed(self):
     _assert_transform(
         nodes.class_("Blah", [nodes.assign([nodes.ref("value")], nodes.none())]),
         cc.class_(
             "Blah",
             methods=[],
             body=[
                 cc.declare("value"),
                 cc.assign(cc.ref("value"), cc.none),
             ],
         ),
     )
Esempio n. 6
0
 def test_module_exports_are_set_directly_on_module(self):
     module_node = nodes.module(
         [nodes.assign([nodes.ref("value")], nodes.none())],
         is_executable=False
     )
     module_type = types.module("blah", [types.attr("value", types.none_type)])
     _assert_transform(
         module_node,
         cc.module(
             [
                 cc.declare("value"),
                 cc.assign(cc.ref("value"), cc.none)
             ],
             is_executable=False,
             exported_names=["value"],
         ),
         type_lookup=[(module_node, module_type)]
     )
Esempio n. 7
0
def test_transform_class_with_attributes():
    _assert_transform(
        cc.class_(
            name="User",
            methods=[],
            body=[
                cc.declare("x"),
                cc.assign(cc.ref("x"), cc.none)
            ],
        ),
        """
            User = function() {
                var $self0 = {
                    "$nopeType": User
                };
                var x;
                x = null;
                $self0.x = $nope.instanceAttribute($self0, x);
                return $self0;
            };
        """
    )