Skip to content

Commit

Permalink
feat(gatsby-plugin-typescript): add support for optional chaining and…
Browse files Browse the repository at this point in the history
… nullish coalescing operator (#19302)

* add plugin

* add optional chaining

* fix test

* explicitely assert babel plugins

* update lock file
  • Loading branch information
Austaras authored and pieh committed Nov 12, 2019
1 parent cae6383 commit 0647089
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"Noah Lange <[email protected]>"
],
"dependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
"@babel/preset-typescript": "^7.7.2",
"@babel/runtime": "^7.7.2",
"babel-plugin-remove-graphql-queries": "^2.7.15"
Expand Down
15 changes: 13 additions & 2 deletions packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe(`gatsby-plugin-typescript`, () => {
})

describe(`onCreateBabelConfig`, () => {
it(`sets the correct babel preset`, () => {
const actions = { setBabelPreset: jest.fn() }
it(`sets the correct babel preset and plugin`, () => {
const actions = { setBabelPreset: jest.fn(), setBabelPlugin: jest.fn() }
const options = {
isTSX: true,
jsxPragma: `jsx`,
Expand All @@ -25,6 +25,17 @@ describe(`gatsby-plugin-typescript`, () => {
name: expect.stringContaining(path.join(`@babel`, `preset-typescript`)),
options,
})
expect(actions.setBabelPlugin).toHaveBeenCalledTimes(2)
expect(actions.setBabelPlugin).toHaveBeenCalledWith({
name: expect.stringContaining(
path.join(`@babel`, `plugin-proposal-optional-chaining`)
),
})
expect(actions.setBabelPlugin).toHaveBeenCalledWith({
name: expect.stringContaining(
path.join(`@babel`, `plugin-proposal-nullish-coalescing-operator`)
),
})
})
})

Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby-plugin-typescript/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ function onCreateBabelConfig({ actions }, options) {
name: require.resolve(`@babel/preset-typescript`),
options,
})
actions.setBabelPlugin({
name: require.resolve(`@babel/plugin-proposal-optional-chaining`),
})
actions.setBabelPlugin({
name: require.resolve(`@babel/plugin-proposal-nullish-coalescing-operator`),
})
}

function onCreateWebpackConfig({ actions, loaders }) {
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.2.0"

"@babel/plugin-proposal-nullish-coalescing-operator@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.4.4.tgz#41c360d59481d88e0ce3a3f837df10121a769b39"
integrity sha512-Amph7Epui1Dh/xxUxS2+K22/MUi6+6JVTvy3P58tja3B6yKTSjwwx0/d83rF7551D6PVSSoplQb8GCwqec7HRw==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.2.0"

"@babel/plugin-proposal-numeric-separator@^7.0.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-numeric-separator/-/plugin-proposal-numeric-separator-7.2.0.tgz#646854daf4cd22fd6733f6076013a936310443ac"
Expand Down

0 comments on commit 0647089

Please sign in to comment.