Skip to content

Commit

Permalink
90
Browse files Browse the repository at this point in the history
# 0.0.90

## 🐞 fix

fix: module_member_usage

```jsx
import { Message } from "antd";
export default () => {
  return [
    {
      render: (d) => {
        if (d.status === 2 && d.filePath) {
          return (
            <a
              onClick={async () => {
                Message.success("xxx", 5);
              }}
            >
              hello
            </a>
          );
        }
        return <div>{d.exportName}</div>;
      },
    },
  ];
};
```

before because the `Message` is in `<a>` , so the result member name is `a`.

but now because the `Message` is in `event handler` , so the result member name is `Message`;
  • Loading branch information
ityuany committed Jan 9, 2025
1 parent 10d0d22 commit c8f782e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 28 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# 0.0.90

## 🐞 fix

fix: module_member_usage

```jsx
import { Message } from "antd";
export default () => {
return [
{
render: (d) => {
if (d.status === 2 && d.filePath) {
return (
<a
onClick={async () => {
Message.success("xxx", 5);
}}
>
hello
</a>
);
}
return <div>{d.exportName}</div>;
},
},
];
};
```

before because the `Message` is in `<a>` , so the result member name is `a`.

but now because the `Message` is in `event handler` , so the result member name is `Message`;

# 0.0.89

## 🐞 fix
Expand Down
87 changes: 60 additions & 27 deletions crates/module_member_usage/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,6 @@ fn each_reference<'a>(
reference_node,
);

let opening_node = is_in(
&semantic,
reference_node,
/**10,*/
|kind| matches!(kind, AstKind::JSXOpeningElement(_)),
);

if let Some(AstKind::JSXOpeningElement(kind)) =
opening_node.map(|node| node.kind())
{
let name = get_jsx_opening_element_name(
kind,
is_default_specifier,
is_namespace_specifier,
imported_name.as_str(),
);

let attributes = get_jsx_props(kind);

return Some(ModuleMemberUsageResponseItem {
lib_name: source_name.to_string(),
member_name: name.to_string(),
ast_node: ast_node,
props: attributes,
});
}

let member_parent_node = is_in(
&semantic,
reference_node,
Expand Down Expand Up @@ -216,6 +189,33 @@ fn each_reference<'a>(
});
}

let opening_node = is_in(
&semantic,
reference_node,
/**10,*/
|kind| matches!(kind, AstKind::JSXOpeningElement(_)),
);

if let Some(AstKind::JSXOpeningElement(kind)) =
opening_node.map(|node| node.kind())
{
let name = get_jsx_opening_element_name(
kind,
is_default_specifier,
is_namespace_specifier,
imported_name.as_str(),
);

let attributes = get_jsx_props(kind);

return Some(ModuleMemberUsageResponseItem {
lib_name: source_name.to_string(),
member_name: name.to_string(),
ast_node: ast_node,
props: attributes,
});
}

return Some(ModuleMemberUsageResponseItem {
lib_name: source_name.to_string(),
member_name: imported_name.to_string(),
Expand Down Expand Up @@ -819,4 +819,37 @@ mod tests {
assert_eq!(item.member_name, "Table");
}
}

#[test]
fn test_in_event_handler() {
let result = util(
vec!["antd".to_string()],
&r#"
import { Message } from "antd";
export default () => {
return [
{
render: (d) => {
if (d.status === 2 && d.filePath) {
return (
<a
onClick={async () => {
Message.success("xxx", 5);
}}
>
hello
</a>
);
}
return <div>{d.exportName}</div>;
},
},
];
};
"#,
);
for item in result.iter() {
assert_eq!(item.member_name, "Message");
}
}
}
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.89",
"version": "0.0.90",
"main": "index.js",
"types": "index.d.ts",
"napi": {
Expand Down

0 comments on commit c8f782e

Please sign in to comment.