Skip to content

Commit e11a946

Browse files
BoshenCopilot
andauthored
fix(rust): fix missing docs (#13541)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e1adb0f commit e11a946

File tree

6 files changed

+166
-8
lines changed

6 files changed

+166
-8
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"allow": [
44
"Bash(find:*)",
55
"Bash(cargo check:*)",
6-
"Bash(cargo clippy:*)"
6+
"Bash(ast-grep:*)",
7+
"Bash(rg:*)",
8+
"Bash(cargo clippy:*)",
9+
"Bash(cargo build:*)"
710
],
811
"deny": [],
912
"ask": []

crates/oxc_ast/src/ast/js.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
//! JavaScript AST node definitions
2+
//!
3+
//! This module contains the core AST node definitions for JavaScript syntax including:
4+
//! - Program structure and statements
5+
//! - Expressions and literals
6+
//! - Functions and classes
7+
//! - Patterns and identifiers
8+
//! - Module declarations (import/export)
9+
//! - JSX syntax support
10+
//!
11+
//! The AST design follows ECMAScript specifications while providing
12+
//! clear distinctions between different identifier types for better type safety.
113
#![expect(
2-
missing_docs, // FIXME
14+
missing_docs, // TODO: document individual struct fields
315
clippy::enum_variant_names,
416
clippy::struct_field_names,
517
)]

crates/oxc_ast/src/ast/ts.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
//! TypeScript Definitions
22
//!
3+
//! This module contains AST node definitions for TypeScript syntax including:
4+
//! - Type annotations and declarations
5+
//! - Interfaces and type aliases
6+
//! - Enums and namespaces
7+
//! - TypeScript-specific expressions
8+
//! - Import/export extensions
9+
//!
10+
//! ## References
311
//! - [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/v8.9.0/packages/ast-spec)
412
//! - [Archived TypeScript spec](https://github.com/microsoft/TypeScript/blob/3c99d50da5a579d9fa92d02664b1b66d4ff55944/doc/spec-ARCHIVED.md)
513
#![expect(
6-
missing_docs, // FIXME
14+
missing_docs, // TODO: document individual struct fields
715
clippy::enum_variant_names,
816
)]
917

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
#![expect(missing_docs)] // FIXME
1+
//! Implementation details for AST node kinds
2+
//!
3+
//! This module provides methods and utilities for working with [`AstKind`],
4+
//! including type checking, conversions, and tree traversal helpers.
25
36
use oxc_allocator::{Address, GetAddress};
47
use oxc_span::{Atom, GetSpan};
58

69
use super::{AstKind, ast::*};
710

