mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
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:
parent
da44fd8999
commit
815db57a25
2 changed files with 15 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = "
|
||||
|
|
|
|||
Loading…
Reference in a new issue