Ext*_*ion -2 asynchronous node.js async-await eslint
我正在使用支持ES6的节点v7.10.0,因此我没有透露我的代码.
ESLint v3.19.0 Parsing error: Unexpected token =>在以下代码中给出错误.
给出错误:
module.exports = {
index: async (req, res) => {
await functionThatReturnsSomePromise();
}
}
Run Code Online (Sandbox Code Playgroud)
此外,当我只使用功能时,它会因错误而失败 Parsing error: Unexpected token function
给出错误:
module.exports = {
index: async function(req, res) {
await functionThatReturnsSomePromise();
}
}
Run Code Online (Sandbox Code Playgroud)
当我定义这样的类时,linter不会抱怨它:
没有错误:
class test {
testing() {
async () => {
console.log('test');
}
}
}
Run Code Online (Sandbox Code Playgroud)
.eslintrc
{
"extends": "eslint:recommended",
"ecmaFeatures": {
"binaryLiterals": true, // enable binary literals
"blockBindings": true, // enable let and const (aka block bindings)
"defaultParams": true, // enable default function parameters
"forOf": true, // enable for-of loops
"generators": true, // enable generators
"objectLiteralComputedProperties": true, // enable computed object literal property names
"objectLiteralDuplicateProperties": true, // enable duplicate object literal properties in strict mode
"objectLiteralShorthandMethods": true, // enable object literal shorthand methods
"objectLiteralShorthandProperties": true, // enable object literal shorthand properties
"octalLiterals": true, // enable octal literals
"regexUFlag": true, // enable the regular expression u flag
"regexYFlag": true, // enable the regular expression y flag
"templateStrings": true, // enable template strings
"unicodeCodePointEscapes": true, // enable code point escapes
"jsx": true // enable JSX
},
"env": {
"browser": false, // browser global variables.
"node": true, // Node.js global variables and Node.js-specific rules.
"es6": true, // for ES6
"amd": false, // defines require() and define() as global variables as per the amd spec.
"mocha": true, // adds all of the Mocha testing global variables.
"jasmine": false, // adds all of the Jasmine testing global variables for version 1.3 and 2.0.
"phantomjs": false, // phantomjs global variables.
"jquery": false, // jquery global variables.
"prototypejs": false, // prototypejs global variables.
"shelljs": false // shelljs global variables.
},
"globals": {
// e.g. "angular": true
},
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
arrowFunctions: true,
defaultParams: true
}
},
"rules": {
////////// Stylistic Issues //////////
"no-underscore-dangle": 0, // disallow dangling underscores in identifiers
////////// ECMAScript 6 //////////
"no-var": 2 // require let or const instead of var (off by default)
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
小智 7
我通过编辑解决了这个问题:
parserOptions.ecmaVersion = 8
Run Code Online (Sandbox Code Playgroud)
async/await在ES8(又名ES2017)中我认为是在ES7中