UNPKG

6.78 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sources":["../src/normalize-options.js","../src/index.js"],"sourcesContent":["import {\n OptionValidator,\n findSuggestion,\n} from \"@babel/helper-validator-option\";\nconst v = new OptionValidator(\"@babel/preset-react\");\n\nexport default function normalizeOptions(options = {}) {\n if (process.env.BABEL_8_BREAKING) {\n if (\"useSpread\" in options) {\n throw new Error(\n '@babel/preset-react: Since Babel 8, an inline object with spread elements is always used, and the \"useSpread\" option is no longer available. Please remove it from your config.',\n );\n }\n\n if (\"useBuiltIns\" in options) {\n const useBuiltInsFormatted = JSON.stringify(options.useBuiltIns);\n throw new Error(\n `@babel/preset-react: Since \"useBuiltIns\" is removed in Babel 8, you can remove it from the config.\n- Babel 8 now transforms JSX spread to object spread. If you need to transpile object spread with\n\\`useBuiltIns: ${useBuiltInsFormatted}\\`, you can use the following config\n{\n \"plugins\": [\n [\"@babel/plugin-proposal-object-rest-spread\", { \"loose\": true, \"useBuiltIns\": ${useBuiltInsFormatted} }]\n ],\n \"presets\": [\"@babel/preset-react\"]\n}`,\n );\n }\n\n const TopLevelOptions = {\n development: \"development\",\n importSource: \"importSource\",\n pragma: \"pragma\",\n pragmaFrag: \"pragmaFrag\",\n pure: \"pure\",\n runtime: \"runtime\",\n throwIfNamespace: \"throwIfNamespace\",\n };\n v.validateTopLevelOptions(options, TopLevelOptions);\n const development = v.validateBooleanOption(\n TopLevelOptions.development,\n options.development,\n false,\n );\n let importSource = v.validateStringOption(\n TopLevelOptions.importSource,\n options.importSource,\n );\n let pragma = v.validateStringOption(TopLevelOptions.pragma, options.pragma);\n let pragmaFrag = v.validateStringOption(\n TopLevelOptions.pragmaFrag,\n options.pragmaFrag,\n );\n const pure = v.validateBooleanOption(TopLevelOptions.pure, options.pure);\n const runtime = v.validateStringOption(\n TopLevelOptions.runtime,\n options.runtime,\n \"automatic\",\n );\n const throwIfNamespace = v.validateBooleanOption(\n TopLevelOptions.throwIfNamespace,\n options.throwIfNamespace,\n true,\n );\n\n const validRuntime = [\"classic\", \"automatic\"];\n\n if (runtime === \"classic\") {\n pragma = pragma || \"React.createElement\";\n pragmaFrag = pragmaFrag || \"React.Fragment\";\n } else if (runtime === \"automatic\") {\n importSource = importSource || \"react\";\n } else {\n throw new Error(\n `@babel/preset-react: 'runtime' must be one of ['automatic', 'classic'] but we have '${runtime}'\\n` +\n `- Did you mean '${findSuggestion(runtime, validRuntime)}'?`,\n );\n }\n\n return {\n development,\n importSource,\n pragma,\n pragmaFrag,\n pure,\n runtime,\n throwIfNamespace,\n };\n } else {\n let { pragma, pragmaFrag } = options;\n\n const {\n pure,\n throwIfNamespace = true,\n runtime = \"classic\",\n importSource,\n useBuiltIns,\n useSpread,\n } = options;\n\n if (runtime === \"classic\") {\n pragma = pragma || \"React.createElement\";\n pragmaFrag = pragmaFrag || \"React.Fragment\";\n }\n\n const development = !!options.development;\n\n return {\n development,\n importSource,\n pragma,\n pragmaFrag,\n pure,\n runtime,\n throwIfNamespace,\n useBuiltIns,\n useSpread,\n };\n }\n}\n","import { declare } from \"@babel/helper-plugin-utils\";\nimport transformReactJSX from \"@babel/plugin-transform-react-jsx\";\nimport transformReactJSXDevelopment from \"@babel/plugin-transform-react-jsx-development\";\nimport transformReactDisplayName from \"@babel/plugin-transform-react-display-name\";\nimport transformReactPure from \"@babel/plugin-transform-react-pure-annotations\";\nimport normalizeOptions from \"./normalize-options\";\n\nexport default declare((api, opts) => {\n api.assertVersion(7);\n\n const {\n development,\n importSource,\n pragma,\n pragmaFrag,\n pure,\n runtime,\n throwIfNamespace,\n } = normalizeOptions(opts);\n\n return {\n plugins: [\n [\n development ? transformReactJSXDevelopment : transformReactJSX,\n process.env.BABEL_8_BREAKING\n ? {\n importSource,\n pragma,\n pragmaFrag,\n runtime,\n throwIfNamespace,\n pure,\n }\n : {\n importSource,\n pragma,\n pragmaFrag,\n runtime,\n throwIfNamespace,\n pure,\n useBuiltIns: !!opts.useBuiltIns,\n useSpread: opts.useSpread,\n },\n ],\n transformReactDisplayName,\n pure !== false && transformReactPure,\n ].filter(Boolean),\n };\n});\n"],"names":["OptionValidator","normalizeOptions","options","pragma","pragmaFrag","pure","throwIfNamespace","runtime","importSource","useBuiltIns","useSpread","development","declare","api","opts","assertVersion","plugins","transformReactJSXDevelopment","transformReactJSX","transformReactDisplayName","transformReactPure","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;AAIU,IAAIA,qCAAJ,CAAoB,qBAApB;AAEK,SAASC,gBAAT,CAA0BC,OAAO,GAAG,EAApC,EAAwC;AAkF9C;AACL,QAAI;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAyBF,OAA7B;AAEA,UAAM;AACJG,MAAAA,IADI;AAEJC,MAAAA,gBAAgB,GAAG,IAFf;AAGJC,MAAAA,OAAO,GAAG,SAHN;AAIJC,MAAAA,YAJI;AAKJC,MAAAA,WALI;AAMJC,MAAAA;AANI,QAOFR,OAPJ;;AASA,QAAIK,OAAO,KAAK,SAAhB,EAA2B;AACzBJ,MAAAA,MAAM,GAAGA,MAAM,IAAI,qBAAnB;AACAC,MAAAA,UAAU,GAAGA,UAAU,IAAI,gBAA3B;AACD;;AAED,UAAMO,WAAW,GAAG,CAAC,CAACT,OAAO,CAACS,WAA9B;AAEA,WAAO;AACLA,MAAAA,WADK;AAELH,MAAAA,YAFK;AAGLL,MAAAA,MAHK;AAILC,MAAAA,UAJK;AAKLC,MAAAA,IALK;AAMLE,MAAAA,OANK;AAOLD,MAAAA,gBAPK;AAQLG,MAAAA,WARK;AASLC,MAAAA;AATK,KAAP;AAWD;AACF;;AChHD,YAAeE,yBAAO,CAAC,CAACC,GAAD,EAAMC,IAAN,KAAe;AACpCD,EAAAA,GAAG,CAACE,aAAJ,CAAkB,CAAlB;AAEA,QAAM;AACJJ,IAAAA,WADI;AAEJH,IAAAA,YAFI;AAGJL,IAAAA,MAHI;AAIJC,IAAAA,UAJI;AAKJC,IAAAA,IALI;AAMJE,IAAAA,OANI;AAOJD,IA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