I'm pretty new at es6, but I've been doing angular for a while now.
I do not understand why the below code doesn't transpile by Babel. Test it yourself by pasting into https://babeljs.io/.
The error is that it expects a (
at the start of the const singleDocumentSample
which seems to be an incorrectly reported error. I tried variations of
const xx;
xx = {};
just in case it was initialization-related. I tried changing to let
and even var
. What is going on?
Whole code file below:
class FakeData {
constructor($httpBackend) {
'ngInject';
this.$httpBackend = $httpBackend;
}
initialize() {
this.$httpBackend.whenGET('/v1/api/documents').respond(function () {
return [200, getAllDocuments()];
});
this.$httpBackend.whenGET(/\/v1\/api\/documents\/[1-9][0-9]*/).respond(function () {
return [200, getDocumentById()];
});
}
getAllDocuments() {
return allDocumentsSample;
}
getDocumentById() {
return singleDocumentSample;
}
const singleDocumentSample = {
"id": "5728fdb8e4b04adb356afb87",
"fileName": "6454841.xlsx",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"fileExtension": "xlsx",
"uploadDate": "2016-05-03T19:36:24Z",
"thumbnails": [
],
"thumbnailsDetailed": null,
"fileSize": 11467,
"description": "",
"position": null,
"confidential": null,
"customMetadata": null,
"who": {
"creationDate": "2016-05-03T19:36:24Z",
"lastUpdateDate": "2016-05-03T19:36:24Z",
"createdBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
},
"lastUpdatedBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
}
},
"url": "http://attachments-api.apps.wwt.com/api/attachments/5728fdb8e4b04adb356afb87/file"
};
const allDocumentsSample = {
"data": [
{
"id": "5728fdb8e4b04adb356afb87",
"fileName": "6454841.xlsx",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"fileExtension": "xlsx",
"uploadDate": "2016-05-03T19:36:24Z",
"thumbnails": [
],
"thumbnailsDetailed": null,
"fileSize": 11467,
"description": "",
"position": null,
"confidential": null,
"customMetadata": null,
"who": {
"creationDate": "2016-05-03T19:36:24Z",
"lastUpdateDate": "2016-05-03T19:36:24Z",
"createdBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
},
"lastUpdatedBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
}
},
"url": "http://attachments-api.apps.wwt.com/api/attachments/5728fdb8e4b04adb356afb87/file"
}
],
"pagination": {
"page": 1,
"pageSize": 50,
"pageCount": 456,
"sort": "id",
"order": "asc",
"itemCount": 22799,
"nextPageUrl": null,
"previousPageUrl": null
}
};
}
appModule.factory('fakeData', $httpBackend => new FakeData($httpBackend));