From 36bb6805c6e350f2d143b14689e2ff9ec0fd7ae3 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Sat, 27 Jul 2024 04:55:03 +0000 Subject: [PATCH] fix(semantic): `TSExportAssignment` cannot reference type binding (#4502) close: #4488 --- crates/oxc_semantic/src/builder.rs | 7 +++++++ .../fixtures/typescript-eslint/export/equals3-type.snap | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 0c17738e7..01af805d7 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -1822,6 +1822,13 @@ impl<'a> SemanticBuilder<'a> { } } } + AstKind::TSExportAssignment(export) => { + // export = a; + // ^ can reference value or type + if export.expression.is_identifier_reference() { + self.current_reference_flag = ReferenceFlag::Read | ReferenceFlag::Type; + } + } AstKind::IdentifierReference(ident) => { self.reference_identifier(ident); } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap index bc10e5da2..aab4be670 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap @@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3- "id": 0, "name": "Foo", "node": "TSInterfaceDeclaration", - "references": [] + "references": [ + { + "flag": "ReferenceFlag(Read | Type)", + "id": 0, + "name": "Foo", + "node_id": 11 + } + ] } ] }