Skip to content

Commit 6c7df1f

Browse files
TypeScript Botjakebailey
andauthored
🤖 Pick PR #59285 (Fix captured shorthand properties i...) into release-5.5 (#59288)
Co-authored-by: Jake Bailey <[email protected]>
1 parent d5434c8 commit 6c7df1f

20 files changed

+157
-30
lines changed

‎src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49223,7 +49223,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4922349223
const nodeLinks = getNodeLinks(node);
4922449224
nodeLinks.calculatedFlags |= NodeCheckFlags.ConstructorReference | NodeCheckFlags.CapturedBlockScopedBinding | NodeCheckFlags.BlockScopedBindingInLoop;
4922549225
if (isIdentifier(node) && isExpressionNode(node) && !(isPropertyAccessExpression(node.parent) && node.parent.name === node)) {
49226-
const s = getSymbolAtLocation(node, /*ignoreErrors*/ true);
49226+
const s = getResolvedSymbol(node);
4922749227
if (s && s !== unknownSymbol) {
4922849228
checkIdentifierCalculateNodeCheckFlags(node, s);
4922949229
}

‎src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ export function isInExpressionContext(node: Node): boolean {
34923492
case SyntaxKind.ExpressionWithTypeArguments:
34933493
return (parent as ExpressionWithTypeArguments).expression === node && !isPartOfTypeNode(parent);
34943494
case SyntaxKind.ShorthandPropertyAssignment:
3495-
return (parent as ShorthandPropertyAssignment).objectAssignmentInitializer === node;
3495+
return ((parent as ShorthandPropertyAssignment).objectAssignmentInitializer ?? (parent as ShorthandPropertyAssignment).name) === node;
34963496
case SyntaxKind.SatisfiesExpression:
34973497
return node === (parent as SatisfiesExpression).expression;
34983498
default:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts] ////
2+
3+
//// [capturedShorthandPropertyAssignmentNoCheck.ts]
4+
const fns = [];
5+
for (const value of [1, 2, 3]) {
6+
fns.push(() => ({ value }));
7+
}
8+
const result = fns.map(fn => fn());
9+
console.log(result)
10+
11+
12+
//// [capturedShorthandPropertyAssignmentNoCheck.js]
13+
var fns = [];
14+
var _loop_1 = function (value) {
15+
fns.push(function () { return ({ value: value }); });
16+
};
17+
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
18+
var value = _a[_i];
19+
_loop_1(value);
20+
}
21+
var result = fns.map(function (fn) { return fn(); });
22+
console.log(result);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts] ////
2+
3+
=== capturedShorthandPropertyAssignmentNoCheck.ts ===
4+
const fns = [];
5+
>fns : Symbol(fns, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 0, 5))
6+
7+
for (const value of [1, 2, 3]) {
8+
>value : Symbol(value, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 1, 10))
9+
10+
fns.push(() => ({ value }));
11+
>fns.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
12+
>fns : Symbol(fns, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 0, 5))
13+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
14+
>value : Symbol(value, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 2, 21))
15+
}
16+
const result = fns.map(fn => fn());
17+
>result : Symbol(result, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 5))
18+
>fns.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
19+
>fns : Symbol(fns, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 0, 5))
20+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
21+
>fn : Symbol(fn, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 23))
22+
>fn : Symbol(fn, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 23))
23+
24+
console.log(result)
25+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
26+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
27+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
28+
>result : Symbol(result, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 5))
29+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//// [tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts] ////
2+
3+
=== capturedShorthandPropertyAssignmentNoCheck.ts ===
4+
const fns = [];
5+
>fns : any[]
6+
> : ^^^^^
7+
>[] : undefined[]
8+
> : ^^^^^^^^^^^
9+
10+
for (const value of [1, 2, 3]) {
11+
>value : number
12+
> : ^^^^^^
13+
>[1, 2, 3] : number[]
14+
> : ^^^^^^^^
15+
>1 : 1
16+
> : ^
17+
>2 : 2
18+
> : ^
19+
>3 : 3
20+
> : ^
21+
22+
fns.push(() => ({ value }));
23+
>fns.push(() => ({ value })) : number
24+
> : ^^^^^^
25+
>fns.push : (...items: any[]) => number
26+
> : ^^^^ ^^^^^^^^^^^^
27+
>fns : any[]
28+
> : ^^^^^
29+
>push : (...items: any[]) => number
30+
> : ^^^^ ^^^^^^^^^^^^
31+
>() => ({ value }) : () => { value: number; }
32+
> : ^^^^^^^^^^^^^^^^^^^^^^^^
33+
>({ value }) : { value: number; }
34+
> : ^^^^^^^^^^^^^^^^^^
35+
>{ value } : { value: number; }
36+
> : ^^^^^^^^^^^^^^^^^^
37+
>value : number
38+
> : ^^^^^^
39+
}
40+
const result = fns.map(fn => fn());
41+
>result : any[]
42+
> : ^^^^^
43+
>fns.map(fn => fn()) : any[]
44+
> : ^^^^^
45+
>fns.map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
46+
> : ^ ^^ ^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^
47+
>fns : any[]
48+
> : ^^^^^
49+
>map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
50+
> : ^ ^^ ^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^
51+
>fn => fn() : (fn: any) => any
52+
> : ^ ^^^^^^^^^^^^^
53+
>fn : any
54+
>fn() : any
55+
>fn : any
56+
57+
console.log(result)
58+
>console.log(result) : void
59+
> : ^^^^
60+
>console.log : (...data: any[]) => void
61+
> : ^^^^ ^^ ^^^^^
62+
>console : Console
63+
> : ^^^^^^^
64+
>log : (...data: any[]) => void
65+
> : ^^^^ ^^ ^^^^^
66+
>result : any[]
67+
> : ^^^^^
68+

‎tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const obj = {
6161

6262
/** @type {string} */
6363
lol
64-
>lol : string
65-
> : ^^^^^^
64+
>lol : undefined
65+
> : ^^^^^^^^^
6666
}
6767
lol = "string"
6868
>lol = "string" : "string"

‎tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export function makeNewChannel<T extends ChannelType>(type: T): NewChannel<Chann
8686
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787
>type : T
8888
> : ^
89-
>localChannelId : string
90-
> : ^^^^^^
89+
>localChannelId : "blahblahblah"
90+
> : ^^^^^^^^^^^^^^
9191
}
9292

9393
const newTextChannel = makeNewChannel('text');

‎tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ function f15() {
178178
> : ^^^^^^
179179
>b4 : number
180180
> : ^^^^^^
181-
>c4 : boolean
182-
> : ^^^^^^^
181+
>c4 : true
182+
> : ^^^^
183183
}
184184
var { a4, b4, c4 } = f15();
185185
>a4 : string

‎tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ function f15() {
7070
> : ^^^^^^
7171
>b4 : number
7272
> : ^^^^^^
73-
>c4 : boolean
74-
> : ^^^^^^^
73+
>c4 : true
74+
> : ^^^^
7575
}
7676
var { a4, b4, c4 } = f15();
7777
>a4 : string

‎tests/baselines/reference/declarationsAndAssignments.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,8 @@ function f15() {
823823
> : ^^^^^^
824824
>b : number
825825
> : ^^^^^^
826-
>c : boolean
827-
> : ^^^^^^^
826+
>c : true
827+
> : ^^^^
828828
}
829829

830830
function f16() {

0 commit comments

Comments
 (0)