[TIMOB-24726] iOS: Error when requiring ES6 class
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-05-23T21:44:30.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | ES6, Titanium |
Reporter | Brenton House |
Assignee | Christopher Williams |
Created | 2017-05-23T20:35:36.000+0000 |
Updated | 2017-05-23T21:44:30.000+0000 |
Description
When calling
require('animal')
I am getting the following error:
{noformat}
[ERROR] message = "Unexpected use of reserved word 'class'";
{noformat}
animal.js
'use strict';
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(this.name + ' makes a noise.');
}
}
module.exports = Animal;
Hello, Can you provide a full reproducible code and steps to generate the issue? Thanks.
Steps to recreate: 1. Create new Titanium app using CLI 2. Create new file:
lib/animal.js
3. Add the following line to
controllers/index.js
:3. Run the app:
appc ti build --platform ios --target simulator --log-level trace
Is this at runtime? If so, it's because you need to switch to the bundled JSCore engine from iOS to get ES6 support. Our TiCore fork is very old. You do that by setting a special value in your tiapp.xml:
there's more details on the PR itself about this: https://github.com/appcelerator/titanium_mobile/pull/8972 But basically, we do not transpire your ES6 code down to ES5 on older engines (yet). We pass the code through and it's up the JS engine if it supports it. TiCore is very old and does not. Using bundled JSCore means it's up to the iOS version you're running (see https://kangax.github.io/compat-table/es6/)
Sorry about that [~cwilliams]! Forgot to switch that on for the new project. You can close this ticket.