Skip to content

Commit b1efe43

Browse files
Andaristgabritto
andauthored
Port "Fix getEffectiveCheckNode" (#1083)
Co-authored-by: Gabriela Araujo Britto <[email protected]>
1 parent dd7b320 commit b1efe43

File tree

5 files changed

+19
-40
lines changed

5 files changed

+19
-40
lines changed

internal/ast/utilities.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,9 @@ const (
802802
OEKNonNullAssertions OuterExpressionKinds = 1 << 2
803803
OEKPartiallyEmittedExpressions OuterExpressionKinds = 1 << 3
804804
OEKExpressionsWithTypeArguments OuterExpressionKinds = 1 << 4
805-
OEKExcludeJSDocTypeAssertion = 1 << 5
806-
OEKAssertions = OEKTypeAssertions | OEKNonNullAssertions
805+
OEKSatisfies OuterExpressionKinds = 1 << 5
806+
OEKExcludeJSDocTypeAssertion = 1 << 6
807+
OEKAssertions = OEKTypeAssertions | OEKNonNullAssertions | OEKSatisfies
807808
OEKAll = OEKParentheses | OEKAssertions | OEKPartiallyEmittedExpressions | OEKExpressionsWithTypeArguments
808809
)
809810

@@ -812,8 +813,10 @@ func IsOuterExpression(node *Expression, kinds OuterExpressionKinds) bool {
812813
switch node.Kind {
813814
case KindParenthesizedExpression:
814815
return kinds&OEKParentheses != 0 && !(kinds&OEKExcludeJSDocTypeAssertion != 0 && isJSDocTypeAssertion(node))
815-
case KindTypeAssertionExpression, KindAsExpression, KindSatisfiesExpression:
816+
case KindTypeAssertionExpression, KindAsExpression:
816817
return kinds&OEKTypeAssertions != 0
818+
case KindSatisfiesExpression:
819+
return kinds&(OEKExpressionsWithTypeArguments|OEKSatisfies) != 0
817820
case KindExpressionWithTypeArguments:
818821
return kinds&OEKExpressionsWithTypeArguments != 0
819822
case KindNonNullExpression:

internal/checker/checker.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9064,11 +9064,12 @@ func (c *Checker) getThisArgumentType(node *ast.Node) *Type {
90649064
}
90659065

90669066
func (c *Checker) getEffectiveCheckNode(argument *ast.Node) *ast.Node {
9067-
argument = ast.SkipParentheses(argument)
9068-
if ast.IsSatisfiesExpression(argument) {
9069-
return ast.SkipParentheses(argument.Expression())
9070-
}
9071-
return argument
9067+
flags := core.IfElse(
9068+
ast.IsInJSFile(argument),
9069+
ast.OEKParentheses|ast.OEKSatisfies|ast.OEKExcludeJSDocTypeAssertion,
9070+
ast.OEKParentheses|ast.OEKSatisfies,
9071+
)
9072+
return ast.SkipOuterExpressions(argument, flags)
90729073
}
90739074

90749075
func (c *Checker) inferTypeArguments(node *ast.Node, signature *Signature, args []*ast.Node, checkMode CheckMode, context *InferenceContext) []*Type {

internal/transformers/typeeraser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node {
230230

231231
case ast.KindParenthesizedExpression:
232232
n := node.AsParenthesizedExpression()
233-
expression := ast.SkipOuterExpressions(n.Expression, ^(ast.OEKTypeAssertions | ast.OEKExpressionsWithTypeArguments))
233+
expression := ast.SkipOuterExpressions(n.Expression, ^(ast.OEKAssertions | ast.OEKExpressionsWithTypeArguments))
234234
if ast.IsAssertionExpression(expression) || ast.IsSatisfiesExpression(expression) {
235235
partial := tx.factory.NewPartiallyEmittedExpression(tx.visitor.VisitNode(n.Expression))
236236
tx.emitContext.SetOriginal(partial, node)

testdata/baselines/reference/submodule/conformance/typeSatisfaction_errorLocations1.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ typeSatisfaction_errorLocations1.ts(47,24): error TS2322: Type 'number' is not a
2828
typeSatisfaction_errorLocations1.ts(48,21): error TS2322: Type '{ a: number; }' is not assignable to type '{ a: true; }'.
2929
Types of property 'a' are incompatible.
3030
Type 'number' is not assignable to type 'true'.
31-
typeSatisfaction_errorLocations1.ts(50,27): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
32-
typeSatisfaction_errorLocations1.ts(51,28): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
31+
typeSatisfaction_errorLocations1.ts(50,23): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
32+
typeSatisfaction_errorLocations1.ts(51,24): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
3333

3434

3535
==== typeSatisfaction_errorLocations1.ts (24 errors) ====
@@ -141,11 +141,11 @@ typeSatisfaction_errorLocations1.ts(51,28): error TS2741: Property 'a' is missin
141141
!!! error TS2322: Type 'number' is not assignable to type 'true'.
142142

143143
((): { a: true } => (({}) satisfies unknown) satisfies unknown)();
144-
~~~~~~~~~
144+
~~
145145
!!! error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
146146
!!! related TS2728 typeSatisfaction_errorLocations1.ts:50:8: 'a' is declared here.
147147
((): { a: true } => ((({}) satisfies unknown)) satisfies unknown)();
148-
~~~~~~~~~
148+
~~
149149
!!! error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
150150
!!! related TS2728 typeSatisfaction_errorLocations1.ts:51:8: 'a' is declared here.
151151

testdata/baselines/reference/submodule/conformance/typeSatisfaction_errorLocations1.errors.txt.diff

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,7 @@
2424
typeSatisfaction_errorLocations1.ts(34,9): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
2525
typeSatisfaction_errorLocations1.ts(36,9): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
2626
typeSatisfaction_errorLocations1.ts(39,3): error TS2322: Type 'string' is not assignable to type 'number'.
27-
@@= skipped -12, +11 lines =@@
28-
typeSatisfaction_errorLocations1.ts(48,21): error TS2322: Type '{ a: number; }' is not assignable to type '{ a: true; }'.
29-
Types of property 'a' are incompatible.
30-
Type 'number' is not assignable to type 'true'.
31-
-typeSatisfaction_errorLocations1.ts(50,23): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
32-
-typeSatisfaction_errorLocations1.ts(51,24): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
33-
+typeSatisfaction_errorLocations1.ts(50,27): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
34-
+typeSatisfaction_errorLocations1.ts(51,28): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
35-
36-
37-
==== typeSatisfaction_errorLocations1.ts (24 errors) ====
38-
@@= skipped -10, +10 lines =@@
27+
@@= skipped -22, +21 lines =@@
3928
const fn1 = (s: { a: true }) => {};
4029
fn1({} satisfies unknown);
4130
~~
@@ -64,18 +53,4 @@
6453
+!!! error TS4104: The type 'readonly [10, "20"]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.
6554

6655
declare function fn4(...args: number[]): void;
67-
fn4(10, ...(["10", "20"] satisfies readonly string[]));
68-
@@= skipped -41, +40 lines =@@
69-
!!! error TS2322: Type 'number' is not assignable to type 'true'.
70-
71-
((): { a: true } => (({}) satisfies unknown) satisfies unknown)();
72-
- ~~
73-
+ ~~~~~~~~~
74-
!!! error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
75-
!!! related TS2728 typeSatisfaction_errorLocations1.ts:50:8: 'a' is declared here.
76-
((): { a: true } => ((({}) satisfies unknown)) satisfies unknown)();
77-
- ~~
78-
+ ~~~~~~~~~
79-
!!! error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: true; }'.
80-
!!! related TS2728 typeSatisfaction_errorLocations1.ts:51:8: 'a' is declared here.
81-
56+
fn4(10, ...(["10", "20"] satisfies readonly string[]));

0 commit comments

Comments
 (0)