From 54003a5812d66edb8decd8b6334dc97581ca33ef Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:53:40 -0700 Subject: [PATCH 1/6] Test --- ...turedShorthandPropertyAssignmentNoCheck.js | 41 +++++++++++ ...ShorthandPropertyAssignmentNoCheck.symbols | 29 ++++++++ ...edShorthandPropertyAssignmentNoCheck.types | 68 +++++++++++++++++++ ...turedShorthandPropertyAssignmentNoCheck.ts | 8 +++ 4 files changed, 146 insertions(+) create mode 100644 tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js create mode 100644 tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.symbols create mode 100644 tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.types create mode 100644 tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts diff --git a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js new file mode 100644 index 0000000000000..a74d2a93974b7 --- /dev/null +++ b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js @@ -0,0 +1,41 @@ +//// [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); + + +!!!! File capturedShorthandPropertyAssignmentNoCheck.js differs from original emit in noCheck emit +//// [capturedShorthandPropertyAssignmentNoCheck.js] +=================================================================== +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -1,10 +1,7 @@ + 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); ++ fns.push(function () { return ({ value: value }); }); + } + var result = fns.map(function (fn) { return fn(); }); + console.log(result); diff --git a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.symbols b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.symbols new file mode 100644 index 0000000000000..0955090e6712f --- /dev/null +++ b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.symbols @@ -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)) + diff --git a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.types b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.types new file mode 100644 index 0000000000000..ff153e104aa65 --- /dev/null +++ b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.types @@ -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 : (callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[] +> : ^ ^^ ^^^ ^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^ +>fns : any[] +> : ^^^^^ +>map : (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[] +> : ^^^^^ + diff --git a/tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts b/tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts new file mode 100644 index 0000000000000..6046c379844de --- /dev/null +++ b/tests/cases/compiler/capturedShorthandPropertyAssignmentNoCheck.ts @@ -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) From 033a906e0c55172fbf38044c2a5818895b9123fa Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:26:48 -0700 Subject: [PATCH 2/6] Fix isInExpressionContext for name-only object prop shorthand --- src/compiler/utilities.ts | 2 +- .../reference/checkJsdocTypeTagOnObjectProperty2.types | 4 ++-- ...edIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types | 4 ++-- ...declarationEmitDestructuringObjectLiteralPattern.types | 4 ++-- ...eclarationEmitDestructuringObjectLiteralPattern2.types | 4 ++-- .../baselines/reference/declarationsAndAssignments.types | 4 ++-- .../inferenceOptionalPropertiesToIndexSignatures.types | 4 ++-- .../reference/jsExportAssignmentNonMutableLocation.types | 4 ++-- .../literalFreshnessPropagationOnNarrowing.types | 4 ++-- .../baselines/reference/shorthand-property-es5-es6.types | 4 ++-- .../baselines/reference/shorthand-property-es6-amd.types | 4 ++-- .../baselines/reference/shorthand-property-es6-es6.types | 4 ++-- ...horthandOfExportedEntity01_targetES2015_CommonJS.types | 2 +- .../shorthandOfExportedEntity02_targetES5_CommonJS.types | 2 +- .../baselines/reference/systemObjectShorthandRename.types | 8 ++++---- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 38146135ae715..c111bbed56f55 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3550,7 +3550,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: diff --git a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types index 6d1f1a0caefeb..00098b7fc295b 100644 --- a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types +++ b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types @@ -61,8 +61,8 @@ const obj = { /** @type {string} */ lol ->lol : string -> : ^^^^^^ +>lol : undefined +> : ^^^^^^^^^ } lol = "string" >lol = "string" : "string" diff --git a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types index bfb1d6d746566..975651a920cce 100644 --- a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types +++ b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types @@ -86,8 +86,8 @@ export function makeNewChannel(type: T): NewChannel : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >type : T > : ^ ->localChannelId : string -> : ^^^^^^ +>localChannelId : "blahblahblah" +> : ^^^^^^^^^^^^^^ } const newTextChannel = makeNewChannel('text'); diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types index 804c8e9533c7b..540977e611acb 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types @@ -178,8 +178,8 @@ function f15() { > : ^^^^^^ >b4 : number > : ^^^^^^ ->c4 : boolean -> : ^^^^^^^ +>c4 : true +> : ^^^^ } var { a4, b4, c4 } = f15(); >a4 : string diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types index 8f94dac153c38..2bbc40e9913e1 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types @@ -70,8 +70,8 @@ function f15() { > : ^^^^^^ >b4 : number > : ^^^^^^ ->c4 : boolean -> : ^^^^^^^ +>c4 : true +> : ^^^^ } var { a4, b4, c4 } = f15(); >a4 : string diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index 9cef609f57bf7..5a37b1d88cf33 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -823,8 +823,8 @@ function f15() { > : ^^^^^^ >b : number > : ^^^^^^ ->c : boolean -> : ^^^^^^^ +>c : true +> : ^^^^ } function f16() { diff --git a/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types b/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types index dbdf6925d6819..661d6526d724a 100644 --- a/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types +++ b/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types @@ -124,8 +124,8 @@ const obj = { > : ^^^^^^^^^^^^^^^ >{param2} : { param2: string; } > : ^^^^^^^^^^^^^^^^^^^ ->param2 : string -> : ^^^^^^ +>param2 : "value2" +> : ^^^^^^^^ >{} : {} > : ^^ diff --git a/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types b/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types index 8b4ccbdf94fea..071d36d54120d 100644 --- a/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types +++ b/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types @@ -25,8 +25,8 @@ module.exports = { > : ^^^^^^^^^^^^^^^^^^^^^^^^^ customSymbol, ->customSymbol : symbol -> : ^^^^^^ +>customSymbol : unique symbol +> : ^^^^^^^^^^^^^ }; diff --git a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types index a2a7572599f0f..7d1ecb0631863 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types @@ -16,8 +16,8 @@ function f1() { > : ^^^^^^^^^^^^^^^ >{ b } : { b: boolean; } > : ^^^^^^^^^^^^^^^ ->b : boolean -> : ^^^^^^^ +>b : true +> : ^^^^ // Desired: OK // 3.0: OK diff --git a/tests/baselines/reference/shorthand-property-es5-es6.types b/tests/baselines/reference/shorthand-property-es5-es6.types index c9c9040effc70..1bd5c857bf727 100644 --- a/tests/baselines/reference/shorthand-property-es5-es6.types +++ b/tests/baselines/reference/shorthand-property-es5-es6.types @@ -18,6 +18,6 @@ const bar = { foo, baz }; > : ^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : any > : ^^^ ->baz : number -> : ^^^^^^ +>baz : 42 +> : ^^ diff --git a/tests/baselines/reference/shorthand-property-es6-amd.types b/tests/baselines/reference/shorthand-property-es6-amd.types index 3b6642c0bc4aa..762c9e033f891 100644 --- a/tests/baselines/reference/shorthand-property-es6-amd.types +++ b/tests/baselines/reference/shorthand-property-es6-amd.types @@ -18,6 +18,6 @@ const bar = { foo, baz }; > : ^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : any > : ^^^ ->baz : number -> : ^^^^^^ +>baz : 42 +> : ^^ diff --git a/tests/baselines/reference/shorthand-property-es6-es6.types b/tests/baselines/reference/shorthand-property-es6-es6.types index c5f5eb87ddcdf..8d4e8919688be 100644 --- a/tests/baselines/reference/shorthand-property-es6-es6.types +++ b/tests/baselines/reference/shorthand-property-es6-es6.types @@ -18,6 +18,6 @@ const bar = { foo, baz }; > : ^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : any > : ^^^ ->baz : number -> : ^^^^^^ +>baz : 42 +> : ^^ diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types index 54d17b8939833..7676cb769458f 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types @@ -16,7 +16,7 @@ export function foo () { > : ^^^^^^^^^^^^^^^^^ >{ test } : { test: string; } > : ^^^^^^^^^^^^^^^^^ ->test : string +>test : "test" > : ^^^^^^ } diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types index 537247f166780..d787cc20387d2 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types @@ -16,7 +16,7 @@ export function foo () { > : ^^^^^^^^^^^^^^^^^ >{ test } : { test: string; } > : ^^^^^^^^^^^^^^^^^ ->test : string +>test : "test" > : ^^^^^^ } diff --git a/tests/baselines/reference/systemObjectShorthandRename.types b/tests/baselines/reference/systemObjectShorthandRename.types index aaa00d147c8e3..5c71481a02d37 100644 --- a/tests/baselines/reference/systemObjectShorthandRename.types +++ b/tests/baselines/reference/systemObjectShorthandRename.types @@ -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" +> : ^^^ From 7e1e976c807b8f87f3770a07ffb431d0b6f322d0 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:27:18 -0700 Subject: [PATCH 3/6] Use getResolvedSymbol to pass into checkIdentifierCalculateNodeCheckFlags like other call --- src/compiler/checker.ts | 2 +- ...turedShorthandPropertyAssignmentNoCheck.js | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 64e7ca0a8164a..f11776b67e0f0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -49377,7 +49377,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); } diff --git a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js index a74d2a93974b7..14b8387479794 100644 --- a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js +++ b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js @@ -20,22 +20,3 @@ for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) { } var result = fns.map(function (fn) { return fn(); }); console.log(result); - - -!!!! File capturedShorthandPropertyAssignmentNoCheck.js differs from original emit in noCheck emit -//// [capturedShorthandPropertyAssignmentNoCheck.js] -=================================================================== ---- Expected The full check baseline -+++ Actual with noCheck set -@@ -1,10 +1,7 @@ - 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); -+ fns.push(function () { return ({ value: value }); }); - } - var result = fns.map(function (fn) { return fn(); }); - console.log(result); From f820ca52fb0c179c77fcdd4682a3edab54608bed Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:53:27 -0700 Subject: [PATCH 4/6] Revert isInExpressionContext change --- src/compiler/utilities.ts | 3 ++- ...turedShorthandPropertyAssignmentNoCheck.js | 19 +++++++++++++++++++ .../checkJsdocTypeTagOnObjectProperty2.types | 4 ++-- ...essKeyofReliesOnKeyofNeverUpperBound.types | 4 ++-- ...mitDestructuringObjectLiteralPattern.types | 4 ++-- ...itDestructuringObjectLiteralPattern2.types | 4 ++-- .../declarationsAndAssignments.types | 4 ++-- ...eOptionalPropertiesToIndexSignatures.types | 4 ++-- ...jsExportAssignmentNonMutableLocation.types | 4 ++-- ...teralFreshnessPropagationOnNarrowing.types | 4 ++-- .../shorthand-property-es5-es6.types | 4 ++-- .../shorthand-property-es6-amd.types | 4 ++-- .../shorthand-property-es6-es6.types | 4 ++-- ...portedEntity01_targetES2015_CommonJS.types | 2 +- ...fExportedEntity02_targetES5_CommonJS.types | 2 +- .../systemObjectShorthandRename.types | 8 ++++---- 16 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c111bbed56f55..927d9032d62c1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3550,7 +3550,8 @@ 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 ?? (parent as ShorthandPropertyAssignment).name) === node; + // TODO(jakebailey): it's possible that node could be the name, too + return (parent as ShorthandPropertyAssignment).objectAssignmentInitializer === node; case SyntaxKind.SatisfiesExpression: return node === (parent as SatisfiesExpression).expression; default: diff --git a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js index 14b8387479794..a74d2a93974b7 100644 --- a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js +++ b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js @@ -20,3 +20,22 @@ for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) { } var result = fns.map(function (fn) { return fn(); }); console.log(result); + + +!!!! File capturedShorthandPropertyAssignmentNoCheck.js differs from original emit in noCheck emit +//// [capturedShorthandPropertyAssignmentNoCheck.js] +=================================================================== +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -1,10 +1,7 @@ + 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); ++ fns.push(function () { return ({ value: value }); }); + } + var result = fns.map(function (fn) { return fn(); }); + console.log(result); diff --git a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types index 00098b7fc295b..6d1f1a0caefeb 100644 --- a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types +++ b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types @@ -61,8 +61,8 @@ const obj = { /** @type {string} */ lol ->lol : undefined -> : ^^^^^^^^^ +>lol : string +> : ^^^^^^ } lol = "string" >lol = "string" : "string" diff --git a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types index 975651a920cce..bfb1d6d746566 100644 --- a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types +++ b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types @@ -86,8 +86,8 @@ export function makeNewChannel(type: T): NewChannel : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >type : T > : ^ ->localChannelId : "blahblahblah" -> : ^^^^^^^^^^^^^^ +>localChannelId : string +> : ^^^^^^ } const newTextChannel = makeNewChannel('text'); diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types index 540977e611acb..804c8e9533c7b 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types @@ -178,8 +178,8 @@ function f15() { > : ^^^^^^ >b4 : number > : ^^^^^^ ->c4 : true -> : ^^^^ +>c4 : boolean +> : ^^^^^^^ } var { a4, b4, c4 } = f15(); >a4 : string diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types index 2bbc40e9913e1..8f94dac153c38 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types @@ -70,8 +70,8 @@ function f15() { > : ^^^^^^ >b4 : number > : ^^^^^^ ->c4 : true -> : ^^^^ +>c4 : boolean +> : ^^^^^^^ } var { a4, b4, c4 } = f15(); >a4 : string diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index 5a37b1d88cf33..9cef609f57bf7 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -823,8 +823,8 @@ function f15() { > : ^^^^^^ >b : number > : ^^^^^^ ->c : true -> : ^^^^ +>c : boolean +> : ^^^^^^^ } function f16() { diff --git a/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types b/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types index 661d6526d724a..dbdf6925d6819 100644 --- a/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types +++ b/tests/baselines/reference/inferenceOptionalPropertiesToIndexSignatures.types @@ -124,8 +124,8 @@ const obj = { > : ^^^^^^^^^^^^^^^ >{param2} : { param2: string; } > : ^^^^^^^^^^^^^^^^^^^ ->param2 : "value2" -> : ^^^^^^^^ +>param2 : string +> : ^^^^^^ >{} : {} > : ^^ diff --git a/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types b/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types index 071d36d54120d..8b4ccbdf94fea 100644 --- a/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types +++ b/tests/baselines/reference/jsExportAssignmentNonMutableLocation.types @@ -25,8 +25,8 @@ module.exports = { > : ^^^^^^^^^^^^^^^^^^^^^^^^^ customSymbol, ->customSymbol : unique symbol -> : ^^^^^^^^^^^^^ +>customSymbol : symbol +> : ^^^^^^ }; diff --git a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types index 7d1ecb0631863..a2a7572599f0f 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types @@ -16,8 +16,8 @@ function f1() { > : ^^^^^^^^^^^^^^^ >{ b } : { b: boolean; } > : ^^^^^^^^^^^^^^^ ->b : true -> : ^^^^ +>b : boolean +> : ^^^^^^^ // Desired: OK // 3.0: OK diff --git a/tests/baselines/reference/shorthand-property-es5-es6.types b/tests/baselines/reference/shorthand-property-es5-es6.types index 1bd5c857bf727..c9c9040effc70 100644 --- a/tests/baselines/reference/shorthand-property-es5-es6.types +++ b/tests/baselines/reference/shorthand-property-es5-es6.types @@ -18,6 +18,6 @@ const bar = { foo, baz }; > : ^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : any > : ^^^ ->baz : 42 -> : ^^ +>baz : number +> : ^^^^^^ diff --git a/tests/baselines/reference/shorthand-property-es6-amd.types b/tests/baselines/reference/shorthand-property-es6-amd.types index 762c9e033f891..3b6642c0bc4aa 100644 --- a/tests/baselines/reference/shorthand-property-es6-amd.types +++ b/tests/baselines/reference/shorthand-property-es6-amd.types @@ -18,6 +18,6 @@ const bar = { foo, baz }; > : ^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : any > : ^^^ ->baz : 42 -> : ^^ +>baz : number +> : ^^^^^^ diff --git a/tests/baselines/reference/shorthand-property-es6-es6.types b/tests/baselines/reference/shorthand-property-es6-es6.types index 8d4e8919688be..c5f5eb87ddcdf 100644 --- a/tests/baselines/reference/shorthand-property-es6-es6.types +++ b/tests/baselines/reference/shorthand-property-es6-es6.types @@ -18,6 +18,6 @@ const bar = { foo, baz }; > : ^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : any > : ^^^ ->baz : 42 -> : ^^ +>baz : number +> : ^^^^^^ diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types index 7676cb769458f..54d17b8939833 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types @@ -16,7 +16,7 @@ export function foo () { > : ^^^^^^^^^^^^^^^^^ >{ test } : { test: string; } > : ^^^^^^^^^^^^^^^^^ ->test : "test" +>test : string > : ^^^^^^ } diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types index d787cc20387d2..537247f166780 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types @@ -16,7 +16,7 @@ export function foo () { > : ^^^^^^^^^^^^^^^^^ >{ test } : { test: string; } > : ^^^^^^^^^^^^^^^^^ ->test : "test" +>test : string > : ^^^^^^ } diff --git a/tests/baselines/reference/systemObjectShorthandRename.types b/tests/baselines/reference/systemObjectShorthandRename.types index 5c71481a02d37..aaa00d147c8e3 100644 --- a/tests/baselines/reference/systemObjectShorthandRename.types +++ b/tests/baselines/reference/systemObjectShorthandRename.types @@ -17,8 +17,8 @@ const x2 = {x} > : ^^^^^^^^^^^^^^ >{x} : { x: string; } > : ^^^^^^^^^^^^^^ ->x : "X" -> : ^^^ +>x : string +> : ^^^^^^ const a = {x2} >a : { x2: { x: string; }; } @@ -39,6 +39,6 @@ const b = {x3} > : ^^^^^^^^^^^^^^^ >{x3} : { x3: string; } > : ^^^^^^^^^^^^^^^ ->x3 : "X" -> : ^^^ +>x3 : string +> : ^^^^^^ From 6c910bfe073703a0c6abbaa90e8012b1cee4a251 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:09:02 -0700 Subject: [PATCH 5/6] Targeted fix --- src/compiler/checker.ts | 13 ++++++++++++- ...turedShorthandPropertyAssignmentNoCheck.js | 19 ------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f11776b67e0f0..04fc001816a24 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -49373,10 +49373,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { forEachNodeRecursively(node, checkIdentifiers); } + function isExpressionNodeOrShorthandPropertyAssignmentName(node: Identifier) { + // TODO(jakebailey): Just use isExpressionNode once that considers these identifiers to be expressions. + if (isExpressionNode(node)) return true; + + if (isShorthandPropertyAssignment(node.parent)) { + return (node.parent.objectAssignmentInitializer ?? node.parent.name) === node; + } + + return false; + } + function checkSingleIdentifier(node: Node) { const nodeLinks = getNodeLinks(node); nodeLinks.calculatedFlags |= NodeCheckFlags.ConstructorReference | NodeCheckFlags.CapturedBlockScopedBinding | NodeCheckFlags.BlockScopedBindingInLoop; - if (isIdentifier(node) && isExpressionNode(node) && !(isPropertyAccessExpression(node.parent) && node.parent.name === node)) { + if (isIdentifier(node) && isExpressionNodeOrShorthandPropertyAssignmentName(node) && !(isPropertyAccessExpression(node.parent) && node.parent.name === node)) { const s = getResolvedSymbol(node); if (s && s !== unknownSymbol) { checkIdentifierCalculateNodeCheckFlags(node, s); diff --git a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js index a74d2a93974b7..14b8387479794 100644 --- a/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js +++ b/tests/baselines/reference/capturedShorthandPropertyAssignmentNoCheck.js @@ -20,22 +20,3 @@ for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) { } var result = fns.map(function (fn) { return fn(); }); console.log(result); - - -!!!! File capturedShorthandPropertyAssignmentNoCheck.js differs from original emit in noCheck emit -//// [capturedShorthandPropertyAssignmentNoCheck.js] -=================================================================== ---- Expected The full check baseline -+++ Actual with noCheck set -@@ -1,10 +1,7 @@ - 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); -+ fns.push(function () { return ({ value: value }); }); - } - var result = fns.map(function (fn) { return fn(); }); - console.log(result); From 66113d3b71c707f8390f6aac82ea2afea176830a Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:10:03 -0700 Subject: [PATCH 6/6] Smaller --- src/compiler/checker.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 04fc001816a24..7b5bbd228f55e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -49375,13 +49375,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isExpressionNodeOrShorthandPropertyAssignmentName(node: Identifier) { // TODO(jakebailey): Just use isExpressionNode once that considers these identifiers to be expressions. - if (isExpressionNode(node)) return true; - - if (isShorthandPropertyAssignment(node.parent)) { - return (node.parent.objectAssignmentInitializer ?? node.parent.name) === node; - } - - return false; + return isExpressionNode(node) + || isShorthandPropertyAssignment(node.parent) && (node.parent.objectAssignmentInitializer ?? node.parent.name) === node; } function checkSingleIdentifier(node: Node) {