Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scope-manager): add support for TS4.9 satisfies expression #6059

Merged
merged 1 commit into from Nov 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
],
},
],
}
`;