BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News NativeScript 7 Moves from ES5 to ES2017+

NativeScript 7 Moves from ES5 to ES2017+

This item in japanese

Bookmarks

NativeScript 7 aligns with modern JavaScript standards by targeting es2017+. Additionally, it streamlines app configuration by consolidating it in a single file and replaces JavaScriptCore with V8 for iOS apps.

Adopting ES2017, which means that NativeScript will now default to using it as an output target, is mostly motivated by the aim of taking advantage of the improvements it brings to the language, such as the ?? Nullish coalescing operator and optional chaining.

In fact, it was already possible to use ES2017 features supported by TypeScript with previous NativeScript versions, but that meant code was transpiled down to ES5, with potential performance loss and making code harder to step through. For example, this is the case with async/await support, which is now "native" in ES2017, and with the class directive.

The switch to ES2017 is made possible by the adoption of the V8 engine for the iOS platform as well, replacing the JavaScriptCore runtime. This decision levels up JavaScript support on both platforms and reduces maintenance cost, since the NativeScript team will only need to maintain one runtime. In case of incompatibilities or any other issues, you can force NativeScript to use JavaScriptCore by using tns-ios.

Another improvement brought by NativeScript 7 is configuration files consolidation. Until now, app configuration was specified in three different files: the root package.json, nsconfig.json, and another package.json hidden in the source directory to specify any runtime flags. Now, you can just use the new nativescript.config.ts or nativescript.config.js to specify the whole app configuration. The new files enable to specify an app's configuration by using code, so, if you use TypeScript, your nativescript.config.ts file will actually contain a type-safe definition of your project. This is an example of a simple nativescript.config.ts:

import { NativeScriptConfig } from '@nativescript/core';

export default {
  id: 'com.company.app',
  main: 'app.js',
  appResourcesPath: 'App_Resources',
  webpackConfigPath: 'webpack.config.js',
  ios: {
    discardUncaughtJsExceptions: true
  },
  android: {
    discardUncaughtJsExceptions: true,
    v8Flags: '--nolazy --expose_gc',
    "markingMode": "none",
    "suppressCallJSMethodExceptions": false
  }
} as NativeScriptConfig;

On the tooling front, NativeScript CLI has been renamed to ns, although you can also use nsc or the old tns if you prefer it. The new CLI introduces a new ns clean command that can be used to clean up a project's files.

As a final note about migrating existing projects, NativeScript CLI provides the command ns migrate to that aim, but you should make sure all of your plugins are compatible with NativeScript 7 before using it. If you are developing a plugin, make sure you check out the list of [adjustments](https://nativescript.org/blog/nativescript-7-for-plugin-authors/0 that concern you.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT