Skip to content

Commit 7acb6fc

Browse files
committed
Enable optional chaining for CRA
1 parent 3489127 commit 7acb6fc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/app/src/sandbox/eval/presets/create-react-app/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default function initialize() {
6060
config: {
6161
plugins: [
6262
'@babel/plugin-transform-react-jsx-source',
63+
'@babel/plugin-proposal-optional-chaining',
6364
'transform-flow-strip-types',
6465
'transform-destructuring',
6566
'babel-plugin-macros',

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

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { flatten } from 'lodash-es';
33
import codeFrame from 'babel-code-frame';
44
import macrosPlugin from 'babel-plugin-macros';
5+
import chainingPlugin from '@babel/plugin-proposal-optional-chaining';
56

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

@@ -622,6 +623,18 @@ self.addEventListener('message', async event => {
622623
Babel.registerPlugin('babel-plugin-macros', macrosPlugin);
623624
}
624625

626+
console.log(flattenedPlugins);
627+
if (
628+
(flattenedPlugins.indexOf('proposal-optional-chaining') > -1 ||
629+
flattenedPlugins.indexOf('@babel/plugin-proposal-optional-chaining') >
630+
-1) &&
631+
Object.keys(Babel.availablePlugins).indexOf(
632+
'proposal-optional-chaining'
633+
) === -1
634+
) {
635+
Babel.registerPlugin('proposal-optional-chaining', chainingPlugin);
636+
}
637+
625638
if (
626639
flattenedPlugins.indexOf('transform-cx-jsx') > -1 &&
627640
Object.keys(Babel.availablePlugins).indexOf('transform-cx-jsx') === -1

0 commit comments

Comments
 (0)