From a16ba0666959dc055e7f81638422743567fd914f Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 11 Oct 2023 00:50:19 +0900 Subject: [PATCH 1/8] resolve --- .../src/analyzer/expr/mod.rs | 22 +++-- .../src/analyzer/scope/mod.rs | 88 ++++++++++++++----- .../tests/conformance.pass.txt | 2 + ...tedInterfacesOfTheSameName.error-diff.json | 7 +- ...portedModulesOfTheSameName.error-diff.json | 7 +- .../import/importTypeAmbient.error-diff.json | 6 +- .../import/importTypeAmbient.stats.rust-debug | 2 +- .../importTypeGenericTypes.error-diff.json | 12 --- .../importTypeGenericTypes.stats.rust-debug | 2 +- .../import/importTypeLocal.error-diff.json | 12 --- .../import/importTypeLocal.stats.rust-debug | 2 +- .../importTypeLocalMissing.error-diff.json | 10 +-- .../importTypeLocalMissing.stats.rust-debug | 2 +- .../tests/tsc-stats.rust-debug | 2 +- 14 files changed, 98 insertions(+), 78 deletions(-) delete mode 100644 crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.error-diff.json diff --git a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs index 4c30da014b..9fc1e2ed2a 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs @@ -3035,9 +3035,9 @@ impl Analyzer<'_, '_> { } Type::Module(ty::Module { name, ref exports, .. }) => { - match id_ctx { - IdCtx::Type => { - if let Key::Normal { sym, .. } = prop { + if let Key::Normal { sym, .. } = prop { + match id_ctx { + IdCtx::Type => { if let Some(types) = exports.types.get(sym).cloned() { if types.len() == 1 { return Ok(types.into_iter().next().unwrap()); @@ -3053,16 +3053,22 @@ impl Analyzer<'_, '_> { if let Some(vars) = exports.vars.get(sym).cloned() { return Ok(vars); } + + for (id, tys) in exports.private_types.iter() { + if id.sym().eq(sym) { + for ty in tys.iter() { + if ty.is_module() || ty.is_interface() { + return Ok(ty.clone()); + } + } + } + } } - } - IdCtx::Var => { - if let Key::Normal { sym, .. } = prop { + IdCtx::Var => { if let Some(item) = exports.vars.get(sym) { return Ok(item.clone()); } - } - if let Key::Normal { sym, .. } = prop { if let Some(types) = exports.types.get(sym) { for ty in types.iter() { if ty.is_module() || ty.is_interface() { diff --git a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs index 0b62af2660..c32c1f4f7e 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs @@ -1220,6 +1220,12 @@ impl Analyzer<'_, '_> { } } + self.find_local_type_without_this(name) + } + + fn find_local_type_without_this(&self, name: &Id) -> Option> { + let _tracing = dev_span!("find_local_type_without_this", name = tracing::field::debug(name)); + if cfg!(debug_assertions) { debug!("({}) Scope.find_type(`{}`)", self.scope.depth(), name); } @@ -2064,6 +2070,7 @@ impl Expander<'_, '_, '_> { type_args: Option<&TypeParamInstantiation>, was_top_level: bool, trying_primitive_expansion: bool, + ignore_this: bool, ) -> VResult> { macro_rules! verify { ($ty:expr) => {{ @@ -2080,26 +2087,19 @@ impl Expander<'_, '_, '_> { match type_name { RTsEntityName::Ident(ref i) => { - if let Some(class) = &self.analyzer.scope.get_this_class_name() { - if *class == *i { - return Ok(Some(Type::This(ThisType { - span, - metadata: Default::default(), - tracker: Default::default(), - }))); - } - } - if i.sym == js_word!("void") { - return Ok(Some(Type::any(span, Default::default()))); - } - info!("Info: {}{:?}", i.sym, i.span.ctxt); if !trying_primitive_expansion && self.dejavu.contains(&i.into()) { error!("Dejavu: {}{:?}", &i.sym, i.span.ctxt); return Ok(None); } - if let Some(types) = self.analyzer.find_type(&i.into())? { + let tys = if ignore_this { + self.analyzer.find_local_type_without_this(&i.into()) + } else { + self.analyzer.find_type(&i.into())? + }; + + if let Some(types) = tys { info!("expand: expanding `{}` using analyzer: {}", Id::from(i), types.clone().count()); let mut stored_ref = None; @@ -2247,6 +2247,16 @@ impl Expander<'_, '_, '_> { Type::Mapped(m) => {} + Type::Namespace(..) => { + dbg!(&t); + return Ok(Some(t.into_owned())); + } + + Type::StaticThis(..) => { + dbg!(&t); + + stored_ref = Some(t) + } _ => stored_ref = Some(t), } } @@ -2258,7 +2268,7 @@ impl Expander<'_, '_, '_> { } } - if i.sym == *"undefined" || i.sym == *"null" { + if i.sym == *"undefined" || i.sym == *"null" || i.sym == *"void" { return Ok(Some(Type::any(span, Default::default()))); } @@ -2269,14 +2279,13 @@ impl Expander<'_, '_, '_> { // // let a: StringEnum.Foo = x; RTsEntityName::TsQualifiedName(box RTsQualifiedName { left, ref right, .. }) => { - let left = self.expand_ts_entity_name(span, left, None, was_top_level, trying_primitive_expansion)?; - - if let Some(left) = &left { - let ty = self + let left_ty = self.expand_ts_entity_name(span, left, None, was_top_level, trying_primitive_expansion, false)?; + if let Some(ty) = &left_ty { + let res = match self .analyzer .access_property( span, - left, + ty, &Key::Normal { span, sym: right.sym.clone(), @@ -2286,9 +2295,33 @@ impl Expander<'_, '_, '_> { Default::default(), ) .context("tried to access property as a part of type expansion") - .report(&mut self.analyzer.storage) - .unwrap_or_else(|| Type::any(span, Default::default())); - return Ok(Some(ty)); + { + Ok(t) => Some(t), + err => { + if let Some(left) = + self.expand_ts_entity_name(span, left, None, was_top_level, trying_primitive_expansion, true)? + { + self.analyzer + .access_property( + span, + &left, + &Key::Normal { + span, + sym: right.sym.clone(), + }, + TypeOfMode::RValue, + IdCtx::Type, + Default::default(), + ) + .context("tried to access property as a part of type expansion") + .report(&mut self.analyzer.storage) + } else { + None + } + } + }; + + return Ok(res.or_else(|| Some(Type::any(span, Default::default())))); } } } @@ -2313,7 +2346,14 @@ impl Expander<'_, '_, '_> { return Ok(None); } - let mut ty = self.expand_ts_entity_name(span, &type_name, type_args.as_deref(), was_top_level, trying_primitive_expansion)?; + let mut ty = self.expand_ts_entity_name( + span, + &type_name, + type_args.as_deref(), + was_top_level, + trying_primitive_expansion, + false, + )?; if let Some(ty) = &mut ty { ty.reposition(r_span); diff --git a/crates/stc_ts_type_checker/tests/conformance.pass.txt b/crates/stc_ts_type_checker/tests/conformance.pass.txt index e438f4eba6..826bb9a4b3 100644 --- a/crates/stc_ts_type_checker/tests/conformance.pass.txt +++ b/crates/stc_ts_type_checker/tests/conformance.pass.txt @@ -2329,6 +2329,8 @@ types/forAwait/types.forAwait.es2018.2.ts types/forAwait/types.forAwait.es2018.3.ts types/import/importTypeAmbientMissing.ts types/import/importTypeAmdBundleRewrite.ts +types/import/importTypeGenericTypes.ts +types/import/importTypeLocal.ts types/intersection/contextualIntersectionType.ts types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts types/intersection/intersectionNarrowing.ts diff --git a/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedInterfacesOfTheSameName.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedInterfacesOfTheSameName.error-diff.json index fc72f54093..1830759d9e 100644 --- a/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedInterfacesOfTheSameName.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedInterfacesOfTheSameName.error-diff.json @@ -2,11 +2,14 @@ "required_errors": {}, "required_error_lines": {}, "extra_errors": { - "TS2339": 2 + "TS2403": 1, + "TS2339": 1 }, "extra_error_lines": { + "TS2403": [ + 17 + ], "TS2339": [ - 17, 36 ] } diff --git a/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.error-diff.json index 47483375cd..519155a71f 100644 --- a/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.error-diff.json @@ -2,11 +2,14 @@ "required_errors": {}, "required_error_lines": {}, "extra_errors": { - "TS2339": 2 + "TS2339": 1, + "TS2403": 1 }, "extra_error_lines": { "TS2339": [ - 13, + 13 + ], + "TS2403": [ 33 ] } diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json index 03d5257c1e..20eacd5b75 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json @@ -2,17 +2,13 @@ "required_errors": {}, "required_error_lines": {}, "extra_errors": { - "TS2307": 3, - "TS0": 1 + "TS2307": 3 }, "extra_error_lines": { "TS2307": [ 10, 33, 40 - ], - "TS0": [ - 28 ] } } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.stats.rust-debug index f8c5b3550b..7d12ad5c64 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 0, - extra_error: 4, + extra_error: 3, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.error-diff.json deleted file mode 100644 index 27fcd6e0ee..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS0": 1 - }, - "extra_error_lines": { - "TS0": [ - 18 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeGenericTypes.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 0, - extra_error: 1, + extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.error-diff.json deleted file mode 100644 index 1dc2bc9b4c..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS0": 1 - }, - "extra_error_lines": { - "TS0": [ - 16 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocal.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 0, - extra_error: 1, + extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.error-diff.json index 77be6774be..e8ffa5f5f8 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.error-diff.json @@ -7,12 +7,6 @@ 3 ] }, - "extra_errors": { - "TS0": 1 - }, - "extra_error_lines": { - "TS0": [ - 16 - ] - } + "extra_errors": {}, + "extra_error_lines": {} } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.stats.rust-debug index c28efdd8e5..8a4b298eee 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeLocalMissing.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 1, matched_error: 3, - extra_error: 1, + extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index 83979399ee..c3fbeb1ada 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 2860, matched_error: 7175, - extra_error: 1107, + extra_error: 1103, panic: 3, } \ No newline at end of file From 3a7f9716b4dac7794701aec891ed52d753df4d4a Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 11 Oct 2023 01:03:50 +0900 Subject: [PATCH 2/8] fix --- crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs index c32c1f4f7e..11c8b00db5 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs @@ -2094,7 +2094,12 @@ impl Expander<'_, '_, '_> { } let tys = if ignore_this { - self.analyzer.find_local_type_without_this(&i.into()) + let res = self.analyzer.find_local_type_without_this(&i.into()); + if res.is_some() { + res + } else { + self.analyzer.find_type(&i.into())? + } } else { self.analyzer.find_type(&i.into())? }; From 6eb7d6418716fd25604673fc2d882e2aa6101d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EB=B3=91=EC=A7=84?= <64676070+sunrabbit123@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:05:36 +0900 Subject: [PATCH 3/8] Update crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs --- crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs index 9fc1e2ed2a..71337903dc 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs @@ -3055,7 +3055,7 @@ impl Analyzer<'_, '_> { } for (id, tys) in exports.private_types.iter() { - if id.sym().eq(sym) { + if *id.sym() == *sym { for ty in tys.iter() { if ty.is_module() || ty.is_interface() { return Ok(ty.clone()); From 0039ea5f1fc90c6cf44bbec8f97a960b39691338 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 11 Oct 2023 19:36:16 +0900 Subject: [PATCH 4/8] rebase --- crates/stc_ts_type_checker/tests/conformance.pass.txt | 1 + .../types/import/importTypeAmbient.error-diff.json | 7 ------- crates/stc_ts_type_checker/tests/tsc-stats.rust-debug | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json diff --git a/crates/stc_ts_type_checker/tests/conformance.pass.txt b/crates/stc_ts_type_checker/tests/conformance.pass.txt index 5d6b291b32..e13517914a 100644 --- a/crates/stc_ts_type_checker/tests/conformance.pass.txt +++ b/crates/stc_ts_type_checker/tests/conformance.pass.txt @@ -2341,6 +2341,7 @@ types/contextualTypes/partiallyAnnotatedFunction/partiallyAnnotatedFunctionWitou types/forAwait/types.forAwait.es2018.1.ts types/forAwait/types.forAwait.es2018.2.ts types/forAwait/types.forAwait.es2018.3.ts +types/import/importTypeAmbient.ts types/import/importTypeAmdBundleRewrite.ts types/import/importTypeGenericTypes.ts types/import/importTypeLocal.ts diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json deleted file mode 100644 index afcedc3845..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": {}, - "extra_error_lines": {}, - "extra_error_lines": {} -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index 88b88f516b..d972a81e03 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 2861, matched_error: 7174, - extra_error: 1089, + extra_error: 1086, panic: 3, } \ No newline at end of file From 690fffba18d3b671adb42f6d2de422f7f3b497aa Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Fri, 13 Oct 2023 22:40:09 +0900 Subject: [PATCH 5/8] apply comment --- crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs index 11c8b00db5..c98f3648f5 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs @@ -2253,15 +2253,10 @@ impl Expander<'_, '_, '_> { Type::Mapped(m) => {} Type::Namespace(..) => { - dbg!(&t); return Ok(Some(t.into_owned())); } - Type::StaticThis(..) => { - dbg!(&t); - - stored_ref = Some(t) - } + Type::StaticThis(..) => stored_ref = Some(t), _ => stored_ref = Some(t), } } From f438855af1f071a2f97237f75a90a8530a1efccc Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Fri, 13 Oct 2023 22:45:51 +0900 Subject: [PATCH 6/8] f --- .../stc_ts_file_analyzer/src/analyzer/scope/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs index c98f3648f5..230cc22215 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs @@ -2094,15 +2094,11 @@ impl Expander<'_, '_, '_> { } let tys = if ignore_this { - let res = self.analyzer.find_local_type_without_this(&i.into()); - if res.is_some() { - res - } else { - self.analyzer.find_type(&i.into())? - } + self.analyzer.find_local_type_without_this(&i.into()) } else { - self.analyzer.find_type(&i.into())? - }; + None + } + .map_or_else(|| self.analyzer.find_type(&i.into()), |res| Ok(Some(res)))?; if let Some(types) = tys { info!("expand: expanding `{}` using analyzer: {}", Id::from(i), types.clone().count()); From b00d60b639ab573462806a48e2d1d04b7cf483f4 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Sat, 14 Oct 2023 01:01:17 +0900 Subject: [PATCH 7/8] refactor --- crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs index 71337903dc..448af7913f 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs @@ -3055,12 +3055,12 @@ impl Analyzer<'_, '_> { } for (id, tys) in exports.private_types.iter() { - if *id.sym() == *sym { - for ty in tys.iter() { - if ty.is_module() || ty.is_interface() { - return Ok(ty.clone()); - } - } + if *id.sym() != *sym { + continue; + } + + if let Some(ty) = tys.iter().find(|ty| ty.is_module() || ty.is_interface()) { + return Ok(ty.clone()); } } } From df504103d079476735359ca7dd8e52c31627ef3d Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Sat, 14 Oct 2023 01:23:23 +0900 Subject: [PATCH 8/8] refactor2 --- .../src/analyzer/scope/mod.rs | 46 ++++++------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs index 230cc22215..b1c36e9bbe 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs @@ -2275,49 +2275,29 @@ impl Expander<'_, '_, '_> { // // let a: StringEnum.Foo = x; RTsEntityName::TsQualifiedName(box RTsQualifiedName { left, ref right, .. }) => { - let left_ty = self.expand_ts_entity_name(span, left, None, was_top_level, trying_primitive_expansion, false)?; - if let Some(ty) = &left_ty { - let res = match self + let prop = Key::Normal { + span, + sym: right.sym.clone(), + }; + if let Some(ty) = self.expand_ts_entity_name(span, left, None, was_top_level, trying_primitive_expansion, false)? { + match self .analyzer - .access_property( - span, - ty, - &Key::Normal { - span, - sym: right.sym.clone(), - }, - TypeOfMode::RValue, - IdCtx::Type, - Default::default(), - ) + .access_property(span, &ty, &prop, TypeOfMode::RValue, IdCtx::Type, Default::default()) .context("tried to access property as a part of type expansion") { - Ok(t) => Some(t), + Ok(t) => return Ok(Some(t)), err => { if let Some(left) = self.expand_ts_entity_name(span, left, None, was_top_level, trying_primitive_expansion, true)? { - self.analyzer - .access_property( - span, - &left, - &Key::Normal { - span, - sym: right.sym.clone(), - }, - TypeOfMode::RValue, - IdCtx::Type, - Default::default(), - ) - .context("tried to access property as a part of type expansion") - .report(&mut self.analyzer.storage) - } else { - None + return Ok(self + .analyzer + .access_property(span, &left, &prop, TypeOfMode::RValue, IdCtx::Type, Default::default()) + .context("tried to access property as a part of type expansion(retry without this type)") + .report(&mut self.analyzer.storage)); } } }; - - return Ok(res.or_else(|| Some(Type::any(span, Default::default())))); } } }