Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.
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
fix: identify any declaration of type parameter
  • Loading branch information
Conaclos committed Feb 14, 2023
commit 35726390cb490263d6600395ae51927f5942b403
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type OtherType = {
[K in keyof number]: number[K];
};

type Flatten<Type> = Type extends Array<infer Item> ? Item : Type;

class Foo<T> {
id(x: T): T {
return x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 91
expression: typeParameters.ts
---
# Input
```js
export type OtherType = {
[K in keyof number]: number[K];
};

type Flatten<Type> = Type extends Array<infer Item> ? Item : Type;

class Foo<T> {
id(x: T): T {
return x;
}
}
```


14 changes: 7 additions & 7 deletions crates/rome_js_semantic/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rome_js_syntax::{
JsCallExpression, JsForVariableDeclaration, JsIdentifierAssignment, JsIdentifierBinding,
JsLanguage, JsParenthesizedExpression, JsReferenceIdentifier, JsSyntaxKind, JsSyntaxNode,
JsSyntaxToken, JsVariableDeclaration, JsVariableDeclarator, JsVariableDeclaratorList,
JsxReferenceIdentifier, TextRange, TextSize, TsIdentifierBinding, TsTypeParameter,
JsxReferenceIdentifier, TextRange, TextSize, TsIdentifierBinding, TsTypeParameterName,
};
use rome_rowan::{syntax::Preorder, AstNode, SyntaxNodeCast, SyntaxNodeOptionExt, SyntaxTokenText};

Expand Down Expand Up @@ -248,7 +248,7 @@ impl SemanticEventExtractor {
use rome_js_syntax::JsSyntaxKind::*;

match node.kind() {
JS_IDENTIFIER_BINDING | TS_IDENTIFIER_BINDING | TS_TYPE_PARAMETER => {
JS_IDENTIFIER_BINDING | TS_IDENTIFIER_BINDING | TS_TYPE_PARAMETER_NAME => {
self.enter_identifier_binding(node);
}
JS_REFERENCE_IDENTIFIER | JSX_REFERENCE_IDENTIFIER => {
Expand Down Expand Up @@ -342,7 +342,7 @@ impl SemanticEventExtractor {
use JsSyntaxKind::*;
debug_assert!(matches!(
node.kind(),
JS_IDENTIFIER_BINDING | TS_IDENTIFIER_BINDING | TS_TYPE_PARAMETER
JS_IDENTIFIER_BINDING | TS_IDENTIFIER_BINDING | TS_TYPE_PARAMETER_NAME
), "specified node is not a identifier binding (JS_IDENTIFIER_BINDING, TS_IDENTIFIER_BINDING, TS_TYPE_PARAMETER)");

let (name_token, is_var) = match node.kind() {
Expand All @@ -358,10 +358,10 @@ impl SemanticEventExtractor {
let is_var = Self::is_var(&binding);
(name_token, is_var)
}
TS_TYPE_PARAMETER => {
let binding = node.clone().cast::<TsTypeParameter>()?;
let name_token = binding.name().ok()?.ident_token().ok()?;
let is_var = Self::is_var(&binding);
TS_TYPE_PARAMETER_NAME => {
let token = node.clone().cast::<TsTypeParameterName>()?;
let name_token = token.ident_token().ok()?;
let is_var = Some(false);
(name_token, is_var)
}
_ => return None,
Expand Down