use std::{cell::Cell, hash::Hash};
use bitflags::bitflags;
use oxc_allocator::{Box, CloneIn, Dummy, TakeIn, UnstableAddress};
use oxc_ast_macros::ast;
use oxc_estree::ESTree;
use oxc_regular_expression::ast::Pattern;
use oxc_span::{ContentEq, GetSpan, GetSpanMut, Span};
use oxc_str::Str;
use oxc_syntax::{
node::NodeId,
number::{BigintBase, NumberBase},
};
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
#[estree(rename = "Literal", add_fields(raw = BooleanLiteralRaw))]
pub struct BooleanLiteral {
pub node_id: Cell<NodeId>,
pub span: Span,
pub value: bool,
}
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
#[estree(rename = "Literal", add_fields(value = Null, raw = NullLiteralRaw))]
pub struct NullLiteral {
pub node_id: Cell<NodeId>,
pub span: Span,
}
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, Dummy, TakeIn, ContentEq, GetSpan, GetSpanMut, ESTree, UnstableAddress)]
#[estree(rename = "Literal")]
pub struct NumericLiteral<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub value: f64,
#[content_eq(skip)]
#[estree(json_safe, from_span)]
pub raw: Option<Str<'a>>,
#[content_eq(skip)]
#[estree(skip)]
pub base: NumberBase,
}
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, Dummy, TakeIn, ContentEq, GetSpan, GetSpanMut, ESTree, UnstableAddress)]
#[estree(rename = "Literal")]
pub struct StringLiteral<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
#[estree(via = StringLiteralValue)]
pub value: Str<'a>,
#[content_eq(skip)]
#[estree(from_span)]
pub raw: Option<Str<'a>>,
#[builder(default)]
#[estree(skip)]
pub lone_surrogates: bool,
}
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, Dummy, TakeIn, ContentEq, GetSpan, GetSpanMut, ESTree, UnstableAddress)]
#[estree(rename = "Literal", add_fields(bigint = BigIntLiteralBigint))]
pub struct BigIntLiteral<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
#[estree(via = BigIntLiteralValue)]
pub value: Str<'a>,
#[content_eq(skip)]
#[estree(json_safe, from_span)]
pub raw: Option<Str<'a>>,
#[content_eq(skip)]
#[estree(skip)]
pub base: BigintBase,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, ContentEq, GetSpan, GetSpanMut, ESTree, UnstableAddress)]
#[estree(
rename = "Literal",
add_fields(value = RegExpLiteralValue),
field_order(value, raw, regex, span),
)]
pub struct RegExpLiteral<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub regex: RegExp<'a>,
#[content_eq(skip)]
#[estree(from_span)]
pub raw: Option<Str<'a>>,
}
#[ast]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, ContentEq, ESTree)]
#[estree(no_type, ts_alias = "{ pattern: string; flags: string; }")]
pub struct RegExp<'a> {
pub pattern: RegExpPattern<'a>,
pub flags: RegExpFlags,
}
#[ast]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, ContentEq, ESTree)]
#[estree(no_type, flatten)]
pub struct RegExpPattern<'a> {
#[estree(rename = "pattern")]
pub text: Str<'a>,
#[content_eq(skip)]
#[estree(skip)]
pub pattern: Option<Box<'a, Pattern<'a>>>,
}
pub const REGEXP_FLAGS_LIST: &str = "gimsuydv";
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RegExpFlags: u8 {
const G = 1 << 0;
const I = 1 << 1;
const M = 1 << 2;
const S = 1 << 3;
const U = 1 << 4;
const Y = 1 << 5;
const D = 1 << 6;
const V = 1 << 7;
}
}
#[ast(foreign = RegExpFlags)]
#[generate_derive(ESTree)]
#[estree(no_type, via = RegExpFlagsConverter)]
#[expect(dead_code)]
struct RegExpFlagsAlias(#[estree(skip)] u8);