@@ -27,12 +27,22 @@ import type {
2727 IComputeEngine as ComputeEngine ,
2828 Metadata ,
2929 Expression ,
30+ FunctionInterface ,
3031 JsonSerializationOptions ,
3132} from '../global-types' ;
3233import { isOperatorDef } from './utils' ;
3334import { isNumber , isSymbol , isString , isFunction } from './type-guards' ;
3435import { matchesNumber , matchesSymbol } from '../../math-json/utils' ;
3536
37+ // Lazy reference to break circular dependency:
38+ // product → arithmetic-mul-div → ... → abstract-boxed-expression → serialize
39+ import type { Product as _ProductClass } from './product' ;
40+ let _Product : typeof _ProductClass ;
41+ /** @internal */
42+ export function _setProduct ( fn : typeof _ProductClass ) {
43+ _Product = fn ;
44+ }
45+
3646function _escapeJsonString ( s : undefined ) : undefined ;
3747function _escapeJsonString ( s : string ) : string ;
3848function _escapeJsonString ( s : string | undefined ) : string | undefined {
@@ -129,20 +139,13 @@ function serializePrettyJsonFunction(
129139 if ( name === 'Multiply' && ! exclusions . includes ( 'Divide' ) ) {
130140 // Display a product with negative exponents as a division if
131141 // there are terms with a negative degree.
132- // Dynamic require to avoid circular dependency:
133- // serialize → product → ... → abstract-boxed-expression → serialize
134- const { Product } = require ( './product' ) ;
135- const result = new Product ( ce , args , {
142+ const result = new _Product ( ce , args , {
136143 canonical : false ,
137144 } ) . asRationalExpression ( ) ;
138- if ( result . operator === 'Divide' )
139- return serializeJsonFunction (
140- ce ,
141- result . operator ,
142- result . ops ! ,
143- options ,
144- metadata
145- ) ;
145+ if ( result . operator === 'Divide' ) {
146+ const ops = ( result as Expression & FunctionInterface ) . ops ;
147+ return serializeJsonFunction ( ce , result . operator , ops , options , metadata ) ;
148+ }
146149 }
147150
148151 if ( name === 'Power' ) {
0 commit comments