How to use the @babel/plugin-proposal-optional-chaining.default function in @babel/plugin-proposal-optional-chaining

To help you get started, we’ve selected a few @babel/plugin-proposal-optional-chaining examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / metro / packages / metro-babel-register / src / babel-register.js View on Github external
'use strict';

const escapeRegExp = require('escape-string-regexp');
const path = require('path');
require('./node-polyfills');

var _only = [];

const PLUGINS = [
  [require('@babel/plugin-transform-flow-strip-types').default],
  [require('@babel/plugin-proposal-object-rest-spread').default],
  [require('@babel/plugin-proposal-class-properties').default],
  [require('@babel/plugin-transform-modules-commonjs').default],
  [require('@babel/plugin-proposal-nullish-coalescing-operator').default],
  [require('@babel/plugin-proposal-optional-catch-binding').default],
  [require('@babel/plugin-proposal-optional-chaining').default],
];

if (/^v[0-7]\./.test(process.version)) {
  PLUGINS.push([require('@babel/plugin-transform-async-to-generator').default]);
}

function registerOnly(onlyList) {
  // This prevents `babel-register` from transforming the code of the
  // plugins/presets that we are require-ing themselves before setting up the
  // actual config.
  require('@babel/register')({only: [], babelrc: false, configFile: false});
  require('@babel/register')(config(onlyList));
}

function config(onlyList) {
  _only = _only.concat(onlyList);
github facebook / metro / packages / metro-babel-register / src / babel-register.js View on Github external
'use strict';

const escapeRegExp = require('escape-string-regexp');
const path = require('path');
require('./node-polyfills');

var _only = [];

const PLUGINS = [
  [require('@babel/plugin-transform-flow-strip-types').default],
  [require('@babel/plugin-proposal-object-rest-spread').default],
  [require('@babel/plugin-proposal-class-properties').default],
  [require('@babel/plugin-transform-modules-commonjs').default],
  [require('@babel/plugin-proposal-nullish-coalescing-operator').default],
  [require('@babel/plugin-proposal-optional-catch-binding').default],
  [require('@babel/plugin-proposal-optional-chaining').default],
];

if (/^v[0-7]\./.test(process.version)) {
  PLUGINS.push([require('@babel/plugin-transform-async-to-generator').default]);
}

function registerOnly(onlyList) {
  // This prevents `babel-register` from transforming the code of the
  // plugins/presets that we are require-ing themselves before setting up the
  // actual config.
  require('@babel/register')({only: [], babelrc: false});
  require('@babel/register')(config(onlyList));
}

function config(onlyList) {
  _only = _only.concat(onlyList);
github instructure / instructure-ui / packages / ui-babel-preset / lib / index.js View on Github external
try {
    // eslint-disable-next-line import/no-extraneous-dependencies
    const version = require('@babel/helpers/package.json').version
    babelHelperVersion.version = version
  } catch (e) {
    // if something goes wrong, continue and don't try to explicitly set a helper version
  }

  plugins = plugins.concat([
    require('babel-plugin-macros'),
    require('@babel/plugin-transform-destructuring').default,
    [require('@babel/plugin-proposal-decorators').default, { legacy: true }], // must run before themeable-styles plugin below
    [require('@babel/plugin-proposal-class-properties').default, { loose: true }],
    require('@babel/plugin-proposal-export-default-from').default,
    [require('@babel/plugin-proposal-object-rest-spread').default, { useBuiltIns: true }],
    require('@babel/plugin-proposal-optional-chaining').default,
    [require('@babel/plugin-transform-runtime').default, {
      ...babelHelperVersion,
      corejs: false,
      regenerator: true,
      helpers: true,
      useESModules: opts.esModules
    }],
    require('@babel/plugin-syntax-dynamic-import').default,
    require('babel-plugin-transform-undefined-to-void')
  ])

  if (process.env.NODE_ENV === 'production') {
    plugins.push(
      require('@babel/plugin-transform-react-constant-elements').default
    )
  }
github christophehurpeau / babel-preset-modern-browsers / lib / index.js View on Github external
es2018 && edge
        ? require('@babel/plugin-proposal-async-generator-functions')
        : require('@babel/plugin-syntax-async-generators'),

      es2019 &&
        (edge
          ? require('@babel/plugin-proposal-optional-catch-binding')
          : require('@babel/plugin-syntax-optional-catch-binding')),

      /* shippedProposals */
      shippedProposals &&
        (edge
          ? require('@babel/plugin-proposal-json-strings')
          : require('@babel/plugin-syntax-json-strings')),
      shippedProposals &&
        require('@babel/plugin-proposal-optional-chaining').default,
      shippedProposals &&
        require('@babel/plugin-proposal-nullish-coalescing-operator').default,
    ].filter(Boolean),
  };
};
github facebook / create-react-app / packages / babel-preset-react-app / create.js View on Github external
// the correct version is used
          // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
          absoluteRuntime: absoluteRuntimePath,
        },
      ],
      isEnvProduction && [
        // Remove PropTypes from production build
        require('babel-plugin-transform-react-remove-prop-types').default,
        {
          removeImport: true,
        },
      ],
      // Adds syntax support for import()
      require('@babel/plugin-syntax-dynamic-import').default,
      // Adds syntax support for optional chaining (?.)
      require('@babel/plugin-proposal-optional-chaining').default,
      // Adds syntax support for default value using ?? operator
      require('@babel/plugin-proposal-nullish-coalescing-operator').default,
      isEnvTest &&
        // Transform dynamic import to require
        require('babel-plugin-dynamic-import-node'),
    ].filter(Boolean),
    overrides: [
      isFlowEnabled && {
        exclude: /\.tsx?$/,
        plugins: [require('@babel/plugin-transform-flow-strip-types').default],
      },
      isTypeScriptEnabled && {
        test: /\.tsx?$/,
        plugins: [
          [
            require('@babel/plugin-proposal-decorators').default,
github electron-userland / electron-builder / packages / app-builder-lib / src / ProtonFramework.ts View on Github external
function testOnlyBabel(babel: any, babelOptions: any, nodeVersion: string) {
  // out test dir can be located outside of electron-builder node_modules and babel cannot resolve string names of preset
  babelOptions.presets = [
    [require("@babel/preset-env").default, {targets: {node: nodeVersion}}],
    require("@babel/preset-react"),
  ]
  babelOptions.plugins = [
    // stage 0
    require("@babel/plugin-proposal-function-bind").default,

    // stage 1
    require("@babel/plugin-proposal-export-default-from").default,
    require("@babel/plugin-proposal-logical-assignment-operators").default,
    [require("@babel/plugin-proposal-optional-chaining").default, {loose: false}],
    [require("@babel/plugin-proposal-pipeline-operator").default, {proposal: "minimal"}],
    [require("@babel/plugin-proposal-nullish-coalescing-operator").default, {loose: false}],
    require("@babel/plugin-proposal-do-expressions").default,

    // stage 2
    [require("@babel/plugin-proposal-decorators").default, {legacy: true}],
    require("@babel/plugin-proposal-function-sent").default,
    require("@babel/plugin-proposal-export-namespace-from").default,
    require("@babel/plugin-proposal-numeric-separator").default,
    require("@babel/plugin-proposal-throw-expressions").default,

    // stage 3
    require("@babel/plugin-syntax-dynamic-import").default,
    require("@babel/plugin-syntax-import-meta").default,
    [require("@babel/plugin-proposal-class-properties").default, {loose: false}],
    require("@babel/plugin-proposal-json-strings").default,
github SUI-Components / sui / packages / babel-preset-sui / src / index.js View on Github external
function plugins(api, opts = {}) {
  return cleanList([
    require('@babel/plugin-syntax-dynamic-import').default,
    require('@babel/plugin-syntax-export-default-from').default,
    require('@babel/plugin-syntax-export-namespace-from').default,
    require('@babel/plugin-proposal-optional-chaining').default,
    require('@babel/plugin-proposal-nullish-coalescing-operator').default,
    [require('@babel/plugin-proposal-decorators').default, {legacy: true}],
    [require('@babel/plugin-proposal-class-properties').default, {loose: true}],
    [
      require('babel-plugin-transform-react-remove-prop-types').default,
      {
        wrap: true
      }
    ],
    [
      require('@babel/plugin-proposal-object-rest-spread').default,
      {useBuiltIns: true} // asume Object.assign is available by browser or polyfill
    ],
    [
      require('@babel/plugin-transform-runtime').default,
      {
github americanexpress / babel-preset-amex / index.js View on Github external
* in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

const envPreset = require('@babel/preset-env');
const reactPreset = require('@babel/preset-react');
const syntaxDynamicImport = require('@babel/plugin-syntax-dynamic-import').default;
const proposalClassProperties = require('@babel/plugin-proposal-class-properties').default;
const exportDefaultFrom = require('@babel/plugin-proposal-export-default-from').default;
const proposalOptionalChaining = require('@babel/plugin-proposal-optional-chaining').default;

const { browserlist, legacyBrowserList } = require('./browserlist');

module.exports = () => ({
  env: {
    modern: {
      presets: [
        [envPreset, {
          targets: {
            browsers: browserlist,
            node: '10.13.0',
          },
        }],
      ],
    },
  },

@babel/plugin-proposal-optional-chaining

Transform optional chaining operators into a series of nil checks

MIT
Latest version published 2 years ago

Package Health Score

72 / 100
Full package analysis

Popular @babel/plugin-proposal-optional-chaining functions