不得在babel 7中使用“ object-rest-spread”结尾的逗号

时间:2019-01-21 02:30:48

标签: reactjs babel

这是我的package.json

"devDependencies": {
    "@babel/core": "7.0.1",
    "@babel/node": "7.0.0",
    "@babel/plugin-proposal-class-properties": "7.0.0",
    "@babel/preset-env": "7.0.0",
    "@babel/preset-es2015": "7.0.0-beta.53",
    "@babel/preset-react": "7.0.0",
    "babel-loader": "8.0.4",
    "css-loader": "1.0.0",
    "es6-promise": "4.2.5",
    "file-loader": "2.0.0",
    "html-webpack-plugin": "3.2.0",
    "node-sass": "4.9.3",
    "path": "0.12.7",
    "sass-loader": "7.1.0",
    "style-loader": "0.23.0",
    "webpack": "4.19.0",
    "webpack-cli": "3.1.0",
    "webpack-dev-server": "3.1.8"
  },

babel-loader 7不允许在对象剩余分布中尾随逗号。

const {
  number,
  ...other, // A trailing comma is not permitted after the rest element 
} = this.state;

但是我应该在babel7的object-rest-spread中使用尾随逗号 如何使用它?有插件吗?

1 个答案:

答案 0 :(得分:0)

EcmaScript标准不支持为对象停留而使用尾随逗号,即它不是有效的代码。如果您以前在这里有逗号,那么我认为纠正语法错误的正确方法是删除不应该出现的逗号。

请阅读此讨论以获取更多详细信息(您也可以按照那里的参考问题进行阅读):https://github.com/tc39/proposal-object-rest-spread/issues/47