1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-20 20:42:19 -05:00

fix(check): ignore errors on ambient modules

This commit is contained in:
David Sherret 2025-01-10 19:56:57 -05:00
parent c27248a8f3
commit c888f22cd0
4 changed files with 59 additions and 8 deletions

View file

@ -146,6 +146,51 @@ pub fn graph_walk_errors<'a>(
roots: &'a [ModuleSpecifier], roots: &'a [ModuleSpecifier],
options: GraphWalkErrorsOptions, options: GraphWalkErrorsOptions,
) -> impl Iterator<Item = JsErrorBox> + 'a { ) -> impl Iterator<Item = JsErrorBox> + 'a {
fn should_ignore_resolution_error_for_types(err: &ResolutionError) -> bool {
match err {
ResolutionError::InvalidSpecifier { .. } => true,
ResolutionError::ResolverError { error, .. } => match error.as_ref() {
ResolveError::Specifier(_) => true,
ResolveError::ImportMap(err) => match err.as_kind() {
import_map::ImportMapErrorKind::UnmappedBareSpecifier(_, _) => true,
import_map::ImportMapErrorKind::JsonParse(_)
| import_map::ImportMapErrorKind::ImportMapNotObject
| import_map::ImportMapErrorKind::ImportsFieldNotObject
| import_map::ImportMapErrorKind::ScopesFieldNotObject
| import_map::ImportMapErrorKind::ScopePrefixNotObject(_)
| import_map::ImportMapErrorKind::BlockedByNullEntry(_)
| import_map::ImportMapErrorKind::SpecifierResolutionFailure {
..
}
| import_map::ImportMapErrorKind::SpecifierBacktracksAbovePrefix {
..
} => false,
},
ResolveError::Other(_) => false,
},
ResolutionError::InvalidDowngrade { .. }
| ResolutionError::InvalidJsrHttpsTypesImport { .. }
| ResolutionError::InvalidLocalImport { .. } => false,
}
}
fn should_ignore_module_graph_error_for_types(
err: &ModuleGraphError,
) -> bool {
match err {
ModuleGraphError::ResolutionError(err) => {
should_ignore_resolution_error_for_types(err)
}
ModuleGraphError::TypesResolutionError(err) => {
should_ignore_resolution_error_for_types(err)
}
ModuleGraphError::ModuleError(module_error) => match module_error {
ModuleError::Missing { .. } => true,
_ => false,
},
}
}
graph graph
.walk( .walk(
roots.iter(), roots.iter(),
@ -187,10 +232,7 @@ pub fn graph_walk_errors<'a>(
if graph.graph_kind().include_types() if graph.graph_kind().include_types()
&& (message.contains(RUN_WITH_SLOPPY_IMPORTS_MSG) && (message.contains(RUN_WITH_SLOPPY_IMPORTS_MSG)
|| matches!( || should_ignore_module_graph_error_for_types(&error))
error,
ModuleGraphError::ModuleError(ModuleError::Missing(..))
))
{ {
// ignore and let typescript surface this as a diagnostic instead // ignore and let typescript surface this as a diagnostic instead
log::debug!("Ignoring: {}", message); log::debug!("Ignoring: {}", message);

View file

@ -295,6 +295,9 @@ impl TypeChecker {
check_mode: type_check_mode, check_mode: type_check_mode,
})?; })?;
eprintln!("Ambient modules: {:?}", response.ambient_modules);
panic!("STOP"); // prevent saving the type checker cache
let response_diagnostics = let response_diagnostics =
response.diagnostics.filter(filter_remote_diagnostics); response.diagnostics.filter(filter_remote_diagnostics);

View file

@ -410,6 +410,7 @@ delete Object.prototype.__proto__;
} }
if (start !== undefined && length !== undefined && file) { if (start !== undefined && length !== undefined && file) {
let startPos = file.getLineAndCharacterOfPosition(start); let startPos = file.getLineAndCharacterOfPosition(start);
/** @type {string | undefined} */
let sourceLine = file.getFullText().split("\n")[startPos.line]; let sourceLine = file.getFullText().split("\n")[startPos.line];
const originalFileName = file.fileName; const originalFileName = file.fileName;
const fileName = ops.op_remap_specifier const fileName = ops.op_remap_specifier
@ -1104,8 +1105,10 @@ delete Object.prototype.__proto__;
performanceProgram({ program }); performanceProgram({ program });
const checker = program.getProgram().getTypeChecker();
ops.op_respond({ ops.op_respond({
diagnostics: fromTypeScriptDiagnostics(diagnostics), diagnostics: fromTypeScriptDiagnostics(diagnostics),
ambientModules: checker.getAmbientModules().map((symbol) => symbol.name),
stats: performanceEnd(), stats: performanceEnd(),
}); });
debug("<<< exec stop"); debug("<<< exec stop");

View file

@ -384,6 +384,7 @@ pub struct Response {
pub diagnostics: Diagnostics, pub diagnostics: Diagnostics,
/// If there was any build info associated with the exec request. /// If there was any build info associated with the exec request.
pub maybe_tsbuildinfo: Option<String>, pub maybe_tsbuildinfo: Option<String>,
pub ambient_modules: Vec<String>,
/// Statistics from the check. /// Statistics from the check.
pub stats: Stats, pub stats: Stats,
} }
@ -1047,8 +1048,10 @@ fn op_is_node_file(state: &mut OpState, #[string] path: &str) -> bool {
} }
#[derive(Debug, Deserialize, Eq, PartialEq)] #[derive(Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
struct RespondArgs { struct RespondArgs {
pub diagnostics: Diagnostics, pub diagnostics: Diagnostics,
pub ambient_modules: Vec<String>,
pub stats: Stats, pub stats: Stats,
} }
@ -1163,14 +1166,13 @@ pub fn exec(request: Request) -> Result<Response, ExecError> {
let state = op_state.take::<State>(); let state = op_state.take::<State>();
if let Some(response) = state.maybe_response { if let Some(response) = state.maybe_response {
let diagnostics = response.diagnostics;
let maybe_tsbuildinfo = state.maybe_tsbuildinfo; let maybe_tsbuildinfo = state.maybe_tsbuildinfo;
let stats = response.stats;
Ok(Response { Ok(Response {
diagnostics, diagnostics: response.diagnostics,
ambient_modules: response.ambient_modules,
maybe_tsbuildinfo, maybe_tsbuildinfo,
stats, stats: response.stats,
}) })
} else { } else {
Err(ExecError::ResponseNotSet) Err(ExecError::ResponseNotSet)
@ -1500,6 +1502,7 @@ mod tests {
reports_unnecessary: None, reports_unnecessary: None,
other: Default::default(), other: Default::default(),
}]), }]),
ambient_modules: vec![],
stats: Stats(vec![("a".to_string(), 12)]) stats: Stats(vec![("a".to_string(), 12)])
}) })
); );