@@ -102,22 +102,26 @@ const returnObject = () => {
102102 return { } ;
103103} ;
104104
105- function isSerializable ( value ) {
106- if ( value === null ) {
107- return true ;
108- } else if ( Array . isArray ( value ) ) {
109- return value . every ( isSerializable ) ;
110- }
111- switch ( typeof value ) {
112- case 'string' :
113- case 'number' :
114- case 'boolean' :
115- return true ;
116- case 'object' :
117- return Object . keys ( value ) . every ( ( key ) => isSerializable ( value [ key ] ) ) ;
118- default :
119- return false ;
105+ function findNonSerializableOption ( obj ) {
106+ const isSerializable = ( value ) => {
107+ if ( value === null ) return true ;
108+ if ( Array . isArray ( value ) ) return value . every ( isSerializable ) ;
109+ switch ( typeof value ) {
110+ case 'string' :
111+ case 'number' :
112+ case 'boolean' :
113+ return true ;
114+ case 'object' :
115+ return Object . values ( value ) . every ( isSerializable ) ;
116+ default :
117+ return false ;
118+ }
119+ } ;
120+
121+ for ( const key of Object . keys ( obj ) ) {
122+ if ( ! isSerializable ( obj [ key ] ) ) return key ;
120123 }
124+ return null ;
121125}
122126
123127function createBabelInputPluginFactory ( customCallback = returnObject ) {
@@ -159,12 +163,16 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
159163 }
160164
161165 if ( parallel ) {
162- const parallelAllowed =
163- isSerializable ( babelOptions ) && ! overrides ?. config && ! overrides ?. result ;
164-
165- if ( ! parallelAllowed ) {
166+ if ( overrides ?. config ) {
167+ throw new Error ( 'Cannot use "parallel" mode with a custom "config" override.' ) ;
168+ }
169+ if ( overrides ?. result ) {
170+ throw new Error ( 'Cannot use "parallel" mode with a custom "result" override.' ) ;
171+ }
172+ const nonSerializableKey = findNonSerializableOption ( babelOptions ) ;
173+ if ( nonSerializableKey ) {
166174 throw new Error (
167- ' Cannot use "parallel" mode alongside custom overrides or non-serializable Babel options.'
175+ ` Cannot use "parallel" mode because the " ${ nonSerializableKey } " option is not serializable.`
168176 ) ;
169177 }
170178
0 commit comments