From 6a194f90865cd2b89b4406cd8498c173c7511887 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:59:41 +0000 Subject: [PATCH] docs(span): document validity of `ModuleKind::Unambiguous` (#6423) relates #6249 --- crates/oxc_span/src/source_type/mod.rs | 3 ++- tasks/coverage/src/driver.rs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/oxc_span/src/source_type/mod.rs b/crates/oxc_span/src/source_type/mod.rs index 8b6a759e75739..37e411fa67800 100644 --- a/crates/oxc_span/src/source_type/mod.rs +++ b/crates/oxc_span/src/source_type/mod.rs @@ -55,7 +55,8 @@ pub enum ModuleKind { /// /// ESM syntax includes `import` statement, `export` statement and `import.meta`. /// - /// Note: Dynamic import expression is not ESM syntax. + /// Note1: This value is only valid as a parser input, and does not appear on a valid AST's `Program::source_type`. + /// Note2: Dynamic import expression is not ESM syntax. /// /// See Unambiguous = 2, diff --git a/tasks/coverage/src/driver.rs b/tasks/coverage/src/driver.rs index e053e8315e29e..aac49759cc9a2 100644 --- a/tasks/coverage/src/driver.rs +++ b/tasks/coverage/src/driver.rs @@ -67,11 +67,14 @@ impl CompilerInterface for Driver { } fn after_parse(&mut self, parser_return: &mut ParserReturn) -> ControlFlow<()> { - let ParserReturn { program, trivias, panicked, .. } = parser_return; + let ParserReturn { program, trivias, panicked, errors } = parser_return; self.panicked = *panicked; if self.check_comments(trivias) { return ControlFlow::Break(()); } + if (errors.is_empty() || !*panicked) && program.source_type.is_unambiguous() { + self.errors.push(OxcDiagnostic::error("SourceType must not be unambiguous.")); + } // Make sure serialization doesn't crash; also for code coverage. let _serializer = program.serializer(); ControlFlow::Continue(())