Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error for generic function named 'of' #10675

alexwalterbos opened this issue Nov 7, 2019 · 3 comments


Copy link

@alexwalterbos alexwalterbos commented Nov 7, 2019

Thanks for the great tool guys! I found a parsing bug regarding generic function definitions and specific naming:

Bug Report

Current Behavior
Babel-eslint parses a generic function just fine:

function someGenericFunction<R>(args: R): Array<R> {
  return [args];

It fails to parse that same function when it is named of, however:

function of<R>(args: R): Array<R> {
  return [args];
  5:12  error  Parsing error: Unexpected token, expected "("

  3 | }
  4 | 
> 5 | function of<R>(args: R): Array<R> {
    |            ^
  6 | 	return [args];
  7 | }
  8 | 

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.

Flow accepts the function just fine and shows 'No errors!'. It confused me for longer than I'd like to admit, hopefully fixing this will save others some time.
It would seem that of is treated as a keyword - maybe because of the for...of syntax?

Input Code
Reproduction repository:

Expected behavior/code
Parse the generic function named of just like any other generic function.

Babel Configuration (.babelrc, package.json, cli command)

// package.json
  "devDependencies": {
    "babel-eslint": "^10.0.3",
    "eslint": "^6.6.0"

// .eslintrc.js
module.exports = {
    "parser": "babel-eslint",
    "env": {
        "browser": true,
        "es6": true
    "extends": [
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    "rules": {

Error is triggered simply with these commands in the reproduction repository linked above;

yarn install
yarn eslint .


  • Babel version(s): v7.7.0 (@babel/parser)
  • Node/npm version: Node v12.13.0, yarn v1.19.1
  • OS: Fedora 29 x64
  • Monorepo: no
  • How you are using Babel: cli

Don't name your generic functions of.


This comment has been minimized.

Copy link

@babel-bot babel-bot commented Nov 7, 2019

Hey @alexwalterbos! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."


This comment has been minimized.

Copy link

@rajasekarm rajasekarm commented Nov 7, 2019

I can pick this.


This comment has been minimized.

Copy link

@rajasekarm rajasekarm commented Nov 8, 2019

The actual error is in babel-eslint.

In this, plugin is always set to estree. But in this example, it a flow code.

So first thing, in the project, we've to configure flow as plugin.

    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module",
        "babelOptions": {
            "plugins": ["flow"]

and we've to use this change in the parser inside babel-eslint.

I raised a PR here in babel-eslint repo to fix this. babel/babel-eslint#807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.