{"version":3,"names":["_estree","require","_flow","_jsx","_typescript","_placeholders","_v8intrinsic","hasPlugin","plugins","expectedConfig","expectedName","expectedOptions","expectedKeys","Object","keys","expectedOptionsIsEmpty","length","some","p","pluginName","pluginOptions","key","getPluginOption","name","option","plugin","find","Array","isArray","PIPELINE_PROPOSALS","TOPIC_TOKENS","RECORD_AND_TUPLE_SYNTAX_TYPES","validatePlugins","Error","decoratorsBeforeExport","allowCallParenthesized","proposal","includes","proposalList","map","join","tupleSyntaxIsHash","syntaxType","topicToken","tokenList","t","moduleAttributesVersionPluginOption","error","missingPlugins","mixinPlugins","estree","jsx","flow","typescript","v8intrinsic","placeholders","exports","mixinPluginNames"],"sources":["../src/plugin-utils.ts"],"sourcesContent":["import type Parser from \"./parser\";\nimport type {\n  ParserPluginWithOptions,\n  PluginConfig,\n  PluginOptions,\n} from \"./typings\";\n\nexport type Plugin = PluginConfig;\n\nexport type PluginList = PluginConfig[];\n\nexport type MixinPlugin = (superClass: { new (...args: any): Parser }) => {\n  new (...args: any): Parser;\n};\n\n// This function鈥檚 second parameter accepts either a string (plugin name) or an\n// array pair (plugin name and options object). If an options object is given,\n// then each value is non-recursively checked for identity with the actual\n// option value of each plugin in the first argument (which is an array of\n// plugin names or array pairs).\nexport function hasPlugin(\n  plugins: PluginList,\n  expectedConfig: PluginConfig,\n): boolean {\n  // The expectedOptions object is by default an empty object if the given\n  // expectedConfig argument does not give an options object (i.e., if it is a\n  // string).\n  const [expectedName, expectedOptions] =\n    typeof expectedConfig === \"string\" ? [expectedConfig, {}] : expectedConfig;\n\n  const expectedKeys = Object.keys(expectedOptions);\n\n  const expectedOptionsIsEmpty = expectedKeys.length === 0;\n\n  return plugins.some(p => {\n    if (typeof p === \"string\") {\n      return expectedOptionsIsEmpty && p === expectedName;\n    } else {\n      const [pluginName, pluginOptions] = p;\n      if (pluginName !== expectedName) {\n        return false;\n      }\n      for (const key of expectedKeys) {\n        // @ts-expect-error key may not exist in plugin options\n        if (pluginOptions[key] !== expectedOptions[key]) {\n          return false;\n        }\n      }\n      return true;\n    }\n  });\n}\n\nexport function getPluginOption<\n  PluginName extends ParserPluginWithOptions[0],\n  OptionName extends keyof PluginOptions<PluginName>,\n>(plugins: PluginList, name: PluginName, option: OptionName) {\n  const plugin = plugins.find(plugin => {\n    if (Array.isArray(plugin)) {\n      return plugin[0] === name;\n    } else {\n      return plugin === name;\n    }\n  });\n\n  if (plugin && Array.isArray(plugin) && plugin.length > 1) {\n    return (plugin[1] as PluginOptions<PluginName>)[option];\n  }\n\n  return null;\n}\n\nconst PIPELINE_PROPOSALS = [\"minimal\", \"fsharp\", \"hack\", \"smart\"];\nconst TOPIC_TOKENS = [\"^^\", \"@@\", \"^\", \"%\", \"#\"];\nconst RECORD_AND_TUPLE_SYNTAX_TYPES = [\"hash\", \"bar\"];\n\nexport function validatePlugins(plugins: PluginList) {\n  if (hasPlugin(plugins, \"decorators\")) {\n    if (hasPlugin(plugins, \"decorators-legacy\")) {\n      throw new Error(\n        \"Cannot use the decorators and decorators-legacy plugin together\",\n      );\n    }\n\n    const decoratorsBeforeExport = getPluginOption(\n      plugins,\n      \"decorators\",\n      \"decoratorsBeforeExport\",\n    );\n    if (\n      decoratorsBeforeExport != null &&\n      typeof decoratorsBeforeExport !== \"boolean\"\n    ) {\n      throw new Error(\n        \"'decoratorsBeforeExport' must be a boolean, if specified.\",\n      );\n    }\n\n    const allowCallParenthesized = getPluginOption(\n      plugins,\n      \"decorators\",\n      \"allowCallParenthesized\",\n    );\n    if (\n      allowCallParenthesized != null &&\n      typeof allowCallParenthesized !== \"boolean\"\n    ) {\n      throw new Error(\"'allowCallParenthesized' must be a boolean.\");\n    }\n  }\n\n  if (hasPlugin(plugins, \"flow\") && hasPlugin(plugins, \"typescript\")) {\n    throw new Error(\"Cannot combine flow and typescript plugins.\");\n  }\n\n  if (hasPlugin(plugins, \"placeholders\") && hasPlugin(plugins, \"v8intrinsic\")) {\n    throw new Error(\"Cannot combine placeholders and v8intrinsic plugins.\");\n  }\n\n  if (hasPlugin(plugins, \"pipelineOperator\")) {\n    const proposal = getPluginOption(plugins, \"pipelineOperator\", \"proposal\");\n\n    if (!PIPELINE_PROPOSALS.includes(proposal)) {\n      const proposalList = PIPELINE_PROPOSALS.map(p => `\"${p}\"`).join(\", \");\n      throw new Error(\n        `\"pipelineOperator\" requires \"proposal\" option whose value must be one of: ${proposalList}.`,\n      );\n    }\n\n    const tupleSyntaxIsHash = hasPlugin(plugins, [\n      \"recordAndTuple\",\n      { syntaxType: \"hash\" },\n    ]);\n\n    if (proposal === \"hack\") {\n      if (hasPlugin(plugins, \"placeholders\")) {\n        throw new Error(\n          \"Cannot combine placeholders plugin and Hack-style pipes.\",\n        );\n      }\n\n      if (hasPlugin(plugins, \"v8intrinsic\")) {\n        throw new Error(\n          \"Cannot combine v8intrinsic plugin and Hack-style pipes.\",\n        );\n      }\n\n      const topicToken = getPluginOption(\n        plugins,\n        \"pipelineOperator\",\n        \"topicToken\",\n      );\n\n      if (!TOPIC_TOKENS.includes(topicToken)) {\n        const tokenList = TOPIC_TOKENS.map(t => `\"${t}\"`).join(\", \");\n\n        throw new Error(\n          `\"pipelineOperator\" in \"proposal\": \"hack\" mode also requires a \"topicToken\" option whose value must be one of: ${tokenList}.`,\n        );\n      }\n\n      if (topicToken === \"#\" && tupleSyntaxIsHash) {\n        throw new Error(\n          'Plugin conflict between `[\"pipelineOperator\", { proposal: \"hack\", topicToken: \"#\" }]` and `[\"recordAndtuple\", { syntaxType: \"hash\"}]`.',\n        );\n      }\n    } else if (proposal === \"smart\" && tupleSyntaxIsHash) {\n      throw new Error(\n        'Plugin conflict between `[\"pipelineOperator\", { proposal: \"smart\" }]` and `[\"recordAndtuple\", { syntaxType: \"hash\"}]`.',\n      );\n    }\n  }\n\n  if (hasPlugin(plugins, \"moduleAttributes\")) {\n    if (process.env.BABEL_8_BREAKING) {\n      throw new Error(\n        \"`moduleAttributes` has been removed in Babel 8, please use `importAttributes` parser plugin, or `@babel/plugin-syntax-import-attributes`.\",\n      );\n    } else {\n      if (\n        hasPlugin(plugins, \"importAssertions\") ||\n        hasPlugin(plugins, \"importAttributes\")\n      ) {\n        throw new Error(\n          \"Cannot combine importAssertions, importAttributes and moduleAttributes plugins.\",\n        );\n      }\n      const moduleAttributesVersionPluginOption = getPluginOption(\n        plugins,\n        \"moduleAttributes\",\n        \"version\",\n      );\n      if (moduleAttributesVersionPluginOption !== \"may-2020\") {\n        throw new Error(\n          \"The 'moduleAttributes' plugin requires a 'version' option,\" +\n            \" representing the last proposal update. Currently, the\" +\n            \" only supported value is 'may-2020'.\",\n        );\n      }\n    }\n  }\n  if (\n    hasPlugin(plugins, \"importAssertions\") &&\n    hasPlugin(plugins, \"importAttributes\")\n  ) {\n    throw new Error(\n      \"Cannot combine importAssertions and importAttributes plugins.\",\n    );\n  }\n\n  if (\n    hasPlugin(plugins, \"recordAndTuple\") &&\n    getPluginOption(plugins, \"recordAndTuple\", \"syntaxType\") != null &&\n    !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(\n      getPluginOption(plugins, \"recordAndTuple\", \"syntaxType\"),\n    )\n  ) {\n    throw new Error(\n      \"The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: \" +\n        RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(\", \"),\n    );\n  }\n\n  if (\n    hasPlugin(plugins, \"asyncDoExpressions\") &&\n    !hasPlugin(plugins, \"doExpressions\")\n  ) {\n    const error = new Error(\n      \"'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.\",\n    );\n    // @ts-expect-error so @babel/core can provide better error message\n    error.missingPlugins = \"doExpressions\";\n    throw error;\n  }\n}\n\n// These plugins are defined using a mixin which extends the parser class.\n\nimport estree from \"./plugins/estree\";\nimport flow from \"./plugins/flow\";\nimport jsx from \"./plugins/jsx\";\nimport typescript from \"./plugins/typescript\";\nimport placeholders from \"./plugins/placeholders\";\nimport v8intrinsic from \"./plugins/v8intrinsic\";\n\n// NOTE: order is important. estree must come first; placeholders must come last.\nexport const mixinPlugins = {\n  estree,\n  jsx,\n  flow,\n  typescript,\n  v8intrinsic,\n  placeholders,\n};\n\nexport const mixinPluginNames = Object.keys(mixinPlugins) as ReadonlyArray<\n  \"estree\" | \"jsx\" | \"flow\" | \"typescript\" | \"v8intrinsic\" | \"placeholders\"\n>;\n"],"mappings":";;;;;;;;;AA8OA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AA/NO,SAASM,SAASA,CACvBC,OAAmB,EACnBC,cAA4B,EACnB;EAIT,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GACnC,OAAOF,cAAc,KAAK,QAAQ,GAAG,CAACA,cAAc,EAAE,CAAC,CAAC,CAAC,GAAGA,cAAc;EAE5E,MAAMG,YAAY,GAAGC,MAAM,CAACC,IAAI,CAACH,eAAe,CAAC;EAEjD,MAAMI,sBAAsB,GAAGH,YAAY,CAACI,MAAM,KAAK,CAAC;EAExD,OAAOR,OAAO,CAACS,IAAI,CAACC,CAAC,IAAI;IACvB,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;MACzB,OAAOH,sBAAsB,IAAIG,CAAC,KAAKR,YAAY;IACrD,CAAC,MAAM;MACL,MAAM,CAACS,UAAU,EAAEC,aAAa,CAAC,GAAGF,CAAC;MACrC,IAAIC,UAAU,KAAKT,YAAY,EAAE;QAC/B,OAAO,KAAK;MACd;MACA,KAAK,MAAMW,GAAG,IAAIT,YAAY,EAAE;QAE9B,IAAIQ,aAAa,CAACC,GAAG,CAAC,KAAKV,eAAe,CAACU,GAAG,CAAC,EAAE;UAC/C,OAAO,KAAK;QACd;MACF;MACA,OAAO,IAAI;IACb;EACF,CAAC,CAAC;AACJ;AAEO,SAASC,eAAeA,CAG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