refactor(span): put types and impl in the same mod file

This commit is contained in:
Boshen 2024-09-08 12:07:47 +08:00
parent 69da677f00
commit 553262842c
No known key found for this signature in database
GPG key ID: 67715A371E534061
2 changed files with 65 additions and 67 deletions

View file

@ -1,13 +1,75 @@
// Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]`
#![allow(non_snake_case)]
mod error;
mod types;
use std::{hash::Hash, path::Path};
pub use error::UnknownExtension;
use oxc_allocator::{Allocator, CloneIn};
pub use types::*;
use oxc_ast_macros::ast;
#[cfg(feature = "serialize")]
use {serde::Serialize, tsify::Tsify};
use crate::{cmp::ContentEq, hash::ContentHash};
pub use error::UnknownExtension;
/// Source Type for JavaScript vs TypeScript / Script vs Module / JSX
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub struct SourceType {
/// JavaScript or TypeScript, default JavaScript
pub(super) language: Language,
/// Script or Module, default Module
pub(super) module_kind: ModuleKind,
/// Support JSX for JavaScript and TypeScript? default without JSX
pub(super) variant: LanguageVariant,
}
/// JavaScript or TypeScript
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "lowercase")]
pub enum Language {
JavaScript = 0,
TypeScript = 1,
#[serde(rename = "typescriptDefinition")]
TypeScriptDefinition = 2,
}
/// Script or Module
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub enum ModuleKind {
/// Regular JS script or CommonJS file
Script = 0,
/// ES6 Module
Module = 1,
/// Consider the file a "module" if ESM syntax is present, or else consider it a "script".
///
/// ESM syntax includes `import` statement, `export` statement and `import.meta`.
///
/// Note: Dynamic import expression is not ESM syntax.
///
/// See <https://babel.dev/docs/options#misc-options>
Unambiguous = 2,
}
/// JSX for JavaScript and TypeScript
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub enum LanguageVariant {
Standard = 0,
Jsx = 1,
}
impl Default for SourceType {
#[inline]

View file

@ -1,64 +0,0 @@
// Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]`
#![allow(non_snake_case)]
use oxc_ast_macros::ast;
#[cfg(feature = "serialize")]
use {serde::Serialize, tsify::Tsify};
/// Source Type for JavaScript vs TypeScript / Script vs Module / JSX
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub struct SourceType {
/// JavaScript or TypeScript, default JavaScript
pub(super) language: Language,
/// Script or Module, default Module
pub(super) module_kind: ModuleKind,
/// Support JSX for JavaScript and TypeScript? default without JSX
pub(super) variant: LanguageVariant,
}
/// JavaScript or TypeScript
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "lowercase")]
pub enum Language {
JavaScript = 0,
TypeScript = 1,
#[serde(rename = "typescriptDefinition")]
TypeScriptDefinition = 2,
}
/// Script or Module
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub enum ModuleKind {
/// Regular JS script or CommonJS file
Script = 0,
/// ES6 Module
Module = 1,
/// Consider the file a "module" if ESM syntax is present, or else consider it a "script".
///
/// ESM syntax includes `import` statement, `export` statement and `import.meta`.
///
/// Note: Dynamic import expression is not ESM syntax.
///
/// See <https://babel.dev/docs/options#misc-options>
Unambiguous = 2,
}
/// JSX for JavaScript and TypeScript
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(rename_all = "camelCase")]
pub enum LanguageVariant {
Standard = 0,
Jsx = 1,
}