Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_js_analyze): skip this reference identifier in the semantic analyzer #4675

Merged
merged 3 commits into from Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,5 +11,16 @@ export type WhateverDefault<S extends number = 2> = `Hello ${S}`
// Const assertions are valid
const fruits = ["banana"] as const;

class X {
f() {
this.g;
type T1 = typeof this.g;
type T2 = X['g'];
}

g() {
}
}

// Invalid
export type Invalid<S extends number> = `Hello ${T}`
export type Invalid<S extends number> = `Hello ${T}`
Expand Up @@ -17,19 +17,32 @@ export type WhateverDefault<S extends number = 2> = `Hello ${S}`
// Const assertions are valid
const fruits = ["banana"] as const;

class X {
f() {
this.g;
type T1 = typeof this.g;
type T2 = X['g'];
}

g() {
}
}

// Invalid
export type Invalid<S extends number> = `Hello ${T}`

```

# Diagnostics
```
noUndeclaredVariables.ts:15:50 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
noUndeclaredVariables.ts:26:50 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! The T variable is undeclared

14 │ // Invalid
> 15 │ export type Invalid<S extends number> = `Hello ${T}`
25 │ // Invalid
> 26 │ export type Invalid<S extends number> = `Hello ${T}`
│ ^
27 │


```
Expand Down
4 changes: 4 additions & 0 deletions crates/rome_js_semantic/src/events.rs
Expand Up @@ -479,6 +479,10 @@ impl SemanticEventExtractor {
// SAFETY: kind check above
let reference = JsReferenceIdentifier::unwrap_cast(node.clone());
let name_token = reference.value_token().ok()?;
// skip `this` reference representing the class instance
if name_token.token_text_trimmed() == "this" {
return None;
}
(
name_token.token_text_trimmed(),
self.is_js_reference_identifier_exported(node),
Expand Down