Skip to content

Commit eeafd3d

Browse files
authored
Merge branch 'main' into fix/62487
2 parents 43dd415 + b78f089 commit eeafd3d

File tree

160 files changed

+5925
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+5925
-433
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ jobs:
164164
run: npm test -- --no-lint --coverage
165165

166166
- name: Upload coverage artifact
167-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
167+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
168168
with:
169169
name: coverage
170170
path: coverage
171171

172-
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
172+
- uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
173173
with:
174174
use_oidc: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }}
175175
disable_search: true
@@ -211,7 +211,7 @@ jobs:
211211
node-version: 'lts/*'
212212
- run: npm ci
213213

214-
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
214+
- uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
215215
with:
216216
path: ~/.cache/dprint
217217
key: ${{ runner.os }}-dprint-${{ hashFiles('package-lock.json', '.dprint.jsonc') }}
@@ -418,7 +418,7 @@ jobs:
418418
419419
- name: Upload baseline diff artifact
420420
if: ${{ failure() && steps.check-baselines.conclusion == 'failure' }}
421-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
421+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
422422
with:
423423
name: fix_baselines.patch
424424
path: fix_baselines.patch

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4.31.7
49+
uses: github/codeql-action/init@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8
5050
with:
5151
config-file: ./.github/codeql/codeql-configuration.yml
5252
# Override language selection by uncommenting this and choosing your languages
@@ -56,7 +56,7 @@ jobs:
5656
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5757
# If this step fails, then you should remove it and run the build manually (see below).
5858
- name: Autobuild
59-
uses: github/codeql-action/autobuild@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4.31.7
59+
uses: github/codeql-action/autobuild@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8
6060

6161
# ℹ️ Command-line programs to run using the OS shell.
6262
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -70,4 +70,4 @@ jobs:
7070
# make release
7171

7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4.31.7
73+
uses: github/codeql-action/analyze@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8

.github/workflows/release-branch-artifact.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
npm pack ./
4545
mv typescript-*.tgz typescript.tgz
4646
- name: Upload built tarfile
47-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
47+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
4848
with:
4949
name: tgz
5050
path: typescript.tgz

.github/workflows/scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ jobs:
4747
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
4848
# format to the repository Actions tab.
4949
- name: 'Upload artifact'
50-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
50+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
5151
with:
5252
name: SARIF file
5353
path: results.sarif
5454
retention-days: 5
5555

5656
# Upload the results to GitHub's code scanning dashboard.
5757
- name: 'Upload to code-scanning'
58-
uses: github/codeql-action/upload-sarif@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4.31.7
58+
uses: github/codeql-action/upload-sarif@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8
5959
with:
6060
sarif_file: results.sarif

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Note
2+
3+
🚨 **Important** 🚨: All code changes should be submitted to the https://github.com/microsoft/typescript-go repo. Development in this codebase [is winding down](https://devblogs.microsoft.com/typescript/progress-on-typescript-7-december-2025/#typescript-6.0-is-the-last-javascript-based-release) and PRs will only be merged if they fix **critical** 6.0 issues (at minimum, any bug that existed in 5.9 is not critical unless it's a security issue).
4+
15
# Instructions for Logging Issues
26

37
## 1. Read the FAQ
@@ -45,7 +49,7 @@ In general, things we find useful when reviewing suggestions are:
4549
* Code examples showing the generated JavaScript (if applicable)
4650
* If relevant, precedent in other languages can be useful for establishing context and expected behavior
4751

48-
# Instructions for Contributing Code
52+
# Instructions for Contributing Code (Legacy)
4953

5054
## What You'll Need
5155

scripts/CopyrightNotice.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ License at http://www.apache.org/licenses/LICENSE-2.0
77
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
88
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
99
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
10+
MERCHANTABILITY OR NON-INFRINGEMENT.
1111

1212
See the Apache Version 2.0 License for specific language governing permissions
1313
and limitations under the License.

