JavaScript Environment
JavaScript Runtime
When using React Native, you're going to be running your JavaScript code in up to three environments:
- In most cases, react-native-gpui uses Hermes, an open-source JavaScript engine optimized for React Native. Other engines can be installed as packages.
- Your code runs in the JavaScript engine of your app. There is no Node.js: Node built-in modules such as
fsandpathare not available.
While these environments are very similar, you may end up hitting some inconsistencies. It is best to avoid relying on specifics of any runtime.
Internationalization (Intl)
Hermes provides Intl.Collator, Intl.DateTimeFormat and Intl.NumberFormat, Intl.getCanonicalLocales, formatToParts, and the locale-aware toLocaleString, toLocaleDateString, toLocaleTimeString, toLocaleUpperCase, toLocaleLowerCase and localeCompare methods. It has no Intl.PluralRules, Intl.ListFormat, Intl.RelativeTimeFormat or Intl.Segmenter.
The formatting data comes from the ICU library of the operating system. Nothing is bundled, so the app does not grow:
| Platform | Library | Minimum |
|---|---|---|
| macOS | libicucore, part of the system | Every supported macOS |
| Windows | icu.dll in System32 | Windows 10, version 1903 |
| Linux | libicu (ICU 64 or later) | Installed by most desktop distributions |
On Linux the engine uses the newest libicui18n.so.N it finds, from 100 down to 64. Set RN_GPUI_ICU_VERSION to use one version.
If no ICU 64 or later is found the app still starts. The engine logs one warning, Intl stays defined, numbers print as plain JavaScript numbers, dates print as ISO 8601 in UTC, strings compare by code unit, and upper- and lower-casing covers ASCII letters only.
JavaScript Syntax Transformers
Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.
React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.
A full list of React Native's enabled transformations can be found in @react-native/babel-preset.
| Transformation | Code |
|---|---|
| ECMAScript 5 | |
| Reserved Words | |
| ECMAScript 2015 (ES6) | |
| Arrow functions | |
| Block scoping | |
| Call spread | |
| Classes | |
| Computed Properties | |
| Constants | |
| Destructuring | |
| for…of | |
| Function Name | |
| Literals | |
| Modules | |
| Object Concise Method | |
| Object Short Notation | |
| Parameters | |
| Rest Params | |
| Shorthand Properties | |
| Sticky Regex | |
| Template Literals | |
| Unicode Regex | |
| ECMAScript 2016 (ES7) | |
| Exponentiation Operator | |
| ECMAScript 2017 (ES8) | |
| Async Functions | |
| Function Trailing Comma | |
| ECMAScript 2018 (ES9) | |
| Object Spread | |
| ECMAScript 2019 (ES10) | |
| Optional Catch Binding | |
| ECMAScript 2020 (ES11) | |
| Dynamic Imports | |
| Nullish Coalescing Operator | |
| Optional Chaining | |
| ECMAScript 2022 (ES13) | |
| Class Fields | |
| Stage 1 Proposal | |
| Export Default From | |
| Miscellaneous | |
| Babel Template | |
| Flow | |
| ESM to CJS | |
| JSX | |
| Object Assign | |
| React Display Name | |
| TypeScript | |
Polyfills
Many standard functions are also available on all the supported JavaScript runtimes.
Browser
- CommonJS
require console.{log, warn, error, info, debug, trace, table, group, groupCollapsed, groupEnd}XMLHttpRequest,fetch{set, clear}{Timeout, Interval, Immediate}, {request, cancel}AnimationFrame
ECMAScript 2015 (ES6)
Array.fromArray.prototype.{find, findIndex}Object.assignString.prototype.{startsWith, endsWith, repeat, includes}
ECMAScript 2016 (ES7)
Array.prototype.includes
ECMAScript 2017 (ES8)
Specific
__DEV__