mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(semantic): defer declare lookup for empty accessors (#22810)
Only compute whether the containing class is `declare` when checking empty-body TypeScript accessors. Ordinary methods and overload signatures do not need that value, so the hot method path can avoid repeated containing-class lookups.
This commit is contained in:
1 parent
1444f82cba
commit
9e496a783c
1 file changed
+17
-15
@@ -276,19 +276,6 @@ fn check_type_name_is_reserved<'a>(
|
||||
|
||||
pub fn check_method_definition<'a>(method: &MethodDefinition<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
let is_abstract = method.r#type.is_abstract();
|
||||
let is_declare = ctx.class_table_builder.current_class_id.map_or(
|
||||
ctx.source_type.is_typescript_definition(),
|
||||
|id| {
|
||||
let node_id = ctx.class_table_builder.classes.declarations[id];
|
||||
let AstKind::Class(class) = ctx.nodes.get_node(node_id).kind() else {
|
||||
#[cfg(debug_assertions)]
|
||||
panic!("current_class_id is set, but does not point to a Class node.");
|
||||
#[cfg(not(debug_assertions))]
|
||||
return ctx.source_type.is_typescript_definition();
|
||||
};
|
||||
class.declare || ctx.source_type.is_typescript_definition()
|
||||
},
|
||||
);
|
||||
|
||||
if is_abstract {
|
||||
// constructors cannot be abstract, no matter what
|
||||
@@ -314,8 +301,23 @@ pub fn check_method_definition<'a>(method: &MethodDefinition<'a>, ctx: &Semantic
|
||||
}
|
||||
|
||||
// Illegal to have `get foo();` or `set foo(a)`
|
||||
if method.kind.is_accessor() && is_empty_body && !is_abstract && !is_declare {
|
||||
ctx.error(diagnostics::accessor_without_body(method.key.span()));
|
||||
if method.kind.is_accessor() && is_empty_body && !is_abstract {
|
||||
let is_declare = ctx.class_table_builder.current_class_id.map_or(
|
||||
ctx.source_type.is_typescript_definition(),
|
||||
|id| {
|
||||
let node_id = ctx.class_table_builder.classes.declarations[id];
|
||||
let AstKind::Class(class) = ctx.nodes.get_node(node_id).kind() else {
|
||||
#[cfg(debug_assertions)]
|
||||
panic!("current_class_id is set, but does not point to a Class node.");
|
||||
#[cfg(not(debug_assertions))]
|
||||
return ctx.source_type.is_typescript_definition();
|
||||
};
|
||||
class.declare || ctx.source_type.is_typescript_definition()
|
||||
},
|
||||
);
|
||||
if !is_declare {
|
||||
ctx.error(diagnostics::accessor_without_body(method.key.span()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user