Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function babelPresetGitHub(api, { useBuiltIns = false, env = true, modules = false, targets = {} }) {
targets = Object.assign({}, { browsers: defaultBrowsers }, targets)
if (targets.browsers === 'mobile') targets.browsers = mobileBrowsers
if (targets.browsers === 'default') targets.browsers = defaultBrowsers
const presets = []
const plugins = [
// ES2019
// Stage 3 with good signals for Stage 4
// Chrome 64+, Firefox 62+, Safari TP42, Opera 51+
require('@babel/plugin-syntax-import-meta').default,
// Chrome 63+, Firefox (https://mzl.la/2LMSnOf), Safari TP25, Opera 50+
require('@babel/plugin-syntax-dynamic-import').default,
// Non-standard
require('@babel/plugin-transform-flow-strip-types').default,
// Custom
require('babel-plugin-transform-invariant-location'),
]
const fullBrowsers = browserslist(targets.browsers)
const needsRestSpread = browserslist(['Edge > 0', 'Safari < 11.1']).some(browser => fullBrowsers.includes(browser))
if (env) {
presets.push([require('@babel/preset-env').default, { modules, targets, useBuiltIns: useBuiltIns ? 'entry' : false }])
} else if (needsRestSpread) {
plugins.push([require('@babel/plugin-proposal-object-rest-spread'), { useBuiltIns }])
}
return { plugins, presets };
};
const jsFeatures = () => [
// old Stage 1
require('@babel/plugin-proposal-export-default-from').default,
// old Stage 2
[require('@babel/plugin-proposal-decorators').default, {legacy: true}],
// old 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,
];
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,
]
babelOptions.babelrc = false
return babel
}