예제 #1
0
    def test_function_declaration(self):
        r = self.parse('''
            function foo() {
                var x;
            }

            function main() {
            }
            ''')
        expected = ast.Program([
            ast.Function('foo', [], [ast.VarDeclaration(['x'])]),
            ast.Function('main', [], [])
        ])
        assert r == expected
예제 #2
0
 def function_function_body(state, p):
     lineno = p[0].getsourcepos().lineno
     return ast.Function(p[1].getstr(),
                         p[2].get_vars(),
                         p[4].get_element_list(),
                         lineno,
                         srcpos=sr(p))
예제 #3
0
    def test_function_declaration(self):
        r = self.parse('''
            def foo() {
                let x;
            }

            def main() {
            }
            ''')
        expected = ast.Program([
            ast.Function('foo', [], [
                ast.VarDeclaration([ast.Var('x', ast.NoTypeDecl(), None)])
            ], lineno=1),
            ast.Function('main', [], [], lineno=4)
        ])
        assert r == expected
예제 #4
0
 def test_function_declaration_args(self):
     r = self.parse('''
         def foo(a0, a1) {
         }
         ''')
     expected = ast.Program([
         ast.Function('foo', [ast.Var('a0', ast.NoTypeDecl(), None),
                              ast.Var('a1', ast.NoTypeDecl(), None)], [
         ], lineno=1)
     ])
     assert r == expected
예제 #5
0
 def function_function_body(state, p):
     return ast.Function(p[1].getstr(), p[2].get_element_list(),
                         p[4].get_element_list())