From abc37ba3a1e221c0b84f44295e110fd3ea05ad4d Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 10 Jul 2022 21:57:26 +0200 Subject: [PATCH 1/2] fix(scope-manager): allow visiting of constraint in infer type --- .prettierignore | 1 + .../src/referencer/TypeVisitor.ts | 2 + .../type-declaration/infer-type-constraint.ts | 2 + .../infer-type-constraint.ts.shot | 133 ++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts create mode 100644 packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot diff --git a/.prettierignore b/.prettierignore index eda67619c874..913e2cce1e9f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -16,6 +16,7 @@ packages/ast-spec/src/*/*/fixtures/_error_/*/fixture.ts # Syntax not yet supported packages/scope-manager/tests/fixtures/type-declaration/type-query-with-parameters.ts +packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts # Ignore CHANGELOG.md files to avoid issues with automated release job CHANGELOG.md diff --git a/packages/scope-manager/src/referencer/TypeVisitor.ts b/packages/scope-manager/src/referencer/TypeVisitor.ts index 4b39676850db..ca80683538f5 100644 --- a/packages/scope-manager/src/referencer/TypeVisitor.ts +++ b/packages/scope-manager/src/referencer/TypeVisitor.ts @@ -167,6 +167,8 @@ class TypeVisitor extends Visitor { typeParameter.name, new TypeDefinition(typeParameter.name, typeParameter), ); + + this.visit(typeParameter.constraint); } protected TSInterfaceDeclaration( diff --git a/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts b/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts new file mode 100644 index 000000000000..1fb19d202516 --- /dev/null +++ b/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts @@ -0,0 +1,2 @@ +type X = string | number; +type Id = T extends { id: infer Id extends X } ? Id : never; diff --git a/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot b/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot new file mode 100644 index 000000000000..eb100d76ec76 --- /dev/null +++ b/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`type-declaration type-constrain 1`] = ` +ScopeManager { + variables: Array [ + ImplicitGlobalConstTypeVariable, + Variable$2 { + defs: Array [ + TypeDefinition$1 { + name: Identifier<"X">, + node: TSTypeAliasDeclaration$1, + }, + ], + name: "X", + references: Array [ + Reference$2 { + identifier: Identifier<"X">, + isRead: true, + isTypeReference: true, + isValueReference: false, + isWrite: false, + resolved: Variable$2, + }, + ], + isValueVariable: false, + isTypeVariable: true, + }, + Variable$3 { + defs: Array [ + TypeDefinition$2 { + name: Identifier<"Id">, + node: TSTypeAliasDeclaration$2, + }, + ], + name: "Id", + references: Array [], + isValueVariable: false, + isTypeVariable: true, + }, + Variable$4 { + defs: Array [ + TypeDefinition$3 { + name: Identifier<"T">, + node: TSTypeParameter$3, + }, + ], + name: "T", + references: Array [ + Reference$1 { + identifier: Identifier<"T">, + isRead: true, + isTypeReference: true, + isValueReference: false, + isWrite: false, + resolved: Variable$4, + }, + ], + isValueVariable: false, + isTypeVariable: true, + }, + Variable$5 { + defs: Array [ + TypeDefinition$4 { + name: Identifier<"Id">, + node: TSTypeParameter$4, + }, + ], + name: "Id", + references: Array [ + Reference$3 { + identifier: Identifier<"Id">, + isRead: true, + isTypeReference: true, + isValueReference: false, + isWrite: false, + resolved: Variable$5, + }, + ], + isValueVariable: false, + isTypeVariable: true, + }, + ], + scopes: Array [ + GlobalScope$1 { + block: Program$5, + isStrict: false, + references: Array [], + set: Map { + "const" => ImplicitGlobalConstTypeVariable, + "X" => Variable$2, + "Id" => Variable$3, + }, + type: "global", + upper: null, + variables: Array [ + ImplicitGlobalConstTypeVariable, + Variable$2, + Variable$3, + ], + }, + TypeScope$2 { + block: TSTypeAliasDeclaration$2, + isStrict: true, + references: Array [], + set: Map { + "T" => Variable$4, + }, + type: "type", + upper: GlobalScope$1, + variables: Array [ + Variable$4, + ], + }, + ConditionalTypeScope$3 { + block: TSConditionalType$6, + isStrict: true, + references: Array [ + Reference$1, + Reference$2, + Reference$3, + ], + set: Map { + "Id" => Variable$5, + }, + type: "conditionalType", + upper: TypeScope$2, + variables: Array [ + Variable$5, + ], + }, + ], +} +`; From d738808908f50407edf13f14fd855595ff41463c Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 10 Jul 2022 22:12:21 +0200 Subject: [PATCH 2/2] test: correct snapshot --- .../fixtures/type-declaration/infer-type-constraint.ts.shot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot b/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot index eb100d76ec76..d26d25584a20 100644 --- a/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot +++ b/packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`type-declaration type-constrain 1`] = ` +exports[`type-declaration infer-type-constraint 1`] = ` ScopeManager { variables: Array [ ImplicitGlobalConstTypeVariable, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy