import { Configuration as CSSBlocksConfiguration , ResolvedConfiguration , resolveConfiguration } from "@css-blocks/core" ; import { ObjectDictionary } from "@opticss/util" ; import { BabylonOptions , PluginName } from "babylon" ; const BABEL_PLUGINS = [ "jsx" , "doExpressions" , "objectRestSpread" , "decorators" , "classProperties" , "classPrivateProperties" , "classPrivateMethods" , "exportDefaultFrom" , "exportNamespaceFrom" , "asyncGenerators" , "functionBind" , "functionSent" , "dynamicImport" , "numericSeparator" , "optionalChaining" , "importMeta" , "bigInt" , "optionalCatchBinding" , "throwExpressions" , "pipelineOperator" , "nullishCoalescingOperator" , ] ; export interface JSXOptions { baseDir ? : string ; types ? : "typescript" | "flow" | "none" ; aliases ? : ObjectDictionary < string > ; compilationOptions ? : CSSBlocksConfiguration ; } export class JSXOptionsReader { public baseDir : string ; public types : JSXOptions [ "types" ] ; public aliases : ObjectDictionary < string > ; public compilationOptions : ResolvedConfiguration ; public parserOptions : BabylonOptions ; constructor ( opts = { } ) { this . baseDir = opts . baseDir || "." ; this . types = opts . types || "none" ; this . aliases = opts . aliases || { } ; this . compilationOptions = resolveConfiguration ( opts . compilationOptions ) ; this . parserOptions = { sourceType : "module" , allowImportExportEverywhere : true , allowReturnOutsideFunction : true , allowSuperOutsideMethod : true , plugins : BABEL_PLUGINS . slice ( 0 ) , } ; if ( this . types === "typescript" ) { this . parserOptions . plugins ! . push ( "typescript" as PluginName ) ; } else if ( this . types === "flow" ) { this . parserOptions . plugins ! . push ( "flow" as PluginName ) ; this . parserOptions . plugins ! . push ( "flowComments" as PluginName ) ; } } }