From 9e4c9b300e5e37311472d722b1c933a7ee4280dc 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 09:48:18 +0900 Subject: [PATCH] fix: Handle `module-not-found` error occurred while preparing module (#1098) --- .../stc_ts_file_analyzer/src/analyzer/import.rs | 11 +++++++++-- .../tests/conformance.pass.txt | 15 ++++++++++++++- ...ntOfExportNamespaceWithDefault.error-diff.json | 12 ------------ ...tOfExportNamespaceWithDefault.stats.rust-debug | 2 +- .../library-reference-1.error-diff.json | 12 ------------ .../library-reference-1.stats.rust-debug | 2 +- .../library-reference-3.error-diff.json | 12 ------------ .../library-reference-3.stats.rust-debug | 2 +- .../library-reference-4.error-diff.json | 14 -------------- .../library-reference-4.stats.rust-debug | 2 +- .../library-reference-5.error-diff.json | 12 ++---------- .../library-reference-5.stats.rust-debug | 2 +- .../library-reference-7.error-diff.json | 12 ------------ .../library-reference-7.stats.rust-debug | 2 +- .../library-reference-8.error-diff.json | 14 -------------- .../library-reference-8.stats.rust-debug | 2 +- ...rary-reference-scoped-packages.error-diff.json | 12 ------------ ...ary-reference-scoped-packages.stats.rust-debug | 2 +- .../import/importTypeAmbient.error-diff.json | 6 ------ .../import/importTypeAmbient.stats.rust-debug | 2 +- .../importTypeAmbientMissing.error-diff.json | 12 ++++++++++++ .../importTypeAmbientMissing.stats.rust-debug | 4 ++-- .../tests/tsc-stats.rust-debug | 6 +++--- 23 files changed, 51 insertions(+), 121 deletions(-) delete mode 100644 crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.error-diff.json delete mode 100644 crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.error-diff.json create mode 100644 crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.error-diff.json diff --git a/crates/stc_ts_file_analyzer/src/analyzer/import.rs b/crates/stc_ts_file_analyzer/src/analyzer/import.rs index 4053cad760..c6bbb8be67 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/import.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/import.rs @@ -79,6 +79,11 @@ impl Analyzer<'_, '_> { if self.config.is_builtin { return; } + + #[inline] + fn is_relative_path(path: &str) -> bool { + path.starts_with("./") || path.starts_with("../") + } // We first load non-circular imports. let imports = ImportFinder::find_imports(&self.comments, module_spans, &self.storage, items); @@ -86,12 +91,14 @@ impl Analyzer<'_, '_> { let mut normal_imports = vec![]; for (ctxt, import) in imports { let span = import.span; - let base = self.storage.path(ctxt); let dep_id = self.loader.module_id(&base, &import.src); let dep_id = match dep_id { Some(v) => v, - None => { + _ if !is_relative_path(&import.src) => { + continue; + } + _ => { self.storage.report(ErrorKind::ModuleNotFound { span }.into()); continue; } diff --git a/crates/stc_ts_type_checker/tests/conformance.pass.txt b/crates/stc_ts_type_checker/tests/conformance.pass.txt index e438f4eba6..3b62640fe9 100644 --- a/crates/stc_ts_type_checker/tests/conformance.pass.txt +++ b/crates/stc_ts_type_checker/tests/conformance.pass.txt @@ -1016,10 +1016,14 @@ es6/spread/iteratorSpreadInCall2.ts es6/spread/iteratorSpreadInCall3.ts es6/spread/iteratorSpreadInCall4.ts es6/spread/iteratorSpreadInCall5.ts +es6/tedirectives/ts-expect-error-nocheck.ts +es6/templates/taggedTemplateStrindirectives/ts-expect-error-nocheck.ts es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01_ES6.ts es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02.ts es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02_ES6.ts +es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02_ES6.tsdirectives/ts-expect-error-nocheck.ts +es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02directives/ts-expect-error-nocheck.ts es6/templates/taggedTemplateStringsPldirectives/ts-expect-error-nocheck.ts es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts @@ -1123,6 +1127,8 @@ es6/templates/templateStringWhitespaceEscapes2_ES6.ts es6/templates/templateStringWithBackslashEscapes01.ts es6/templates/templateStringWithBackslashEscapes01_ES6.ts es6/templates/templateStringWithCommentsInArrowFunction.ts +es6/templates/templateStringWithE +es6/templates/templateStringWithEdirectives/ts-expect-error-nocheck.ts es6/templates/templateStringWithEmbeddedAddition.ts es6/templates/templateStringWithEmbeddedAdditionES6.ts es6/templates/templateStringWithEmbeddedArray.ts @@ -1163,6 +1169,7 @@ es6/templates/templateStringWithEmptyLiteralPortions.ts es6/templates/templateStringWithEmptyLiteralPortionsES6.ts es6/templates/templateStringWithOpenCommentInStringPortion.ts es6/templates/templateStringWithOpenCommentInStringPortionES6.ts +es6/templates/templateStringWithPdirectives/ts-expect-error-nocheck.ts es6/templates/templateStringWithPropertyAccess.ts es6/templates/templateStringWithPropertyAccessES6.ts es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts @@ -1683,6 +1690,7 @@ externalModules/exportAssignImportedIdentifier.ts externalModules/exportAssignTypes.ts externalModules/exportAssignmentAndDeclaration.ts externalModules/exportAssignmentGenericType.ts +externalModules/exportAssignmentOfExportNamespaceWithDefault.ts externalModules/exportAssignmentTopLevelIdentifier.ts externalModules/exportClassNameWithObjectAMD.ts externalModules/exportClassNameWithObjectCommonJS.ts @@ -2199,8 +2207,14 @@ parser/ecmascript6/Symbols/parserSymbolProperty6.ts parser/ecmascript6/Symbols/parserSymbolProperty7.ts parser/ecmascript6/Symbols/parserSymbolProperty8.ts parser/ecmascript6/Symbols/parserSymbolProperty9.ts +references/library-reference-1.ts references/library-reference-14.ts +references/library-reference-3.ts +references/library-reference-4.ts references/library-reference-6.ts +references/library-reference-7.ts +references/library-reference-8.ts +references/library-reference-scoped-packages.ts salsa/constructorNameInObjectLiteralAccessor.ts salsa/inferringClassMembersFromAssignments8.ts salsa/mixedPropertyElementAccessAssignmentDeclaration.ts @@ -2327,7 +2341,6 @@ 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/importTypeAmbientMissing.ts types/import/importTypeAmdBundleRewrite.ts types/intersection/contextualIntersectionType.ts types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts diff --git a/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.error-diff.json deleted file mode 100644 index e38ae59eac..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 1 - }, - "extra_error_lines": { - "TS2307": [ - 11 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.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/references/library-reference-1.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.error-diff.json deleted file mode 100644 index 7c6e505964..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 1 - }, - "extra_error_lines": { - "TS2307": [ - 2 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-1.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/references/library-reference-3.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.error-diff.json deleted file mode 100644 index 7c6e505964..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 1 - }, - "extra_error_lines": { - "TS2307": [ - 2 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-3.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/references/library-reference-4.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.error-diff.json deleted file mode 100644 index 70141c5123..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.error-diff.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 3 - }, - "extra_error_lines": { - "TS2307": [ - 2, - 4, - 1 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.stats.rust-debug index 7d12ad5c64..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-4.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 0, - extra_error: 3, + extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.error-diff.json index 3a1b51456c..d96d78547f 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.error-diff.json @@ -7,14 +7,6 @@ 1 ] }, - "extra_errors": { - "TS2307": 3 - }, - "extra_error_lines": { - "TS2307": [ - 2, - 4, - 1 - ] - } + "extra_errors": {}, + "extra_error_lines": {} } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.stats.rust-debug index efea2c0329..4af5bf17ec 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-5.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 1, matched_error: 0, - extra_error: 3, + extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.error-diff.json deleted file mode 100644 index 7c6e505964..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 1 - }, - "extra_error_lines": { - "TS2307": [ - 2 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-7.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/references/library-reference-8.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.error-diff.json deleted file mode 100644 index 9df5d88278..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.error-diff.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 3 - }, - "extra_error_lines": { - "TS2307": [ - 3, - 4, - 2 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.stats.rust-debug index 7d12ad5c64..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-8.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 0, - extra_error: 3, + extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.error-diff.json deleted file mode 100644 index dba7272865..0000000000 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.error-diff.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required_errors": {}, - "required_error_lines": {}, - "extra_errors": { - "TS2307": 1 - }, - "extra_error_lines": { - "TS2307": [ - 1 - ] - } -} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.stats.rust-debug index 0498397634..c086b5ab15 100644 --- a/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/references/library-reference-scoped-packages.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/importTypeAmbient.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbient.error-diff.json index 03d5257c1e..d8db441db2 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,15 +2,9 @@ "required_errors": {}, "required_error_lines": {}, "extra_errors": { - "TS2307": 3, "TS0": 1 }, "extra_error_lines": { - "TS2307": [ - 10, - 33, - 40 - ], "TS0": [ 28 ] 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..0498397634 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: 1, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.error-diff.json new file mode 100644 index 0000000000..5e7c93b207 --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.error-diff.json @@ -0,0 +1,12 @@ +{ + "required_errors": { + "TS2307": 1 + }, + "required_error_lines": { + "TS2307": [ + 10 + ] + }, + "extra_errors": {}, + "extra_error_lines": {} +} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.stats.rust-debug index f3e39f53bd..4af5bf17ec 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/import/importTypeAmbientMissing.stats.rust-debug @@ -1,6 +1,6 @@ Stats { - required_error: 0, - matched_error: 1, + required_error: 1, + matched_error: 0, 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..3bad9ce15d 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, + required_error: 2861, + matched_error: 7174, + extra_error: 1090, panic: 3, } \ No newline at end of file