This repository was archived by the owner on Aug 31, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +36
-4
lines changed
rome_js_analyze/tests/specs/correctness/noUndeclaredVariables Expand file tree Collapse file tree 4 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,10 @@ if no error diagnostics are emitted.
272272
273273 This rule's code action emits an invalid AST, so I fixed using JsxString instead of JsStringLiteral
274274
275+ - Fix [ noUndeclaredVariables] ( https://docs.rome.tools/lint/rules/noundeclaredvariables/ ) 's false positive diagnostics ([ #4675 ] ( https://github.com/rome/tools/issues/4675 ) )
276+
277+ The semantic analyzer no longer handles ` this ` reference identifier in the semantic analyzer.
278+
275279### Parser
276280
277281- Add support for decorators in class method parameters, example:
Original file line number Diff line number Diff line change @@ -11,5 +11,16 @@ export type WhateverDefault<S extends number = 2> = `Hello ${S}`
1111// Const assertions are valid
1212const fruits = [ "banana" ] as const ;
1313
14+ class X {
15+ f ( ) {
16+ this . g ;
17+ type T1 = typeof this . g ;
18+ type T2 = X [ 'g' ] ;
19+ }
20+
21+ g ( ) {
22+ }
23+ }
24+
1425// Invalid
15- export type Invalid < S extends number > = `Hello ${T } `
26+ export type Invalid < S extends number > = `Hello ${T } `
Original file line number Diff line number Diff line change @@ -17,19 +17,32 @@ export type WhateverDefault<S extends number = 2> = `Hello ${S}`
1717// Const assertions are valid
1818const fruits = ["banana"] as const;
1919
20+ class X {
21+ f () {
22+ this.g;
23+ type T1 = typeof this.g;
24+ type T2 = X['g'];
25+ }
26+
27+ g () {
28+ }
29+ }
30+
2031// Invalid
2132export type Invalid<S extends number > = `Hello ${ T } `
33+
2234```
2335
2436# Diagnostics
2537```
26- noUndeclaredVariables.ts:15 :50 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
38+ noUndeclaredVariables.ts:26 :50 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2739
2840 ! The T variable is undeclared
2941
30- 14 │ // Invalid
31- > 15 │ export type Invalid<S extends number > = `Hello ${ T } `
42+ 25 │ // Invalid
43+ > 26 │ export type Invalid<S extends number > = `Hello ${ T } `
3244 │ ^
45+ 27 │
3346
3447
3548```
Original file line number Diff line number Diff line change @@ -479,6 +479,10 @@ impl SemanticEventExtractor {
479479 // SAFETY: kind check above
480480 let reference = JsReferenceIdentifier :: unwrap_cast ( node. clone ( ) ) ;
481481 let name_token = reference. value_token ( ) . ok ( ) ?;
482+ // skip `this` reference representing the class instance
483+ if name_token. token_text_trimmed ( ) == "this" {
484+ return None ;
485+ }
482486 (
483487 name_token. token_text_trimmed ( ) ,
484488 self . is_js_reference_identifier_exported ( node) ,
You can’t perform that action at this time.
0 commit comments