-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lili.21
committed
Aug 11, 2023
1 parent
26f4f2e
commit 213961a
Showing
3 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { removeAntdImportAndAddSemiImport } = require('./utils') | ||
|
||
module.exports = function (file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
removeAntdImportAndAddSemiImport(j, root, 'Select', 'Select') | ||
|
||
// Find all Select JSXElements | ||
const selectElements = root.findJSXElements('Select') | ||
|
||
selectElements.forEach((element) => { | ||
const { openingElement } = element.node | ||
|
||
// options -> optionList | ||
const optionsAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'options' | ||
) | ||
if (optionsAttribute) { | ||
optionsAttribute.name.name = 'optionList' | ||
} | ||
|
||
// mode="multiple" -> multiple | ||
const modeAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'mode' && attr.value.value === 'multiple' | ||
) | ||
if (modeAttribute) { | ||
openingElement.attributes = openingElement.attributes.filter( | ||
(attr) => attr !== modeAttribute | ||
) | ||
openingElement.attributes.push( | ||
j.jsxAttribute(j.jsxIdentifier('multiple')) | ||
) | ||
} | ||
|
||
// showSearch -> filter | ||
const showSearchAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'showSearch' | ||
) | ||
if (showSearchAttribute) { | ||
showSearchAttribute.name.name = 'filter' | ||
} | ||
|
||
// filterOption处理 | ||
const filterOptionAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'filterOption' | ||
) | ||
if (filterOptionAttribute) { | ||
openingElement.attributes = openingElement.attributes.filter( | ||
(attr) => attr !== filterOptionAttribute | ||
) | ||
if (filterOptionAttribute.value.expression.value === false) { | ||
openingElement.attributes.push( | ||
j.jsxAttribute(j.jsxIdentifier('remote')) | ||
) | ||
} else { | ||
showSearchAttribute.value = filterOptionAttribute.value | ||
} | ||
} | ||
|
||
// notFoundContent -> emptyContent | ||
const notFoundContentAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'notFoundContent' | ||
) | ||
if (notFoundContentAttribute) { | ||
notFoundContentAttribute.name.name = 'emptyContent' | ||
} | ||
}) | ||
|
||
return root.toSource() | ||
} |