diff --git a/README.md b/README.md index b07bcba..3a34400 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Replacing `` and `` with appropriate values. - [x] Table - [x] Breadcrumb - [x] Notification -- [ ] message +- [x] message - [ ] Button - [ ] Popconfirm - [ ] Tooltip diff --git a/transforms/Toast.js b/transforms/Toast.js new file mode 100644 index 0000000..0b9b3ab --- /dev/null +++ b/transforms/Toast.js @@ -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(); +}