<commit_before>import _ast
from jaspyx.ast_util import ast_call, ast_load
from jaspyx.context.function import FunctionContext
from jaspyx.visitor import BaseVisitor


class Function(BaseVisitor):
    def visit_FunctionDef(self, node):
        self.stack[-1].scope.declare(node.name)

        args = [arg.id for arg in node.args.args]
        if node.args.kwarg is not None:
            raise Exception('**kwargs not supported')

        self.indent()

        func = FunctionContext(self.stack[-1], node.name, args)
        self.push(func)

        # Emit vararg
        if node.args.vararg is not None:
            self.visit(
                _ast.Assign(
                    [_ast.Name(node.args.vararg, _ast.Store())],
                    ast_call(
                        ast_load('Array.prototype.slice.call'),
                        _ast.Name('arguments', _ast.Load()),
                        _ast.Num(len(args)),
                    )
                )
            )

        # Emit default arguments
        def_args = node.args.defaults
        for arg_name, arg_val in zip(args[-len(def_args):], def_args):
            self.block([
                _ast.If(
                    _ast.Compare(
                        ast_call(
                            _ast.Name('type', _ast.Load()),
                            _ast.Name(arg_name, _ast.Load()),
                        ),
                        [_ast.Eq(), ],
                        [_ast.Str('undefined'), ],
                    ),
                    [
                        _ast.Assign(
                            [_ast.Name(arg_name, _ast.Store())],
                            arg_val
                        ),
                    ],
                    [],
                )
            ])

        self.block(node.body)
        self.pop()
        self.output('\n')<commit_msg>Inline function definition for anonymous functions.<commit_after>import _ast
from jaspyx.ast_util import ast_call, ast_load
from jaspyx.context.function import FunctionContext
from jaspyx.visitor import BaseVisitor


class Function(BaseVisitor):
    def visit_FunctionDef(self, node):
        self.stack[-1].scope.declare(node.name)

        args = [arg.id for arg in node.args.args]
        if node.args.kwarg is not None:
            raise Exception('**kwargs not supported')

        # Name is empty when a lambda function is generated
        if node.name:
            self.indent()
        else:
            self.output('(')

        func = FunctionContext(self.stack[-1], node.name, args)
        self.push(func)

        # Emit vararg
        if node.args.vararg is not None:
            self.visit(
                _ast.Assign(
                    [_ast.Name(node.args.vararg, _ast.Store())],
                    ast_call(
                        ast_load('Array.prototype.slice.call'),
                        _ast.Name('arguments', _ast.Load()),
                        _ast.Num(len(args)),
                    )
                )
            )

        # Emit default arguments
        def_args = node.args.defaults
        for arg_name, arg_val in zip(args[-len(def_args):], def_args):
            self.block([
                _ast.If(
                    _ast.Compare(
                        ast_call(
                            _ast.Name('type', _ast.Load()),
                            _ast.Name(arg_name, _ast.Load()),
                        ),
                        [_ast.Eq(), ],
                        [_ast.Str('undefined'), ],
                    ),
                    [
                        _ast.Assign(
                            [_ast.Name(arg_name, _ast.Store())],
                            arg_val
                        ),
                    ],
                    [],
                )
            ])

        # Emit function body
        self.block(node.body)

        self.pop()

        if node.name:
            self.output('\n')
        else:
            self.output(')')
{'fraction_non_alphanumeric': 0.10596526554241127, 'fraction_numerical': 0.0010067958721369243, 'mean_word_length': 1.0926803580832016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7217853', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1005, 'n_words': 196}