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
1 change: 0 additions & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use super::{macros::inherit_variants, *};
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub struct Program<'a> {
pub span: Span,
#[estree(via = crate::serialize::ESTreeSourceType, ts_type = "ModuleKind")]
pub source_type: SourceType,
#[estree(skip)]
pub source_text: &'a str,
Expand Down
5 changes: 1 addition & 4 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ impl Serialize for Program<'_> {
map.serialize_entry("type", "Program")?;
map.serialize_entry("start", &self.span.start)?;
map.serialize_entry("end", &self.span.end)?;
map.serialize_entry(
"sourceType",
&crate::serialize::ESTreeSourceType::from(&self.source_type),
)?;
self.source_type.serialize(FlatMapSerializer(&mut map))?;
map.serialize_entry("hashbang", &self.hashbang)?;
map.serialize_entry("directives", &self.directives)?;
map.serialize_entry("body", &self.body)?;
Expand Down
16 changes: 1 addition & 15 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{
};

use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec};
use oxc_span::{Atom, SourceType, Span};
use oxc_span::{Atom, Span};
use oxc_syntax::number::BigintBase;

use crate::ast::{
Expand Down Expand Up @@ -323,17 +323,3 @@ impl Serialize for JSXMemberExpressionObject<'_> {
}
}
}

pub struct ESTreeSourceType<'a>(pub &'a SourceType);

impl<'a> From<&'a SourceType> for ESTreeSourceType<'a> {
fn from(inner: &'a SourceType) -> Self {
Self(inner)
}
}

impl Serialize for ESTreeSourceType<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.module_kind().serialize(serializer)
}
}
27 changes: 1 addition & 26 deletions crates/oxc_span/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,11 @@ impl Serialize for Span {
impl Serialize for SourceType {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("language", &self.language)?;
map.serialize_entry("moduleKind", &self.module_kind)?;
map.serialize_entry("variant", &self.variant)?;
map.serialize_entry("sourceType", &self.module_kind)?;
map.end()
}
}

impl Serialize for Language {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Language::JavaScript => serializer.serialize_unit_variant("Language", 0, "javascript"),
Language::TypeScript => serializer.serialize_unit_variant("Language", 1, "typescript"),
Language::TypeScriptDefinition => {
serializer.serialize_unit_variant("Language", 2, "typescriptDefinition")
}
}
}
}

impl Serialize for ModuleKind {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Expand All @@ -52,14 +38,3 @@ impl Serialize for ModuleKind {
}
}
}

impl Serialize for LanguageVariant {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
LanguageVariant::Standard => {
serializer.serialize_unit_variant("LanguageVariant", 0, "standard")
}
LanguageVariant::Jsx => serializer.serialize_unit_variant("LanguageVariant", 1, "jsx"),
}
}
}
10 changes: 4 additions & 6 deletions crates/oxc_span/src/source_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@ pub use error::UnknownExtension;
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[generate_derive(ESTree)]
#[estree(no_type)]
#[estree(no_type, flatten)]
pub struct SourceType {
/// JavaScript or TypeScript, default JavaScript
#[estree(skip)]
pub(super) language: Language,

/// Script or Module, default Module
#[estree(rename = "sourceType")]
pub(super) module_kind: ModuleKind,

/// Support JSX for JavaScript and TypeScript? default without JSX
#[estree(skip)]
pub(super) variant: LanguageVariant,
}

/// JavaScript or TypeScript
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[generate_derive(ESTree)]
pub enum Language {
/// Indicates a JavaScript or JSX file
#[estree(rename = "javascript")]
JavaScript = 0,
/// Indicates a TypeScript file
#[estree(rename = "typescript")]
TypeScript = 1,
/// Indicates a TypeScript definition file (`*.d.ts`)
#[estree(rename = "typescriptDefinition")]
TypeScriptDefinition = 2,
}

Expand All @@ -64,7 +63,6 @@ pub enum ModuleKind {
/// JSX for JavaScript and TypeScript
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[generate_derive(ESTree)]
pub enum LanguageVariant {
/// Standard JavaScript or TypeScript without any language extensions. Stage
/// 3 proposals do not count as language extensions.
Expand Down
10 changes: 0 additions & 10 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,18 +1806,8 @@ export interface Span {
end: number;
}

export interface SourceType {
language: Language;
moduleKind: ModuleKind;
variant: LanguageVariant;
}

export type Language = 'javascript' | 'typescript' | 'typescriptDefinition';

export type ModuleKind = 'script' | 'module' | 'unambiguous';

export type LanguageVariant = 'standard' | 'jsx';

export interface Pattern extends Span {
type: 'Pattern';
body: Disjunction;
Expand Down
Loading