{"version":3,"names":["babel","require","convert","astInfo","extractParserOptionsPlugin","getVisitorKeys","getTokLabels","ref","extractParserOptionsConfigItem","MULTIPLE_OVERRIDES","module","exports","maybeParse","code","options","createConfigItemSync","dirname","__dirname","type","plugins","concat","ast","parserOptions","parseSync","err","test","message","convertError","convertFile"],"sources":["../../src/worker/maybeParse.cts"],"sourcesContent":["import babel = require(\"./babel-core.cts\");\nimport convert = require(\"../convert/index.cts\");\nimport astInfo = require(\"./ast-info.cts\");\nimport extractParserOptionsPlugin = require(\"./extract-parser-options-plugin.cjs\");\n\nimport type { InputOptions, ConfigItem } from \"@babel/core\";\nimport type { AST, ParseResult } from \"../types.cts\";\n\nconst { getVisitorKeys, getTokLabels } = astInfo;\n\nconst ref = {};\nlet extractParserOptionsConfigItem: ConfigItem;\n\nconst MULTIPLE_OVERRIDES = /More than one plugin attempted to override parsing/;\n\nexport = function maybeParse(\n code: string,\n options: InputOptions,\n): {\n ast: AST.Program | null;\n parserOptions: ParseResult | null;\n} {\n if (!extractParserOptionsConfigItem) {\n extractParserOptionsConfigItem = babel.createConfigItemSync(\n [extractParserOptionsPlugin, ref],\n { dirname: __dirname, type: \"plugin\" },\n );\n }\n const { plugins } = options;\n options.plugins = plugins.concat(extractParserOptionsConfigItem);\n\n let ast;\n\n try {\n return {\n parserOptions: babel.parseSync(code, options),\n ast: null,\n };\n } catch (err) {\n if (!MULTIPLE_OVERRIDES.test(err.message)) {\n throw err;\n }\n }\n\n // There was already a parserOverride, so remove our plugin.\n options.plugins = plugins;\n\n try {\n ast = babel.parseSync(code, options);\n } catch (err) {\n throw convert.convertError(err);\n }\n\n return {\n ast: convert.convertFile(ast, code, getTokLabels(), getVisitorKeys()),\n parserOptions: null,\n };\n};\n"],"mappings":";;MAAOA,KAAK,GAAAC,OAAA,CAAW,kBAAkB;AAAA,MAClCC,OAAO,GAAAD,OAAA,CAAW,sBAAsB;AAAA,MACxCE,OAAO,GAAAF,OAAA,CAAW,gBAAgB;AAAA,MAClCG,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