Files
Kigi-CLI/crates/codegen/kigi-codebase-graph/src/languages/javascript.rs
T
ZacharyZhang-NY a02b555e66 docs(comments): rewrite comments across all crates to the guidelines
Sweep every first-party crate source (1956 .rs files) to the project comment
guidelines: delete redundant restatements, decorative banners, change
narration, and end-of-line comments; keep and tighten the crucial ones
(invariants, bug rationale, SAFETY blocks, ported-source attribution).

No functional code changed. Every edit is proven comment-only against the
prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a
separate doctest-fence check. Where removing a comment made rustfmt or clippy
want to re-lay-out adjacent code, the minimal triggering comment is restored so
code tokens stay byte-identical.

Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy
--workspace --all-targets (0 warnings).

Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for
these guidelines (flags banners, end-of-line comments, change narration, and
commented-out code).
2026-07-23 16:55:39 -04:00

93 lines
3.0 KiB
Rust

use crate::languages::types::TSLanguageConfig;
pub fn js_lang() -> TSLanguageConfig {
TSLanguageConfig::new(
vec![
"JavaScript".to_owned(),
"javascript".to_owned(),
"js".to_owned(),
"jsx".to_owned(),
],
vec!["js".to_owned(), "jsx".to_owned()],
vec![vec![
"function".to_owned(),
"class".to_owned(),
"variable".to_owned(),
"const".to_owned(),
"let".to_owned(),
]],
r#"
; Class definitions
(class_declaration
name: (identifier) @name.definition.class) @definition.class
; Function definitions
(function_declaration
name: (identifier) @name.definition.function) @definition.function
; Arrow function with variable
(lexical_declaration
(variable_declarator
name: (identifier) @name.definition.function
value: (arrow_function))) @definition.function
; Method definitions
(method_definition
name: (property_identifier) @name.definition.method) @definition.method
; Variable declarations
(lexical_declaration
(variable_declarator
name: (identifier) @name.definition.variable)) @definition.variable
; Var declarations
(variable_declaration
(variable_declarator
name: (identifier) @name.definition.variable)) @definition.variable
; ============ REFERENCES ============
; Function calls
(call_expression
function: (identifier) @name.reference.call) @reference.call
; Method calls
(call_expression
function: (member_expression
property: (property_identifier) @name.reference.call)) @reference.call
; JSX element names
(jsx_opening_element
name: (identifier) @name.reference.jsx)
(jsx_self_closing_element
name: (identifier) @name.reference.jsx)
; ============ IMPORTS ============
; Named imports: import { Foo } from 'bar'
(import_specifier
name: (identifier) @name.reference.import)
; Default import: import Foo from 'bar'
(import_clause
(identifier) @name.reference.import)
; Import alias: import { Foo as Bar } from 'bar'
(import_specifier
name: (identifier) @alias.original
alias: (identifier) @alias.name)
; Named exports: export { Foo }
(export_specifier
name: (identifier) @name.reference.export)
; Array element identifiers: [foo, bar] (e.g., React useCallback/useEffect dependency arrays)
(array
(identifier) @name.reference.variable)
"#
.to_owned(),
|| tree_sitter_javascript::LANGUAGE.into(),
)
}