From 5cf6a0417bc3fc029d0748663f444e4b07943394 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Fri, 20 Dec 2024 18:15:31 +0800 Subject: [PATCH] fix(binder): bind declare class --- crates/oxc_semantic/src/binder.rs | 22 ++++------ .../class/declaration/declare-class.snap | 44 +++++++++++++++++++ .../class/declaration/declare-class.ts | 3 ++ 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.snap create mode 100644 crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.ts diff --git a/crates/oxc_semantic/src/binder.rs b/crates/oxc_semantic/src/binder.rs index 9747af557a0de..d8e7413c963f0 100644 --- a/crates/oxc_semantic/src/binder.rs +++ b/crates/oxc_semantic/src/binder.rs @@ -100,20 +100,14 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> { impl<'a> Binder<'a> for Class<'a> { fn bind(&self, builder: &mut SemanticBuilder) { - if !self.declare { - let Some(ident) = &self.id else { return }; - let symbol_id = builder.declare_symbol( - ident.span, - &ident.name, - SymbolFlags::Class, - if self.is_declaration() { - SymbolFlags::ClassExcludes - } else { - SymbolFlags::empty() - }, - ); - ident.symbol_id.set(Some(symbol_id)); - } + let Some(ident) = &self.id else { return }; + let symbol_id = builder.declare_symbol( + ident.span, + &ident.name, + SymbolFlags::Class, + if self.is_declaration() { SymbolFlags::ClassExcludes } else { SymbolFlags::empty() }, + ); + ident.symbol_id.set(Some(symbol_id)); } } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.snap new file mode 100644 index 0000000000000..447874913dc9b --- /dev/null +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.snap @@ -0,0 +1,44 @@ +--- +source: crates/oxc_semantic/tests/main.rs +input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare.ts +snapshot_kind: text +--- +[ + { + "children": [ + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 1, + "node": "Class(A)", + "symbols": [] + }, + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 2, + "node": "Class(B)", + "symbols": [] + } + ], + "flags": "ScopeFlags(StrictMode | Top)", + "id": 0, + "node": "Program", + "symbols": [ + { + "flags": "SymbolFlags(Class)", + "id": 0, + "name": "A", + "node": "Class(A)", + "references": [] + }, + { + "flags": "SymbolFlags(Class)", + "id": 1, + "name": "B", + "node": "Class(B)", + "references": [] + } + ] + } +] diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.ts b/crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.ts new file mode 100644 index 0000000000000..e4c7b3541870a --- /dev/null +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/declare-class.ts @@ -0,0 +1,3 @@ +declare class A { } + +class B { }