I am learning to use es6 in one of my react project and apply new spread operator ...
this is working fine when using array []
( as spread operator) syntax but failed when using inside object {}
( as rest properties) i.e. not assigning value just modifying.
Are these both are two completely different things? here are my system detail
- node v 6.11.4
- babel-core v 6.26.0
- macOS Sierra v 10.12.6
- Sublime Text 3 build 3143
/*eslint no-unused-vars:0 */
let alpha = ['a','b','c', {first: 'first'}];
let beta = ['be', 'ta', { first: 'second'}];
let more = {text:'more', date: new Date()};
const gamma = [...alpha, more]; // this is working fine
console.log(gamma, alpha);
let todos = [{id: 1, completed: false}, {id:2, completed: true}];
const noCurlyFatArrow = () => {
return todos.map(todo =>
(todo.id === action.index)
? {...todo, completed: !todo.completed }
: todo
)
};
noCurlyFatArrow();
and run the JS Build System in the sublime text (⌘ + B
) and it gives following error in the console
/opt/rqt/src/react-only/spread.js:1
? {...todo, completed: !todo.completed }
^^^
SyntaxError: Unexpected token ...
Also made few changes in .babelrc filr from this issue dicussion but no luck.
.babelrc
{
"presets": ["es2015", "stage-3", "react"], //
"plugins": ["transform-es2015-destructuring", "transform-object-rest-spread"]
}
tried without "stage" and with "stage-0"
as well.
package.json
{
"name": "rqt",
"version": "0.1.0",
"private": true,
"dependencies": {
"jquery": "^3.2.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-redux": "^5.0.6",
"react-scripts": "1.0.14",
"redux": "^3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"eslint": "^4.10.0",
"eslint-config-airbnb": "^16.0.0",
"eslint-config-react-app": "^2.0.1",
"eslint-plugin-flowtype": "^2.39.1",
"eslint-plugin-html": "^4.0.0-alpha.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.4.0"
}
}