简体   繁体   English

如何确认是否正在使用ES6(ReactJS + Redux)

[英]How to confirm if ES6 is being used (ReactJS + Redux)

I have the following set up: 我有以下设置:

在此处输入图片说明

And I am trying to do the following: 我正在尝试执行以下操作:

case 'UPDATE_PASSWORD':
  return {
    ...state, //preserve current state, apply changes to it below
    password: action.password,
  }; 

but I am getting: 但我得到:

Unexpected token (5:8) at where '...' starts '...'开头的Unexpected token (5:8)

What may be the issue? 可能是什么问题? How do I check if I am using ES6? 如何检查我是否正在使用ES6?

This is a proposed ECMAScript feature (object spread) and can be enabled by adding stage-0 to your babel presets: 这是建议的ECMAScript功能(对象扩展),可以通过将stage-0添加到babel预设中来启用:

npm install --save-dev babel-preset-stage-0

Then, in your .babelrc or within your webpack.config.js query add the preset to your babel settings. 然后,在您的.babelrcwebpack.config.js查询中,将预设添加到babel设置中。 Example .babelrc : 例如.babelrc

{
    "presets": [
        "es2015",
        "react",
        "stage-0"
    ]
}

Or, if you make use of the webpack babel-loader query string: 或者,如果您使用webpack babel-loader查询字符串:

{
    test: /\.jsx?$/,
    loader: 'babel-loader',
    exclude: /node_modules/,
    query: {
        presets: ['es2015', 'react', 'stage-0']
    }
}

EDIT 编辑

Babel presets are an assortment of many transformations. Babel预设是许多变换的组合。 As per zerkms' suggestion, you could use stage-2 , which does not include/transpile many other features you may not be using at this time. 根据zerkms的建议,您可以使用stage-2 ,该stage-2不包含/移植当前可能没有使用的许多其他功能。 If you really just want the object spread to work, you can also just install transform object rest spread . 如果您真的只是想让对象传播起作用,那么您也可以只安装transform object rest spread

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM