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")
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")
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")
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")
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")