811
impl<'a> AstKind<'a> {
12+
/// Check if this AST node is a statement
13+
///
14+
/// Returns `true` for all statement types including iteration statements,
15+
/// control flow statements, and declaration statements.
916
#[rustfmt::skip]
1017
pub fn is_statement(self) -> bool {
1118
self.is_iteration_statement()
@@ -16,6 +23,10 @@ impl<'a> AstKind<'a> {
1623
| Self::IfStatement(_) | Self::VariableDeclaration(_) | Self::ExportDefaultDeclaration(_))
1724
}
1825

26+
/// Check if this AST node is a declaration
27+
///
28+
/// Returns `true` for function declarations, class declarations,
29+
/// variable declarations, TypeScript declarations, and module declarations.
1930
#[rustfmt::skip]
2031
pub fn is_declaration(self) -> bool {
2132
matches!(self, Self::Function(func) if func.is_declaration())
@@ -26,10 +37,17 @@ impl<'a> AstKind<'a> {
2637
) || self.is_module_declaration()
2738
}
2839

40+
/// Check if this AST node is a module declaration
41+
///
42+
/// Returns `true` for import/export declarations.
2943
pub fn is_module_declaration(self) -> bool {
3044
self.as_module_declaration_kind().is_some()
3145
}
3246

47+
/// Attempt to convert this AST node to a module declaration kind
48+
///
49+
/// Returns `Some(ModuleDeclarationKind)` if this is a module declaration,
50+
/// `None` otherwise.
3351
pub fn as_module_declaration_kind(&self) -> Option<ModuleDeclarationKind<'a>> {
3452
match self {
3553
Self::ImportDeclaration(decl) => Some(ModuleDeclarationKind::Import(decl)),
@@ -46,19 +64,30 @@ impl<'a> AstKind<'a> {
4664
}
4765
}
4866

67+
/// Check if this AST node is an iteration statement
68+
///
69+
/// Returns `true` for do-while, while, for-in, for-of, and for statements.
4970
#[rustfmt::skip]
5071
pub fn is_iteration_statement(self) -> bool {
5172
matches!(self, Self::DoWhileStatement(_) | Self::WhileStatement(_) | Self::ForInStatement(_)
5273
| Self::ForOfStatement(_) | Self::ForStatement(_))
5374
}
5475

76+
/// Check if this AST node is any kind of identifier
77+
///
78+
/// Returns `true` for binding identifiers, identifier references,
79+
/// and label identifiers.
5580
#[rustfmt::skip]
5681
pub fn is_identifier(self) -> bool {
5782
matches!(self, Self::BindingIdentifier(_)
5883
| Self::IdentifierReference(_)
5984
| Self::LabelIdentifier(_))
6085
}
6186

87+
/// Check if this AST node is a TypeScript type
88+
///
89+
/// Returns `true` for all TypeScript type nodes including keywords,
90+
/// type references, unions, intersections, etc.
6291
#[rustfmt::skip]
6392
pub fn is_type(self) -> bool {
6493
matches!(self, Self::TSAnyKeyword(_) | Self::TSBigIntKeyword(_) | Self::TSBooleanKeyword(_) | Self::TSIntrinsicKeyword(_)
@@ -69,6 +98,10 @@ impl<'a> AstKind<'a> {
6998
| Self::TSTypeLiteral(_) | Self::TSTypeReference(_) | Self::TSUnionType(_))
7099
}
71100

101+
/// Check if this AST node is a literal
102+
///
103+
/// Returns `true` for numeric, string, boolean, null, bigint,
104+
/// regexp, and template literals.
72105
pub fn is_literal(self) -> bool {
73106
matches!(
74107
self,
@@ -82,10 +115,17 @@ impl<'a> AstKind<'a> {
82115
)
83116
}
84117

118+
/// Check if this AST node is function-like
119+
///
120+
/// Returns `true` for function expressions/declarations and arrow functions.
85121
pub fn is_function_like(self) -> bool {
86122
matches!(self, Self::Function(_) | Self::ArrowFunctionExpression(_))
87123
}
88124

125+
/// Get the name of an identifier node
126+
///
127+
/// Returns the identifier name if this is any kind of identifier node,
128+
/// `None` otherwise.
89129
pub fn identifier_name(self) -> Option<Atom<'a>> {
90130
match self {
91131
Self::BindingIdentifier(ident) => Some(ident.name),
@@ -96,6 +136,9 @@ impl<'a> AstKind<'a> {
96136
}
97137
}
98138

139+
/// Check if this is an identifier reference with a specific name
140+
///
141+
/// Returns `true` if this is an `IdentifierReference` with the given name.
99142
pub fn is_specific_id_reference(&self, name: &str) -> bool {
100143
match self {
101144
Self::IdentifierReference(ident) => ident.name == name,
@@ -125,10 +168,17 @@ impl<'a> AstKind<'a> {
125168
}
126169
}
127170

171+
/// Check if this AST node is a property key
172+
///
173+
/// Returns `true` for identifier names and private identifiers used as property keys.
128174
pub fn is_property_key(&self) -> bool {
129175
self.as_property_key_kind().is_some()
130176
}
131177

178+
/// Attempt to convert this AST node to a property key kind
179+
///
180+
/// Returns `Some(PropertyKeyKind)` if this is a property key,
181+
/// `None` otherwise.
132182
pub fn as_property_key_kind(&self) -> Option<PropertyKeyKind<'a>> {
133183
match self {
134184
Self::IdentifierName(ident) => Some(PropertyKeyKind::Static(ident)),
@@ -137,6 +187,9 @@ impl<'a> AstKind<'a> {
137187
}
138188
}
139189

190+
/// Create an `AstKind` from an expression
191+
///
192+
/// Converts any expression type to its corresponding `AstKind` variant.
140193
pub fn from_expression(e: &'a Expression<'a>) -> Self {
141194
match e {
142195
Expression::BooleanLiteral(e) => Self::BooleanLiteral(e),
@@ -649,12 +702,21 @@ impl GetAddress for MemberExpressionKind<'_> {
649702
}
650703
}
651704

705+
/// Module declaration types
706+
///
707+
/// Represents different kinds of module import and export declarations.
652708
pub enum ModuleDeclarationKind<'a> {
709+
/// An import declaration like `import foo from 'bar'`
653710
Import(&'a ImportDeclaration<'a>),
711+
/// An export all declaration like `export * from 'foo'`
654712
ExportAll(&'a ExportAllDeclaration<'a>),
713+
/// A named export declaration like `export { foo, bar }`
655714
ExportNamed(&'a ExportNamedDeclaration<'a>),
715+
/// A default export declaration like `export default foo`
656716
ExportDefault(&'a ExportDefaultDeclaration<'a>),
717+
/// A TypeScript export assignment like `export = foo`
657718
TSExportAssignment(&'a TSExportAssignment<'a>),
719+
/// A TypeScript namespace export like `export as namespace foo`
658720
TSNamespaceExport(&'a TSNamespaceExportDeclaration<'a>),
659721
}
660722

@@ -685,6 +747,9 @@ impl GetSpan for ModuleDeclarationKind<'_> {
685747
}
686748
}
687749

750+
/// Property key types
751+
///
752+
/// Represents different kinds of property keys in objects and classes.
688753
pub enum PropertyKeyKind<'a> {
689754
/// A static identifier property key, like `a` in `{ a: 1 }`.
690755
Static(&'a IdentifierName<'a>),

crates/oxc_ast/src/trivia.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Trivia such as comments and irregular whitespaces
2-
#![expect(missing_docs)] // FIXME
2+
//!
3+
//! This module provides utilities for working with source code comments,
4+
//! including efficient range-based queries and iteration over comment collections.
35
46
use std::{
57
iter::FusedIterator,
@@ -10,18 +12,59 @@ use oxc_span::Span;
1012

1113
use crate::ast::comment::*;
1214

15+
/// Create an iterator over comments within a given range
16+
///
17+
/// Returns a double-ended iterator that yields comments whose starting positions
18+
/// fall within the specified range bounds.
19+
///
20+
/// # Arguments
21+
///
22+
/// * `comments` - A slice of comments sorted by starting position
23+
/// * `range` - The range of positions to filter comments by
24+
///
25+
/// # Examples
26+
///
27+
/// ```ignore
28+
/// let comments_in_range = comments_range(&all_comments, 10..50);
29+
/// for comment in comments_in_range {
30+
/// // Process comments starting between positions 10 and 50
31+
/// }
32+
/// ```
1333
pub fn comments_range<R>(comments: &[Comment], range: R) -> CommentsRange<'_>
1434
where
1535
R: RangeBounds<u32>,
1636
{
1737
CommentsRange::new(comments, range.start_bound().cloned(), range.end_bound().cloned())
1838
}
1939

40+
/// Check if there are any comments within a given span
41+
///
42+
/// Returns `true` if at least one comment starts within the specified span.
43+
///
44+
/// # Arguments
45+
///
46+
/// * `comments` - A slice of comments sorted by starting position
47+
/// * `span` - The span to check for comments
48+
///
49+
/// # Examples
50+
///
51+
/// ```ignore
52+
/// if has_comments_between(&comments, node.span) {
53+
/// // Handle nodes that have comments within their span
54+
/// }
55+
/// ```
2056
pub fn has_comments_between(comments: &[Comment], span: Span) -> bool {
2157
comments_range(comments, span.start..span.end).count() > 0
2258
}
2359

24-
/// Double-ended iterator over a range of comments, by starting position.
60+
/// Double-ended iterator over a range of comments, by starting position
61+
///
62+
/// This iterator efficiently filters comments based on their starting positions,
63+
/// using binary search to skip comments outside the range. It supports both
64+
/// forward and backward iteration.
65+
///
66+
/// The iterator is created using [`comments_range`] and yields references to
67+
/// comments whose `span.start` falls within the specified range bounds.
2568
pub struct CommentsRange<'c> {
2669
comments: &'c [Comment],
2770
range: (Bound<u32>, Bound<u32>),
@@ -30,6 +73,10 @@ pub struct CommentsRange<'c> {
3073
}
3174

3275
impl<'c> CommentsRange<'c> {
76+
/// Create a new iterator over comments in the specified range
77+
///
78+
/// Uses `partition_point` to efficiently skip comments outside the range,
79+
/// avoiding unnecessary iteration over comments that won't be yielded.
3380
fn new(comments: &'c [Comment], start: Bound<u32>, end: Bound<u32>) -> Self {
3481
// Directly skip all comments that are already known to start
3582
// outside the requested range.

crates/oxc_codegen/src/context.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,70 @@
1-
#![expect(missing_docs)] // FIXME
1+
//! Code generation context management
2+
//!
3+
//! This module provides the [`Context`] type for managing the state and configuration
4+
//! during code generation, including JavaScript/TypeScript-specific syntax rules.
25
36
use bitflags::bitflags;
47

58
bitflags! {
9+
/// Code generation context flags
10+
///
11+
/// Controls various aspects of code generation including operator precedence,
12+
/// language features, and syntax restrictions.
613
#[derive(Debug, Default, Clone, Copy)]
714
pub struct Context: u8 {
8-
/// [In]
15+
/// Forbid the `in` operator in expressions
16+
///
17+
/// Used in contexts where the `in` operator could be ambiguous,
18+
/// such as in the init clause of a for loop.
919
const FORBID_IN = 1 << 0;
20+
/// Forbid call expressions
21+
///
22+
/// Used to prevent ambiguity in contexts like new expressions
23+
/// where parentheses could be interpreted differently.
1024
const FORBID_CALL = 1 << 1;
25+
/// Enable TypeScript-specific code generation
26+
///
27+
/// When set, TypeScript syntax features are enabled in the output.
1128
const TYPESCRIPT = 1 << 2;
1229
}
1330
}
1431

1532
impl Context {
33+
/// Check if the `in` operator is forbidden in the current context
1634
#[inline]
1735
pub fn forbid_in(self) -> bool {
1836
self.contains(Self::FORBID_IN)
1937
}
2038

39+
/// Check if call expressions are forbidden in the current context
2140
#[inline]
2241
pub fn forbid_call(self) -> bool {
2342
self.contains(Self::FORBID_CALL)
2443
}
2544

45+
/// Create a new context with TypeScript support enabled
2646
#[inline]
2747
#[must_use]
2848
pub fn with_typescript(mut self) -> Self {
2949
self |= Self::TYPESCRIPT;
3050
self
3151
}
3252

53+
/// Conditionally set or unset the `FORBID_IN` flag
3354
#[inline]
3455
#[must_use]
3556
pub fn and_forbid_in(self, include: bool) -> Self {
3657
self.and(Self::FORBID_IN, include)
3758
}
3859

60+
/// Conditionally set or unset the `FORBID_CALL` flag
3961
#[inline]
4062
#[must_use]
4163
pub fn and_forbid_call(self, include: bool) -> Self {
4264
self.and(Self::FORBID_CALL, include)
4365
}
4466

67+
/// Helper method to conditionally set or unset a flag
4568
#[inline]
4669
fn and(self, flag: Self, set: bool) -> Self {
4770
if set { self | flag } else { self - flag }

0 commit comments

Comments
 (0)