Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(ast): add doc comments to literal nodes #4551

Merged
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
63 changes: 62 additions & 1 deletion crates/oxc_ast/src/ast/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ use serde::Serialize;
#[cfg(feature = "serialize")]
use tsify::Tsify;

/// Boolean literal
///
/// <https://tc39.es/ecma262/#prod-BooleanLiteral>
#[ast(visit)]
#[derive(Debug, Clone, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand All @@ -28,6 +31,9 @@ pub struct BooleanLiteral {
pub value: bool,
}

/// Null literal
///
/// <https://tc39.es/ecma262/#sec-null-literals>
#[ast(visit)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand All @@ -37,31 +43,43 @@ pub struct NullLiteral {
pub span: Span,
}

/// Numeric literal
///
/// <https://tc39.es/ecma262/#sec-literals-numeric-literals>
#[ast(visit)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct NumericLiteral<'a> {
#[serde(flatten)]
pub span: Span,
/// The value of the number, converted into base 10
pub value: f64,
/// The number as it appears in the source code
pub raw: &'a str,
/// The base representation used by the literal in the source code
#[serde(skip)]
pub base: NumberBase,
}

/// BigInt literal
#[ast(visit)]
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct BigIntLiteral<'a> {
#[serde(flatten)]
pub span: Span,
/// The bigint as it appears in the source code
pub raw: Atom<'a>,
/// The base representation used by the literal in the source code
#[serde(skip)]
pub base: BigintBase,
}

/// Regular expression literal
///
/// <https://tc39.es/ecma262/#sec-literals-regular-expression-literals>
#[ast(visit)]
#[derive(Debug, Clone, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand All @@ -75,11 +93,16 @@ pub struct RegExpLiteral<'a> {
pub regex: RegExp<'a>,
}

/// A regular expression
///
/// <https://tc39.es/ecma262/multipage/text-processing.html#sec-regexp-regular-expression-objects>
#[ast]
#[derive(Debug, Clone, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub struct RegExp<'a> {
/// The regex pattern between the slashes
pub pattern: Atom<'a>,
/// Regex flags after the closing slash
pub flags: RegExpFlags,
}

Expand All @@ -88,6 +111,9 @@ pub struct RegExp<'a> {
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub struct EmptyObject;

/// String literal
///
/// <https://tc39.es/ecma262/#sec-literals-string-literals>
#[ast(visit)]
#[derive(Debug, Clone, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand All @@ -99,16 +125,43 @@ pub struct StringLiteral<'a> {
}

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)]
pub struct RegExpFlags: u8 {
/// Global flag
///
/// Causes the pattern to match multiple times.
const G = 1 << 0;
/// Ignore case flag
///
/// Causes the pattern to ignore case.
const I = 1 << 1;
/// Multiline flag
///
/// Causes `^` and `$` to match the start/end of each line.
const M = 1 << 2;
/// DotAll flag
///
/// Causes `.` to also match newlines.
const S = 1 << 3;
/// Unicode flag
///
/// Causes the pattern to treat the input as a sequence of Unicode code points.
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;
/// Indices flag
///
/// Causes the regular expression to generate indices for substring matches.
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;
}
}
Expand All @@ -117,13 +170,21 @@ bitflags! {
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
export type RegExpFlags = {
/** Global flag */
G: 1,
/** Ignore case flag */
I: 2,
/** Multiline flag */
M: 4,
/** DotAll flag */
S: 8,
/** Unicode flag */
U: 16,
/** Sticky flag */
Y: 32,
/** Indices flag */
D: 64,
/** Unicode sets flag */
V: 128
};
"#;
46 changes: 23 additions & 23 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - value
/// - raw
/// - base
/// - value: The value of the number, converted into base 10
/// - raw: The number as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn numeric_literal<S>(
self,
Expand All @@ -101,9 +101,9 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - value
/// - raw
/// - base
/// - value: The value of the number, converted into base 10
/// - raw: The number as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn alloc_numeric_literal<S>(
self,
Expand All @@ -124,8 +124,8 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - raw
/// - base
/// - raw: The bigint as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn big_int_literal<A>(self, span: Span, raw: A, base: BigintBase) -> BigIntLiteral<'a>
where
Expand All @@ -140,8 +140,8 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - raw
/// - base
/// - raw: The bigint as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn alloc_big_int_literal<A>(
self,
Expand Down Expand Up @@ -312,9 +312,9 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - value
/// - raw
/// - base
/// - value: The value of the number, converted into base 10
/// - raw: The number as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn expression_numeric_literal<S>(
self,
Expand Down Expand Up @@ -344,8 +344,8 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - raw
/// - base
/// - raw: The bigint as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn expression_big_int_literal<A>(
self,
Expand Down Expand Up @@ -8153,9 +8153,9 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - value
/// - raw
/// - base
/// - value: The value of the number, converted into base 10
/// - raw: The number as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn ts_enum_member_name_numeric_literal<S>(
self,
Expand Down Expand Up @@ -8293,9 +8293,9 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - value
/// - raw
/// - base
/// - value: The value of the number, converted into base 10
/// - raw: The number as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn ts_literal_numeric_literal<S>(
self,
Expand Down Expand Up @@ -8325,8 +8325,8 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - raw
/// - base
/// - raw: The bigint as it appears in the source code
/// - base: The base representation used by the literal in the source code
#[inline]
pub fn ts_literal_big_int_literal<A>(
self,
Expand Down