From e027829cdbdbdb8bf0b6674fe6f0ce9638a6e6d5 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 5 Jul 2022 11:26:31 -0700 Subject: [PATCH] Reduce babel junk in built files Configure babel preset-env to match the documentation's browser support list. --- .github/CONTRIBUTING.md | 10 +-- configs/babel.config.js | 70 ++++++++++--------- .../src/exports/Text/index.js | 29 ++++---- .../src/exports/TextInput/index.js | 57 ++++++++------- .../src/exports/View/index.js | 36 ++++++---- 5 files changed, 106 insertions(+), 96 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index bf305938..24b753a1 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -99,17 +99,13 @@ Please open an issue with a proposal for a new feature or refactoring before sta 3. If you've changed APIs, update the documentation. 4. Ensure the tests pass (`npm run test`). -You should see a pre-commit hook run before each commit. If it does not, you may need to reset you Git hookspath: - -``` -git config --unset core.hookspath -``` +You should see a pre-commit hook run before each commit. You can now submit a pull request, referencing any issues it addresses. Please try to keep your pull request focused in scope and avoid including unrelated commits. -After you have submitted your pull request, we'll try to get back to you as soon as possible. We may suggest some changes or improvements. +After you have submitted your pull request, it's recommended that **you** perform the first code review. We'll try to get back to you as soon as possible and may suggest changes. Thank you for contributing! @@ -118,7 +114,7 @@ Thank you for contributing! To commit, publish, and push a final version: ``` -npm run release -- +npm run release -- --opt= ``` Release candidates or versions that you'd like to publish to npm, but do not want to produce a commit and push it to GitHub: diff --git a/configs/babel.config.js b/configs/babel.config.js index 3f75acb1..ae0b9d69 100644 --- a/configs/babel.config.js +++ b/configs/babel.config.js @@ -1,15 +1,22 @@ -module.exports = function (api) { - if (api) { - api.cache(true); - } - - let modules = false; - - if (process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test') { - modules = 'commonjs'; - } +const createConfig = ({ modules }) => { + const plugins = [ + '@babel/plugin-transform-flow-strip-types', + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }], + '@babel/plugin-proposal-nullish-coalescing-operator', + [ + '@babel/plugin-transform-runtime', + { + version: '7.18.6' + } + ] + ].concat(modules ? ['babel-plugin-add-module-exports'] : []); return { + assumptions: { + iterableIsArray: true + }, + comments: true, presets: [ [ '@babel/preset-env', @@ -19,18 +26,14 @@ module.exports = function (api) { exclude: ['transform-typeof-symbol'], targets: { browsers: [ - 'chrome 38', - 'android 4', - 'firefox 40', - 'ios_saf 7', - 'safari 7', - 'ie 10', - 'ie_mob 11', - 'edge 12', - 'opera 16', - 'op_mini 12', - 'and_uc 9', - 'and_chr 38' + 'chrome 49', + // https://www.mozilla.org/en-US/firefox/all/#product-desktop-esr + 'firefox 91', + 'ios_saf 10', + 'safari 10', + // https://docs.microsoft.com/en-us/DeployEdge/microsoft-edge-support-lifecycle + 'edge 94', + 'opera 36' ] } } @@ -38,17 +41,16 @@ module.exports = function (api) { '@babel/preset-react', '@babel/preset-flow' ], - plugins: [ - '@babel/plugin-transform-flow-strip-types', - ['@babel/plugin-proposal-class-properties', { loose: true }], - ['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }], - '@babel/plugin-proposal-nullish-coalescing-operator', - [ - '@babel/plugin-transform-runtime', - { - version: '7.18.6' - } - ] - ].concat(modules ? ['babel-plugin-add-module-exports'] : []) + plugins: plugins }; }; + +module.exports = function (api) { + if (api) { + api.cache(true); + } + + return process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test' + ? createConfig({ modules: 'commonjs' }) + : createConfig({ modules: false }); +}; diff --git a/packages/react-native-web/src/exports/Text/index.js b/packages/react-native-web/src/exports/Text/index.js index f8518235..d5b47c28 100644 --- a/packages/react-native-web/src/exports/Text/index.js +++ b/packages/react-native-web/src/exports/Text/index.js @@ -23,19 +23,22 @@ import StyleSheet from '../StyleSheet'; import TextAncestorContext from './TextAncestorContext'; import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale'; -const forwardPropsList = { - ...forwardedProps.defaultProps, - ...forwardedProps.accessibilityProps, - ...forwardedProps.clickProps, - ...forwardedProps.focusProps, - ...forwardedProps.keyboardProps, - ...forwardedProps.mouseProps, - ...forwardedProps.touchProps, - ...forwardedProps.styleProps, - href: true, - lang: true, - pointerEvents: true -}; +const forwardPropsList = Object.assign( + {}, + forwardedProps.defaultProps, + forwardedProps.accessibilityProps, + forwardedProps.clickProps, + forwardedProps.focusProps, + forwardedProps.keyboardProps, + forwardedProps.mouseProps, + forwardedProps.touchProps, + forwardedProps.styleProps, + { + href: true, + lang: true, + pointerEvents: true + } +); const pickProps = (props) => pick(props, forwardPropsList); diff --git a/packages/react-native-web/src/exports/TextInput/index.js b/packages/react-native-web/src/exports/TextInput/index.js index 95dbd077..8073cc6c 100644 --- a/packages/react-native-web/src/exports/TextInput/index.js +++ b/packages/react-native-web/src/exports/TextInput/index.js @@ -47,33 +47,36 @@ const setSelection = (node, selection) => { } }; -const forwardPropsList = { - ...forwardedProps.defaultProps, - ...forwardedProps.accessibilityProps, - ...forwardedProps.clickProps, - ...forwardedProps.focusProps, - ...forwardedProps.keyboardProps, - ...forwardedProps.mouseProps, - ...forwardedProps.touchProps, - ...forwardedProps.styleProps, - autoCapitalize: true, - autoComplete: true, - autoCorrect: true, - autoFocus: true, - defaultValue: true, - disabled: true, - lang: true, - maxLength: true, - onChange: true, - onScroll: true, - placeholder: true, - pointerEvents: true, - readOnly: true, - rows: true, - spellCheck: true, - value: true, - type: true -}; +const forwardPropsList = Object.assign( + {}, + forwardedProps.defaultProps, + forwardedProps.accessibilityProps, + forwardedProps.clickProps, + forwardedProps.focusProps, + forwardedProps.keyboardProps, + forwardedProps.mouseProps, + forwardedProps.touchProps, + forwardedProps.styleProps, + { + autoCapitalize: true, + autoComplete: true, + autoCorrect: true, + autoFocus: true, + defaultValue: true, + disabled: true, + lang: true, + maxLength: true, + onChange: true, + onScroll: true, + placeholder: true, + pointerEvents: true, + readOnly: true, + rows: true, + spellCheck: true, + value: true, + type: true + } +); const pickProps = (props) => pick(props, forwardPropsList); diff --git a/packages/react-native-web/src/exports/View/index.js b/packages/react-native-web/src/exports/View/index.js index c4a9be14..c2737b40 100644 --- a/packages/react-native-web/src/exports/View/index.js +++ b/packages/react-native-web/src/exports/View/index.js @@ -23,21 +23,27 @@ import StyleSheet from '../StyleSheet'; import TextAncestorContext from '../Text/TextAncestorContext'; import { useLocaleContext, getLocaleDirection } from '../../modules/useLocale'; -const forwardPropsList = { - ...forwardedProps.defaultProps, - ...forwardedProps.accessibilityProps, - ...forwardedProps.clickProps, - ...forwardedProps.focusProps, - ...forwardedProps.keyboardProps, - ...forwardedProps.mouseProps, - ...forwardedProps.touchProps, - ...forwardedProps.styleProps, - href: true, - lang: true, - onScroll: true, - onWheel: true, - pointerEvents: true -}; +const forwardPropsList = Object.assign( + {}, + forwardedProps.defaultProps, + forwardedProps.accessibilityProps, + forwardedProps.clickProps, + forwardedProps.defaultProps, + forwardedProps.accessibilityProps, + forwardedProps.clickProps, + forwardedProps.focusProps, + forwardedProps.keyboardProps, + forwardedProps.mouseProps, + forwardedProps.touchProps, + forwardedProps.styleProps, + { + href: true, + lang: true, + onScroll: true, + onWheel: true, + pointerEvents: true + } +); const pickProps = (props) => pick(props, forwardPropsList);