Description
*I'm making this a story because to me it's something that we need to investigate, discuss and act on*
With the addition of babel in 7.1.0 users can now use new syntax in their applications without worrying about what their targets support. While that is the theory it's not the reality.
If you review Babels [Learning ES2015](
https://babeljs.io/learn-es2015/) guide, some features denote
Support via polyfill
, this is because babel can only handle syntactical changes (arrow function to function expressions, let/const to var etc.), and for features such as maps and promises it is impossible to transpile these down so babel makes use of polyfills, which instead add these into the JS environment.
To me, there are a two avenues to us handling this
* We distribute [babel-polyfill](
https://www.npmjs.com/package/babel-polyfill) in the SDK
* We pass this on down to the user, either through usage of a module or just requiring them to add the module themselves.
* We evaluate including babel-runtime/transform-runtime in the transpile step
https://babeljs.io/docs/plugins/transform-runtime
This has been attempted already (kind of) in two ways
* I attempted to add babel-polyfill to an app [~hknoechel] was writing (TIMOB-25740), it didn't go well for me, I believe we could fix this
* [~gmathews] [node-titanium-sdk](
https://github.com/appcelerator/node-titanium-sdk/pull/24) PR, which includes regenerator-runtime to allow apps to use async/await
Here's my first thoughts on drawbacks I see with both ways
* User owned
** Doesn't adhere with our current way of handling this kind of thing where we deal with it
* SDK owned
** Unless we're detect what's needed every app will include it, whether they need it or not.
** We'll need to continually maintain this each release I believe
I looked at how others handle this, and discovered the following
* react-native [rolls its own preset](
https://github.com/facebook/react-native), which appears to be dynamic dependent on an apps usage. Polyfills look to be baked into react-native with them being defined when the [app start](
https://github.com/facebook/react-native/blob/master/Libraries/Core/InitializeCore.js)
I've had some luck with babel-polyfill on iOS after trying this again, I moved Hans' example to an async function for the geolocation https://github.com/ewanharris/titanium-es6-sample/tree/async_await. Android currently throws when requiring babel-polyfill, see TIMOB-25826.
*NOTE* -
@babel/polyfill
is used byti.es6
https://github.com/appcelerator/ti.es6/blob/master/plugins/ti.es6/1.1.0/hooks/ti.es6.js#L52node-titanium-sdk: https://github.com/appcelerator/node-titanium-sdk/pull/32