import { Rule , RootCompilerOptions } from "@mizchi/pargen/src/types" ; import { createContext } from "@mizchi/pargen/src" ; import { detectPragma , preprocessLight } from "./preprocess" ; const { compile } = createContext ( { } ) ; const defaultJsx = "React.createElement" ; const defaultJsxFragment = "React.Fragment" ; export let config = { jsx : defaultJsx , jsxFragment : defaultJsxFragment , } ; const compileWithPreprocess = ( inputRule , opts = { } ) => { const parser = compile ( inputRule , opts ) ; const wrappedParser = ( input , opts ? ) => { const pragma = detectPragma ( input ) ; const overrideJsx = pragma . jsx ?? opts ?. jsx ; if ( overrideJsx ) config . jsx = overrideJsx ; const overrideJsxFragment = pragma . jsxFragment ?? opts ?. jsxFragment ; if ( overrideJsxFragment ) config . jsxFragment = overrideJsxFragment ; const pre = preprocessLight ( input ) ; const parseResult = parser ( pre , 0 ) ; config . jsx = defaultJsx ; config . jsxFragment = defaultJsxFragment ; return parseResult ; } ; return wrappedParser ; } ; export { compileWithPreprocess as compile } ;