Skip to content

fix(parser): add visiting of type parameters in JSXOpeningElement #150

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

Merged
merged 4 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,20 @@ export interface Bar extends foo.i18n {}
import foo from 'foo';
import bar from 'foo';
export interface Bar extends foo.i18n<bar> {}
`
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/141
{
filename: 'test.tsx',
code: `
import { TypeA } from './interface';
export const a = <GenericComponent<TypeA> />;
`,
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
}
],

invalid: [
Expand Down
9 changes: 9 additions & 0 deletions packages/parser/src/analyze-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ class Referencer extends OriginalReferencer {
}
}

/**
* Override.
*/
JSXOpeningElement(node: any) {
this.visit(node.name);
this.visitTypeParameters(node);
this.visit(node.attributes);
}

/**
* Override.
* Don't create the reference object in the type mode.
Expand Down
7 changes: 7 additions & 0 deletions packages/parser/src/visitor-keys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import eslintVisitorKeys from 'eslint-visitor-keys';

export const visitorKeys = eslintVisitorKeys.unionWith({
// Additional estree nodes.
Import: [],
// Additional Properties.
ArrayPattern: ['elements', 'typeAnnotation'],
ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'],
Expand Down Expand Up @@ -30,6 +32,11 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
RestElement: ['argument', 'typeAnnotation'],
NewExpression: ['callee', 'typeParameters', 'arguments'],
CallExpression: ['callee', 'typeParameters', 'arguments'],
// JSX
JSXOpeningElement: ['name', 'typeParameters', 'attributes'],
JSXClosingFragment: [],
JSXOpeningFragment: [],
JSXSpreadChild: ['expression'],

// Additional Nodes.
BigIntLiteral: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import('test');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = <GenericComponent<TypeA> />;
Loading