-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: merge AST structure of TSAsExpression with TSTypeAssertion #3005
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,7 +31,10 @@ export default util.createRule<Options, MessageIds>({ | |||||||||||
const baseRules = baseRule.create(context); | ||||||||||||
return { | ||||||||||||
...baseRules, | ||||||||||||
TSAsExpression(node): void { | ||||||||||||
TSTypeAssertion(node): void { | ||||||||||||
if (node.kind !== 'as') { | ||||||||||||
return; | ||||||||||||
} | ||||||||||||
Comment on lines
+34
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could do this via a selector
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could also add this as a typed selector to |
||||||||||||
const asToken = util.nullThrows( | ||||||||||||
sourceCode.getTokenAfter( | ||||||||||||
node.expression, | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,13 +297,6 @@ class Referencer extends Visitor { | |
TypeVisitor.visit(this, node); | ||
} | ||
|
||
protected visitTypeAssertion( | ||
node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion, | ||
): void { | ||
this.visit(node.expression); | ||
this.visitType(node.typeAnnotation); | ||
} | ||
|
||
///////////////////// | ||
// Visit selectors // | ||
///////////////////// | ||
|
@@ -317,7 +310,6 @@ class Referencer extends Visitor { | |
protected AssignmentExpression(node: TSESTree.AssignmentExpression): void { | ||
let left = node.left; | ||
switch (left.type) { | ||
case AST_NODE_TYPES.TSAsExpression: | ||
case AST_NODE_TYPES.TSTypeAssertion: | ||
// explicitly visit the type annotation | ||
this.visit(left.typeAnnotation); | ||
|
@@ -603,10 +595,6 @@ class Referencer extends Visitor { | |
this.visitType(node.typeParameters); | ||
} | ||
|
||
protected TSAsExpression(node: TSESTree.TSAsExpression): void { | ||
this.visitTypeAssertion(node); | ||
} | ||
|
||
protected TSDeclareFunction(node: TSESTree.TSDeclareFunction): void { | ||
this.visitFunction(node); | ||
} | ||
|
@@ -707,7 +695,13 @@ class Referencer extends Visitor { | |
} | ||
|
||
protected TSTypeAssertion(node: TSESTree.TSTypeAssertion): void { | ||
this.visitTypeAssertion(node); | ||
if (node.kind === 'as') { | ||
this.visit(node.expression); | ||
this.visitType(node.typeAnnotation); | ||
} else { | ||
this.visitType(node.typeAnnotation); | ||
this.visit(node.expression); | ||
} | ||
Comment on lines
+698
to
+704
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while doing this change i noticed that order of creating references was not correct |
||
} | ||
|
||
protected UpdateExpression(node: TSESTree.UpdateExpression): void { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no unit case for type assertion with brackets