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

Error occured in Eslint when parsing code with @babel/eslint-parser #12868

Closed
1 task
jayshah123 opened this issue Feb 23, 2021 · 2 comments
Closed
1 task

Error occured in Eslint when parsing code with @babel/eslint-parser #12868

jayshah123 opened this issue Feb 23, 2021 · 2 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@jayshah123
Copy link

jayshah123 commented Feb 23, 2021

Bug Report

Crash while runinning eslint with "@babel/eslint-parser" as a parser

  • I would like to work on a fix!

Current behavior

Input Code

// @flow

// DashedLineView.js
import React, { Component } from "react";
import PropTypes from "prop-types";
import { requireNativeComponent, ViewPropTypes } from "react-native";

export default class DashedLineView extends Component {
  render() {
    return <DashedLineViewNative {...this.props} />;
  }
}

DashedLineView.propTypes = {
  ...ViewPropTypes,
  lineStyle: PropTypes.oneOf(["vertical", "horizontal"]).isRequired,
};

const DashedLineViewNative = requireNativeComponent(
  "DashedLineView",
  DashedLineView,
);

Expected behavior

No crashes while running eslint

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = {
  "presets": [
    "module:metro-react-native-babel-preset"
  ],
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["./src"],
        "alias": {
          "src": "./src",
          "di": "./src/di",
          "img": "./src/ui/img",
          "network": "./src/network"
        }
      }
    ],
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    "@babel/plugin-transform-exponentiation-operator",
    "@babel/plugin-external-helpers"
  ]
};

Environment

Eslint config:

{
  "parser": "@babel/eslint-parser",
  "extends": [
    "airbnb",
    "plugin:flowtype/recommended",
    "plugin:react/recommended",
    "prettier",
    "prettier/flowtype",
    "prettier/react",
    "plugin:react-native/all",
    "plugin:jest/recommended"
  ],
  "settings": {
    "import/resolver": {
      "babel-module": {
        "root": ["./src"],
        "alias": {
          "src": "./src",
          "img": "./src/ui/img",
          "di": "./src/di"
        }
      },
      "node": {
        "extensions": [".js", ".ios.js", ".android.js"]
      }
    }
  },
  "plugins": ["@babel","flowtype", "react", "react-native", "prettier","jest"],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true,
      "legacyDecorators": true
    },
    "babelOptions": {
      "configFile": "./babel.config.js",
    }
  },
  "env": {
    "es6": true,
    "node": true,
    "jest/globals": true
  },
  "rules": {
    "prettier/prettier": [
      0,
      {
        "trailingComma": "none",
        "singleQuote": false,
        "printWidth": 80,
        "semi": true,
        "parser": "babylon"
      }
    ],
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
  },
  "globals": {
    "fetch": false,
    "FormData": false,
    "navigator": false
  }
}
"@babel/eslint-parser": "7.13.0",
"@babel/eslint-plugin": "7.13.0",
"@babel/core": "7.11.6",
  • Babel version(s): [7.11.6]
  • React Native: 0.63.2
  • Node/npm version: [e.g. v10.15.0/npm 6.4.1]
  • OS: [macOS 10.15.7]
  • Monorepo: [no]
  • How you are using Babel: [metro bundler]

Possible Solution

