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>
104 lines
3.1 KiB
JavaScript
104 lines
3.1 KiB
JavaScript
/**
|
|
* External dependencies
|
|
*/
|
|
import { transform } from '@babel/core';
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
import babelPlugin from '../babel-plugin';
|
|
|
|
function join( ...strings ) {
|
|
return strings.join( '\n' );
|
|
}
|
|
|
|
function transformCode( input, options = {} ) {
|
|
const { code } = transform( input, {
|
|
configFile: false,
|
|
plugins: [ [ babelPlugin, options ] ],
|
|
} );
|
|
return code;
|
|
}
|
|
|
|
describe( 'babel-plugin', () => {
|
|
it( 'should replace warning calls with import declaration', () => {
|
|
const input = join(
|
|
'import warning from "@wordpress/warning";',
|
|
'warning("a");'
|
|
);
|
|
const expected = join(
|
|
'import warning from "@wordpress/warning";',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warning("a") : void 0;'
|
|
);
|
|
|
|
expect( transformCode( input ) ).toEqual( expected );
|
|
} );
|
|
|
|
it( 'should not replace warning calls without import declaration', () => {
|
|
const input = 'warning("a");';
|
|
const expected = 'warning("a");';
|
|
|
|
expect( transformCode( input ) ).toEqual( expected );
|
|
} );
|
|
|
|
it( 'should replace warning calls without import declaration with plugin options', () => {
|
|
const input = 'warning("a");';
|
|
const options = { callee: 'warning' };
|
|
const expected =
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warning("a") : void 0;';
|
|
|
|
expect( transformCode( input, options ) ).toEqual( expected );
|
|
} );
|
|
|
|
it( 'should replace multiple warning calls', () => {
|
|
const input = join(
|
|
'import warning from "@wordpress/warning";',
|
|
'warning("a");',
|
|
'warning("b");',
|
|
'warning("c");'
|
|
);
|
|
const expected = join(
|
|
'import warning from "@wordpress/warning";',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warning("a") : void 0;',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warning("b") : void 0;',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warning("c") : void 0;'
|
|
);
|
|
|
|
expect( transformCode( input ) ).toEqual( expected );
|
|
} );
|
|
|
|
it( 'should identify warning callee name', () => {
|
|
const input = join(
|
|
'import warn from "@wordpress/warning";',
|
|
'warn("a");',
|
|
'warn("b");',
|
|
'warn("c");'
|
|
);
|
|
const expected = join(
|
|
'import warn from "@wordpress/warning";',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn("a") : void 0;',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn("b") : void 0;',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn("c") : void 0;'
|
|
);
|
|
|
|
expect( transformCode( input ) ).toEqual( expected );
|
|
} );
|
|
|
|
it( 'should identify warning callee name by', () => {
|
|
const input = join(
|
|
'import warn from "@wordpress/warning";',
|
|
'warn("a");',
|
|
'warn("b");',
|
|
'warn("c");'
|
|
);
|
|
const expected = join(
|
|
'import warn from "@wordpress/warning";',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn("a") : void 0;',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn("b") : void 0;',
|
|
'typeof SCRIPT_DEBUG !== "undefined" && SCRIPT_DEBUG === true ? warn("c") : void 0;'
|
|
);
|
|
|
|
expect( transformCode( input ) ).toEqual( expected );
|
|
} );
|
|
} );
|