-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove redundant expression containers. Added test
- Loading branch information
Showing
9 changed files
with
653 additions
and
28 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
17 changes: 17 additions & 0 deletions
17
packages/cozy-codeshifts/src/transforms/__testfixtures__/apply-flag.input.js
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,17 @@ | ||
import Old from './old' | ||
import New from './old' | ||
import React from 'react' | ||
import flag from 'cozy-flags' | ||
|
||
const Component = () => { | ||
return flag('test-flag') ? <New /> : <Old /> | ||
} | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
{/* My comment */} | ||
{flag('test-flag') ? <Component /> : null} | ||
</div> | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/cozy-codeshifts/src/transforms/__testfixtures__/apply-flag.output.js
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,15 @@ | ||
import New from './old' | ||
import React from 'react' | ||
|
||
const Component = () => { | ||
return <New />; | ||
} | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
{/* My comment */} | ||
<Component /> | ||
</div> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/cozy-codeshifts/src/transforms/__tests__/apply-flag.spec.js
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,2 @@ | ||
const defineTest = require('jscodeshift/dist/testUtils').defineTest | ||
defineTest(__dirname, 'apply-flag') |
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
23 changes: 0 additions & 23 deletions
23
packages/cozy-codeshifts/src/utils/remove-redundant-expression-containers.js
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
packages/cozy-codeshifts/src/utils/remove-redundant-jsx-expression-containers.js
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,22 @@ | ||
/** | ||
* Remove redundant expression containers. | ||
* | ||
* @example | ||
* <div>{<div></div>}</div> -> <div><div></div></div> | ||
* | ||
* @param {PathNode} root | ||
* @param {Object} j | ||
* @return | ||
*/ | ||
const removeRedundantExpressionContainers = (root, j) => { | ||
root.find(j.JSXExpressionContainer).forEach(path => { | ||
if ( | ||
path.parentPath.node.type == 'JSXElement' && | ||
path.node.expression.type === 'JSXElement' | ||
) { | ||
path.replace(path.node.expression) | ||
} | ||
}) | ||
} | ||
|
||
export default removeRedundantExpressionContainers |
Oops, something went wrong.