Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

TypeError: Cannot read property 'loc' of undefined - When creating React Component with indent rule #125

Closed
soda0289 opened this issue Dec 13, 2016 · 2 comments
Labels

Comments

@soda0289
Copy link
Member

soda0289 commented Dec 13, 2016

What version of TypeScript are you using?
2.0.10

What version of typescript-eslint-parser are you using?
1.00

What code were you trying to parse?

import * as React from 'react';

export class Indent2 extends React.Component<any, any> {

    public render() {
        return (
            <div>
                <h1>Todos</h1>
                <br />
                <form onSubmit={this.createToDo.bind(this)}>
                    <input ref="todo-input" />
                </form>
            </div>
        );
    }

    public createToDo(event: any) {
    }
}

Eslintrc

{
    "extends": ["plugin:react/recommended"],
    "parser": "typescript-eslint-parser",
        "parserOptions": {
                "ecmaVersion": 6,
                "sourceType": "module",
                "ecmaFeatures": {
                  "modules": true
                }
        },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            "error"
        ]
    }
}

What did you expect to happen?
It to parse

What happened?
Uncaught Exception

Cannot read property 'loc' of undefined
TypeError: Cannot read property 'loc' of undefined
    at getNodeIndent (/usr/lib/node_modules/eslint/lib/rules/indent.js:290:71)
    at checkNodeIndent (/usr/lib/node_modules/eslint/lib/rules/indent.js:325:34)
    at /usr/lib/node_modules/eslint/lib/rules/indent.js:373:35
    at Array.forEach (native)
    at checkNodesIndent (/usr/lib/node_modules/eslint/lib/rules/indent.js:373:19)
    at EventEmitter.blockIndentationCheck (/usr/lib/node_modules/eslint/lib/rules/indent.js:800:17)
    at emitOne (events.js:77:13)
    at EventEmitter.emit (events.js:169:7)
    at NodeEventGenerator.enterNode (/usr/lib/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/usr/lib/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)

@soda0289 soda0289 changed the title TypeError: Cannot read property 'loc' of undefined - When creating React Component TypeError: Cannot read property 'loc' of undefined - When creating React Component with indent rule Dec 13, 2016
@soda0289
Copy link
Member Author

After digging through the code it seems to be related to Issue #70
The tokens do not generate for anything past the first div

@JamesHenry
Copy link
Member

Yes, again a duplicate of #70. The issue is currently with the whitespace between JSX nodes. This parses without error:

return (
  <div><h1>Todos</h1><br /><form onSubmit={this.createToDo.bind(this)}><input ref="todo-input" /></form></div>
);

(I do realise that totally sucks 😄 I will try and get a fix merged into the TypeScript compiler as soon as possible)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants