This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make the babel plugin configurable through options (#27)
* feat: Make the babel plugin configurable through options * Add changeset
- Loading branch information
Showing
9 changed files
with
136 additions
and
27 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 @@ | ||
--- | ||
"@react-unforget/babel-plugin": minor | ||
--- | ||
|
||
Make the babel plugin configurable through options |
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 |
---|---|---|
@@ -1 +1,23 @@ | ||
# `@react-unforget/compiler` | ||
# `@react-unforget/babel-plugin` | ||
|
||
To use the babel plugin, you need to install it and add it to your Babel configuration. | ||
|
||
```sh | ||
npm install --save-dev @react-unforget/babel-plugin | ||
``` | ||
|
||
Then, add it to your Babel configuration. For example, in your `.babelrc`: | ||
|
||
```json | ||
{ | ||
"plugins": ["@react-unforget/babel-plugin"] | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
The babel plugin accepts a few options: | ||
|
||
- `throwOnFailure` (default: `false`): If `true`, the plugin will throw an error if it fails to analyze the component / hook. | ||
- `skipComponents` (default: `[]`): An array of component names to skip. For example, `["MyComponent"]`. | ||
- `skipComponentsWithMutation` (default: `false`): If `true`, the plugin will skip components that have variables that are mutated e.g. `array.push()` or variable re-assignment. This is configurable because despite thorough testing, we are still not 100% sure that this is safe to do in all cases. |
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,24 @@ | ||
export interface Options { | ||
throwOnFailure?: boolean; | ||
skipComponents?: string[]; | ||
skipComponentsWithMutation?: boolean; | ||
} | ||
|
||
export function makeTransformationContext({ | ||
throwOnFailure = true, | ||
skipComponents = [], | ||
skipComponentsWithMutation = false, | ||
}: Options = {}) { | ||
return { | ||
throwOnFailure, | ||
skipComponents, | ||
skipComponentsWithMutation, | ||
shouldSkipComponent(componentName: string) { | ||
return skipComponents.includes(componentName); | ||
}, | ||
}; | ||
} | ||
|
||
export type TransformationContext = ReturnType< | ||
typeof makeTransformationContext | ||
>; |
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