mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
docs(ast): add doc comments to literal nodes (#4551)
This commit is contained in:
parent
72337b1063
commit
0914e47660
2 changed files with 85 additions and 24 deletions
|
|
@ -18,6 +18,9 @@ use serde::Serialize;
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
use tsify::Tsify;
|
use tsify::Tsify;
|
||||||
|
|
||||||
|
/// Boolean literal
|
||||||
|
///
|
||||||
|
/// <https://tc39.es/ecma262/#prod-BooleanLiteral>
|
||||||
#[ast(visit)]
|
#[ast(visit)]
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
|
|
@ -28,6 +31,9 @@ pub struct BooleanLiteral {
|
||||||
pub value: bool,
|
pub value: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Null literal
|
||||||
|
///
|
||||||
|
/// <https://tc39.es/ecma262/#sec-null-literals>
|
||||||
#[ast(visit)]
|
#[ast(visit)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
|
|
@ -37,6 +43,9 @@ pub struct NullLiteral {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Numeric literal
|
||||||
|
///
|
||||||
|
/// <https://tc39.es/ecma262/#sec-literals-numeric-literals>
|
||||||
#[ast(visit)]
|
#[ast(visit)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
|
|
@ -44,12 +53,16 @@ pub struct NullLiteral {
|
||||||
pub struct NumericLiteral<'a> {
|
pub struct NumericLiteral<'a> {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
/// The value of the number, converted into base 10
|
||||||
pub value: f64,
|
pub value: f64,
|
||||||
|
/// The number as it appears in the source code
|
||||||
pub raw: &'a str,
|
pub raw: &'a str,
|
||||||
|
/// The base representation used by the literal in the source code
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub base: NumberBase,
|
pub base: NumberBase,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// BigInt literal
|
||||||
#[ast(visit)]
|
#[ast(visit)]
|
||||||
#[derive(Debug, Hash)]
|
#[derive(Debug, Hash)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
|
|
@ -57,11 +70,16 @@ pub struct NumericLiteral<'a> {
|
||||||
pub struct BigIntLiteral<'a> {
|
pub struct BigIntLiteral<'a> {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
/// The bigint as it appears in the source code
|
||||||
pub raw: Atom<'a>,
|
pub raw: Atom<'a>,
|
||||||
|
/// The base representation used by the literal in the source code
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub base: BigintBase,
|
pub base: BigintBase,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Regular expression literal
|
||||||
|
///
|
||||||
|
/// <https://tc39.es/ecma262/#sec-literals-regular-expression-literals>
|
||||||
#[ast(visit)]
|
#[ast(visit)]
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
|
|
@ -75,11 +93,16 @@ pub struct RegExpLiteral<'a> {
|
||||||
pub regex: RegExp<'a>,
|
pub regex: RegExp<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A regular expression
|
||||||
|
///
|
||||||
|
/// <https://tc39.es/ecma262/multipage/text-processing.html#sec-regexp-regular-expression-objects>
|
||||||
#[ast]
|
#[ast]
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
pub struct RegExp<'a> {
|
pub struct RegExp<'a> {
|
||||||
|
/// The regex pattern between the slashes
|
||||||
pub pattern: Atom<'a>,
|
pub pattern: Atom<'a>,
|
||||||
|
/// Regex flags after the closing slash
|
||||||
pub flags: RegExpFlags,
|
pub flags: RegExpFlags,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,6 +111,9 @@ pub struct RegExp<'a> {
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
pub struct EmptyObject;
|
pub struct EmptyObject;
|
||||||
|
|
||||||
|
/// String literal
|
||||||
|
///
|
||||||
|
/// <https://tc39.es/ecma262/#sec-literals-string-literals>
|
||||||
#[ast(visit)]
|
#[ast(visit)]
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
|
||||||
|
|
@ -99,16 +125,43 @@ pub struct StringLiteral<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
/// Regular expression flags.
|
||||||
|
///
|
||||||
|
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags>
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct RegExpFlags: u8 {
|
pub struct RegExpFlags: u8 {
|
||||||
|
/// Global flag
|
||||||
|
///
|
||||||
|
/// Causes the pattern to match multiple times.
|
||||||
const G = 1 << 0;
|
const G = 1 << 0;
|
||||||
|
/// Ignore case flag
|
||||||
|
///
|
||||||
|
/// Causes the pattern to ignore case.
|
||||||
const I = 1 << 1;
|
const I = 1 << 1;
|
||||||
|
/// Multiline flag
|
||||||
|
///
|
||||||
|
/// Causes `^` and `$` to match the start/end of each line.
|
||||||
const M = 1 << 2;
|
const M = 1 << 2;
|
||||||
|
/// DotAll flag
|
||||||
|
///
|
||||||
|
/// Causes `.` to also match newlines.
|
||||||
const S = 1 << 3;
|
const S = 1 << 3;
|
||||||
|
/// Unicode flag
|
||||||
|
///
|
||||||
|
/// Causes the pattern to treat the input as a sequence of Unicode code points.
|
||||||
const U = 1 << 4;
|
const U = 1 << 4;
|
||||||
|
/// Sticky flag
|
||||||
|
///
|
||||||
|
/// Perform a "sticky" search that matches starting at the current position in the target string.
|
||||||
const Y = 1 << 5;
|
const Y = 1 << 5;
|
||||||
|
/// Indices flag
|
||||||
|
///
|
||||||
|
/// Causes the regular expression to generate indices for substring matches.
|
||||||
const D = 1 << 6;
|
const D = 1 << 6;
|
||||||
/// v flag from `https://github.com/tc39/proposal-regexp-set-notation`
|
/// Unicode sets flag
|
||||||
|
///
|
||||||
|
/// Similar to the `u` flag, but also enables the `\\p{}` and `\\P{}` syntax.
|
||||||
|
/// Added by the [`v` flag proposal](https://github.com/tc39/proposal-regexp-set-notation).
|
||||||
const V = 1 << 7;
|
const V = 1 << 7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -117,13 +170,21 @@ bitflags! {
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
|
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
|
||||||
const TS_APPEND_CONTENT: &'static str = r#"
|
const TS_APPEND_CONTENT: &'static str = r#"
|
||||||
export type RegExpFlags = {
|
export type RegExpFlags = {
|
||||||
|
/** Global flag */
|
||||||
G: 1,
|
G: 1,
|
||||||
|
/** Ignore case flag */
|
||||||
I: 2,
|
I: 2,
|
||||||
|
/** Multiline flag */
|
||||||
M: 4,
|
M: 4,
|
||||||
|
/** DotAll flag */
|
||||||
S: 8,
|
S: 8,
|
||||||
|
/** Unicode flag */
|
||||||
U: 16,
|
U: 16,
|
||||||
|
/** Sticky flag */
|
||||||
Y: 32,
|
Y: 32,
|
||||||
|
/** Indices flag */
|
||||||
D: 64,
|
D: 64,
|
||||||
|
/** Unicode sets flag */
|
||||||
V: 128
|
V: 128
|
||||||
};
|
};
|
||||||
"#;
|
"#;
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,9 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - value
|
/// - value: The value of the number, converted into base 10
|
||||||
/// - raw
|
/// - raw: The number as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn numeric_literal<S>(
|
pub fn numeric_literal<S>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -101,9 +101,9 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - value
|
/// - value: The value of the number, converted into base 10
|
||||||
/// - raw
|
/// - raw: The number as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn alloc_numeric_literal<S>(
|
pub fn alloc_numeric_literal<S>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -124,8 +124,8 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - raw
|
/// - raw: The bigint as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn big_int_literal<A>(self, span: Span, raw: A, base: BigintBase) -> BigIntLiteral<'a>
|
pub fn big_int_literal<A>(self, span: Span, raw: A, base: BigintBase) -> BigIntLiteral<'a>
|
||||||
where
|
where
|
||||||
|
|
@ -140,8 +140,8 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - raw
|
/// - raw: The bigint as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn alloc_big_int_literal<A>(
|
pub fn alloc_big_int_literal<A>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -312,9 +312,9 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - value
|
/// - value: The value of the number, converted into base 10
|
||||||
/// - raw
|
/// - raw: The number as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expression_numeric_literal<S>(
|
pub fn expression_numeric_literal<S>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -344,8 +344,8 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - raw
|
/// - raw: The bigint as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expression_big_int_literal<A>(
|
pub fn expression_big_int_literal<A>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -8153,9 +8153,9 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - value
|
/// - value: The value of the number, converted into base 10
|
||||||
/// - raw
|
/// - raw: The number as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ts_enum_member_name_numeric_literal<S>(
|
pub fn ts_enum_member_name_numeric_literal<S>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -8293,9 +8293,9 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - value
|
/// - value: The value of the number, converted into base 10
|
||||||
/// - raw
|
/// - raw: The number as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ts_literal_numeric_literal<S>(
|
pub fn ts_literal_numeric_literal<S>(
|
||||||
self,
|
self,
|
||||||
|
|
@ -8325,8 +8325,8 @@ impl<'a> AstBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - span: The [`Span`] covering this node
|
/// - span: The [`Span`] covering this node
|
||||||
/// - raw
|
/// - raw: The bigint as it appears in the source code
|
||||||
/// - base
|
/// - base: The base representation used by the literal in the source code
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ts_literal_big_int_literal<A>(
|
pub fn ts_literal_big_int_literal<A>(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue