mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
feat(ast/semantic): parse jsdoc on PropertyDefinition (#1517)
This should be enough to handle jsdoc comments on class properties/fields. See #1506
This commit is contained in:
parent
490a589ded
commit
0115314cf4
2 changed files with 17 additions and 6 deletions
|
|
@ -183,7 +183,7 @@ impl<'a> AstKind<'a> {
|
||||||
|| matches!(self, Self::Class(class) if class.is_declaration())
|
|| matches!(self, Self::Class(class) if class.is_declaration())
|
||||||
|| matches!(self, Self::ModuleDeclaration(_) | Self::TSEnumDeclaration(_) | Self::TSModuleDeclaration(_)
|
|| matches!(self, Self::ModuleDeclaration(_) | Self::TSEnumDeclaration(_) | Self::TSModuleDeclaration(_)
|
||||||
| Self::VariableDeclaration(_) | Self::TSInterfaceDeclaration(_)
|
| Self::VariableDeclaration(_) | Self::TSInterfaceDeclaration(_)
|
||||||
| Self::TSTypeAliasDeclaration(_) | Self::TSImportEqualsDeclaration(_)
|
| Self::TSTypeAliasDeclaration(_) | Self::TSImportEqualsDeclaration(_) | Self::PropertyDefinition(_)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,9 @@ mod test {
|
||||||
allocator: &'a Allocator,
|
allocator: &'a Allocator,
|
||||||
source_text: &'a str,
|
source_text: &'a str,
|
||||||
symbol: &'a str,
|
symbol: &'a str,
|
||||||
|
source_type: Option<SourceType>,
|
||||||
) -> Option<JSDocComment<'a>> {
|
) -> Option<JSDocComment<'a>> {
|
||||||
let source_type = SourceType::default();
|
let source_type = source_type.unwrap_or_default();
|
||||||
let ret = Parser::new(allocator, source_text, source_type).parse();
|
let ret = Parser::new(allocator, source_text, source_type).parse();
|
||||||
let program = allocator.alloc(ret.program);
|
let program = allocator.alloc(ret.program);
|
||||||
let semantic = SemanticBuilder::new(source_text, source_type)
|
let semantic = SemanticBuilder::new(source_text, source_type)
|
||||||
|
|
@ -92,10 +93,10 @@ mod test {
|
||||||
jsdoc.get_by_span(span)
|
jsdoc.get_by_span(span)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_jsdoc(source_text: &str, symbol: &str) {
|
fn test_jsdoc(source_text: &str, symbol: &str, source_type: Option<SourceType>) {
|
||||||
let allocator = Allocator::default();
|
let allocator = Allocator::default();
|
||||||
assert!(
|
assert!(
|
||||||
get_jsdoc(&allocator, source_text, symbol).is_some(),
|
get_jsdoc(&allocator, source_text, symbol, source_type).is_some(),
|
||||||
"{symbol} not found in {source_text}"
|
"{symbol} not found in {source_text}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +104,7 @@ mod test {
|
||||||
fn test_jsdoc_not_found(source_text: &str, symbol: &str) {
|
fn test_jsdoc_not_found(source_text: &str, symbol: &str) {
|
||||||
let allocator = Allocator::default();
|
let allocator = Allocator::default();
|
||||||
assert!(
|
assert!(
|
||||||
get_jsdoc(&allocator, source_text, symbol).is_none(),
|
get_jsdoc(&allocator, source_text, symbol, None).is_none(),
|
||||||
"{symbol} found in {source_text}"
|
"{symbol} found in {source_text}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +140,17 @@ mod test {
|
||||||
function foo() {}",
|
function foo() {}",
|
||||||
];
|
];
|
||||||
for source_text in source_texts {
|
for source_text in source_texts {
|
||||||
test_jsdoc(source_text, "function foo() {}");
|
test_jsdoc(source_text, "function foo() {}", None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn found_on_property_definition() {
|
||||||
|
let source = "class Foo {
|
||||||
|
/** jsdoc */
|
||||||
|
bar: string;
|
||||||
|
}";
|
||||||
|
let source_type = SourceType::default().with_typescript(true);
|
||||||
|
test_jsdoc(source, "bar: string;", Some(source_type));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue