Skip to content

Commit a263ad8

Browse files
authored
Add coalescing plugin to CRA v3 (codesandbox#3264)
1 parent 2f6ba18 commit a263ad8

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
"@babel/core": "^7.5.5",
227227
"@babel/helper-module-imports": "^7.0.0",
228228
"@babel/plugin-proposal-class-properties": "^7.5.5",
229+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
229230
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
230231
"@babel/plugin-proposal-optional-chaining": "^7.7.4",
231232
"@babel/plugin-syntax-dynamic-import": "^7.2.0",

packages/app/src/sandbox/eval/presets/create-react-app/v3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const BABEL7_CONFIG = {
5252
['proposal-decorators', { legacy: true }],
5353
'@babel/plugin-transform-react-jsx-source',
5454
'@babel/plugin-proposal-optional-chaining',
55+
'@babel/plugin-proposal-nullish-coalescing-operator',
5556
'transform-flow-strip-types',
5657
'transform-destructuring',
5758
'babel-plugin-macros',

packages/app/src/sandbox/eval/transpilers/babel/worker/babel-worker.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { flatten } from 'lodash-es';
33
import codeFrame from 'babel-code-frame';
44
import macrosPlugin from 'babel-plugin-macros';
55
import chainingPlugin from '@babel/plugin-proposal-optional-chaining';
6+
import coalescingPlugin from '@babel/plugin-proposal-nullish-coalescing-operator';
67

78
import delay from '@codesandbox/common/lib/utils/delay';
89

@@ -634,6 +635,23 @@ self.addEventListener('message', async event => {
634635
Babel.registerPlugin('proposal-optional-chaining', chainingPlugin);
635636
}
636637

638+
const coalescingInPlugins =
639+
flattenedPlugins.indexOf('proposal-nullish-coalescing-operator') > -1 ||
640+
flattenedPlugins.indexOf(
641+
'@babel/plugin-proposal-nullish-coalescing-operator'
642+
) > -1;
643+
if (
644+
coalescingInPlugins &&
645+
Object.keys(Babel.availablePlugins).indexOf(
646+
'proposal-nullish-coalescing-operator'
647+
) === -1
648+
) {
649+
Babel.registerPlugin(
650+
'proposal-nullish-coalescing-operator',
651+
coalescingPlugin
652+
);
653+
}
654+
637655
if (
638656
flattenedPlugins.indexOf('transform-cx-jsx') > -1 &&
639657
Object.keys(Babel.availablePlugins).indexOf('transform-cx-jsx') === -1

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@
404404
"@babel/helper-plugin-utils" "^7.0.0"
405405
"@babel/plugin-syntax-json-strings" "^7.2.0"
406406

407+
"@babel/plugin-proposal-nullish-coalescing-operator@^7.7.4":
408+
version "7.7.4"
409+
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.7.4.tgz#7db302c83bc30caa89e38fee935635ef6bd11c28"
410+
integrity sha512-TbYHmr1Gl1UC7Vo2HVuj/Naci5BEGNZ0AJhzqD2Vpr6QPFWpUmBRLrIDjedzx7/CShq0bRDS2gI4FIs77VHLVQ==
411+
dependencies:
412+
"@babel/helper-plugin-utils" "^7.0.0"
413+
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.7.4"
414+
407415
408416
version "7.0.0"
409417
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.0.0.tgz#9a17b547f64d0676b6c9cecd4edf74a82ab85e7e"
@@ -505,6 +513,13 @@
505513
dependencies:
506514
"@babel/helper-plugin-utils" "^7.0.0"
507515

516+
"@babel/plugin-syntax-nullish-coalescing-operator@^7.7.4":
517+
version "7.7.4"
518+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.7.4.tgz#e53b751d0c3061b1ba3089242524b65a7a9da12b"
519+
integrity sha512-XKh/yIRPiQTOeBg0QJjEus5qiSKucKAiApNtO1psqG7D17xmE+X2i5ZqBEuSvo0HRuyPaKaSN/Gy+Ha9KFQolw==
520+
dependencies:
521+
"@babel/helper-plugin-utils" "^7.0.0"
522+
508523
"@babel/plugin-syntax-object-rest-spread@^7.0.0", "@babel/plugin-syntax-object-rest-spread@^7.2.0":
509524
version "7.2.0"
510525
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e"

0 commit comments

Comments
 (0)