diff --git a/crates/oxc_semantic/src/post_transform_checker.rs b/crates/oxc_semantic/src/post_transform_checker.rs index 9c51f23f34bd0..bdb3c638e0e9c 100644 --- a/crates/oxc_semantic/src/post_transform_checker.rs +++ b/crates/oxc_semantic/src/post_transform_checker.rs @@ -117,6 +117,11 @@ pub fn check_semantic_after_transform( ) -> Option> { let mut errors = Errors::default(); + let source_type = program.source_type; + if !source_type.is_typescript_definition() && !source_type.is_javascript() { + errors.push(format!("SourceType is not javascript: {:?}", program.source_type)); + } + // Collect `ScopeId`s, `SymbolId`s and `ReferenceId`s from AST after transformer let scoping_after_transform = Scoping { symbols: symbols_after_transform, scopes: scopes_after_transform }; diff --git a/crates/oxc_span/src/source_type/mod.rs b/crates/oxc_span/src/source_type/mod.rs index 209fb6a0a9eb3..8b6a759e75739 100644 --- a/crates/oxc_span/src/source_type/mod.rs +++ b/crates/oxc_span/src/source_type/mod.rs @@ -294,6 +294,14 @@ impl SourceType { self } + #[must_use] + pub const fn with_javascript(mut self, yes: bool) -> Self { + if yes { + self.language = Language::JavaScript; + } + self + } + #[must_use] pub const fn with_typescript(mut self, yes: bool) -> Self { if yes { @@ -318,6 +326,14 @@ impl SourceType { self } + #[must_use] + pub const fn with_standard(mut self, yes: bool) -> Self { + if yes { + self.variant = LanguageVariant::Standard; + } + self + } + /// Converts a file [`Path`] to [`SourceType`]. /// /// ## Examples diff --git a/crates/oxc_transformer/src/react/mod.rs b/crates/oxc_transformer/src/react/mod.rs index 2ecfc9712b7bf..c9523b6ad43c6 100644 --- a/crates/oxc_transformer/src/react/mod.rs +++ b/crates/oxc_transformer/src/react/mod.rs @@ -70,6 +70,9 @@ impl<'a> React<'a> { impl<'a> Traverse<'a> for React<'a> { fn enter_program(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { + if self.jsx_plugin { + program.source_type = program.source_type.with_standard(true); + } if self.refresh_plugin { self.refresh.enter_program(program, ctx); } diff --git a/crates/oxc_transformer/src/typescript/mod.rs b/crates/oxc_transformer/src/typescript/mod.rs index 243d9b2837552..609a62f118f04 100644 --- a/crates/oxc_transformer/src/typescript/mod.rs +++ b/crates/oxc_transformer/src/typescript/mod.rs @@ -77,6 +77,7 @@ impl<'a> Traverse<'a> for TypeScript<'a> { program.hashbang = None; program.body.clear(); } else { + program.source_type = program.source_type.with_javascript(true); self.namespace.enter_program(program, ctx); } }