[ALOY-1574] Unable to use ES6 import/exports in alloy controllers due to bad code generation
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2017-09-21T01:00:31.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.10.4 |
Components | Tooling |
Labels | n/a |
Reporter | Christopher Williams |
Assignee | Feon Sua Xin Miao |
Created | 2017-08-02T15:54:56.000+0000 |
Updated | 2018-01-29T15:52:57.000+0000 |
Description
If you add imports or exports to an alloy controller, we can now parse the code and handle it in our use of babel/babylon instead of uglify. BUT, we don't "hoist" the imports/exports to the top of the generated code, so it can become embedded underneath a function which is invalid ES6 code. imports and exports must be "moved" up to the global top-level or else the code is invalid.
i.e.
import 'foo' from 'bar';
export const foo = Math.sqrt(2);
On a related note, we don't really "handle" ES6 imports/exports anyways down the line, but that's another ticket we can address in titanium CLI/build to just use babel transpilation to generate requires out of them (until the wider JS community has settled how to handle module vs script difference and imports/exports)
PR: https://github.com/appcelerator/alloy/pull/850 Alloy compile should be able to parse import/export without error. *Import* 1. Default import, i.e.
import test from '/test/hello';
2. Namespace import, i.e.import * as test from '/test/hello';
3. Named imports, i.e.import { a, b } from '/test/hello';
4. Empty import, i.e.import '/test/hellot';
*Export* 1. Inline Named exports , i.e.export const sqrt = Math.sqrt;
*Note* Default export, i.e.export default 'abc';
, is not supported in controller.