From accb699c5920acb5334cb67bd0c0cf1ffec900b8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 6 Apr 2020 08:58:24 +0200 Subject: [PATCH 1/4] feat: enable syntax plugins for syntax that works in node --- CHANGELOG.md | 1 + packages/babel-preset-jest/index.js | 8 ++++++-- packages/babel-preset-jest/package.json | 3 +++ yarn.lock | 9 ++++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8946e97c57a1..f0cc5a558ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[babel-preset-jest]` Enable all syntax plugins not enabled by default ([#9775](https://github.com/facebook/jest/pull/9775)) - `[babel-jest]` Support passing `supportsDynamicImport` and `supportsStaticESM` ([#9766](https://github.com/facebook/jest/pull/9766)) - `[jest-runtime, @jest/transformer]` Support passing `supportsDynamicImport` and `supportsStaticESM` ([#9597](https://github.com/facebook/jest/pull/9597)) diff --git a/packages/babel-preset-jest/index.js b/packages/babel-preset-jest/index.js index c8c235eae479..11edbc08e99b 100644 --- a/packages/babel-preset-jest/index.js +++ b/packages/babel-preset-jest/index.js @@ -5,10 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = () => ({ +module.exports = { plugins: [ require.resolve('babel-plugin-jest-hoist'), + // TODO: replace all the below with a single preset in Jest 26: https://github.com/facebook/jest/pull/9774 require.resolve('@babel/plugin-syntax-object-rest-spread'), require.resolve('@babel/plugin-syntax-bigint'), + require.resolve('@babel/plugin-syntax-class-properties'), + require.resolve('@babel/plugin-syntax-logical-assignment-operators'), + require.resolve('@babel/plugin-syntax-numeric-separator'), ], -}); +}; diff --git a/packages/babel-preset-jest/package.json b/packages/babel-preset-jest/package.json index 4db8b5daadae..ef0a5ef9a2c5 100644 --- a/packages/babel-preset-jest/package.json +++ b/packages/babel-preset-jest/package.json @@ -10,6 +10,9 @@ "main": "index.js", "dependencies": { "@babel/plugin-syntax-bigint": "^7.0.0", + "@babel/plugin-syntax-class-properties": "^7.0.0", + "@babel/plugin-syntax-logical-assignment-operators": "^7.0.0", + "@babel/plugin-syntax-numeric-separator": "^7.0.0", "@babel/plugin-syntax-object-rest-spread": "^7.0.0", "babel-plugin-jest-hoist": "^25.2.6" }, diff --git a/yarn.lock b/yarn.lock index c026650daa0f..3f397fb1e469 100644 --- a/yarn.lock +++ b/yarn.lock @@ -479,6 +479,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.3" +"@babel/plugin-syntax-logical-assignment-operators@^7.0.0": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.8.3.tgz#3995d7d7ffff432f6ddc742b47e730c054599897" + integrity sha512-Zpg2Sgc++37kuFl6ppq2Q7Awc6E6AIW671x5PY8E/f7MCIyPPGK/EoeZXvvY3P42exZ3Q4/t3YOzP/HiN79jDg== + dependencies: + "@babel/helper-plugin-utils" "^7.8.3" + "@babel/plugin-syntax-nullish-coalescing-operator@^7.8.0": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz#167ed70368886081f74b5c36c65a88c03b66d1a9" @@ -486,7 +493,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-numeric-separator@^7.8.0", "@babel/plugin-syntax-numeric-separator@^7.8.3": +"@babel/plugin-syntax-numeric-separator@^7.0.0", "@babel/plugin-syntax-numeric-separator@^7.8.0", "@babel/plugin-syntax-numeric-separator@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.8.3.tgz#0e3fb63e09bea1b11e96467271c8308007e7c41f" integrity sha512-H7dCMAdN83PcCmqmkHB5dtp+Xa9a6LKSvA2hiFBC/5alSHxM5VgWZXFqDi0YFe8XNGT6iCa+z4V4zSt/PdZ7Dw== From 09322c13bad550e2588ffbd02c392f924d7c483a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 6 Apr 2020 09:05:16 +0200 Subject: [PATCH 2/4] we need the function :( --- packages/babel-preset-jest/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-preset-jest/index.js b/packages/babel-preset-jest/index.js index 11edbc08e99b..9bd7904aa7a9 100644 --- a/packages/babel-preset-jest/index.js +++ b/packages/babel-preset-jest/index.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = { +module.exports = () =>({ plugins: [ require.resolve('babel-plugin-jest-hoist'), // TODO: replace all the below with a single preset in Jest 26: https://github.com/facebook/jest/pull/9774 @@ -15,4 +15,4 @@ module.exports = { require.resolve('@babel/plugin-syntax-logical-assignment-operators'), require.resolve('@babel/plugin-syntax-numeric-separator'), ], -}; +}); From 1d63c651c1e38e8fb7ace5d1546a3080a953acc5 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 6 Apr 2020 09:08:12 +0200 Subject: [PATCH 3/4] make it purdy --- packages/babel-preset-jest/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-preset-jest/index.js b/packages/babel-preset-jest/index.js index 9bd7904aa7a9..cd830f84c856 100644 --- a/packages/babel-preset-jest/index.js +++ b/packages/babel-preset-jest/index.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = () =>({ +module.exports = () => ({ plugins: [ require.resolve('babel-plugin-jest-hoist'), // TODO: replace all the below with a single preset in Jest 26: https://github.com/facebook/jest/pull/9774 From 3c1c9252a56964b342125e2f5db3945793b9adc9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 6 Apr 2020 11:27:08 +0200 Subject: [PATCH 4/4] remove logical-assignment and lift resolving out of function --- packages/babel-preset-jest/index.js | 22 +++++++++++----------- packages/babel-preset-jest/package.json | 1 - yarn.lock | 7 ------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/packages/babel-preset-jest/index.js b/packages/babel-preset-jest/index.js index cd830f84c856..9378f2902d5b 100644 --- a/packages/babel-preset-jest/index.js +++ b/packages/babel-preset-jest/index.js @@ -5,14 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = () => ({ - plugins: [ - require.resolve('babel-plugin-jest-hoist'), - // TODO: replace all the below with a single preset in Jest 26: https://github.com/facebook/jest/pull/9774 - require.resolve('@babel/plugin-syntax-object-rest-spread'), - require.resolve('@babel/plugin-syntax-bigint'), - require.resolve('@babel/plugin-syntax-class-properties'), - require.resolve('@babel/plugin-syntax-logical-assignment-operators'), - require.resolve('@babel/plugin-syntax-numeric-separator'), - ], -}); +const plugins = [ + require.resolve('babel-plugin-jest-hoist'), + // TODO: replace all the below with a single preset in Jest 26: https://github.com/facebook/jest/pull/9774 + require.resolve('@babel/plugin-syntax-object-rest-spread'), + require.resolve('@babel/plugin-syntax-bigint'), + require.resolve('@babel/plugin-syntax-class-properties'), + require.resolve('@babel/plugin-syntax-numeric-separator'), +]; + +// @babel/core requires us to export a function +module.exports = () => ({plugins}); diff --git a/packages/babel-preset-jest/package.json b/packages/babel-preset-jest/package.json index ef0a5ef9a2c5..c8b67798be53 100644 --- a/packages/babel-preset-jest/package.json +++ b/packages/babel-preset-jest/package.json @@ -11,7 +11,6 @@ "dependencies": { "@babel/plugin-syntax-bigint": "^7.0.0", "@babel/plugin-syntax-class-properties": "^7.0.0", - "@babel/plugin-syntax-logical-assignment-operators": "^7.0.0", "@babel/plugin-syntax-numeric-separator": "^7.0.0", "@babel/plugin-syntax-object-rest-spread": "^7.0.0", "babel-plugin-jest-hoist": "^25.2.6" diff --git a/yarn.lock b/yarn.lock index 3f397fb1e469..c0b73ea0df03 100644 --- a/yarn.lock +++ b/yarn.lock @@ -479,13 +479,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.3" -"@babel/plugin-syntax-logical-assignment-operators@^7.0.0": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.8.3.tgz#3995d7d7ffff432f6ddc742b47e730c054599897" - integrity sha512-Zpg2Sgc++37kuFl6ppq2Q7Awc6E6AIW671x5PY8E/f7MCIyPPGK/EoeZXvvY3P42exZ3Q4/t3YOzP/HiN79jDg== - dependencies: - "@babel/helper-plugin-utils" "^7.8.3" - "@babel/plugin-syntax-nullish-coalescing-operator@^7.8.0": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz#167ed70368886081f74b5c36c65a88c03b66d1a9"