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 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ if no error diagnostics are emitted.

This rule's code action emits an invalid AST, so I fixed using JsxString instead of JsStringLiteral

- Fix [noUndeclaredVariables](https://docs.rome.tools/lint/rules/noundeclaredvariables/)'s false positive diagnostics ([#4675](https://github.com/rome/tools/issues/4675))

The semantic analyzer no longer handles `this` reference identifier in the semantic analyzer.

### Parser

- Add support for decorators in class method parameters, example:
Expand Down
Original file line number Diff line number Diff line change
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}`
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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