Files
formipay/node_modules/@wordpress/warning/babel-plugin.js
dwindown e8fbfb14c1 fix: prevent asset conflicts between React and Grid.js versions
Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 17:02:14 +07:00

86 lines
2.0 KiB
JavaScript

/**
* Internal dependencies
*/
const pkg = require( './package.json' );
/**
* Babel plugin which transforms `warning` function calls to wrap within a
* condition that checks if `SCRIPT_DEBUG === true`.
*
* @param {import('@babel/core')} babel Current Babel object.
*
* @return {import('@babel/core').PluginObj} Babel plugin object.
*/
function babelPlugin( { types: t } ) {
const seen = Symbol();
const typeofProcessExpression = t.binaryExpression(
'!==',
t.unaryExpression( 'typeof', t.identifier( 'SCRIPT_DEBUG' ), false ),
t.stringLiteral( 'undefined' )
);
const scriptDebugCheckExpression = t.binaryExpression(
'===',
t.identifier( 'SCRIPT_DEBUG' ),
t.booleanLiteral( true )
);
const logicalExpression = t.logicalExpression(
'&&',
typeofProcessExpression,
scriptDebugCheckExpression
);
return {
visitor: {
ImportDeclaration( path, state ) {
const { node } = path;
const isThisPackageImport =
node.source.value.indexOf( pkg.name ) !== -1;
if ( ! isThisPackageImport ) {
return;
}
const defaultSpecifier = node.specifiers.find(
( specifier ) => specifier.type === 'ImportDefaultSpecifier'
);
if ( defaultSpecifier && defaultSpecifier.local ) {
const { name } = defaultSpecifier.local;
state.callee = name;
}
},
CallExpression( path, state ) {
const { node } = path;
// Ignore if it's already been processed.
if ( node[ seen ] ) {
return;
}
const name = state.callee || state.opts.callee;
if ( path.get( 'callee' ).isIdentifier( { name } ) ) {
// Turns this code:
// warning(argument);
// into this:
// typeof SCRIPT_DEBUG !== 'undefined' && SCRIPT_DEBUG === true ? warning(argument) : void 0;
node[ seen ] = true;
path.replaceWith(
t.ifStatement(
logicalExpression,
t.blockStatement( [
t.expressionStatement( node ),
] )
)
);
}
},
},
};
}
module.exports = babelPlugin;