src/compiler/binder.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
10001000
const saveExceptionTarget = currentExceptionTarget;
10011001
const saveActiveLabelList = activeLabelList;
10021002
const saveHasExplicitReturn = hasExplicitReturn;
1003+
const saveSeenThisKeyword = seenThisKeyword;
10031004
const isImmediatelyInvoked = (
10041005
containerFlags & ContainerFlags.IsFunctionExpression &&
10051006
!hasSyntacticModifier(node, ModifierFlags.Async) &&
@@ -1022,19 +1023,22 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
10221023
currentContinueTarget = undefined;
10231024
activeLabelList = undefined;
10241025
hasExplicitReturn = false;
1026+
seenThisKeyword = false;
10251027
bindChildren(node);
1026-
// Reset all reachability check related flags on node (for incremental scenarios)
1027-
node.flags &= ~NodeFlags.ReachabilityAndEmitFlags;
1028+
// Reset flags (for incremental scenarios)
1029+
node.flags &= ~(NodeFlags.ReachabilityAndEmitFlags | NodeFlags.ContainsThis);
10281030
if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & ContainerFlags.IsFunctionLike && nodeIsPresent((node as FunctionLikeDeclaration | ClassStaticBlockDeclaration).body)) {
10291031
node.flags |= NodeFlags.HasImplicitReturn;
10301032
if (hasExplicitReturn) node.flags |= NodeFlags.HasExplicitReturn;
10311033
(node as FunctionLikeDeclaration | ClassStaticBlockDeclaration).endFlowNode = currentFlow;
10321034
}
1035+
if (seenThisKeyword) {
1036+
node.flags |= NodeFlags.ContainsThis;
1037+
}
10331038
if (node.kind === SyntaxKind.SourceFile) {
10341039
node.flags |= emitFlags;
10351040
(node as SourceFile).endFlowNode = currentFlow;
10361041
}
1037-
10381042
if (currentReturnTarget) {
10391043
addAntecedent(currentReturnTarget, currentFlow);
10401044
currentFlow = finishFlowLabel(currentReturnTarget);
@@ -1051,12 +1055,15 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
10511055
currentExceptionTarget = saveExceptionTarget;
10521056
activeLabelList = saveActiveLabelList;
10531057
hasExplicitReturn = saveHasExplicitReturn;
1058+
seenThisKeyword = node.kind === SyntaxKind.ArrowFunction ? saveSeenThisKeyword || seenThisKeyword : saveSeenThisKeyword;
10541059
}
10551060
else if (containerFlags & ContainerFlags.IsInterface) {
1061+
const saveSeenThisKeyword = seenThisKeyword;
10561062
seenThisKeyword = false;
10571063
bindChildren(node);
10581064
Debug.assertNotNode(node, isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier
10591065
node.flags = seenThisKeyword ? node.flags | NodeFlags.ContainsThis : node.flags & ~NodeFlags.ContainsThis;
1066+
seenThisKeyword = saveSeenThisKeyword;
10601067
}
10611068
else {
10621069
bindChildren(node);
@@ -2852,6 +2859,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
28522859
}
28532860
// falls through
28542861
case SyntaxKind.ThisKeyword:
2862+
if (node.kind === SyntaxKind.ThisKeyword) {
2863+
seenThisKeyword = true;
2864+
}
28552865
// TODO: Why use `isExpression` here? both Identifier and ThisKeyword are expressions.
28562866
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
28572867
(node as Identifier | ThisExpression).flowNode = currentFlow;
@@ -3833,28 +3843,27 @@ export function getContainerFlags(node: Node): ContainerFlags {
38333843
// falls through
38343844
case SyntaxKind.Constructor:
38353845
case SyntaxKind.FunctionDeclaration:
3846+
case SyntaxKind.ClassStaticBlockDeclaration:
3847+
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike;
38363848
case SyntaxKind.MethodSignature:
38373849
case SyntaxKind.CallSignature:
38383850
case SyntaxKind.JSDocSignature:
38393851
case SyntaxKind.JSDocFunctionType:
38403852
case SyntaxKind.FunctionType:
38413853
case SyntaxKind.ConstructSignature:
38423854
case SyntaxKind.ConstructorType:
3843-
case SyntaxKind.ClassStaticBlockDeclaration:
3844-
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike;
3855+
return ContainerFlags.IsContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike;
38453856

38463857
case SyntaxKind.JSDocImportTag:
38473858
// treat as a container to prevent using an enclosing effective host, ensuring import bindings are scoped correctly
3848-
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals;
3859+
return ContainerFlags.IsContainer | ContainerFlags.HasLocals;
38493860

38503861
case SyntaxKind.FunctionExpression:
38513862
case SyntaxKind.ArrowFunction:
38523863
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsFunctionExpression;
38533864

38543865
case SyntaxKind.ModuleBlock:
38553866
return ContainerFlags.IsControlFlowContainer;
3856-
case SyntaxKind.PropertyDeclaration:
3857-
return (node as PropertyDeclaration).initializer ? ContainerFlags.IsControlFlowContainer : 0;
38583867

38593868
case SyntaxKind.CatchClause:
38603869
case SyntaxKind.ForStatement:

src/compiler/checker.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ import {
347347
getNamespaceDeclarationNode,
348348
getNewTargetContainer,
349349
getNonAugmentationDeclaration,
350-
getNonModifierTokenPosOfNode,
351350
getNormalizedAbsolutePath,
352351
getObjectFlags,
353352
getOriginalNode,
@@ -21143,9 +21142,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2114321142
const { initializer } = node as JsxAttribute;
2114421143
return !!initializer && isContextSensitive(initializer);
2114521144
}
21146-
case SyntaxKind.JsxExpression: {
21145+
case SyntaxKind.JsxExpression:
21146+
case SyntaxKind.YieldExpression: {
2114721147
// It is possible to that node.expression is undefined (e.g <div x={} />)
21148-
const { expression } = node as JsxExpression;
21148+
const { expression } = node as JsxExpression | YieldExpression;
2114921149
return !!expression && isContextSensitive(expression);
2115021150
}
2115121151
}
@@ -21154,7 +21154,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2115421154
}
2115521155

2115621156
function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
21157-
return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node);
21157+
return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node) || hasContextSensitiveYieldExpression(node);
2115821158
}
2115921159

