* Parses plugin names and presets from the specified options.
(options)
| 132 | * Parses plugin names and presets from the specified options. |
| 133 | */ |
| 134 | function processOptions(options) { |
| 135 | // Parse preset names |
| 136 | var presets = (options.presets || []).map(function (presetName) { |
| 137 | var preset = loadBuiltin(availablePresets, presetName); |
| 138 | |
| 139 | if (preset) { |
| 140 | // workaround for babel issue |
| 141 | // at some point, babel copies the preset, losing the non-enumerable |
| 142 | // buildPreset key; convert it into an enumerable key. |
| 143 | if (isArray(preset) && _typeof(preset[0]) === 'object' && preset[0].hasOwnProperty('buildPreset')) { |
| 144 | preset[0] = _extends({}, preset[0], { buildPreset: preset[0].buildPreset }); |
| 145 | } |
| 146 | } else { |
| 147 | throw new Error('Invalid preset specified in Babel options: "' + presetName + '"'); |
| 148 | } |
| 149 | return preset; |
| 150 | }); |
| 151 | |
| 152 | // Parse plugin names |
| 153 | var plugins = (options.plugins || []).map(function (pluginName) { |
| 154 | var plugin = loadBuiltin(availablePlugins, pluginName); |
| 155 | |
| 156 | if (!plugin) { |
| 157 | throw new Error('Invalid plugin specified in Babel options: "' + pluginName + '"'); |
| 158 | } |
| 159 | return plugin; |
| 160 | }); |
| 161 | |
| 162 | return _extends({ |
| 163 | babelrc: false |
| 164 | }, options, { |
| 165 | presets: presets, |
| 166 | plugins: plugins |
| 167 | }); |
| 168 | } |
| 169 | |
| 170 | function transform(code, options) { |
| 171 | return Babel.transform(code, processOptions(options)); |
no test coverage detected