“关键字yield是保留的”eslint错误

时间:2016-11-26 17:46:40

标签: javascript ecmascript-6 es6-promise eslint superagent

我正在尝试使用Webpack 1.13.12和eslint 3.11.0以及eslint-plugin-promise 3.4.0。我正在尝试使用答案in this question让Superagent产生Web服务调用的结果。

import agent from 'superagent';
require('superagent-as-promised')(agent);
import Promise from 'promise';

const API_URL = 'http://localhost/services/merchant';

export function createVendorCall() {
    const responsePromise = yield Promise.resolve(agent.put(`${API_URL}/create`));

    let response = responsePromise.next();

    return response.body;
}

当我尝试lint时,eslint抱怨The keyword 'yield' is reserved.我已经尝试在我的.eslintrc.json文件中将require-yield设置为0,但它仍然不会lint。使用内联注释来禁用eslint也不起作用。

我该怎么办?我是以错误的方式使用Superagent,还是我必须禁用它?

编辑:此问题被标记为this question的副本。然而,这个问题并没有使用linter并且有不同的错误信息。这里的问题是,eslint会将看似有效语法的内容标记为错误。

1 个答案:

答案 0 :(得分:2)

尝试在函数名称中添加*,使其成为生成器:

export function *createVendorCall() {
    const responsePromise = yield Promise.resolve(agent.put(`${API_URL}/create`));

    let response = responsePromise.next();

    return response.body;
}

yield只能在生成器中使用。