Additional context
Logs:

  eslint:ignored-paths   target   = "/Users/jay.shah/Documents/stableworkspace/ipartner/src/native/DashedLineView.js" +0ms
  eslint:ignored-paths   base     = "/Users/jay.shah/Documents/stableworkspace/ipartner" +0ms
  eslint:ignored-paths   relative = "src/native/DashedLineView.js" +0ms
  eslint:ignored-paths   result   = false +0ms
  eslint:file-enumerator Yield: DashedLineView.js +1ms
  eslint:cli-engine Lint /Users/jay.shah/Documents/stableworkspace/ipartner/src/native/DashedLineView.js +111ms
  eslint:linter Linting code for /Users/jay.shah/Documents/stableworkspace/ipartner/src/native/DashedLineView.js (pass 1) +3ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: /Users/jay.shah/Documents/stableworkspace/ipartner/src/native/DashedLineView.js +0ms
  eslint:code-path onCodePathStart s1 +32ms
  eslint:code-path onCodePathSegmentStart s1_1 +0ms
  eslint:code-path s1_1) Program +0ms
  eslint:code-path s1_1) ImportDeclaration +1ms
  eslint:code-path s1_1) ImportDefaultSpecifier +26ms
  eslint:code-path s1_1) Identifier +14ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) ImportDefaultSpecifier:exit +0ms
  eslint:code-path s1_1) ImportSpecifier +0ms
  eslint:code-path s1_1) Identifier +1ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) Identifier +0ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) ImportSpecifier:exit +0ms
  eslint:code-path s1_1) Literal +0ms
  eslint:code-path s1_1) Literal:exit +0ms
  eslint:code-path s1_1) ImportDeclaration:exit +0ms
  eslint:code-path s1_1) ImportDeclaration +0ms
  eslint:code-path s1_1) ImportDefaultSpecifier +18ms
  eslint:code-path s1_1) Identifier +2ms
  eslint:code-path s1_1) Identifier:exit +1ms
  eslint:code-path s1_1) ImportDefaultSpecifier:exit +0ms
  eslint:code-path s1_1) Literal +0ms
  eslint:code-path s1_1) Literal:exit +0ms
  eslint:code-path s1_1) ImportDeclaration:exit +0ms
  eslint:code-path s1_1) ImportDeclaration +0ms
  eslint:code-path s1_1) ImportSpecifier +31ms
  eslint:code-path s1_1) Identifier +1ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) Identifier +0ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) ImportSpecifier:exit +0ms
  eslint:code-path s1_1) ImportSpecifier +0ms
  eslint:code-path s1_1) Identifier +0ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) Identifier +0ms
  eslint:code-path s1_1) Identifier:exit +1ms
  eslint:code-path s1_1) ImportSpecifier:exit +0ms
  eslint:code-path s1_1) Literal +0ms
  eslint:code-path s1_1) Literal:exit +0ms
  eslint:code-path s1_1) ImportDeclaration:exit +0ms
  eslint:code-path s1_1) ExportDefaultDeclaration +0ms
  eslint:code-path s1_1) ClassDeclaration +0ms
  eslint:code-path s1_1) Identifier +1ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) ClassBody +0ms
  eslint:code-path s1_1) MethodDefinition +0ms
  eslint:code-path s1_1) Identifier +0ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) FunctionExpression +0ms
  eslint:code-path onCodePathStart s2 +1ms
  eslint:code-path onCodePathSegmentStart s2_1 +0ms
  eslint:code-path s2_1) FunctionExpression +0ms
  eslint:code-path s2_1) BlockStatement +1ms
  eslint:code-path s2_1) ReturnStatement +0ms
  eslint:code-path s2_1) JSXElement +1ms
  eslint:code-path s2_1) JSXOpeningElement +2ms
  eslint:code-path s2_1) JSXIdentifier +8ms
  eslint:code-path s2_1) JSXIdentifier:exit +0ms
  eslint:code-path s2_1) JSXSpreadAttribute +1ms
  eslint:code-path s2_1) MemberExpression +0ms
  eslint:code-path s2_1) ThisExpression +4ms
  eslint:code-path s2_1) ThisExpression:exit +0ms
  eslint:code-path s2_1) Identifier +1ms
  eslint:code-path s2_1) Identifier:exit +0ms
  eslint:code-path s2_1) MemberExpression:exit +0ms
  eslint:code-path s2_1) JSXSpreadAttribute:exit +0ms
  eslint:code-path s2_1) JSXOpeningElement:exit +0ms
  eslint:code-path s2_1) JSXElement:exit +0ms
  eslint:code-path s2_1) ReturnStatement:exit +0ms
  eslint:code-path onCodePathSegmentEnd s2_1 +0ms
  eslint:code-path onCodePathSegmentStart s2_2 +0ms
  eslint:code-path s2_2!) BlockStatement:exit +0ms
  eslint:code-path s2_2!) FunctionExpression:exit +1ms
  eslint:code-path onCodePathSegmentEnd s2_2 +0ms
  eslint:code-path onCodePathEnd s2 +0ms
  eslint:code-path DOT 
digraph {
node[shape=box,style="rounded,filled",fillcolor=white];
initial[label="",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];
final[label="",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];
s2_1[label="FunctionExpression\nBlockStatement\nReturnStatement\nJSXElement\nJSXOpeningElement\nJSXIdentifier\nJSXSpreadAttribute\nMemberExpression\nThisExpression\nIdentifier (props)\nJSXIdentifier:exit\nThisExpression:exit\nIdentifier:exit (props)\nMemberExpression:exit\nJSXSpreadAttribute:exit\nJSXOpeningElement:exit\nJSXElement:exit\nReturnStatement:exit"];
s2_2[style="rounded,dashed,filled",fillcolor="#FF9800",label="<<unreachable>>\nBlockStatement:exit\nFunctionExpression:exit"];
initial->s2_1->s2_2;
s2_1->final;
} +0ms
  eslint:code-path s1_1) FunctionExpression:exit +0ms
  eslint:code-path s1_1) MethodDefinition:exit +0ms
  eslint:code-path s1_1) ClassBody:exit +0ms
  eslint:code-path s1_1) Identifier +0ms
  eslint:code-path s1_1) Identifier:exit +0ms
  eslint:code-path s1_1) ClassDeclaration:exit +0ms
  eslint:code-path s1_1) ExportDefaultDeclaration:exit +1ms
  eslint:code-path s1_1) ExpressionStatement +0ms
  eslint:code-path s1_1) AssignmentExpression +0ms
  eslint:code-path s1_1) MemberExpression +0ms
  eslint:linter An error occurred while traversing +151ms
  eslint:linter Filename: /Users/jay.shah/Documents/stableworkspace/ipartner/src/native/DashedLineView.js +0ms
  eslint:linter Line: 14 +0ms
  eslint:linter Parser Options: { ecmaVersion: 8,
  ecmaFeatures:
   { globalReturn: false,
     jsx: true,
     legacyDecorators: true,
     experimentalObjectRestSpread: true,
     generators: false,
     objectLiteralDuplicateProperties: false },
  babelOptions: { configFile: './babel.config.js' },
  sourceType: 'module' } +0ms
  eslint:linter Parser Path: /Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/@babel/eslint-parser/lib/index.js +1ms
  eslint:linter Settings: { 'import/resolver':
   { 'babel-module': { root: [Array], alias: [Object] },
     node: { extensions: [Array] } },
  flowtype: { onlyFilesWithFlowAnnotation: false },
  react: { pragma: 'React', version: '15.0' },
  propWrapperFunctions: [ 'forbidExtraProps', 'exact', 'Object.freeze' ],
  'import/extensions': [ '.js', '.jsx' ],
  'import/core-modules': [],
  'import/ignore':
   [ 'node_modules', '\\.(coffee|scss|css|less|hbs|svg|json)$' ] } +0ms
TypeError: Cannot read property 'name' of undefined
Occurred while linting /Users/jay.shah/Documents/stableworkspace/ipartner/src/native/DashedLineView.js:14
    at props.map.property (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:98:28)
    at Array.map (<anonymous>)
    at getPropTypesFromObjectExpression (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:97:20)
    at MemberExpression (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:372:48)
    at listeners.(anonymous function).forEach.listener (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint/lib/linter/node-event-generator.js:253:26)
    at NodeEventGenerator.applySelectors (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint/lib/linter/node-event-generator.js:282:22)
    at NodeEventGenerator.enterNode (/Users/jay.shah/Documents/stableworkspace/ipartner/node_modules/eslint/lib/linter/node-event-generator.js:296:14)

@babel-bot
Copy link
Collaborator

Hey @jayshah123! 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."

@JLHwung
Copy link
Contributor

JLHwung commented Feb 23, 2021

This issue has been fixed in #12867, please upgrade to latest @babel/eslint-parser.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants