Skip to content

Commit

Permalink
throwing if runtime is wrong, move the logic out of the object
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurie committed Feb 25, 2021
1 parent 70938cd commit 6007072
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/babel-preset-gatsby/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ export default function preset(_, options = {}) {
}
}

let importSource = undefined

if (options.reactImportSource && options.reactRuntime !== `automatic`) {
throw Error(
`\`@babel/preset-react\` requires reactRuntime \`automatic\` in order to use \`importSource\`.`
)
} else if (options.reactImportSource) {
importSource = options.reactImportSource
}

return {
presets: [
[
Expand Down Expand Up @@ -83,9 +93,7 @@ export default function preset(_, options = {}) {
: `React.createElement`,
development: stage === `develop`,
runtime: options.reactRuntime || `classic`,
...(options.reactImportSource
? { importSource: options.reactImportSource }
: {}),
importSource,
},
],
],
Expand Down

0 comments on commit 6007072

Please sign in to comment.