I'm using grunt and grunt-babel to transpile ES6 code whenever I change an es6 file. However, it seems like I have an error in one of those files, as I get this message when I make a change
Waiting...
>> File "scripts/test.es6.js" changed.
Running "babel:files" (babel) task
Warning: scripts/actions.es6.js: Unexpected token (38:5) Used --force, continuing.
Done, but with warnings.
Completed in 0.758s at Mon Sep 14 2015 20:11:53 GMT-0700 (PDT) - Waiting...
I have a few questions.
- scripts/test.es6.js is a correct ES6 file, yet the ES5 version of it doesn't appear in my output folder when it is changed because of an error in scripts/actions.es6.js - why?
- How do I find this error in my ES6 code?
- Why isn't the force flag causing this to compile?
Thanks
This is test.es6.js
class Person { // The 'class' keyword
constructor(name, age) { // Constructors
this.name = name;
this.age = age;
}
}
class Developer extends Person { // The 'extends' keyword
constructor(name, age, ...languages) { // Rest parameters
super(name, age); // Super calls
this.languages = [...languages]; // The spread operator
}
printLanguages() { // Short method definitions
for(let lang of this.languages) { // The for..of loop
console.log(lang);
}
}
}
let me = new Developer("James", 23, "ES5", "ES6"); // Block scoping hello
This is actions.es6.js
/*
* Action types
*/
export const REQUEST_DISTRICTS = 'REQUEST_DISTRICTS';
export function requestDistricts(geoState) {
return {
type: REQUEST_DISTRICTS,
geoState
};
}
export const RECEIVE_DISTRICTS = 'RECEIVE_DISTRICTS';
export function receiveDistricts(geoState, json) {
return {
type: RECEIVE_DISTRICTS,
geoState,
receivedAt: Date.now(),
districts: json.data.districts.map(district => district.data)
}
}
export function fetchDistricts(geoState) {
return function (dispatch) {
dispatch(requestDistricts(geoState));
var districtsDfd = $.ajax({
url: "http://localhost:8080/districts/",
type: "GET",
dataType: "json"
});
var demographiesDfd = [];
$.when(districtsDfd).then(function(data, textStatus, jqXhr){
if (data) {
_.each(data, datum =>
var id = datum.id;
demographiesDfd.push($.getJSON("http://localhost:8080/district/${id}/demography"));
);
}
});
$.when(...demographiesDfd).done(result =>
//so I have demographic data right now.
dispatch(receiveDistricts(geoState, result));
);
}
}
The error is happening on var id = datum.id;