Complex Async Arrow Throws Parser Error
See original GitHub issueEnvironment Information
Node / Yarn Versions:
$ node --version
v6.11.4
$ yarn --version
1.3.2
ESLint Package Versions:
{
"babel-eslint": "^8.0.2",
"eslint": "^4.3.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-import-resolver-node": "^0.3.1",
"eslint-plugin-dependencies": "^2.4.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.1.0"
}
Configuration
{
"extends": "airbnb",
"plugins": [
"dependencies"
],
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": [
"client",
"node_modules"
]
}
}
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"rules": {
"comma-dangle": ["error", "never"],
"semi": ["error", "always"],
"react/jsx-filename-extension": 0,
"react/prop-types": 0,
"react/no-find-dom-node": 0,
"jsx-a11y/label-has-for": 0,
"jsx-a11y/href-no-hash": 0,
"dependencies/no-cycles": 1
},
"globals": {
"document": true,
"window": true
},
"env": {
"jest": true
}
}
Issue Details
const reducer = async (state = initialState, action) => {
const { payload } = action;
switch (action.type) {
// ...
};
Specifically, the errors that are thrown are via the import
module; rules no-named-as-default
and no-named-as-default-member
introduce Parse
errors when attempting to validate.
8:63 error Parse errors in imported module './Path/pathReducer': Unexpected token => (18:54) import/no-named-as-default
8:63 error Parse errors in imported module './Path/pathReducer': Unexpected token => (18:54) import/no-named-as-default-member
Unfortunately this is entirely valid syntax. I’m not quite sure why this isn’t working.
After further investigation, it seems as though the eslint’s parser is interpreting async ( //...
as a function call, not as a function declaration modifier construct; it’s as if it’s favoring the following code (which is entirely invalid):
const reducer = async(state = initialState, action); // => {
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
ESLint parsing error when using arrow syntax with async
I'm using ESLint to analyze my code. The code runs fine, but I get this error from ...
Read more >javascript arrow function async | The Search Engine You Control
The error you're having says consistent-return at the end, which basically means your function should consistently return the same type. With that in...
Read more >JavaScript async and await - in plain English, please
It means the function may be taking a while before it finishes execution, returns a result, or throw an error. We use the...
Read more >async - Documentation - GitHub Pages
A callback which is called when all iteratee functions have finished, or an error occurs. Invoked with (err). Returns: a promise, if a...
Read more >Typing and semantics of asynchronous arrows in JavaScript
Asynchronous programs in JavaScript using callbacks and promises are difficult to write correctly. Many programs have subtle errors due to the unwanted ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue is that you’re using
ecmaVersion: 6
in your configuration, and async functions were only added in ECMAScript 2017. To fix this, you should update your config:my eslintrc:
deps: “eslint”: “4.15.0”, “eslint-config-standard”: “11.0.0-beta.0”, “eslint-plugin-async-await”: “0.0.0”, “eslint-plugin-import”: “2.8.0”, “eslint-plugin-node”: “5.2.1”, “eslint-plugin-promise”: “3.6.0”, “eslint-plugin-standard”: “3.0.1”,