Skip to content

Commit 37dbab9

Browse files
Merge pull request #584 from microsoft/main
Create a new pull request by comparing changes across two branches
2 parents 0b156ef + 9987812 commit 37dbab9

10 files changed

+166
-6
lines changed

src/compiler/factory/nodeFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6553,6 +6553,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
65536553
return updateSatisfiesExpression(outerExpression, expression, outerExpression.type);
65546554
case SyntaxKind.NonNullExpression:
65556555
return updateNonNullExpression(outerExpression, expression);
6556+
case SyntaxKind.ExpressionWithTypeArguments:
6557+
return updateExpressionWithTypeArguments(outerExpression, expression, outerExpression.typeArguments);
65566558
case SyntaxKind.PartiallyEmittedExpression:
65576559
return updatePartiallyEmittedExpression(outerExpression, expression);
65586560
}

src/compiler/factory/utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,10 @@ export function isOuterExpression(node: Node, kinds = OuterExpressionKinds.All):
630630
return (kinds & OuterExpressionKinds.Parentheses) !== 0;
631631
case SyntaxKind.TypeAssertionExpression:
632632
case SyntaxKind.AsExpression:
633-
case SyntaxKind.ExpressionWithTypeArguments:
634633
case SyntaxKind.SatisfiesExpression:
635634
return (kinds & OuterExpressionKinds.TypeAssertions) !== 0;
635+
case SyntaxKind.ExpressionWithTypeArguments:
636+
return (kinds & OuterExpressionKinds.ExpressionsWithTypeArguments) !== 0;
636637
case SyntaxKind.NonNullExpression:
637638
return (kinds & OuterExpressionKinds.NonNullAssertions) !== 0;
638639
case SyntaxKind.PartiallyEmittedExpression:

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ export function transformTypeScript(context: TransformationContext) {
16891689
}
16901690