2116021160
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
@@ -21167,6 +21167,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2116721167
return !!forEachReturnStatement(node.body as Block, statement => !!statement.expression && isContextSensitive(statement.expression));
2116821168
}
2116921169

21170+
function hasContextSensitiveYieldExpression(node: FunctionLikeDeclaration): boolean {
21171+
// yield expressions can be context sensitive in situations like:
21172+
//
21173+
// declare function test(gen: () => Generator<(arg: number) => string, void, void>): void;
21174+
//
21175+
// test(function* () {
21176+
// yield (arg) => String(arg);
21177+
// });
21178+
return !!(getFunctionFlags(node) & FunctionFlags.Generator && node.body && forEachYieldExpression(node.body as Block, isContextSensitive));
21179+
}
21180+
2117021181
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
2117121182
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
2117221183
isContextSensitiveFunctionLikeDeclaration(func);
@@ -32629,17 +32640,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3262932640
if (inferenceContext && contextFlags! & ContextFlags.Signature && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault)) {
3263032641
// For contextual signatures we incorporate all inferences made so far, e.g. from return
3263132642
// types as well as arguments to the left in a function call.
32632-
return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
32643+
const type = instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
32644+
if (!(type.flags & TypeFlags.AnyOrUnknown)) {
32645+
return type;
32646+
}
3263332647
}
3263432648
if (inferenceContext?.returnMapper) {
3263532649
// For other purposes (e.g. determining whether to produce literal types) we only
3263632650
// incorporate inferences made from the return type in a function call. We remove
3263732651
// the 'boolean' type from the contextual type such that contextually typed boolean
3263832652
// literals actually end up widening to 'boolean' (see #48363).
3263932653
const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
32640-
return type.flags & TypeFlags.Union && containsType((type as UnionType).types, regularFalseType) && containsType((type as UnionType).types, regularTrueType) ?
32641-
filterType(type, t => t !== regularFalseType && t !== regularTrueType) :
32642-
type;
32654+
if (!(type.flags & TypeFlags.AnyOrUnknown)) {
32655+
return type.flags & TypeFlags.Union && containsType((type as UnionType).types, regularFalseType) && containsType((type as UnionType).types, regularTrueType) ?
32656+
filterType(type, t => t !== regularFalseType && t !== regularTrueType) :
32657+
type;
32658+
}
3264332659
}
3264432660
}
3264532661
return contextualType;
@@ -48104,12 +48120,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4810448120
if (isIdentifier(node.name)) {
4810548121
checkCollisionsForDeclarationName(node, node.name);
4810648122
if (!(node.flags & (NodeFlags.Namespace | NodeFlags.GlobalAugmentation))) {
48107-
const sourceFile = getSourceFileOfNode(node);
48108-
const pos = getNonModifierTokenPosOfNode(node);
48109-
const span = getSpanOfTokenAtPosition(sourceFile, pos);
48110-
suggestionDiagnostics.add(
48111-
createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead),
48112-
);
48123+
error(node.name, Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead);
4811348124
}
4811448125
}
4811548126

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,9 +1821,8 @@
18211821
"code": 1539
18221822
},
18231823
"A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead.": {
1824-
"category": "Suggestion",
1825-
"code": 1540,
1826-
"reportsDeprecated": true
1824+
"category": "Error",
1825+
"code": 1540
18271826
},
18281827
"Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.": {
18291828
"category": "Error",

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6526,7 +6526,7 @@ export const enum ObjectFlags {
65266526
/** @internal */
65276527
ContainsObjectOrArrayLiteral = 1 << 17, // Type is or contains object literal type
65286528
/** @internal */
6529-
NonInferrableType = 1 << 18, // Type is or contains anyFunctionType or silentNeverType
6529+
NonInferrableType = 1 << 18, // Type is or contains anyFunctionType or silentNeverType, or it's a context free `returnTypeOnly`
65306530
/** @internal */
65316531
CouldContainTypeVariablesComputed = 1 << 19, // CouldContainTypeVariables flag has been computed
65326532
/** @internal */

0 commit comments

Comments
 (0)