每当我更改 es6 文件时,我都会使用 grunt 和 grunt-babel 转译 ES6 代码。但是,其中一个文件似乎有错误,因为我在进行更改时收到此消息
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...
我有几个问题。
- scripts/test.es6.js 是一个正确的 ES6 文件,但是由于 scripts/actions.es6.js 中的错误而更改它的 ES5 版本时它没有出现在我的输出文件夹中 - 为什么?
- 如何在我的 ES6 代码中找到这个错误?
- 为什么强制标志不导致它编译?
谢谢
这是 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
这是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));
);
}
}
错误发生在 var id = datum.id;