我使用grunt和grunt-babel來轉儲ES6代碼,只要我更改es6文件。但是,好像我在其中一個文件中有錯誤,因爲我在更改時收到此消息Grunt監視任務無法轉儲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...
我有幾個問題。
- 腳本/ test.es6.js是一個正確的ES6文件,但是當它在腳本,因爲一個錯誤而改變它的ES5版本不會出現在我的輸出文件夾/ actions.es6.js - 爲什麼?
- 如何在我的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));
);
}
}
的錯誤是在無功ID = datum.id發生;
你可以從'test.es6.js'文件添加代碼 – Tushar
它在那裏,我還添加了來自actions.es6.js的代碼 – praks5432