fix(semantic): symbol of identifier of top level function declaration should be in the root scope (#843)

---------

Co-authored-by: Boshen <boshenc@gmail.com>
This commit is contained in:
Yunfei He 2023-09-03 10:16:47 +08:00 committed by GitHub
parent da44fd8999
commit 815db57a25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -252,8 +252,7 @@ impl<'a> SemanticBuilder<'a> {
}
let includes = includes | self.current_symbol_flags;
let symbol_id =
self.symbols.create_symbol(span, name.clone(), includes, self.current_scope_id);
let symbol_id = self.symbols.create_symbol(span, name.clone(), includes, scope_id);
self.symbols.add_declaration(self.current_node_id);
self.scope.add_binding(scope_id, name.clone(), symbol_id);
symbol_id

View file

@ -169,6 +169,20 @@ mod tests {
assert_eq!(references.count(), 1);
}
#[test]
fn test_top_level_symbols() {
let source = "function Fn() {}";
let allocator = Allocator::default();
let semantic = get_semantic(&allocator, source, SourceType::default());
let top_level_a = semantic
.scopes()
.iter_bindings()
.find(|(_scope_id, _symbol_id, name)| name == &Atom::from("Fn"))
.unwrap();
assert_eq!(semantic.symbols.get_scope_id(top_level_a.1), top_level_a.0);
}
#[test]
fn test_is_global() {
let source = "