-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE(web-react): Rename TooltipModern to Tooltip
- Loading branch information
1 parent
80cae41
commit 24fb6b0
Showing
50 changed files
with
540 additions
and
1,290 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
9 changes: 9 additions & 0 deletions
9
...emods/src/transforms/v2/web-react/__testfixtures__/tooltipmodern-component-name.input.tsx
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,9 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { TooltipModern } from '@lmc-eu/spirit-web-react'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<TooltipModern>Tooltip</TooltipModern> | ||
</> | ||
); |
9 changes: 9 additions & 0 deletions
9
...mods/src/transforms/v2/web-react/__testfixtures__/tooltipmodern-component-name.output.tsx
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,9 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { Tooltip } from '@lmc-eu/spirit-web-react'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<Tooltip>Tooltip</Tooltip> | ||
</> | ||
); |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/transforms/v2/web-react/__tests__/tooltipmodern-component-name.test.ts
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,3 @@ | ||
import { testTransform } from '../../../../../tests/testUtils'; | ||
|
||
testTransform(__dirname, 'tooltipmodern-component-name'); |
65 changes: 65 additions & 0 deletions
65
packages/codemods/src/transforms/v2/web-react/tooltipmodern-component-name.ts
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,65 @@ | ||
import { API, FileInfo, JSXIdentifier, JSXOpeningElement, JSXClosingElement } from 'jscodeshift'; | ||
|
||
const transform = (fileInfo: FileInfo, api: API) => { | ||
const j = api.jscodeshift; | ||
const root = j(fileInfo.source); | ||
|
||
// Find import statements for the specific module and TooltipModern specifier | ||
const importStatements = root.find(j.ImportDeclaration, { | ||
source: { | ||
value: (value: string) => /^@lmc-eu\/spirit-web-react(\/.*)?$/.test(value), | ||
}, | ||
}); | ||
|
||
// Check if the module is imported | ||
if (importStatements.length > 0) { | ||
const componentSpecifier = importStatements.find(j.ImportSpecifier, { | ||
imported: { | ||
type: 'Identifier', | ||
name: 'TooltipModern', | ||
}, | ||
}); | ||
|
||
// Check if TooltipModern specifier is present | ||
if (componentSpecifier.length > 0) { | ||
// Find opening tags for TooltipModern components | ||
root | ||
.find<JSXOpeningElement>(j.JSXOpeningElement, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'TooltipModern', | ||
}, | ||
}) | ||
.forEach((openingTagPath) => { | ||
// Change component name to 'Tooltip' | ||
if (openingTagPath.node.name.type === 'JSXIdentifier') { | ||
(openingTagPath.node.name as JSXIdentifier).name = 'Tooltip'; | ||
} | ||
}); | ||
|
||
// Find closing tags for TooltipModern components | ||
root | ||
.find<JSXClosingElement>(j.JSXClosingElement, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'TooltipModern', | ||
}, | ||
}) | ||
.forEach((closingTagPath) => { | ||
// Change closing tag name to 'Tooltip' | ||
if (closingTagPath.node.name.type === 'JSXIdentifier') { | ||
(closingTagPath.node.name as JSXIdentifier).name = 'Tooltip'; | ||
} | ||
}); | ||
|
||
// Change 'TooltipModern' to 'Tooltip' in import statement | ||
componentSpecifier.forEach((path) => { | ||
j(path).replaceWith(j.importSpecifier(j.identifier('Tooltip'), j.identifier('Tooltip'))); | ||
}); | ||
} | ||
} | ||
|
||
return root.toSource(); | ||
}; | ||
|
||
export default transform; |
Oops, something went wrong.