[TIMOB-25057] Hyperloop: Support ES6 user code
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | High |
| Status | Resolved |
| Resolution | Fixed |
| Resolution Date | 2018-03-28T18:48:16.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Hyperloop 3.1.0 |
| Components | Hyperloop |
| Labels | n/a |
| Reporter | Christopher Williams |
| Assignee | Christopher Williams |
| Created | 2017-08-02T16:05:29.000+0000 |
| Updated | 2018-03-28T18:48:16.000+0000 |
Description
We need to be able to handle es6 user code in hyperloop.
I don't know if we have any issues around using uglify for any of the hooks we use, but I do know that we have an issue around our
require detection if users starts using import instead.
We currently do some ugly regexp searching of the code to look for native require calls. We need to modify that regexp to find native import calls as well (or even use a real JS parser like babylon).
We should also consider if we can ease use of the hyperloop wrappers by allowing nice ES6 imports of frameworks/packages. i.e. in Android you can require a Java package and access types off of the returned object. Do we need to do anything special to support something like this?
import { ArrayList, Calendar } from 'java.util';
Proposed functionality (by [~cwilliams] from the [PR](https://github.com/appcelerator/hyperloop.next/pull/270)): iOS:
Android:// types var UIAlertController = require('UIKit/UIAlertController'); import UIAlertController from 'UIKit/UIAlertController'; import * as UIAlertController from 'UIKit/UIAlertController'; // types from frameworks import { UIAlertController, UIView } from 'UIKit'; // builtins/methods/whatever from frameworks var CGRectMake = require('CoreGraphics/CoreGraphics').CGRectMake; var CGRectMake = require('CoreGraphics').CGRectMake; import { CGRectMake, CGAffineTransformRotate } from 'CoreGraphics'; // invalid/ambiguous/unsupported? import UIView from 'UIKit'; // are they trying to import UIKit/UIKit and alias it as 'UIView'? // Or import UIView from 'UIKit/UIView';?// types var Activity = require('android.app.Activity'); import Activity from 'android.app.Activity'; import * as Activity from 'android.app.Activity'; // packages import { ArrayList, Calendar } from 'java.util.*'; var javaUtil = require('java.util.*'); var ArrayList = javaUtil.ArrayList;