Move plugin processing to top of plugins (#6381)
* centralize plugin options * Centralize plugins options - move more options to the top - move validations that depend on options to the top * use isLoose option * Move more validations to the top * Move ref parameter for rewriteModuleStatementsAndPrepareHeader() to the top * fix eslint errors * remove unused parameter * set default systemGlobal value * Revert "Move ref parameter for rewriteModuleStatementsAndPrepareHeader() to the top" This reverts commit b3855302d17fa19d8acb4c8accab3680c8d2710e. * Revert "Move more validations to the top" This reverts commit e5861d8a034ff8f553391f55654f753bcf428a5d. * fix allowMutablePropsOnTags option usage * improve naming * change Contructor definition for sake of consistency * move allowMutablePropsOnTags validation to the top * add missing !
This commit is contained in:
committed by
Logan Smyth
parent
d89063bb32
commit
fcdfc61bdb
@@ -1,4 +1,15 @@
|
||||
export default function transformReactConstantElement({ types: t }) {
|
||||
export default function transformReactConstantElement({ types: t }, options) {
|
||||
const { allowMutablePropsOnTags } = options;
|
||||
|
||||
if (
|
||||
allowMutablePropsOnTags != null &&
|
||||
!Array.isArray(allowMutablePropsOnTags)
|
||||
) {
|
||||
throw new Error(
|
||||
".allowMutablePropsOnTags must be an array, null, or undefined.",
|
||||
);
|
||||
}
|
||||
|
||||
const HOISTED = new WeakSet();
|
||||
|
||||
const immutabilityVisitor = {
|
||||
@@ -71,12 +82,7 @@ export default function transformReactConstantElement({ types: t }) {
|
||||
// This transform takes the option `allowMutablePropsOnTags`, which is an array
|
||||
// of JSX tags to allow mutable props (such as objects, functions) on. Use sparingly
|
||||
// and only on tags you know will never modify their own props.
|
||||
if (this.opts.allowMutablePropsOnTags != null) {
|
||||
if (!Array.isArray(this.opts.allowMutablePropsOnTags)) {
|
||||
throw new Error(
|
||||
".allowMutablePropsOnTags must be an array, null, or undefined.",
|
||||
);
|
||||
}
|
||||
if (allowMutablePropsOnTags != null) {
|
||||
// Get the element's name. If it's a member expression, we use the last part of the path.
|
||||
// So the option ["FormattedMessage"] would match "Intl.FormattedMessage".
|
||||
let namePath = path.get("openingElement.name");
|
||||
@@ -86,7 +92,7 @@ export default function transformReactConstantElement({ types: t }) {
|
||||
|
||||
const elementName = namePath.node.name;
|
||||
state.mutablePropsAllowed =
|
||||
this.opts.allowMutablePropsOnTags.indexOf(elementName) > -1;
|
||||
allowMutablePropsOnTags.indexOf(elementName) > -1;
|
||||
}
|
||||
|
||||
// Traverse all props passed to this element for immutability.
|
||||
|
||||
Reference in New Issue
Block a user