16911691
function visitParenthesizedExpression(node: ParenthesizedExpression): Expression {
1692-
const innerExpression = skipOuterExpressions(node.expression, ~OuterExpressionKinds.Assertions);
1692+
const innerExpression = skipOuterExpressions(node.expression, ~(OuterExpressionKinds.Assertions | OuterExpressionKinds.ExpressionsWithTypeArguments));
16931693
if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
16941694
// Make sure we consider all nested cast expressions, e.g.:
16951695
// (<any><number><any>-A).x;

src/compiler/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8476,11 +8476,12 @@ export const enum OuterExpressionKinds {
84768476
TypeAssertions = 1 << 1,
84778477
NonNullAssertions = 1 << 2,
84788478
PartiallyEmittedExpressions = 1 << 3,
8479+
ExpressionsWithTypeArguments = 1 << 4,
84798480

84808481
Assertions = TypeAssertions | NonNullAssertions,
8481-
All = Parentheses | Assertions | PartiallyEmittedExpressions,
8482+
All = Parentheses | Assertions | PartiallyEmittedExpressions | ExpressionsWithTypeArguments,
84828483

8483-
ExcludeJSDocTypeAssertion = 1 << 4,
8484+
ExcludeJSDocTypeAssertion = 1 << 31,
84848485
}
84858486

84868487
/** @internal */
@@ -8490,6 +8491,7 @@ export type OuterExpression =
84908491
| SatisfiesExpression
84918492
| AsExpression
84928493
| NonNullExpression
8494+
| ExpressionWithTypeArguments
84938495
| PartiallyEmittedExpression;
84948496

84958497
/** @internal */

tests/baselines/reference/api/typescript.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7346,9 +7346,10 @@ declare namespace ts {
73467346
TypeAssertions = 2,
73477347
NonNullAssertions = 4,
73487348
PartiallyEmittedExpressions = 8,
7349+
ExpressionsWithTypeArguments = 16,
73497350
Assertions = 6,
7350-
All = 15,
7351-
ExcludeJSDocTypeAssertion = 16,
7351+
All = 31,
7352+
ExcludeJSDocTypeAssertion = -2147483648,
73527353
}
73537354
type ImmediatelyInvokedFunctionExpression = CallExpression & {
73547355
readonly expression: FunctionExpression;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
assignmentToInstantiationExpression.ts(2,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
2+
assignmentToInstantiationExpression.ts(6,1): error TS2454: Variable 'getValue' is used before being assigned.
3+
assignmentToInstantiationExpression.ts(6,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
4+
assignmentToInstantiationExpression.ts(10,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
5+
6+
7+
==== assignmentToInstantiationExpression.ts (4 errors) ====
8+
let obj: { fn?: <T>() => T } = {};
9+
obj.fn<number> = () => 1234;
10+
~~~~~~~~~~~~~~
11+
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
12+
13+
14+
let getValue: <T>() => T;
15+
getValue<number> = () => 1234;
16+
~~~~~~~~
17+
!!! error TS2454: Variable 'getValue' is used before being assigned.
18+
~~~~~~~~~~~~~~~~
19+
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
20+
21+
22+
let getValue2!: <T>() => T;
23+
getValue2<number> = () => 1234;
24+
~~~~~~~~~~~~~~~~~
25+
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
26+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [tests/cases/compiler/assignmentToInstantiationExpression.ts] ////
2+
3+
//// [assignmentToInstantiationExpression.ts]
4+
let obj: { fn?: <T>() => T } = {};
5+
obj.fn<number> = () => 1234;
6+
7+
8+
let getValue: <T>() => T;
9+
getValue<number> = () => 1234;
10+
11+
12+
let getValue2!: <T>() => T;
13+
getValue2<number> = () => 1234;
14+
15+
16+
//// [assignmentToInstantiationExpression.js]
17+
"use strict";
18+
var obj = {};
19+
(obj.fn) = function () { return 1234; };
20+
var getValue;
21+
(getValue) = function () { return 1234; };
22+
var getValue2;
23+
(getValue2) = function () { return 1234; };
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/assignmentToInstantiationExpression.ts] ////
2+
3+
=== assignmentToInstantiationExpression.ts ===
4+
let obj: { fn?: <T>() => T } = {};
5+
>obj : Symbol(obj, Decl(assignmentToInstantiationExpression.ts, 0, 3))
6+
>fn : Symbol(fn, Decl(assignmentToInstantiationExpression.ts, 0, 10))
7+
>T : Symbol(T, Decl(assignmentToInstantiationExpression.ts, 0, 17))
8+
>T : Symbol(T, Decl(assignmentToInstantiationExpression.ts, 0, 17))
9+
10+
obj.fn<number> = () => 1234;
11+
>obj.fn : Symbol(fn, Decl(assignmentToInstantiationExpression.ts, 0, 10))
12+
>obj : Symbol(obj, Decl(assignmentToInstantiationExpression.ts, 0, 3))
13+
>fn : Symbol(fn, Decl(assignmentToInstantiationExpression.ts, 0, 10))
14+
15+
16+
let getValue: <T>() => T;
17+
>getValue : Symbol(getValue, Decl(assignmentToInstantiationExpression.ts, 4, 3))
18+
>T : Symbol(T, Decl(assignmentToInstantiationExpression.ts, 4, 15))
19+
>T : Symbol(T, Decl(assignmentToInstantiationExpression.ts, 4, 15))
20+
21+
getValue<number> = () => 1234;
22+
>getValue : Symbol(getValue, Decl(assignmentToInstantiationExpression.ts, 4, 3))
23+
24+
25+
let getValue2!: <T>() => T;
26+
>getValue2 : Symbol(getValue2, Decl(assignmentToInstantiationExpression.ts, 8, 3))
27+
>T : Symbol(T, Decl(assignmentToInstantiationExpression.ts, 8, 17))
28+
>T : Symbol(T, Decl(assignmentToInstantiationExpression.ts, 8, 17))
29+
30+
getValue2<number> = () => 1234;
31+
>getValue2 : Symbol(getValue2, Decl(assignmentToInstantiationExpression.ts, 8, 3))
32+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [tests/cases/compiler/assignmentToInstantiationExpression.ts] ////
2+
3+
=== assignmentToInstantiationExpression.ts ===
4+
let obj: { fn?: <T>() => T } = {};
5+
>obj : { fn?: <T>() => T; }
6+
> : ^^^^^^^ ^^^
7+
>fn : (<T>() => T) | undefined
8+
> : ^^ ^^^^^^^ ^^^^^^^^^^^^^
9+
>{} : {}
10+
> : ^^
11+
12+
obj.fn<number> = () => 1234;
13+
>obj.fn<number> = () => 1234 : () => number
14+
> : ^^^^^^^^^^^^
15+
>obj.fn<number> : (() => number) | undefined
16+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
>obj.fn : (<T>() => T) | undefined
18+
> : ^^ ^^^^^^^ ^^^^^^^^^^^^^
19+
>obj : { fn?: <T>() => T; }
20+
> : ^^^^^^^ ^^^
21+
>fn : (<T>() => T) | undefined
22+
> : ^^ ^^^^^^^ ^^^^^^^^^^^^^
23+
>() => 1234 : () => number
24+
> : ^^^^^^^^^^^^
25+
>1234 : 1234
26+
> : ^^^^
27+
28+
29+
let getValue: <T>() => T;
30+
>getValue : <T>() => T
31+
> : ^ ^^^^^^^
32+
33+
getValue<number> = () => 1234;
34+
>getValue<number> = () => 1234 : () => number
35+
> : ^^^^^^^^^^^^
36+
>getValue<number> : () => number
37+
> : ^^^^^^^^^^^^
38+
>getValue : <T>() => T
39+
> : ^ ^^^^^^^
40+
>() => 1234 : () => number
41+
> : ^^^^^^^^^^^^
42+
>1234 : 1234
43+
> : ^^^^
44+
45+
46+
let getValue2!: <T>() => T;
47+
>getValue2 : <T>() => T
48+
> : ^ ^^^^^^^
49+
50+
getValue2<number> = () => 1234;
51+
>getValue2<number> = () => 1234 : () => number
52+
> : ^^^^^^^^^^^^
53+
>getValue2<number> : () => number
54+
> : ^^^^^^^^^^^^
55+
>getValue2 : <T>() => T
56+
> : ^ ^^^^^^^
57+
>() => 1234 : () => number
58+
> : ^^^^^^^^^^^^
59+
>1234 : 1234
60+
> : ^^^^
61+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @strict: true
2+
3+
let obj: { fn?: <T>() => T } = {};
4+
obj.fn<number> = () => 1234;
5+
6+
7+
let getValue: <T>() => T;
8+
getValue<number> = () => 1234;
9+
10+
11+
let getValue2!: <T>() => T;
12+
getValue2<number> = () => 1234;

0 commit comments

Comments
 (0)