Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(parser): fix crash when visiting decorators in parameters#237

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
armano2 merged 5 commits intotypescript-eslint:masterfromarmano2:no-unused-vars
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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
18 changes: 0 additions & 18 deletionspackages/eslint-plugin/src/rules/no-unused-vars.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,22 +24,6 @@ export default util.createRule({
create(context) {
const rules = baseRule.create(context);

/**
* Mark this function parameter as used
* @param node The node currently being traversed
*/
function markThisParameterAsUsed(node: TSESTree.Identifier): void {
if (node.name) {
const variable = context
.getScope()
.variables.find(scopeVar => scopeVar.name === node.name);

if (variable) {
variable.eslintUsed = true;
}
}
}

/**
* Mark heritage clause as used
* @param node The node currently being traversed
Expand All@@ -59,8 +43,6 @@ export default util.createRule({
}

return Object.assign({}, rules, {
"FunctionDeclaration Identifier[name='this']": markThisParameterAsUsed,
"FunctionExpression Identifier[name='this']": markThisParameterAsUsed,
'TSTypeReference Identifier'(node: TSESTree.Identifier) {
context.markVariableAsUsed(node.name);
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,12 @@ function bar(foo: any) {}
`
export abstract class Foo {}
export class FooBar extends Foo {}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/207
`
function test(this: Foo) {
function test2(this: Bar) {}
}
`
],
invalid: []
Expand Down
View file
Open in desktop

This file was deleted.

31 changes: 30 additions & 1 deletionpackages/eslint-plugin/tests/rules/no-unused-vars.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -577,7 +577,36 @@ export function Foo() {
);
}
`
}
},
// https://github.com/eslint/typescript-eslint-parser/issues/535
`
import { observable } from 'mobx';
export default class ListModalStore {
@observable
orderList: IObservableArray<BizPurchaseOrderTO> = observable([]);
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/122#issuecomment-462008078
`
import { Dec, TypeA, Class } from 'test';
export default class Foo {
constructor(
@Dec(Class)
private readonly prop: TypeA<Class>,
) {}
}
`,
`
import { Dec, TypeA, Class } from 'test';
export default class Foo {
constructor(
@Dec(Class)
...prop: TypeA<Class>,
) {
prop()
}
}
`
],

invalid: [
Expand Down
24 changes: 18 additions & 6 deletionspackages/parser/src/analyze-scope.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ import {
PatternVisitorCallback,
PatternVisitorOptions
} from 'eslint-scope/lib/options';
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';

/**
* Define the override function of `Scope#__define` for global augmentation.
Expand DownExpand Up@@ -90,6 +90,13 @@ class PatternVisitor extends OriginalPatternVisitor {
this.rightHandNodes.push(node.typeAnnotation);
}
}

TSParameterProperty(node: TSESTree.TSParameterProperty): void {
this.visit(node.parameter);
if (node.decorators) {
this.rightHandNodes.push(...node.decorators);
}
}
}

class Referencer extends OriginalReferencer {
Expand DownExpand Up@@ -182,11 +189,16 @@ class Referencer extends OriginalReferencer {
params[i],
{ processRightHandNodes: true },
(pattern, info) => {
innerScope.__define(
pattern,
new ParameterDefinition(pattern, node, i, info.rest)
);
this.referencingDefaultValue(pattern, info.assignments, null, true);
if (
pattern.type !== AST_NODE_TYPES.Identifier ||
pattern.name !== 'this'
) {
innerScope.__define(
pattern,
new ParameterDefinition(pattern, node, i, info.rest)
);
this.referencingDefaultValue(pattern, info.assignments, null, true);
}
}
);
}
Expand Down
11 changes: 6 additions & 5 deletionspackages/parser/src/visitor-keys.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
// Additional estree nodes.
Import: [],
// Additional Properties.
ArrayPattern: ['elements', 'typeAnnotation'],
ArrayPattern: ['decorators', 'elements', 'typeAnnotation'],
ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'],
ClassDeclaration: [
'decorators',
Expand All@@ -24,12 +24,13 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
'implements',
'body'
],
TaggedTemplateExpression: ['tag', 'typeParameters', 'quasi'],
FunctionDeclaration: ['id', 'typeParameters', 'params', 'returnType', 'body'],
FunctionExpression: ['id', 'typeParameters', 'params', 'returnType', 'body'],
Identifier: ['decorators', 'typeAnnotation'],
MethodDefinition: ['decorators', 'key', 'value'],
ObjectPattern: ['properties', 'typeAnnotation'],
RestElement: ['argument', 'typeAnnotation'],
ObjectPattern: ['decorators', 'properties', 'typeAnnotation'],
RestElement: ['decorators', 'argument', 'typeAnnotation'],
NewExpression: ['callee', 'typeParameters', 'arguments'],
CallExpression: ['callee', 'typeParameters', 'arguments'],
// JSX
Expand All@@ -56,7 +57,7 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
TSConditionalType: ['checkType', 'extendsType', 'trueType', 'falseType'],
TSConstructSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
TSConstructorType: ['typeParameters', 'params', 'returnType'],
TSDeclareFunction: ['id', 'typeParameters', 'params', 'returnType'],
TSDeclareFunction: ['id', 'typeParameters', 'params', 'returnType', 'body'],
TSDeclareKeyword: [],
TSEmptyBodyFunctionExpression: [
'id',
Expand DownExpand Up@@ -91,7 +92,7 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
TSNumberKeyword: [],
TSObjectKeyword: [],
TSOptionalType: ['typeAnnotation'],
TSParameterProperty: ['parameter'],
TSParameterProperty: ['decorators', 'parameter'],
TSParenthesizedType: ['typeAnnotation'],
TSPrivateKeyword: [],
TSPropertySignature: ['typeAnnotation', 'key', 'initializer'],
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export default class Foo {
constructor(@Dec []: string[]) {}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export default class Foo {
constructor(@Dec test: string) {}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export default class Foo {
constructor(@Dec {}: any) {}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export default class Foo {
constructor(@Dec private readonly test: string) {}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export default class Foo {
constructor(@Dec ...test: string[]) {}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp