| 1 |
import { declarePreset } from "@babel/helper-plugin-utils"; |
| 2 |
import transformReactJSX from "@babel/plugin-transform-react-jsx"; |
| 3 |
import transformReactJSXDevelopment from "@babel/plugin-transform-react-jsx-development"; |
| 4 |
import transformReactDisplayName from "@babel/plugin-transform-react-display-name"; |
| 5 |
import transformReactPure from "@babel/plugin-transform-react-pure-annotations"; |
| 6 |
import normalizeOptions from "./normalize-options"; |
| 7 |
|
| 8 |
export interface Options { |
| 9 |
development?: boolean; |
| 10 |
importSource?: string; |
| 11 |
pragma?: string; |
| 12 |
pragmaFrag?: string; |
| 13 |
pure?: string; |
| 14 |
runtime?: "automatic" | "classic"; |
| 15 |
throwIfNamespace?: boolean; |
| 16 |
useBuiltIns?: boolean; |
| 17 |
useSpread?: boolean; |
| 18 |
} |
| 19 |
|
| 20 |
export default declarePreset((api, opts: Options) => { |
| 21 |
api.assertVersion(7); |
| 22 |
|
| 23 |
const { |
| 24 |
development, |
| 25 |
importSource, |
| 26 |
pragma, |
| 27 |
pragmaFrag, |
| 28 |
pure, |
| 29 |
runtime, |
| 30 |
throwIfNamespace, |
| 31 |
} = normalizeOptions(opts); |
| 32 |
|
| 33 |
return { |
| 34 |
plugins: [ |
| 35 |
[ |
| 36 |
development ? transformReactJSXDevelopment : transformReactJSX, |
| 37 |
process.env.BABEL_8_BREAKING |
| 38 |
? { |
| 39 |
importSource, |
| 40 |
pragma, |
| 41 |
pragmaFrag, |
| 42 |
runtime, |
| 43 |
throwIfNamespace, |
| 44 |
pure, |
| 45 |
} |
| 46 |
: { |
| 47 |
importSource, |
| 48 |
pragma, |
| 49 |
pragmaFrag, |
| 50 |
runtime, |
| 51 |
throwIfNamespace, |
| 52 |
pure, |
| 53 |
useBuiltIns: !!opts.useBuiltIns, |
| 54 |
useSpread: opts.useSpread, |
| 55 |
}, |
| 56 |
], |
| 57 |
transformReactDisplayName, |
| 58 |
pure !== false && transformReactPure, |
| 59 |
].filter(Boolean), |
| 60 |
}; |
| 61 |
}); |