mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor: reduce cfg_attr boilerplate with SerAttrs derive (#2669)
Closes #2641. Also added `tsify` attribute to the `SerAttrs` derive macro, so `#[cfg_attr(feature = "wasm", tsify(...))]` can also be reduced to `#[tsify(...)]`.
This commit is contained in:
parent
f27db301a9
commit
3c1e0db53f
15 changed files with 1010 additions and 759 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1356,6 +1356,7 @@ dependencies = [
|
|||
"num-bigint",
|
||||
"oxc_allocator",
|
||||
"oxc_index",
|
||||
"oxc_macros",
|
||||
"oxc_span",
|
||||
"oxc_syntax",
|
||||
"ryu-js",
|
||||
|
|
@ -1699,6 +1700,7 @@ dependencies = [
|
|||
"oxc_ast",
|
||||
"oxc_diagnostics",
|
||||
"oxc_index",
|
||||
"oxc_macros",
|
||||
"oxc_parser",
|
||||
"oxc_span",
|
||||
"oxc_syntax",
|
||||
|
|
@ -1717,6 +1719,7 @@ version = "0.9.0"
|
|||
dependencies = [
|
||||
"compact_str",
|
||||
"miette",
|
||||
"oxc_macros",
|
||||
"serde",
|
||||
"tsify",
|
||||
"wasm-bindgen",
|
||||
|
|
@ -1730,6 +1733,7 @@ dependencies = [
|
|||
"dashmap",
|
||||
"indexmap",
|
||||
"oxc_index",
|
||||
"oxc_macros",
|
||||
"oxc_span",
|
||||
"phf",
|
||||
"rustc-hash",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ oxc_allocator = { workspace = true }
|
|||
oxc_span = { workspace = true }
|
||||
oxc_syntax = { workspace = true }
|
||||
oxc_index = { workspace = true }
|
||||
oxc_macros = { workspace = true }
|
||||
|
||||
bitflags = { workspace = true }
|
||||
num-bigint = { workspace = true }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,7 @@
|
|||
//! [JSX](https://facebook.github.io/jsx)
|
||||
|
||||
use oxc_allocator::{Box, Vec};
|
||||
use oxc_macros::SerAttrs;
|
||||
use oxc_span::{Atom, Span};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::Serialize;
|
||||
|
|
@ -12,11 +13,12 @@ use super::{js::*, literal::*, ts::*};
|
|||
// 1.2 JSX Elements
|
||||
|
||||
/// JSX Element
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
pub struct JSXElement<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub opening_element: Box<'a, JSXOpeningElement<'a>>,
|
||||
pub closing_element: Option<Box<'a, JSXClosingElement<'a>>>,
|
||||
|
|
@ -24,11 +26,12 @@ pub struct JSXElement<'a> {
|
|||
}
|
||||
|
||||
/// JSX Opening Element
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
pub struct JSXOpeningElement<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub self_closing: bool,
|
||||
pub name: JSXElementName<'a>,
|
||||
|
|
@ -37,47 +40,52 @@ pub struct JSXOpeningElement<'a> {
|
|||
}
|
||||
|
||||
/// JSX Closing Element
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXClosingElement<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub name: JSXElementName<'a>,
|
||||
}
|
||||
|
||||
/// JSX Fragment
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
pub struct JSXFragment<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub opening_fragment: JSXOpeningFragment,
|
||||
pub closing_fragment: JSXClosingFragment,
|
||||
pub children: Vec<'a, JSXChild<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXOpeningFragment {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXClosingFragment {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// JSX Element Name
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXElementName<'a> {
|
||||
/// `<Apple />`
|
||||
Identifier(JSXIdentifier<'a>),
|
||||
|
|
@ -88,11 +96,12 @@ pub enum JSXElementName<'a> {
|
|||
}
|
||||
|
||||
/// JSX Namespaced Name
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXNamespacedName<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub namespace: JSXIdentifier<'a>,
|
||||
pub property: JSXIdentifier<'a>,
|
||||
|
|
@ -105,11 +114,12 @@ impl<'a> std::fmt::Display for JSXNamespacedName<'a> {
|
|||
}
|
||||
|
||||
/// JSX Member Expression
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXMemberExpression<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub object: JSXMemberExpressionObject<'a>,
|
||||
pub property: JSXIdentifier<'a>,
|
||||
|
|
@ -124,56 +134,62 @@ impl<'a> JSXMemberExpression<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXMemberExpressionObject<'a> {
|
||||
Identifier(JSXIdentifier<'a>),
|
||||
MemberExpression(Box<'a, JSXMemberExpression<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXExpressionContainer<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub expression: JSXExpression<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXExpression<'a> {
|
||||
Expression(Expression<'a>),
|
||||
EmptyExpression(JSXEmptyExpression),
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXEmptyExpression {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// 1.3 JSX Attributes
|
||||
|
||||
/// JSX Attributes
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXAttributeItem<'a> {
|
||||
Attribute(Box<'a, JSXAttribute<'a>>),
|
||||
SpreadAttribute(Box<'a, JSXSpreadAttribute<'a>>),
|
||||
}
|
||||
|
||||
/// JSX Attribute
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXAttribute<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub name: JSXAttributeName<'a>,
|
||||
pub value: Option<JSXAttributeValue<'a>>,
|
||||
|
|
@ -186,28 +202,31 @@ impl<'a> JSXAttribute<'a> {
|
|||
}
|
||||
|
||||
/// JSX Spread Attribute
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXSpreadAttribute<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub argument: Expression<'a>,
|
||||
}
|
||||
|
||||
/// JSX Attribute Name
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXAttributeName<'a> {
|
||||
Identifier(JSXIdentifier<'a>),
|
||||
NamespacedName(Box<'a, JSXNamespacedName<'a>>),
|
||||
}
|
||||
|
||||
/// JSX Attribute Value
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXAttributeValue<'a> {
|
||||
StringLiteral(StringLiteral<'a>),
|
||||
ExpressionContainer(JSXExpressionContainer<'a>),
|
||||
|
|
@ -215,11 +234,12 @@ pub enum JSXAttributeValue<'a> {
|
|||
Fragment(Box<'a, JSXFragment<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXIdentifier<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub name: Atom<'a>,
|
||||
}
|
||||
|
|
@ -227,9 +247,10 @@ pub struct JSXIdentifier<'a> {
|
|||
// 1.4 JSX Children
|
||||
|
||||
/// JSX Child
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(untagged)]
|
||||
pub enum JSXChild<'a> {
|
||||
Text(JSXText<'a>),
|
||||
Element(Box<'a, JSXElement<'a>>),
|
||||
|
|
@ -238,20 +259,22 @@ pub enum JSXChild<'a> {
|
|||
Spread(JSXSpreadChild<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXSpreadChild<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub expression: Expression<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct JSXText<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub value: Atom<'a>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use std::{
|
|||
};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use oxc_macros::SerAttrs;
|
||||
use oxc_span::{Atom, Span};
|
||||
use oxc_syntax::{BigintBase, NumberBase};
|
||||
#[cfg(feature = "serde")]
|
||||
|
|
@ -13,11 +14,12 @@ use serde::Serialize;
|
|||
#[cfg(feature = "wasm")]
|
||||
use tsify::Tsify;
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Clone, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct BooleanLiteral {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub value: bool,
|
||||
}
|
||||
|
|
@ -36,11 +38,12 @@ impl BooleanLiteral {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Clone, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct NullLiteral {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
|
|
@ -56,15 +59,16 @@ impl NullLiteral {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Clone, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct NumericLiteral<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub value: f64,
|
||||
pub raw: &'a str,
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
#[serde(skip)]
|
||||
pub base: NumberBase,
|
||||
}
|
||||
|
||||
|
|
@ -107,14 +111,15 @@ impl<'a> Hash for NumericLiteral<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct BigIntLiteral<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub raw: Atom<'a>,
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
#[serde(skip)]
|
||||
pub base: BigintBase,
|
||||
}
|
||||
|
||||
|
|
@ -124,11 +129,12 @@ impl<'a> BigIntLiteral<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Clone, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct RegExpLiteral<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
// valid regex is printed as {}
|
||||
// invalid regex is printed as null, which we can't implement yet
|
||||
|
|
@ -233,11 +239,12 @@ impl fmt::Display for RegExpFlags {
|
|||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
pub struct EmptyObject;
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
|
||||
#[derive(Debug, Clone, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(tag = "type")]
|
||||
pub struct StringLiteral<'a> {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub value: Atom<'a>,
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -58,3 +58,12 @@ pub fn declare_all_lint_rules(input: proc_macro::TokenStream) -> proc_macro::Tok
|
|||
|
||||
declare_all_lint_rules::declare_all_lint_rules(metadata).into()
|
||||
}
|
||||
|
||||
/// Dummy derive macro which doesn't actually derive anything,
|
||||
/// but allows `#[serde]` and `#[tsify]` attrs on the item it's applied to,
|
||||
/// without deriving `Serialize` or `Tsify`, and without `#[cfg_attr]`.
|
||||
#[proc_macro_derive(SerAttrs, attributes(serde, tsify))]
|
||||
pub fn ser_attrs(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
// Return an empty token stream
|
||||
proc_macro::TokenStream::new()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ oxc_syntax = { workspace = true }
|
|||
oxc_diagnostics = { workspace = true }
|
||||
oxc_index = { workspace = true }
|
||||
oxc_allocator = { workspace = true }
|
||||
oxc_macros = { workspace = true }
|
||||
|
||||
indexmap = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use oxc_macros::SerAttrs;
|
||||
use oxc_span::{CompactStr, Span};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::Serialize;
|
||||
|
|
@ -8,9 +9,10 @@ use crate::{symbol::SymbolId, AstNodeId};
|
|||
|
||||
pub use oxc_syntax::reference::{ReferenceFlag, ReferenceId};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Debug, Clone, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Reference {
|
||||
span: Span,
|
||||
/// The name of the identifier that was referred to
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use oxc_ast::ast::Expression;
|
||||
use oxc_index::IndexVec;
|
||||
use oxc_macros::SerAttrs;
|
||||
use oxc_span::{Atom, CompactStr, Span};
|
||||
pub use oxc_syntax::{
|
||||
scope::ScopeId,
|
||||
|
|
@ -25,9 +26,10 @@ export type IndexVec<I, T> = Array<T>;
|
|||
/// Symbol Table
|
||||
///
|
||||
/// `SoA` (Struct of Arrays) for memory efficiency.
|
||||
#[derive(Debug, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Debug, Default, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SymbolTable {
|
||||
pub spans: IndexVec<SymbolId, Span>,
|
||||
pub names: IndexVec<SymbolId, CompactStr>,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ workspace = true
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
oxc_macros = { workspace = true }
|
||||
|
||||
miette = { workspace = true }
|
||||
compact_str = { version = "0.7.1" }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
use std::path::Path;
|
||||
|
||||
use oxc_macros::SerAttrs;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::Serialize;
|
||||
#[cfg(feature = "wasm")]
|
||||
use tsify::Tsify;
|
||||
|
||||
/// Source Type for JavaScript vs TypeScript / Script vs Module / JSX
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SourceType {
|
||||
/// JavaScript or TypeScript, default JavaScript
|
||||
language: Language,
|
||||
|
|
@ -25,30 +28,33 @@ pub struct SourceType {
|
|||
}
|
||||
|
||||
/// JavaScript or TypeScript
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum Language {
|
||||
JavaScript,
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
TypeScript {
|
||||
is_definition_file: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// Script or Module
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum ModuleKind {
|
||||
Script,
|
||||
Module,
|
||||
}
|
||||
|
||||
/// JSX for JavaScript and TypeScript
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum LanguageVariant {
|
||||
Standard,
|
||||
Jsx,
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ workspace = true
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
oxc_index = { workspace = true }
|
||||
oxc_span = { workspace = true }
|
||||
oxc_index = { workspace = true }
|
||||
oxc_macros = { workspace = true }
|
||||
oxc_span = { workspace = true }
|
||||
|
||||
unicode-id-start = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"], optional = true }
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
use oxc_macros::SerAttrs;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Compiler assumptions
|
||||
///
|
||||
/// See <https://babeljs.io/docs/assumptions>
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
#[derive(Debug, Default, Clone, Copy, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CompilerAssumptions {
|
||||
/// When using operators that check for null or undefined, assume that they are never used with the special value document.all.
|
||||
/// See <https://babeljs.io/docs/assumptions#nodocumentall>.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
#[serde(default)]
|
||||
pub no_document_all: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use oxc_macros::SerAttrs;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::Serialize;
|
||||
#[cfg(feature = "wasm")]
|
||||
|
|
@ -5,41 +7,41 @@ use tsify::Tsify;
|
|||
|
||||
use crate::precedence::{GetPrecedence, Precedence};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
pub enum AssignmentOperator {
|
||||
#[cfg_attr(feature = "serde", serde(rename = "="))]
|
||||
#[serde(rename = "=")]
|
||||
Assign,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "+="))]
|
||||
#[serde(rename = "+=")]
|
||||
Addition,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "-="))]
|
||||
#[serde(rename = "-=")]
|
||||
Subtraction,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "*="))]
|
||||
#[serde(rename = "*=")]
|
||||
Multiplication,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "/="))]
|
||||
#[serde(rename = "/=")]
|
||||
Division,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "%="))]
|
||||
#[serde(rename = "%=")]
|
||||
Remainder,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "<<="))]
|
||||
#[serde(rename = "<<=")]
|
||||
ShiftLeft,
|
||||
#[cfg_attr(feature = "serde", serde(rename = ">>="))]
|
||||
#[serde(rename = ">>=")]
|
||||
ShiftRight,
|
||||
#[cfg_attr(feature = "serde", serde(rename = ">>>="))]
|
||||
#[serde(rename = ">>>=")]
|
||||
ShiftRightZeroFill,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "|="))]
|
||||
#[serde(rename = "|=")]
|
||||
BitwiseOR,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "^="))]
|
||||
#[serde(rename = "^=")]
|
||||
BitwiseXOR,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "&="))]
|
||||
#[serde(rename = "&=")]
|
||||
BitwiseAnd,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "&&="))]
|
||||
#[serde(rename = "&&=")]
|
||||
LogicalAnd,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "||="))]
|
||||
#[serde(rename = "||=")]
|
||||
LogicalOr,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "??="))]
|
||||
#[serde(rename = "??=")]
|
||||
LogicalNullish,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "**="))]
|
||||
#[serde(rename = "**=")]
|
||||
Exponential,
|
||||
}
|
||||
|
||||
|
|
@ -84,53 +86,53 @@ impl AssignmentOperator {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
pub enum BinaryOperator {
|
||||
#[cfg_attr(feature = "serde", serde(rename = "=="))]
|
||||
#[serde(rename = "==")]
|
||||
Equality,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "!="))]
|
||||
#[serde(rename = "!=")]
|
||||
Inequality,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "==="))]
|
||||
#[serde(rename = "===")]
|
||||
StrictEquality,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "!=="))]
|
||||
#[serde(rename = "!==")]
|
||||
StrictInequality,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "<"))]
|
||||
#[serde(rename = "<")]
|
||||
LessThan,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "<="))]
|
||||
#[serde(rename = "<=")]
|
||||
LessEqualThan,
|
||||
#[cfg_attr(feature = "serde", serde(rename = ">"))]
|
||||
#[serde(rename = ">")]
|
||||
GreaterThan,
|
||||
#[cfg_attr(feature = "serde", serde(rename = ">="))]
|
||||
#[serde(rename = ">=")]
|
||||
GreaterEqualThan,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "<<"))]
|
||||
#[serde(rename = "<<")]
|
||||
ShiftLeft,
|
||||
#[cfg_attr(feature = "serde", serde(rename = ">>"))]
|
||||
#[serde(rename = ">>")]
|
||||
ShiftRight,
|
||||
#[cfg_attr(feature = "serde", serde(rename = ">>>"))]
|
||||
#[serde(rename = ">>>")]
|
||||
ShiftRightZeroFill,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "+"))]
|
||||
#[serde(rename = "+")]
|
||||
Addition,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "-"))]
|
||||
#[serde(rename = "-")]
|
||||
Subtraction,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "*"))]
|
||||
#[serde(rename = "*")]
|
||||
Multiplication,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "/"))]
|
||||
#[serde(rename = "/")]
|
||||
Division,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "%"))]
|
||||
#[serde(rename = "%")]
|
||||
Remainder,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "|"))]
|
||||
#[serde(rename = "|")]
|
||||
BitwiseOR,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "^"))]
|
||||
#[serde(rename = "^")]
|
||||
BitwiseXOR,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "&"))]
|
||||
#[serde(rename = "&")]
|
||||
BitwiseAnd,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "in"))]
|
||||
#[serde(rename = "in")]
|
||||
In,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "instanceof"))]
|
||||
#[serde(rename = "instanceof")]
|
||||
Instanceof,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "**"))]
|
||||
#[serde(rename = "**")]
|
||||
Exponential,
|
||||
}
|
||||
|
||||
|
|
@ -271,15 +273,15 @@ impl GetPrecedence for BinaryOperator {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
pub enum LogicalOperator {
|
||||
#[cfg_attr(feature = "serde", serde(rename = "||"))]
|
||||
#[serde(rename = "||")]
|
||||
Or,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "&&"))]
|
||||
#[serde(rename = "&&")]
|
||||
And,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "??"))]
|
||||
#[serde(rename = "??")]
|
||||
Coalesce,
|
||||
}
|
||||
|
||||
|
|
@ -303,23 +305,23 @@ impl GetPrecedence for LogicalOperator {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
pub enum UnaryOperator {
|
||||
#[cfg_attr(feature = "serde", serde(rename = "-"))]
|
||||
#[serde(rename = "-")]
|
||||
UnaryNegation,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "+"))]
|
||||
#[serde(rename = "+")]
|
||||
UnaryPlus,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "!"))]
|
||||
#[serde(rename = "!")]
|
||||
LogicalNot,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "~"))]
|
||||
#[serde(rename = "~")]
|
||||
BitwiseNot,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "typeof"))]
|
||||
#[serde(rename = "typeof")]
|
||||
Typeof,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "void"))]
|
||||
#[serde(rename = "void")]
|
||||
Void,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "delete"))]
|
||||
#[serde(rename = "delete")]
|
||||
Delete,
|
||||
}
|
||||
|
||||
|
|
@ -349,13 +351,13 @@ impl UnaryOperator {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerAttrs)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[cfg_attr(feature = "wasm", derive(Tsify))]
|
||||
pub enum UpdateOperator {
|
||||
#[cfg_attr(feature = "serde", serde(rename = "++"))]
|
||||
#[serde(rename = "++")]
|
||||
Increment,
|
||||
#[cfg_attr(feature = "serde", serde(rename = "--"))]
|
||||
#[serde(rename = "--")]
|
||||
Decrement,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue