Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ pub fn check_semantic_after_transform(
) -> Option<Vec<OxcDiagnostic>> {
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 };
Expand Down
16 changes: 16 additions & 0 deletions crates/oxc_span/src/source_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_transformer/src/react/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_transformer/src/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down