def node_funcdef(self, node, is_lambda=False):
        jsvars = self.jsvars.copy()
        #print 'node.depth():', node.depth()
        depth = self.get_names_depth()
        childs = node.children.__iter__()
        if is_lambda:
            self.assert_value(node, childs.next().value, 'lambda')
            name = "<lambda>"
            assign_name = self.get_tmp_jsname('lamb$')
            assign = "var %s = " % assign_name
            if isinstance(node.children[1], Leaf) and \
               node.children[1].value == ':':
                params = Parameters([], None, None, None)
            else:
                child = childs.next()
                if isinstance(child, Leaf):
                    params = Parameters([child.value], None, None, None)
                    #args, star_args, dstar_args, defaults
                else:
                    params = self.dispatch(child)
        else:
            self.assert_value(node, childs.next().value, 'def')
            name = childs.next().value
            self.add_name(name, force=True)
            assign = ''
            params = self.dispatch(childs.next())
        self.assert_instance(node, params, Parameters)
        if params.star_args is None:
            star_args = 'null'
        else:
            star_args = repr(params.star_args)
        if params.dstar_args is None:
            dstar_args = 'null'
        else:
            dstar_args = repr(params.dstar_args)
        if params.defaults is None:
            defaults = 'null'
        else:
            defaults = ', '.join([str(self.dispatch(i)) for i in params.defaults])
            defaults = '[%s]' % defaults
        tfpdef = {}
        jsargs = []
        locals_init = []
        for arg in params.all_args:
            if isinstance(arg, tuple):
                tfpdef_name = self.get_tmp_jsname('tfpdef$')
                jsargs.append(tfpdef_name)
                def flatten_arg(names):
                    args = []
                    for name in names:
                        if isinstance(name, tuple):
                            name = flatten_arg(name)
                        else:
                            self.add_name(name)
                        args.append(name)
                    args = ', '.join(args)
                    return "(%s)" % args
                tfpdef[tfpdef_name] = flatten_arg(arg)
            else:
                jsargs.append('$%s' % arg)
                if is_lambda:
                    locals_init.append(
                        "%s['%s'] = $%s;" % (
                            jsvars['locals'],
                            arg, 
                            arg,
                        )
                    )
                else:
                    locals_init.append("'%s': $%s" % (arg, arg))
        args = params.args
        if not jsargs:
            jsargs = ''
        else:
            jsargs = ', '.join(jsargs)
        self.assert_value(node, childs.next().value, ':')
        type = self.next_func_type[-1]
        lineno = self.track_lineno(node)
        jsvars.update(locals())
        self.add_lines("""\
%(assign)s(function(%(funcbase)s, $%(locals)s){
+   return %(builtin)s['func'](%(module)s, %(lineno)s, %(funcbase)s, '%(name)s', %(type)s, %(args)r, %(star_args)s, %(dstar_args)s, %(defaults)s, function(%(jsargs)s) {\
""" % jsvars)
        if not is_lambda:
            self.add_lines("""\
++      var %(namestack)s = $%(locals)s.slice(0);
++      var %(locals)s = {""" % jsvars)
        else:
            for line in locals_init:
                self.add_lines("++%s" % line)
        lines = self.lines
        self.lines = func_lines = []
        names = Names()
        self.names.append(names)
        for a in params.all_args:
            self.add_name(a)
        if not is_lambda:
            self.collect_locals(node)
        indent_level = self.indent(2)

        try:
            lambda_code = None
            while True:
                child = childs.next()
                code = self.dispatch(child)
                if is_lambda:
                    if lambda_code is None:
                        self.add_lines(
                            "return %s" % code, self.track_lineno(child),
                        )
                        lambda_code = code
                    else:
                        self.TranslationError(
                            "Multiple lines found in lambda definition",
                            self.get_lineno(node)
                        )
        except StopIteration:
            pass
        self.assert_dedent(self.dedent(2), indent_level)
        self.lines = lines
        assert names is self.names.pop()
        for n in names.itervalues():
            if n.name not in params.all_args and \
               n.builtin is False and \
               n.to_js is None and \
               n.depth <= depth and \
               n.glob is False:
                scope = 'locals'
                src = self.jsvars['funcbase']
                src = '$%(locals)s' % self.jsvars
                src = '%s[%s]' % (self.jsvars['namestack'], n.depth)
                locals_init.append(
                    "'%s': %s['%s']" % (
                        n.name, src, n.name,
                    ),
                )
        locals_init = ',\n+++'.join(locals_init)
        locals_init = locals_init.strip()
        jsvars.update(locals())
        if not is_lambda:
            self.add_lines("""\
+++         %(locals_init)s
++      };
++      %(namestack)s[%(depth)s + 1] = %(locals)s;""" % jsvars)
        if tfpdef:
            self.indent(2)
            for k, v in tfpdef.iteritems():
                n = self.create_assign_stmt(
                    lhs=str(v),
                    subst_rhs=Code(k, self.track_lineno(node)),
                ).children[0]
                line = self.node_expr_stmt(n)
                self.add_lines(line)
            self.dedent(2)
        self.lines += func_lines
        if is_lambda:
            self.add_lines("""\
+   });
})({}, %(namestack)s);""" % jsvars)
            return assign_name
        if isinstance(self.names[-1], ClassNames):
            self.add_lines("""\
++      return %(None)s;
+   });
})(%(funcbase)s, %(namestack)s);""" % jsvars)
        else:
            self.add_lines("""\
++      return %(None)s;
+   });
})(%(locals)s, %(namestack)s);""" % jsvars)
        return name
dataset/ETHPy150Open anandology/pyjamas/pyjs/src/pyjs/translator_dict.py/Translator.node_funcdef/original