Example #1
0
def test_scope_of_initialized_variable():
    js = """function smoo() {
                var a = 0;
            }"""
    ast = parse(js)
    assignment = first(assignments(ast))
    eq_(scope_of(assignment["id"]["name"], assignment)["id"]["name"], "smoo")
Example #2
0
def test_scope_of_global_function():
    js = """function smoo() {
                var a;
                a = 0;
            }"""
    ast = parse(js)
    assignment = first(assignments(ast))
    eq_(scope_of(assignment["left"]["name"], assignment)["type"], "FunctionDeclaration")
Example #3
0
def test_scope_of_inner_function():
    js = """function smoo() {
                function bar() {
                    a = 0;
                }
            }"""
    ast = parse(js)
    assignment = first(assignments(ast))
    eq_(scope_of(assignment["left"]["name"], assignment)["type"], "Program")
Example #4
0
def test_scope_of_inner_reference():
    js = """function smoo() {
                var a;

                function bar() {
                    a = 0;
                }
            }"""
    ast = parse(js)
    assignment = first(assignments(ast))
    eq_(scope_of(assignment["left"]["name"], assignment)["id"]["name"], "smoo")
Example #5
0
def test_scope_of_global():
    """Make sure the scope of a global is the entire program."""
    js = """a = 0;"""
    ast = parse(js)
    assignment = first(assignments(ast))
    eq_(scope_of(assignment["left"]["name"], assignment)["type"], "Program")