示例#1
0
 def program_body(state, p):
     element_list = p[0].get_element_list()
     for elem in element_list:
         if isinstance(elem, ast.VarDeclaration):
             raise errorhandler(state, elem,
                                'var declarations in body disallowed')
     return ast.Program(element_list, srcpos=sr(element_list))
示例#2
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
示例#3
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
示例#4
0
 def test_import_stuff(self):
     r = self.parse('''
         import foo
         import foo.bar
         import foo{a,b,c,d}
         import foo.bar{a,b,c};
         ''')
     expected = ast.Program([
         ast.Import(["foo"], []),
         ast.Import(["foo"], ["bar"]),
         ast.Import(["foo"], ["a", "b", "c", "d"]),
         ast.Import(["foo", "bar"], ["a", "b", 'c'])
     ])
     assert r == expected
示例#5
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
示例#6
0
 def body_empty(state, p):
     return ast.Program([])