From 1a612adba93515251298874648dbd9069eb24728 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Tue, 1 Jul 2025 13:47:14 +0000 Subject: [PATCH] docs(semantic): add docs for `JSDoctagTypeNamePart` (#11997) --- .../src/jsdoc/parser/jsdoc_parts.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_parts.rs b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_parts.rs index c6f8869f693b6..089199e7b5c70 100644 --- a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_parts.rs +++ b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_parts.rs @@ -127,13 +127,40 @@ impl<'a> JSDocTagTypePart<'a> { } } +/// Represents a single component of a type name in a JSDoc tag +/// typically seen within unions, generics, or optional/defaulted parameters. +/// +/// This structure captures the raw source string, its span in the original code, +/// and any modifiers like optional (`?`) or default (`=`). +/// +/// For example, in a JSDoc tag like: +/// +/// ```js +/// /** +/// * @param {foo=} bar +/// * ^^^ +/// * This is the `JSDocTagTypeNamePart` +/// * @type {string} [myStr] +/// * ~~~~~~~ This is `optional: true` case +/// * +/// * @property {number} [myNum = 1] +/// * ~~~~~~~~~~~ This is `optional: true` and `default: true` case +/// */ +/// ``` #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct JSDocTagTypeNamePart<'a> { raw: &'a str, + + /// The span in the source text corresponding to this part. pub span: Span, + + /// Indicates whether the type name part is marked as optional (`foo?`). pub optional: bool, + + /// Indicates whether the type name part has a default value (`foo=`). pub default: bool, } + impl<'a> JSDocTagTypeNamePart<'a> { pub fn new(part_content: &'a str, span: Span) -> Self { debug_assert!(part_content.trim() == part_content);