Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Nov 21, 2024
1 parent dc09667 commit d2e2818
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions crates/module_member_usage/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ impl<'a> ModuleMemberUsageHandler<'a> {
}
};

let is_specifier = match specifier {
ImportDeclarationSpecifier::ImportSpecifier(import_specifier) => {
!(import_specifier.imported.name() == "default")
}
ImportDeclarationSpecifier::ImportDefaultSpecifier(_)
| ImportDeclarationSpecifier::ImportNamespaceSpecifier(_) => false,
};

mapper.insert(local_name, imported_name);

let references = self
Expand Down Expand Up @@ -117,6 +125,16 @@ impl<'a> ModuleMemberUsageHandler<'a> {
});

if is_in_member_expr {
if is_specifier {
inline_usages.push(Response {
lib_name: source_name.to_string(),
member_name: imported_name.to_string(),
file_path: self.path_str.clone(),
ast_node: AstNode::new((span.start, span.end), loc),
});
continue;
}

// JSXMemberExpressionObject
let parent_node =
self.semantic_handler.get_parent_node(reference_node);
Expand Down Expand Up @@ -223,6 +241,31 @@ mod tests {
use std::path::PathBuf;
use utils::SemanticBuilder;

#[test]
fn test_form_item() {
let file_path_str = PathBuf::from("file_path_str");
let semantic_builder = SemanticBuilder::js(
&r#"
import {Form} from 'shineout';
function App(){
return (
<Form>
<Form.Item></Form.Item>
</Form>
)
}
"#,
);
let semantic_handler = semantic_builder.build_handler();
let handler = ModuleMemberUsageHandler::new(
vec!["shineout".to_string()],
file_path_str,
semantic_handler.unwrap(),
);
let result = handler.handle();
assert_eq!(result.len(), 2);
}

#[test]
fn test_computed_member_with_template() {
let file_path_str = PathBuf::from("file_path_str");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shined/source-code-diagnosis",
"version": "0.0.58",
"version": "0.0.59",
"main": "index.js",
"types": "index.d.ts",
"napi": {
Expand Down

0 comments on commit d2e2818

Please sign in to comment.