pub struct ModuleResolver { /* private fields */ }Expand description
Module resolver that implements TypeScript’s resolution algorithms
Implementations§
Source§impl ModuleResolver
impl ModuleResolver
Sourcepub fn new(options: &ResolvedCompilerOptions) -> Self
pub fn new(options: &ResolvedCompilerOptions) -> Self
Create a new module resolver with the given options
Sourcepub fn node_resolver() -> Self
pub fn node_resolver() -> Self
Create a resolver with default Node resolution
Sourcepub fn resolve(
&mut self,
specifier: &str,
containing_file: &Path,
specifier_span: Span,
) -> Result<ResolvedModule, ResolutionFailure>
pub fn resolve( &mut self, specifier: &str, containing_file: &Path, specifier_span: Span, ) -> Result<ResolvedModule, ResolutionFailure>
Resolve a module specifier from a containing file
Sourcepub fn resolve_with_kind(
&mut self,
specifier: &str,
containing_file: &Path,
specifier_span: Span,
import_kind: ImportKind,
) -> Result<ResolvedModule, ResolutionFailure>
pub fn resolve_with_kind( &mut self, specifier: &str, containing_file: &Path, specifier_span: Span, import_kind: ImportKind, ) -> Result<ResolvedModule, ResolutionFailure>
Resolve a module specifier from a containing file, with import kind information.
The import_kind is used to determine whether to emit TS2834 (extensionless ESM import)
or TS2307 (cannot find module) for extensionless imports in Node16/NodeNext.
Sourcepub fn probe_js_file(
&mut self,
specifier: &str,
containing_file: &Path,
specifier_span: Span,
import_kind: ImportKind,
) -> Option<PathBuf>
pub fn probe_js_file( &mut self, specifier: &str, containing_file: &Path, specifier_span: Span, import_kind: ImportKind, ) -> Option<PathBuf>
Probe for a JS file that would resolve for this specifier.
Used for TS7016: when normal resolution fails but a JS file exists, we can report “Could not find declaration file” instead of “Cannot find module”. Returns the resolved JS file path if found.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the resolution cache
Sourcepub const fn resolution_kind(&self) -> ModuleResolutionKind
pub const fn resolution_kind(&self) -> ModuleResolutionKind
Get the current resolution kind
Sourcepub fn emit_resolution_error(
&self,
diagnostics: &mut DiagnosticBag,
failure: &ResolutionFailure,
)
pub fn emit_resolution_error( &self, diagnostics: &mut DiagnosticBag, failure: &ResolutionFailure, )
Emit TS2307 error for a resolution failure into a diagnostic bag
All module resolution failures emit TS2307 “Cannot find module” error. This includes:
NotFound: Module specifier could not be resolvedInvalidSpecifier: Module specifier is malformedPackageJsonError: Package.json is missing or invalidCircularResolution: Circular dependency detected during resolutionPathMappingFailed: Path mapping from tsconfig did not resolve
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModuleResolver
impl RefUnwindSafe for ModuleResolver
impl Send for ModuleResolver
impl Sync for ModuleResolver
impl Unpin for ModuleResolver
impl UnsafeUnpin for ModuleResolver
impl UnwindSafe for ModuleResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more