Skip to content

Commit

Permalink
feat: Resolve panic! cause by import.meta (#1089)
Browse files Browse the repository at this point in the history
**Description:**

```ts
declare global { interface ImportMeta {foo?: () => void} };

if (import.meta.foo) {
  import.meta.foo();
}
```
  • Loading branch information
sunrabbit123 authored Sep 18, 2023
1 parent f390577 commit 8ac1d0d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion crates/stc_ts_file_analyzer/src/analyzer/expr/meta_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ impl Analyzer<'_, '_> {
Ok(Type::any(e.span, Default::default()))
}

_ => {
MetaPropKind::ImportMeta => {
if let Ok(mut ty) = self.env.get_global_type(e.span(), &"ImportMeta".into()) {
ty.reposition(e.span());
return Ok(ty);
}

todo!("Unsupported meta property {:?}", e)
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/stc_ts_type_checker/tests/conformance.pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ es2018/es2018IntlAPIs.ts
es2018/usePromiseFinally.ts
es2018/useRegexpGroups.ts
es2019/globalThisTypeIndexAccess.ts
es2019/importMeta/importMetaNarrowing.ts
es2020/bigintMissingES2019.ts
es2020/bigintMissingES2020.ts
es2020/bigintMissingESNext.ts
Expand Down Expand Up @@ -1018,6 +1019,7 @@ es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts
es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01_ES6.ts
es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02.ts
es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02_ES6.ts
es6/templates/taggedTemplateStringsPldirectives/ts-expect-error-nocheck.ts
es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts
es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts
es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts
Expand Down Expand Up @@ -1148,6 +1150,7 @@ es6/templates/templateStringWithEmbeddedObjectLiteral.ts
es6/templates/templateStringWithEmbeddedObjectLiteralES6.ts
es6/templates/templateStringWithEmbeddedTemplateString.ts
es6/templates/templateStringWithEmbeddedTemplateStringES6.ts
es6/templates/templateStringWithEmbeddedTypdirectives/ts-expect-error-nocheck.ts
es6/templates/templateStringWithEmbeddedTypeAssertionOnAddition.ts
es6/templates/templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts
es6/templates/templateStringWithEmbeddedTypeOfOperator.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Stats {
required_error: 0,
matched_error: 0,
extra_error: 0,
panic: 1,
panic: 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Stats {
required_error: 0,
matched_error: 0,
extra_error: 0,
panic: 1,
panic: 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Stats {
required_error: 0,
matched_error: 0,
extra_error: 0,
panic: 1,
panic: 0,
}
2 changes: 1 addition & 1 deletion crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Stats {
required_error: 3487,
matched_error: 6548,
extra_error: 768,
panic: 63,
panic: 60,
}

0 comments on commit 8ac1d0d

Please sign in to comment.