Skip to content

Commit

Permalink
fix: Handle module-not-found error occurred while preparing module (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunrabbit123 authored Oct 11, 2023
1 parent bec48ce commit 9e4c9b3
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 121 deletions.
11 changes: 9 additions & 2 deletions crates/stc_ts_file_analyzer/src/analyzer/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,26 @@ 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);

let loader = self.loader;
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;
}
Expand Down
15 changes: 14 additions & 1 deletion crates/stc_ts_type_checker/tests/conformance.pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 1,
extra_error: 0,
panic: 0,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 1,
extra_error: 0,
panic: 0,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 1,
extra_error: 0,
panic: 0,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 3,
extra_error: 0,
panic: 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
1
]
},
"extra_errors": {
"TS2307": 3
},
"extra_error_lines": {
"TS2307": [
2,
4,
1
]
}
"extra_errors": {},
"extra_error_lines": {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 1,
matched_error: 0,
extra_error: 3,
extra_error: 0,
panic: 0,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 1,
extra_error: 0,
panic: 0,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 3,
extra_error: 0,
panic: 0,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 1,
extra_error: 0,
panic: 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
"required_errors": {},
"required_error_lines": {},
"extra_errors": {
"TS2307": 3,
"TS0": 1
},
"extra_error_lines": {
"TS2307": [
10,
33,
40
],
"TS0": [
28
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 0,
extra_error: 4,
extra_error: 1,
panic: 0,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required_errors": {
"TS2307": 1
},
"required_error_lines": {
"TS2307": [
10
]
},
"extra_errors": {},
"extra_error_lines": {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 1,
required_error: 1,
matched_error: 0,
extra_error: 0,
panic: 0,
}
6 changes: 3 additions & 3 deletions crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 9e4c9b3

Please sign in to comment.