Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
- Loading branch information
Showing
42 changed files
with
395 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"types-react-codemod": minor | ||
--- | ||
|
||
Add `preset-18` codemod |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
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,77 @@ | ||
import contextAnyTransform from "./context-any"; | ||
import deprecatedReactTypeTransform from "./deprecated-react-type"; | ||
import deprecatedSFCTransform from "./deprecated-sfc"; | ||
import deprecatedSFCElementTransform from "./deprecated-sfc-element"; | ||
import deprecatedStatelessComponentTransform from "./deprecated-stateless-component"; | ||
import implicitChildrenTransform from "./implicit-children"; | ||
import implicitAnyTransform from "./useCallback-implicit-any"; | ||
|
||
/** | ||
* @type {import('jscodeshift').Transform} | ||
* test: https://astexplorer.net/#/gist/efb6993a6dda29edfa15087323d95d8b/649afe43341d87843b0e90d737ceefc8f90c321b | ||
* | ||
* Summary for Klarna's klapp@19fc4dafed84670398644298bf19c8c2a781dcf8/clients | ||
* 28172 Files unmodified | ||
* 11 skipped | ||
* 5 Ok | ||
* 1 false-positive due to `this.props.context` access | ||
* 2 false-positive due to `path['context']` access | ||
* 1 false-positive due to `constructor(props, context)` | ||
*/ | ||
const transform = (file, api, options) => { | ||
const { preset18Transforms } = options; | ||
|
||
const transformNames = new Set(preset18Transforms.split(",")); | ||
/** | ||
* @type {import('jscodeshift').Transform[]} | ||
*/ | ||
const transforms = []; | ||
if (transformNames.has("context-any")) { | ||
transforms.push(contextAnyTransform); | ||
} | ||
if (transformNames.has("deprecated-react-type")) { | ||
transforms.push(deprecatedReactTypeTransform); | ||
} | ||
if (transformNames.has("deprecated-sfc")) { | ||
transforms.push(deprecatedSFCTransform); | ||
} | ||
if (transformNames.has("deprecated-sfc-element")) { | ||
transforms.push(deprecatedSFCElementTransform); | ||
} | ||
if (transformNames.has("deprecated-stateless-component")) { | ||
transforms.push(deprecatedStatelessComponentTransform); | ||
} | ||
if (transformNames.has("implicit-children")) { | ||
transforms.push(implicitChildrenTransform); | ||
} | ||
if (transformNames.has("useCallback-implicit-any")) { | ||
transforms.push(implicitAnyTransform); | ||
} | ||
|
||
console.log(transformNames, transforms); | ||
|
||
let wasAlwaysSkipped = true; | ||
const newSource = transforms.reduce((currentFileSource, transform) => { | ||
// TODO: currently we parse -> transform -> print on every transform | ||
// Instead, we could parse and prince once in the preset and the transformers just deal with an AST. | ||
// That requires refactoring of every transform into source-transformer and ast-transformer | ||
const transformResult = transform( | ||
{ path: file.path, source: currentFileSource }, | ||
api, | ||
options | ||
); | ||
|
||
if (transformResult == null) { | ||
return currentFileSource; | ||
} else { | ||
wasAlwaysSkipped = false; | ||
return transformResult; | ||
} | ||
}, file.source); | ||
|
||
if (!wasAlwaysSkipped) { | ||
return newSource; | ||
} | ||
}; | ||
|
||
export default transform; |
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
Oops, something went wrong.