Skip to content

Commit

Permalink
fix(scope-manager): add support for TS4.9 satisfies expression (#6059)
Browse files Browse the repository at this point in the history
feat(scope-manager): add support for TS4.9 satisfies expression
  • Loading branch information
bradzacher committed Nov 22, 2022
1 parent b1f4dad commit 44027db
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -14,6 +14,7 @@ packages/ast-spec/src/*/*/fixtures/_error_/*/fixture.ts

# prettier doesn't yet support satisfies
packages/ast-spec/src/expression/TSSatisfiesExpression/fixtures/
packages/scope-manager/tests/fixtures/type-assertion/satisfies.ts

# Ignore CHANGELOG.md files to avoid issues with automated release job
CHANGELOG.md
Expand Down
9 changes: 8 additions & 1 deletion packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -301,7 +301,10 @@ class Referencer extends Visitor {
}

protected visitTypeAssertion(
node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion,
node:
| TSESTree.TSAsExpression
| TSESTree.TSTypeAssertion
| TSESTree.TSSatisfiesExpression,
): void {
this.visit(node.expression);
this.visitType(node.typeAnnotation);
Expand Down Expand Up @@ -724,6 +727,10 @@ class Referencer extends Visitor {
this.close(node);
}

protected TSSatisfiesExpression(node: TSESTree.TSSatisfiesExpression): void {
this.visitTypeAssertion(node);
}

protected TSTypeAliasDeclaration(
node: TSESTree.TSTypeAliasDeclaration,
): void {
Expand Down
@@ -0,0 +1,4 @@
const x = 1;
type T = 1;

x satisfies T;
@@ -0,0 +1,84 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`type-assertion satisfies 1`] = `
ScopeManager {
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2 {
defs: Array [
VariableDefinition$1 {
name: Identifier<"x">,
node: VariableDeclarator$1,
},
],
name: "x",
references: Array [
Reference$1 {
identifier: Identifier<"x">,
init: true,
isRead: false,
isTypeReference: false,
isValueReference: true,
isWrite: true,
resolved: Variable$2,
writeExpr: Literal$2,
},
Reference$2 {
identifier: Identifier<"x">,
isRead: true,
isTypeReference: false,
isValueReference: true,
isWrite: false,
resolved: Variable$2,
},
],
isValueVariable: true,
isTypeVariable: false,
},
Variable$3 {
defs: Array [
TypeDefinition$2 {
name: Identifier<"T">,
node: TSTypeAliasDeclaration$3,
},
],
name: "T",
references: Array [
Reference$3 {
identifier: Identifier<"T">,
isRead: true,
isTypeReference: true,
isValueReference: false,
isWrite: false,
resolved: Variable$3,
},
],
isValueVariable: false,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$4,
isStrict: false,
references: Array [
Reference$1,
Reference$2,
Reference$3,
],
set: Map {
"const" => ImplicitGlobalConstTypeVariable,
"x" => Variable$2,
"T" => Variable$3,
},
type: "global",
upper: null,
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2,
Variable$3,
],
},
],
}
`;

0 comments on commit 44027db

Please sign in to comment.