Skip to content

Commit

Permalink
feat: 增加toast transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoyali-0216 committed Aug 1, 2023
1 parent 9f56f36 commit db6d436
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Replacing `<path>` and `<transform>` with appropriate values.
- [x] Table
- [x] Breadcrumb
- [x] Notification
- [ ] message
- [x] message
- [ ] Button
- [ ] Popconfirm
- [ ] Tooltip
Expand Down
35 changes: 35 additions & 0 deletions transforms/Toast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { removeAntdImportAndAddSemiImport } = require('./utils')

export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);

removeAntdImportAndAddSemiImport(j, root, 'message', 'Toast')


// Replace usage of message with Toast
root
.find(j.CallExpression, {
callee: {
object: {
name: 'message'
}
}
})
.replaceWith(nodePath => {
const { node } = nodePath;
const { arguments: args } = node;

if (args.length === 1) {
const [arg] = args;
return j.callExpression(
j.memberExpression(j.identifier('Toast'), j.identifier(node.callee.property.name)),
[arg]
);
}

return node;
});

return root.toSource();
}

0 comments on commit db6d436

Please sign in to comment.