Reputation: 27527
I'm trying to use the spread operator in my firebase function and it's not working.
Package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"axios": "^0.16.2",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"case": "^1.5.3",
"change-case": "^3.0.1",
"cheerio": "^1.0.0-rc.2",
"emailjs": "^1.0.12",
"firebase-admin": "~5.2.1",
"firebase-functions": "^0.7.2",
"lodash": "^4.17.4",
"moment": "^2.18.1"
},
"babel": {
"presets": [
"env"
]
},
"private": true
}
featured.js:
"use strict";
const moment = require("moment");
const genDateWithStatus = (startDate, endDate) => ({
startDate: moment(startDate).valueOf(),
endDate: moment(endDate).valueOf(),
status: moment(startDate).valueOf() > moment().valueOf()
? "upcoming"
: moment(endDate).valueOf() > moment().valueOf() ? "active" : "recent"
});
module.exports = [
{
url: "https://blah.io/",
...genDateWithStatus("11/06/2017", "12/06/2017") // <---------- this part fails
},
];
This is the error that shows up when I try to start my server
/Users/edmundmai/Documents/src/myapp/functions/src/config/featured.js:19
...genDateWithStatus("11/06/2017", "12/06/2017")
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
Upvotes: 0
Views: 527
Reputation: 8376
Object spread operator is currently (November 2017) not supported in Node and browsers, so you could either use Object.assign
syntax
module.exports = [
Object.assign({}, { url: "https://blah.io/" }, genDateWithStatus("11/06/2017", "12/06/2017")),
];
or add the babel-plugin-transform-object-rest-spread transform plugin explicitly.
On the latter, see also Github issue: https://github.com/babel/babel-preset-env/issues/49.
Upvotes: 2