Skip to content

Commit 27b2268

Browse files
committed
refactor(semantic)!: remove SymbolFlags::Export (#7414)
close: #7338 close: #7344 The `SymbolFlags::Export` is Initially used to solve `ExportSpecifier` that is not `IdentifierReference` that causes we cannot determine whether a Binding is not used everywhere by `Semantic`. Since #3820 this problem is solved, so we don't need `SymbolFlags::Export` no longer. Also, removing this can help us easier to pass the `Semantic` check in `Transformer`
1 parent c90537f commit 27b2268

29 files changed

+331
-2057
lines changed

crates/oxc_semantic/src/builder.rs

-45
Original file line numberDiff line numberDiff line change
@@ -564,32 +564,6 @@ impl<'a> SemanticBuilder<'a> {
564564
pub(crate) fn add_redeclare_variable(&mut self, symbol_id: SymbolId, span: Span) {
565565
self.symbols.add_redeclaration(symbol_id, span);
566566
}
567-
568-
fn add_export_flag_to_export_identifiers(&mut self, program: &Program<'a>) {
569-
for stmt in &program.body {
570-
if let Statement::ExportDefaultDeclaration(decl) = stmt {
571-
if let ExportDefaultDeclarationKind::Identifier(ident) = &decl.declaration {
572-
self.add_export_flag_to_identifier(ident.name.as_str());
573-
}
574-
}
575-
if let Statement::ExportNamedDeclaration(decl) = stmt {
576-
for specifier in &decl.specifiers {
577-
if specifier.export_kind.is_value() {
578-
if let Some(name) = specifier.local.identifier_name() {
579-
self.add_export_flag_to_identifier(name.as_str());
580-
}
581-
}
582-
}
583-
}
584-
}
585-
}
586-
587-
/// Flag the symbol bound to an identifier in the current scope as exported.
588-
fn add_export_flag_to_identifier(&mut self, name: &str) {
589-
if let Some(symbol_id) = self.scope.get_binding(self.current_scope_id, name) {
590-
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
591-
}
592-
}
593567
}
594568

595569
impl<'a> Visit<'a> for SemanticBuilder<'a> {
@@ -1870,19 +1844,7 @@ impl<'a> SemanticBuilder<'a> {
18701844
/* cfg */
18711845

18721846
match kind {
1873-
AstKind::ExportDefaultDeclaration(decl) => {
1874-
// Only if the declaration has an ID, we mark it as an export
1875-
if match &decl.declaration {
1876-
ExportDefaultDeclarationKind::FunctionDeclaration(func) => func.id.is_some(),
1877-
ExportDefaultDeclarationKind::ClassDeclaration(class) => class.id.is_some(),
1878-
ExportDefaultDeclarationKind::TSInterfaceDeclaration(_) => true,
1879-
_ => false,
1880-
} {
1881-
self.current_symbol_flags |= SymbolFlags::Export;
1882-
}
1883-
}
18841847
AstKind::ExportNamedDeclaration(decl) => {
1885-
self.current_symbol_flags |= SymbolFlags::Export;
18861848
if decl.export_kind.is_type() {
18871849
self.current_reference_flags = ReferenceFlags::Type;
18881850
}
@@ -1959,7 +1921,6 @@ impl<'a> SemanticBuilder<'a> {
19591921
.get(module_declaration.id.name().as_str())
19601922
.copied();
19611923
self.namespace_stack.push(symbol_id);
1962-
self.current_symbol_flags -= SymbolFlags::Export;
19631924
}
19641925
AstKind::TSTypeAliasDeclaration(type_alias_declaration) => {
19651926
type_alias_declaration.bind(self);
@@ -2048,16 +2009,10 @@ impl<'a> SemanticBuilder<'a> {
20482009
#[allow(clippy::single_match)]
20492010
fn leave_kind(&mut self, kind: AstKind<'a>) {
20502011
match kind {
2051-
AstKind::Program(program) => {
2052-
self.add_export_flag_to_export_identifiers(program);
2053-
}
20542012
AstKind::Class(_) => {
20552013
self.current_node_flags -= NodeFlags::Class;
20562014
self.class_table_builder.pop_class();
20572015
}
2058-
AstKind::BindingIdentifier(_) => {
2059-
self.current_symbol_flags -= SymbolFlags::Export;
2060-
}
20612016
AstKind::ExportSpecifier(_) => {
20622017
if !self.current_reference_flags.is_type_only() {
20632018
self.current_reference_flags = ReferenceFlags::empty();

crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -73,7 +72,7 @@ snapshot_kind: text
7372
]
7473
},
7574
{
76-
"flags": "SymbolFlags(Export | Interface)",
75+
"flags": "SymbolFlags(Interface)",
7776
"id": 2,
7877
"name": "A",
7978
"node": "TSInterfaceDeclaration",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default-type.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default-type.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export | TypeAlias)",
21+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | TypeAlias)",
2322
"id": 0,
2423
"name": "T",
2524
"node": "VariableDeclarator(T)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default1.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default1.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(BlockScopedVariable | Export | Function)",
21+
"flags": "SymbolFlags(BlockScopedVariable | Function)",
2322
"id": 0,
2423
"name": "f",
2524
"node": "Function(f)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default2.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default2.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -11,7 +10,7 @@ snapshot_kind: text
1110
"node": "Program",
1211
"symbols": [
1312
{
14-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
13+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1514
"id": 0,
1615
"name": "a",
1716
"node": "VariableDeclarator(a)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named-dual.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named-dual.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export | TypeAlias)",
21+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | TypeAlias)",
2322
"id": 0,
2423
"name": "T",
2524
"node": "VariableDeclarator(T)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named-type1.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named-type1.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(Export | TypeAlias)",
21+
"flags": "SymbolFlags(TypeAlias)",
2322
"id": 0,
2423
"name": "X",
2524
"node": "TSTypeAliasDeclaration",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named1.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named1.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -11,7 +10,7 @@ snapshot_kind: text
1110
"node": "Program",
1211
"symbols": [
1312
{
14-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
13+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1514
"id": 0,
1615
"name": "x",
1716
"node": "VariableDeclarator(x)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-type.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-type.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(Export | TypeAlias)",
21+
"flags": "SymbolFlags(TypeAlias)",
2322
"id": 0,
2423
"name": "A",
2524
"node": "TSTypeAliasDeclaration",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -11,7 +10,7 @@ snapshot_kind: text
1110
"node": "Program",
1211
"symbols": [
1312
{
14-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
13+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1514
"id": 0,
1615
"name": "a",
1716
"node": "VariableDeclarator(a)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-type.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-type.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(Export | TypeAlias)",
21+
"flags": "SymbolFlags(TypeAlias)",
2322
"id": 0,
2423
"name": "V",
2524
"node": "TSTypeAliasDeclaration",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -11,7 +10,7 @@ snapshot_kind: text
1110
"node": "Program",
1211
"symbols": [
1312
{
14-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
13+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1514
"id": 0,
1615
"name": "v",
1716
"node": "VariableDeclarator(v)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/type.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/type.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -19,7 +18,7 @@ snapshot_kind: text
1918
"node": "Program",
2019
"symbols": [
2120
{
22-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export | TypeAlias)",
21+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | TypeAlias)",
2322
"id": 0,
2423
"name": "T",
2524
"node": "VariableDeclarator(T)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/declaration-merging/class-namespace.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/declaration-merging/class-namespace.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -20,7 +19,7 @@ snapshot_kind: text
2019
"node": "TSModuleDeclaration(Foo)",
2120
"symbols": [
2221
{
23-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
22+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
2423
"id": 1,
2524
"name": "x",
2625
"node": "VariableDeclarator(x)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/declaration-merging/function-namespace.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/declaration-merging/function-namespace.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -20,7 +19,7 @@ snapshot_kind: text
2019
"node": "TSModuleDeclaration(Foo)",
2120
"symbols": [
2221
{
23-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
22+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
2423
"id": 1,
2524
"name": "x",
2625
"node": "VariableDeclarator(x)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/external-ref.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/external-ref.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -13,7 +12,7 @@ snapshot_kind: text
1312
"node": "TSModuleDeclaration(Foo)",
1413
"symbols": [
1514
{
16-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
15+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1716
"id": 1,
1817
"name": "x",
1918
"node": "VariableDeclarator(x)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/name-shadowed-in-body.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/name-shadowed-in-body.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -13,7 +12,7 @@ snapshot_kind: text
1312
"node": "TSModuleDeclaration(Foo)",
1413
"symbols": [
1514
{
16-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
15+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1716
"id": 1,
1817
"name": "Foo",
1918
"node": "VariableDeclarator(Foo)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/namespace.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/namespace.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -13,7 +12,7 @@ snapshot_kind: text
1312
"node": "TSModuleDeclaration(Foo)",
1413
"symbols": [
1514
{
16-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
15+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1716
"id": 1,
1817
"name": "x",
1918
"node": "VariableDeclarator(x)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/self-ref.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
33
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/self-ref.ts
4-
snapshot_kind: text
54
---
65
[
76
{
@@ -13,7 +12,7 @@ snapshot_kind: text
1312
"node": "TSModuleDeclaration(Foo)",
1413
"symbols": [
1514
{
16-
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | Export)",
15+
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
1716
"id": 1,
1817
"name": "x",
1918
"node": "VariableDeclarator(x)",

0 commit comments

Comments
 (0)