| 1 | import * as babelPlugins from "./generated/plugins"; |
| 2 | |
| 3 | export default (_: any, opts: any): any => { |
| 4 | let loose = false; |
| 5 | let modules = "commonjs"; |
| 6 | let spec = false; |
| 7 | |
| 8 | if (opts !== undefined) { |
| 9 | if (opts.loose !== undefined) loose = opts.loose; |
| 10 | if (opts.modules !== undefined) modules = opts.modules; |
| 11 | if (opts.spec !== undefined) spec = opts.spec; |
| 12 | } |
| 13 | |
| 14 | // be DRY |
| 15 | const optsLoose = { loose }; |
| 16 | |
| 17 | return { |
| 18 | plugins: [ |
| 19 | [babelPlugins.transformTemplateLiterals, { loose, spec }], |
| 20 | babelPlugins.transformLiterals, |
| 21 | babelPlugins.transformFunctionName, |
| 22 | [babelPlugins.transformArrowFunctions, { spec }], |
| 23 | babelPlugins.transformBlockScopedFunctions, |
| 24 | [babelPlugins.transformClasses, optsLoose], |
| 25 | babelPlugins.transformObjectSuper, |
| 26 | babelPlugins.transformShorthandProperties, |
| 27 | babelPlugins.transformDuplicateKeys, |
| 28 | [babelPlugins.transformComputedProperties, optsLoose], |
| 29 | [babelPlugins.transformForOf, optsLoose], |
| 30 | babelPlugins.transformStickyRegex, |
| 31 | babelPlugins.transformUnicodeEscapes, |
| 32 | babelPlugins.transformUnicodeRegex, |
| 33 | [babelPlugins.transformSpread, optsLoose], |
| 34 | [babelPlugins.transformParameters, optsLoose], |
| 35 | [babelPlugins.transformDestructuring, optsLoose], |
| 36 | babelPlugins.transformBlockScoping, |
| 37 | babelPlugins.transformTypeofSymbol, |
| 38 | babelPlugins.transformInstanceof, |
| 39 | (modules === "commonjs" || modules === "cjs") && [ |
| 40 | babelPlugins.transformModulesCommonjs, |
| 41 | optsLoose, |
| 42 | ], |
| 43 | modules === "systemjs" && [ |
| 44 | babelPlugins.transformModulesSystemjs, |
| 45 | optsLoose, |
| 46 | ], |
| 47 | modules === "amd" && [babelPlugins.transformModulesAmd, optsLoose], |
| 48 | modules === "umd" && [babelPlugins.transformModulesUmd, optsLoose], |
| 49 | [ |
| 50 | babelPlugins.transformRegenerator, |
| 51 | { async: false, asyncGenerators: false }, |
| 52 | ], |
| 53 | ].filter(Boolean), // filter out falsy values |
| 54 | }; |
| 55 | }; |