mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-08 18:11:45 -06:00
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
parent
d5434c85f7
commit
6c7df1f324
@ -49223,7 +49223,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const nodeLinks = getNodeLinks(node);
|
||||
nodeLinks.calculatedFlags |= NodeCheckFlags.ConstructorReference | NodeCheckFlags.CapturedBlockScopedBinding | NodeCheckFlags.BlockScopedBindingInLoop;
|
||||
if (isIdentifier(node) && isExpressionNode(node) && !(isPropertyAccessExpression(node.parent) && node.parent.name === node)) {
|
||||
const s = getSymbolAtLocation(node, /*ignoreErrors*/ true);
|
||||
const s = getResolvedSymbol(node);
|
||||
if (s && s !== unknownSymbol) {
|
||||
checkIdentifierCalculateNodeCheckFlags(node, s);
|
||||
}
|
||||
|
||||
@ -3492,7 +3492,7 @@ export function isInExpressionContext(node: Node): boolean {
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return (parent as ExpressionWithTypeArguments).expression === node && !isPartOfTypeNode(parent);
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
return (parent as ShorthandPropertyAssignment).objectAssignmentInitializer === node;
|
||||
return ((parent as ShorthandPropertyAssignment).objectAssignmentInitializer ?? (parent as ShorthandPropertyAssignment).name) === node;
|
||||
case SyntaxKind.SatisfiesExpression:
|
||||
return node === (parent as SatisfiesExpression).expression;
|
||||
default:
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
//// [tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts] ////
|
||||
|
||||
//// [capturedShorthandPropertyAssignmentNoCheck.ts]
|
||||
const fns = [];
|
||||
for (const value of [1, 2, 3]) {
|
||||
fns.push(() => ({ value }));
|
||||
}
|
||||
const result = fns.map(fn => fn());
|
||||
console.log(result)
|
||||
|
||||
|
||||
//// [capturedShorthandPropertyAssignmentNoCheck.js]
|
||||
var fns = [];
|
||||
var _loop_1 = function (value) {
|
||||
fns.push(function () { return ({ value: value }); });
|
||||
};
|
||||
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
|
||||
var value = _a[_i];
|
||||
_loop_1(value);
|
||||
}
|
||||
var result = fns.map(function (fn) { return fn(); });
|
||||
console.log(result);
|
||||
@ -0,0 +1,29 @@
|
||||
//// [tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts] ////
|
||||
|
||||
=== capturedShorthandPropertyAssignmentNoCheck.ts ===
|
||||
const fns = [];
|
||||
>fns : Symbol(fns, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 0, 5))
|
||||
|
||||
for (const value of [1, 2, 3]) {
|
||||
>value : Symbol(value, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 1, 10))
|
||||
|
||||
fns.push(() => ({ value }));
|
||||
>fns.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
|
||||
>fns : Symbol(fns, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 0, 5))
|
||||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
|
||||
>value : Symbol(value, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 2, 21))
|
||||
}
|
||||
const result = fns.map(fn => fn());
|
||||
>result : Symbol(result, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 5))
|
||||
>fns.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
|
||||
>fns : Symbol(fns, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 0, 5))
|
||||
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
|
||||
>fn : Symbol(fn, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 23))
|
||||
>fn : Symbol(fn, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 23))
|
||||
|
||||
console.log(result)
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>result : Symbol(result, Decl(capturedShorthandPropertyAssignmentNoCheck.ts, 4, 5))
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
//// [tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts] ////
|
||||
|
||||
=== capturedShorthandPropertyAssignmentNoCheck.ts ===
|
||||
const fns = [];
|
||||
>fns : any[]
|
||||
> : ^^^^^
|
||||
>[] : undefined[]
|
||||
> : ^^^^^^^^^^^
|
||||
|
||||
for (const value of [1, 2, 3]) {
|
||||
>value : number
|
||||
> : ^^^^^^
|
||||
>[1, 2, 3] : number[]
|
||||
> : ^^^^^^^^
|
||||
>1 : 1
|
||||
> : ^
|
||||
>2 : 2
|
||||
> : ^
|
||||
>3 : 3
|
||||
> : ^
|
||||
|
||||
fns.push(() => ({ value }));
|
||||
>fns.push(() => ({ value })) : number
|
||||
> : ^^^^^^
|
||||
>fns.push : (...items: any[]) => number
|
||||
> : ^^^^ ^^^^^^^^^^^^
|
||||
>fns : any[]
|
||||
> : ^^^^^
|
||||
>push : (...items: any[]) => number
|
||||
> : ^^^^ ^^^^^^^^^^^^
|
||||
>() => ({ value }) : () => { value: number; }
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>({ value }) : { value: number; }
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>{ value } : { value: number; }
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>value : number
|
||||
> : ^^^^^^
|
||||
}
|
||||
const result = fns.map(fn => fn());
|
||||
>result : any[]
|
||||
> : ^^^^^
|
||||
>fns.map(fn => fn()) : any[]
|
||||
> : ^^^^^
|
||||
>fns.map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
|
||||
> : ^ ^^ ^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^
|
||||
>fns : any[]
|
||||
> : ^^^^^
|
||||
>map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
|
||||
> : ^ ^^ ^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^
|
||||
>fn => fn() : (fn: any) => any
|
||||
> : ^ ^^^^^^^^^^^^^
|
||||
>fn : any
|
||||
>fn() : any
|
||||
>fn : any
|
||||
|
||||
console.log(result)
|
||||
>console.log(result) : void
|
||||
> : ^^^^
|
||||
>console.log : (...data: any[]) => void
|
||||
> : ^^^^ ^^ ^^^^^
|
||||
>console : Console
|
||||
> : ^^^^^^^
|
||||
>log : (...data: any[]) => void
|
||||
> : ^^^^ ^^ ^^^^^
|
||||
>result : any[]
|
||||
> : ^^^^^
|
||||
|
||||
@ -61,8 +61,8 @@ const obj = {
|
||||
|
||||
/** @type {string} */
|
||||
lol
|
||||
>lol : string
|
||||
> : ^^^^^^
|
||||
>lol : undefined
|
||||
> : ^^^^^^^^^
|
||||
}
|
||||
lol = "string"
|
||||
>lol = "string" : "string"
|
||||
|
||||
@ -86,8 +86,8 @@ export function makeNewChannel<T extends ChannelType>(type: T): NewChannel<Chann
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>type : T
|
||||
> : ^
|
||||
>localChannelId : string
|
||||
> : ^^^^^^
|
||||
>localChannelId : "blahblahblah"
|
||||
> : ^^^^^^^^^^^^^^
|
||||
}
|
||||
|
||||
const newTextChannel = makeNewChannel('text');
|
||||
|
||||
@ -178,8 +178,8 @@ function f15() {
|
||||
> : ^^^^^^
|
||||
>b4 : number
|
||||
> : ^^^^^^
|
||||
>c4 : boolean
|
||||
> : ^^^^^^^
|
||||
>c4 : true
|
||||
> : ^^^^
|
||||
}
|
||||
var { a4, b4, c4 } = f15();
|
||||
>a4 : string
|
||||
|
||||
@ -70,8 +70,8 @@ function f15() {
|
||||
> : ^^^^^^
|
||||
>b4 : number
|
||||
> : ^^^^^^
|
||||
>c4 : boolean
|
||||
> : ^^^^^^^
|
||||
>c4 : true
|
||||
> : ^^^^
|
||||
}
|
||||
var { a4, b4, c4 } = f15();
|
||||
>a4 : string
|
||||
|
||||
@ -823,8 +823,8 @@ function f15() {
|
||||
> : ^^^^^^
|
||||
>b : number
|
||||
> : ^^^^^^
|
||||
>c : boolean
|
||||
> : ^^^^^^^
|
||||
>c : true
|
||||
> : ^^^^
|
||||
}
|
||||
|
||||
function f16() {
|
||||
|
||||
@ -124,8 +124,8 @@ const obj = {
|
||||
> : ^^^^^^^^^^^^^^^
|
||||
>{param2} : { param2: string; }
|
||||
> : ^^^^^^^^^^^^^^^^^^^
|
||||
>param2 : string
|
||||
> : ^^^^^^
|
||||
>param2 : "value2"
|
||||
> : ^^^^^^^^
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
|
||||
@ -25,8 +25,8 @@ module.exports = {
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
customSymbol,
|
||||
>customSymbol : symbol
|
||||
> : ^^^^^^
|
||||
>customSymbol : unique symbol
|
||||
> : ^^^^^^^^^^^^^
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@ function f1() {
|
||||
> : ^^^^^^^^^^^^^^^
|
||||
>{ b } : { b: boolean; }
|
||||
> : ^^^^^^^^^^^^^^^
|
||||
>b : boolean
|
||||
> : ^^^^^^^
|
||||
>b : true
|
||||
> : ^^^^
|
||||
|
||||
// Desired: OK
|
||||
// 3.0: OK
|
||||
|
||||
@ -18,6 +18,6 @@ const bar = { foo, baz };
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>foo : any
|
||||
> : ^^^
|
||||
>baz : number
|
||||
> : ^^^^^^
|
||||
>baz : 42
|
||||
> : ^^
|
||||
|
||||
|
||||
@ -18,6 +18,6 @@ const bar = { foo, baz };
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>foo : any
|
||||
> : ^^^
|
||||
>baz : number
|
||||
> : ^^^^^^
|
||||
>baz : 42
|
||||
> : ^^
|
||||
|
||||
|
||||
@ -18,6 +18,6 @@ const bar = { foo, baz };
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>foo : any
|
||||
> : ^^^
|
||||
>baz : number
|
||||
> : ^^^^^^
|
||||
>baz : 42
|
||||
> : ^^
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ export function foo () {
|
||||
> : ^^^^^^^^^^^^^^^^^
|
||||
>{ test } : { test: string; }
|
||||
> : ^^^^^^^^^^^^^^^^^
|
||||
>test : string
|
||||
>test : "test"
|
||||
> : ^^^^^^
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ export function foo () {
|
||||
> : ^^^^^^^^^^^^^^^^^
|
||||
>{ test } : { test: string; }
|
||||
> : ^^^^^^^^^^^^^^^^^
|
||||
>test : string
|
||||
>test : "test"
|
||||
> : ^^^^^^
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,8 @@ const x2 = {x}
|
||||
> : ^^^^^^^^^^^^^^
|
||||
>{x} : { x: string; }
|
||||
> : ^^^^^^^^^^^^^^
|
||||
>x : string
|
||||
> : ^^^^^^
|
||||
>x : "X"
|
||||
> : ^^^
|
||||
|
||||
const a = {x2}
|
||||
>a : { x2: { x: string; }; }
|
||||
@ -39,6 +39,6 @@ const b = {x3}
|
||||
> : ^^^^^^^^^^^^^^^
|
||||
>{x3} : { x3: string; }
|
||||
> : ^^^^^^^^^^^^^^^
|
||||
>x3 : string
|
||||
> : ^^^^^^
|
||||
>x3 : "X"
|
||||
> : ^^^
|
||||
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
// @target: es5
|
||||
|
||||
const fns = [];
|
||||
for (const value of [1, 2, 3]) {
|
||||
fns.push(() => ({ value }));
|
||||
}
|
||||
const result = fns.map(fn => fn());
|
||||
console.log(result)
|
||||
Loading…
x
Reference in New Issue
Block a user