mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(semantic): use a simpler way to resolve reference for ReferenceFlag::Type (#3430)
This commit is contained in:
parent
2216066e86
commit
9c58231c62
1 changed files with 6 additions and 20 deletions
|
|
@ -52,8 +52,6 @@ pub struct SemanticBuilder<'a> {
|
||||||
// and when we reach a value declaration we set it
|
// and when we reach a value declaration we set it
|
||||||
// to value like
|
// to value like
|
||||||
pub namespace_stack: Vec<SymbolId>,
|
pub namespace_stack: Vec<SymbolId>,
|
||||||
/// If true, the current node is in the type definition
|
|
||||||
in_type_definition: bool,
|
|
||||||
current_reference_flag: ReferenceFlag,
|
current_reference_flag: ReferenceFlag,
|
||||||
|
|
||||||
// builders
|
// builders
|
||||||
|
|
@ -93,7 +91,6 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
current_node_id: AstNodeId::new(0),
|
current_node_id: AstNodeId::new(0),
|
||||||
current_node_flags: NodeFlags::empty(),
|
current_node_flags: NodeFlags::empty(),
|
||||||
current_symbol_flags: SymbolFlags::empty(),
|
current_symbol_flags: SymbolFlags::empty(),
|
||||||
in_type_definition: false,
|
|
||||||
current_reference_flag: ReferenceFlag::empty(),
|
current_reference_flag: ReferenceFlag::empty(),
|
||||||
current_scope_id,
|
current_scope_id,
|
||||||
function_stack: vec![],
|
function_stack: vec![],
|
||||||
|
|
@ -1875,24 +1872,17 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
.get_bindings(self.current_scope_id)
|
.get_bindings(self.current_scope_id)
|
||||||
.get(module_declaration.id.name().as_str());
|
.get(module_declaration.id.name().as_str());
|
||||||
self.namespace_stack.push(*symbol_id.unwrap());
|
self.namespace_stack.push(*symbol_id.unwrap());
|
||||||
self.in_type_definition = true;
|
|
||||||
}
|
}
|
||||||
AstKind::TSTypeAliasDeclaration(type_alias_declaration) => {
|
AstKind::TSTypeAliasDeclaration(type_alias_declaration) => {
|
||||||
type_alias_declaration.bind(self);
|
type_alias_declaration.bind(self);
|
||||||
self.in_type_definition = true;
|
|
||||||
}
|
}
|
||||||
AstKind::TSInterfaceDeclaration(interface_declaration) => {
|
AstKind::TSInterfaceDeclaration(interface_declaration) => {
|
||||||
interface_declaration.bind(self);
|
interface_declaration.bind(self);
|
||||||
self.in_type_definition = true;
|
|
||||||
}
|
}
|
||||||
AstKind::TSEnumDeclaration(enum_declaration) => {
|
AstKind::TSEnumDeclaration(enum_declaration) => {
|
||||||
enum_declaration.bind(self);
|
enum_declaration.bind(self);
|
||||||
// TODO: const enum?
|
// TODO: const enum?
|
||||||
self.make_all_namespaces_valuelike();
|
self.make_all_namespaces_valuelike();
|
||||||
self.in_type_definition = true;
|
|
||||||
}
|
|
||||||
AstKind::TSTypeParameterInstantiation(_) | AstKind::TSTypeAnnotation(_) => {
|
|
||||||
self.in_type_definition = true;
|
|
||||||
}
|
}
|
||||||
AstKind::TSEnumMember(enum_member) => {
|
AstKind::TSEnumMember(enum_member) => {
|
||||||
enum_member.bind(self);
|
enum_member.bind(self);
|
||||||
|
|
@ -1900,6 +1890,9 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
AstKind::TSTypeParameter(type_parameter) => {
|
AstKind::TSTypeParameter(type_parameter) => {
|
||||||
type_parameter.bind(self);
|
type_parameter.bind(self);
|
||||||
}
|
}
|
||||||
|
AstKind::TSTypeName(_) => {
|
||||||
|
self.current_reference_flag = ReferenceFlag::Type;
|
||||||
|
}
|
||||||
AstKind::IdentifierReference(ident) => {
|
AstKind::IdentifierReference(ident) => {
|
||||||
self.reference_identifier(ident);
|
self.reference_identifier(ident);
|
||||||
}
|
}
|
||||||
|
|
@ -1971,13 +1964,8 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
AstKind::TSModuleBlock(_) => {
|
AstKind::TSModuleBlock(_) => {
|
||||||
self.namespace_stack.pop();
|
self.namespace_stack.pop();
|
||||||
}
|
}
|
||||||
AstKind::TSEnumDeclaration(_)
|
AstKind::TSTypeName(_) => {
|
||||||
| AstKind::TSTypeAliasDeclaration(_)
|
self.current_reference_flag -= ReferenceFlag::Type;
|
||||||
| AstKind::TSInterfaceDeclaration(_)
|
|
||||||
| AstKind::TSModuleDeclaration(_)
|
|
||||||
| AstKind::TSTypeParameterInstantiation(_)
|
|
||||||
| AstKind::TSTypeAnnotation(_) => {
|
|
||||||
self.in_type_definition = false;
|
|
||||||
}
|
}
|
||||||
AstKind::UpdateExpression(_) => {
|
AstKind::UpdateExpression(_) => {
|
||||||
if self.is_not_expression_statement_parent() {
|
if self.is_not_expression_statement_parent() {
|
||||||
|
|
@ -2030,9 +2018,7 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
|
|
||||||
/// Resolve reference flags for the current ast node.
|
/// Resolve reference flags for the current ast node.
|
||||||
fn resolve_reference_usages(&self) -> ReferenceFlag {
|
fn resolve_reference_usages(&self) -> ReferenceFlag {
|
||||||
if self.in_type_definition {
|
if self.current_reference_flag.is_write() || self.current_reference_flag.is_type() {
|
||||||
ReferenceFlag::Type
|
|
||||||
} else if self.current_reference_flag.is_write() {
|
|
||||||
self.current_reference_flag
|
self.current_reference_flag
|
||||||
} else {
|
} else {
|
||||||
ReferenceFlag::Read
|
ReferenceFlag::Read
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue