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

Components.js report error:"Cannot read property 'length' of undefined" #854

Closed
linxiaowu66 opened this issue Sep 20, 2016 · 2 comments
Closed
Labels

Comments

@linxiaowu66
Copy link

Hi guys,
I had met a problem, I am not sure this is a bug, so can you help me to check this ?

Scenerio:

The source code you can checkout from: https://github.com/linxiaowu66/demo-for-ghooks.git (Branch: eslint-react-issue)

The key location is

 {
                title: '操作',
                key: 'operate',
                fixed: 'right',
                width: 60,
                render: (text, record) => (<span><Button type="button" className="btn btn-primary btn-xs" title="xxx" onClick={_self._handleToDetail.bind(null,record)}>XXX</Button><Button type="button" title="xxx" className="btn btn-primary btn-xs" style={{display:record.state==0&&record.allowManualDispatch==1?"inline-block":"none",marginLeft:10}} onClick={_self._handleDistribute.bind(null,record)}>XXXX</Button></span>),
            }

and the report error:

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at Object.utils.findReturnStatement (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.6.3.0@eslint-plugin-react/lib/util/Components.js:281:35)
    at Object.utils.isReturningJSX (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.6.3.0@eslint-plugin-react/lib/util/Components.js:233:24)
    at EventEmitter.CallExpression (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.6.3.0@eslint-plugin-react/lib/rules/jsx-no-bind.js:62:23)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.3.5.0@eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.3.5.0@eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at CommentEventGenerator.enterNode (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.3.5.0@eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.enter (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.3.5.0@eslint/lib/eslint.js:918:36)
    at Controller.__execute (/home/nodejsTest/testingProject/demo-for-ghooks/node_modules/.4.2.0@estraverse/estraverse.js:397:31)

I had print the log before reported this error, as following:

create(lib/rules/jsx-no-bind.js)==>isReturningJSX(lib/util/Components.js) ==> findReturnStatement(lib/util/Components.js)

and print location:

/**
     * Find a return statment in the current node
     *
     * @param {ASTNode} ASTnode The AST node being checked
     */
    findReturnStatement: function(node) {
      if (!node.value || !node.value.body) {
        return false;
      }
      console.log(node.value.body);
      var i = node.value.body.body.length - 1;
      for (; i >= 0; i--) {
        if (node.value.body.body[i].type === 'ReturnStatement') {
          return node.value.body.body[i];
        }
      }
      return false;
    },

log:

Node {
  type: 'JSXElement',
  start: 495,
  end: 873,
  loc: 
   SourceLocation {
     start: Position { line: 17, column: 43 },
     end: Position { line: 17, column: 421 } },
  openingElement: 
   Node {
     type: 'JSXOpeningElement',
     start: 495,
     end: 501,
     loc: SourceLocation { start: [Object], end: [Object] },
     attributes: [],
     name: 
      Node {
        type: 'JSXIdentifier',
        start: 496,
        end: 500,
        loc: [Object],
        name: 'span',
        range: [Object],
        _babelType: 'JSXIdentifier',
        parent: [Circular] },
     selfClosing: false,
     range: [ 495, 501 ],
     _babelType: 'JSXOpeningElement',
     parent: [Circular] },
  closingElement: 
   Node {
     type: 'JSXClosingElement',
     start: 866,
     end: 873,
     loc: SourceLocation { start: [Object], end: [Object] },
     name: 
      Node {
        type: 'JSXIdentifier',
        start: 868,
        end: 872,
        loc: [Object],
        name: 'span',
        range: [Object],
        _babelType: 'JSXIdentifier' },
     range: [ 866, 873 ],
     _babelType: 'JSXClosingElement' },
  children: 
   [ Node {
       type: 'JSXElement',
       start: 501,
       end: 630,
       loc: [Object],
       openingElement: [Object],
       closingElement: [Object],
       children: [Object],
       range: [Object],
       _babelType: 'JSXElement',
       parent: [Circular] },
     Node {
       type: 'JSXElement',
       start: 630,
       end: 866,
       loc: [Object],
       openingElement: [Object],
       closingElement: [Object],
       children: [Object],
       range: [Object],
       _babelType: 'JSXElement' } ],
  extra: { parenthesized: true, parenStart: 494 },
  range: [ 495, 873 ],
  _babelType: 'JSXElement',
  parent: 
   Node {
     type: 'ArrowFunctionExpression',
     start: 476,
     end: 874,
     loc: SourceLocation { start: [Object], end: [Object] },
     id: null,
     generator: false,
     expression: true,
     async: false,
     params: [ [Object], [Object] ],
     body: [Circular],
     range: [ 476, 874 ],
     _babelType: 'ArrowFunctionExpression',
     defaults: [],
     parent: 
      Node {
        type: 'Property',
        start: 468,
        end: 874,
        loc: [Object],
        method: false,
        shorthand: false,
        computed: false,
        key: [Object],
        value: [Circular],
        range: [Object],
        _babelType: 'ObjectProperty',
        kind: 'init',
        parent: [Object] } } }

Thanks in advance.

@yannickcr
Copy link
Member

Thanks for all these details, this crash should be fixed in next release.

@linxiaowu66
Copy link
Author

@yannickcr It is my pleasure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants