From 1650dec5ecd1fc31adbd66268e82ed1449c1fd59 Mon Sep 17 00:00:00 2001 From: austaras Date: Wed, 6 Nov 2019 17:13:45 +0800 Subject: [PATCH 1/5] add plugin --- packages/gatsby-plugin-typescript/package.json | 1 + packages/gatsby-plugin-typescript/src/gatsby-node.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/gatsby-plugin-typescript/package.json b/packages/gatsby-plugin-typescript/package.json index 566921596fde6..3edc44535058c 100644 --- a/packages/gatsby-plugin-typescript/package.json +++ b/packages/gatsby-plugin-typescript/package.json @@ -10,6 +10,7 @@ "Noah Lange " ], "dependencies": { + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4", "@babel/preset-typescript": "^7.6.0", "@babel/runtime": "^7.6.3", "babel-plugin-remove-graphql-queries": "^2.7.14" diff --git a/packages/gatsby-plugin-typescript/src/gatsby-node.js b/packages/gatsby-plugin-typescript/src/gatsby-node.js index e8abc45920a47..e71cd85a4f28e 100644 --- a/packages/gatsby-plugin-typescript/src/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/gatsby-node.js @@ -5,6 +5,9 @@ function onCreateBabelConfig({ actions }, options) { name: require.resolve(`@babel/preset-typescript`), options, }) + actions.setBabelPlugin({ + name: require.resolve(`@babel/plugin-proposal-nullish-coalescing-operator`), + }) } function onCreateWebpackConfig({ actions, loaders }) { From e943a4f573fe8d2c6bc20764b048165b90afbd60 Mon Sep 17 00:00:00 2001 From: austaras Date: Wed, 6 Nov 2019 17:33:19 +0800 Subject: [PATCH 2/5] add optional chaining --- packages/gatsby-plugin-typescript/package.json | 1 + packages/gatsby-plugin-typescript/src/gatsby-node.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/gatsby-plugin-typescript/package.json b/packages/gatsby-plugin-typescript/package.json index 3edc44535058c..50fbef3740c97 100644 --- a/packages/gatsby-plugin-typescript/package.json +++ b/packages/gatsby-plugin-typescript/package.json @@ -11,6 +11,7 @@ ], "dependencies": { "@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4", + "@babel/plugin-proposal-optional-chaining": "^7.6.0", "@babel/preset-typescript": "^7.6.0", "@babel/runtime": "^7.6.3", "babel-plugin-remove-graphql-queries": "^2.7.14" diff --git a/packages/gatsby-plugin-typescript/src/gatsby-node.js b/packages/gatsby-plugin-typescript/src/gatsby-node.js index e71cd85a4f28e..a530ee259d046 100644 --- a/packages/gatsby-plugin-typescript/src/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/gatsby-node.js @@ -5,6 +5,9 @@ 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`), }) From e64d69b7cc1f1a3f6c7b75bf3f0dc68810e2de21 Mon Sep 17 00:00:00 2001 From: austaras Date: Wed, 6 Nov 2019 17:48:43 +0800 Subject: [PATCH 3/5] fix test --- .../gatsby-plugin-typescript/src/__tests__/gatsby-node.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js index b5e94400893f3..74642fe526d17 100644 --- a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js @@ -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`, @@ -25,6 +25,7 @@ describe(`gatsby-plugin-typescript`, () => { name: expect.stringContaining(path.join(`@babel`, `preset-typescript`)), options, }) + expect(actions.setBabelPlugin).toHaveBeenCalledTimes(2) }) }) From d247aac5c12a6fddf3f48ff1956ff55e6dc187ab Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 8 Nov 2019 14:07:07 +0100 Subject: [PATCH 4/5] explicitely assert babel plugins --- .../src/__tests__/gatsby-node.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js index 74642fe526d17..6feabab22706a 100644 --- a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js @@ -26,6 +26,16 @@ describe(`gatsby-plugin-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`) + ), + }) }) }) From 99f5faf21109540624521dde84b6a49ddb895a73 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 8 Nov 2019 14:07:15 +0100 Subject: [PATCH 5/5] update lock file --- yarn.lock | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/yarn.lock b/yarn.lock index ad3537c1a85e7..90ffb81815ff6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -458,6 +458,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"