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

Commit

Permalink
fix(rome_js_analyze): skip this reference identifier in the semanti…
Browse files Browse the repository at this point in the history
…c analyzer (#4675)
  • Loading branch information
nissy-dev committed Jul 10, 2023
1 parent def7584 commit 17d66a1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,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

0 comments on commit 17d66a1

Please sign in to comment.