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

Missing name for this in <this.Component /> #337

Closed
backus opened this issue Jul 13, 2017 · 1 comment
Closed

Missing name for this in <this.Component /> #337

backus opened this issue Jul 13, 2017 · 1 comment
Assignees
Labels

Comments

@backus
Copy link

backus commented Jul 13, 2017

This is sort of a clone of #307. The fix for that PR fixed <this.state.Component /> but not <this.Component />

What version of TypeScript are you using?

2.3.2

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

4.0.0

What code were you trying to parse?

import * as React from "react";

export class Comment extends React.Component {
  render() {
    return (
      <div>
        <this.Author />
      </div>
    );
  }

  Author = () => {
    return <span>John Doe</span>;
  };
}

What did you expect to happen?

To have "name": "this" on JSXIdentifier.

What happened?

The identifier for this does not have a name:

"object": {
  "type": "JSXIdentifier",
  "range": [
    1,
    5
  ],
  "loc": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 1,
      "column": 5
    }
  }
}

Script I used to get the AST:

var parser = require("typescript-eslint-parser");

const parsed = parser.parse("<this.Foo />", {
  loc: true,
  range: true,
  tokens: true,
  comment: true,
  useJSXTextNode: true,
  ecmaFeatures: { jsx: true },
  // Override logger function with noop,
  // to avoid unsupported version errors being logged
  loggerFn: () => {}
});

delete parsed.tokens;

console.log(JSON.stringify(parsed));
backus added a commit to backus/prettier that referenced this issue Jul 13, 2017
This is a workaround while waiting on
eslint/typescript-eslint-parser#337.

Fixes prettier#2471
azz pushed a commit to prettier/prettier that referenced this issue Jul 13, 2017
@soda0289 soda0289 added bug and removed triage labels Jul 13, 2017
@soda0289
Copy link
Member

Thanks for the report. I can reproduce this problem.

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