在开玩笑中使用es7装饰器

时间:2017-10-31 10:26:08

标签: javascript reactjs babeljs jestjs

我在我的项目中使用装饰器,但似乎巴贝尔开玩笑不支持这个新的实验功能 我从github issue ===>中找到了一些支持。用webpack-babel-jest取代babel-jest,它解决了装饰问题。但是当我运行npm run test ==>时出现了一个新问题。 " ReferenceError:未定义regeneratorRuntime" 看来我们需要再生器 - 运行时。(我在我的项目中使用redux-saga)我无法找到解决这个问题的方法。

package.json {
"babel-core": "^6.7.6",
"babel-eslint": "^7.2.3",
"babel-jest": "^21.2.0",
"babel-loader": "^6.2.4",
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-react-jsx-source": "^6.22.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"css-loader": "^0.23.1",
"enzyme": "^3.1.0",
"enzyme-adapter-react-15.4": "^1.0.3",
"jest": "^21.2.1",
"node-sass": "^3.4.2",
"react-addons-test-utils": "^15.4.2",
"regenerator-runtime": "^0.11.0" }
   .babelrc {
{
"presets": [
    "es2015",
    "react",
    "stage-0"
],
"plugins": [
    "transform-decorators-legacy",
    "transform-react-jsx-source",
    "transform-class-properties",
["transform-runtime", {
  "polyfill": false,
  "regenerator": true
    }
],
"env": {
    "development": {

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

1 个答案:

答案 0 :(得分:0)

  

我无法解决这个问题。

这是众所周知的再生器变换babel插件的问题,它通常用于传输带有传奇的代码。

请参阅此处的详细说明:Unable to export generator functions