Skip to content

Commit 463138a

Browse files
committed
Merge branch 'main' into import_assertion
# Conflicts: # src/compiler/diagnosticMessages.json
2 parents bf7ca71 + 8346143 commit 463138a

File tree

181 files changed

+1742
-6588
lines changed

Some content is hidden

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

181 files changed

+1742
-6588
lines changed

.github/pr_owners.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ ahejlsberg
1010
amcasey
1111
jessetrinity
1212
minestarks
13-
uniqueiniquity
13+
armanio123
14+
gabritto

.github/workflows/accept-baselines-fix-lints.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
git config user.email "[email protected]"
2121
git config user.name "TypeScript Bot"
2222
npm install
23+
git rm -r --quiet tests/baselines/reference :^tests/baselines/reference/docker :^tests/baselines/reference/user
2324
gulp runtests-parallel --ci --fix || true
2425
gulp baseline-accept
2526
git add ./src

package-lock.json

+21-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"mkdirp": "latest",
8585
"mocha": "latest",
8686
"mocha-fivemat-progress-reporter": "latest",
87-
"ms": "latest",
87+
"ms": "^2.1.3",
8888
"node-fetch": "^2.6.1",
8989
"plugin-error": "latest",
9090
"pretty-hrtime": "^1.0.3",

src/compiler/checker.ts

+66-19
Original file line numberDiff line numberDiff line change
@@ -17842,6 +17842,13 @@ namespace ts {
1784217842
message = Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties;
1784317843
}
1784417844
else {
17845+
if (source.flags & TypeFlags.StringLiteral && target.flags & TypeFlags.Union) {
17846+
const suggestedType = getSuggestedTypeForNonexistentStringLiteralType(source as StringLiteralType, target as UnionType);
17847+
if (suggestedType) {
17848+
reportError(Diagnostics.Type_0_is_not_assignable_to_type_1_Did_you_mean_2, generalizedSourceType, targetType, typeToString(suggestedType));
17849+
return;
17850+
}
17851+
}
1784517852
message = Diagnostics.Type_0_is_not_assignable_to_type_1;
1784617853
}
1784717854
}
@@ -23244,9 +23251,10 @@ namespace ts {
2324423251

2324523252
function isConstantReference(node: Node): boolean {
2324623253
switch (node.kind) {
23247-
case SyntaxKind.Identifier:
23254+
case SyntaxKind.Identifier: {
2324823255
const symbol = getResolvedSymbol(node as Identifier);
23249-
return isConstVariable(symbol) || !!symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration).kind === SyntaxKind.Parameter && !isParameterAssigned(symbol);
23256+
return isConstVariable(symbol) || isParameterOrCatchClauseVariable(symbol) && !isSymbolAssigned(symbol);
23257+
}
2325023258
case SyntaxKind.PropertyAccessExpression:
2325123259
case SyntaxKind.ElementAccessExpression:
2325223260
// The resolvedSymbol property is initialized by checkPropertyAccess or checkElementAccess before we get here.
@@ -24380,37 +24388,38 @@ namespace ts {
2438024388
node.kind === SyntaxKind.PropertyDeclaration)!;
2438124389
}
2438224390

24383-
// Check if a parameter is assigned anywhere within its declaring function.
24384-
function isParameterAssigned(symbol: Symbol) {
24391+
// Check if a parameter or catch variable is assigned anywhere
24392+
function isSymbolAssigned(symbol: Symbol) {
2438524393
if (!symbol.valueDeclaration) {
2438624394
return false;
2438724395
}
24388-
const func = getRootDeclaration(symbol.valueDeclaration).parent as FunctionLikeDeclaration;
24389-
const links = getNodeLinks(func);
24396+
const parent = getRootDeclaration(symbol.valueDeclaration).parent;
24397+
const links = getNodeLinks(parent);
2439024398
if (!(links.flags & NodeCheckFlags.AssignmentsMarked)) {
2439124399
links.flags |= NodeCheckFlags.AssignmentsMarked;
24392-
if (!hasParentWithAssignmentsMarked(func)) {
24393-
markParameterAssignments(func);
24400+
if (!hasParentWithAssignmentsMarked(parent)) {
24401+
markNodeAssignments(parent);
2439424402
}
2439524403
}
2439624404
return symbol.isAssigned || false;
2439724405
}
2439824406

2439924407
function hasParentWithAssignmentsMarked(node: Node) {
24400-
return !!findAncestor(node.parent, node => isFunctionLike(node) && !!(getNodeLinks(node).flags & NodeCheckFlags.AssignmentsMarked));
24408+
return !!findAncestor(node.parent, node =>
24409+
(isFunctionLike(node) || isCatchClause(node)) && !!(getNodeLinks(node).flags & NodeCheckFlags.AssignmentsMarked));
2440124410
}
2440224411

24403-
function markParameterAssignments(node: Node) {
24412+
function markNodeAssignments(node: Node) {
2440424413
if (node.kind === SyntaxKind.Identifier) {
2440524414
if (isAssignmentTarget(node)) {
2440624415
const symbol = getResolvedSymbol(node as Identifier);
24407-
if (symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration).kind === SyntaxKind.Parameter) {
24416+
if (isParameterOrCatchClauseVariable(symbol)) {
2440824417
symbol.isAssigned = true;
2440924418
}
2441024419
}
2441124420
}
2441224421
else {
24413-
forEachChild(node, markParameterAssignments);
24422+
forEachChild(node, markNodeAssignments);
2441424423
}
2441524424
}
2441624425

@@ -24479,7 +24488,19 @@ namespace ts {
2447924488
}
2448024489

2448124490
function isExportOrExportExpression(location: Node) {
24482-
return !!findAncestor(location, e => e.parent && isExportAssignment(e.parent) && e.parent.expression === e && isEntityNameExpression(e));
24491+
return !!findAncestor(location, n => {
24492+
const parent = n.parent;
24493+
if (parent === undefined) {
24494+
return "quit";
24495+
}
24496+
if (isExportAssignment(parent)) {
24497+
return parent.expression === n && isEntityNameExpression(n);
24498+
}
24499+
if (isExportSpecifier(parent)) {
24500+
return parent.name === n || parent.propertyName === n;
24501+
}
24502+
return false;
24503+
});
2448324504
}
2448424505

2448524506
function markAliasReferenced(symbol: Symbol, location: Node) {
@@ -24648,7 +24669,7 @@ namespace ts {
2464824669
// analysis to include the immediately enclosing function.
2464924670
while (flowContainer !== declarationContainer && (flowContainer.kind === SyntaxKind.FunctionExpression ||
2465024671
flowContainer.kind === SyntaxKind.ArrowFunction || isObjectLiteralOrClassExpressionMethodOrAccessor(flowContainer)) &&
24651-
(isConstVariable(localOrExportSymbol) && type !== autoArrayType || isParameter && !isParameterAssigned(localOrExportSymbol))) {
24672+
(isConstVariable(localOrExportSymbol) && type !== autoArrayType || isParameter && !isSymbolAssigned(localOrExportSymbol))) {
2465224673
flowContainer = getControlFlowContainer(flowContainer);
2465324674
}
2465424675
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
@@ -28241,6 +28262,11 @@ namespace ts {
2824128262
return suggestion;
2824228263
}
2824328264

28265+
function getSuggestedTypeForNonexistentStringLiteralType(source: StringLiteralType, target: UnionType): StringLiteralType | undefined {
28266+
const candidates = target.types.filter((type): type is StringLiteralType => !!(type.flags & TypeFlags.StringLiteral));
28267+
return getSpellingSuggestion(source.value, candidates, type => type.value);
28268+
}
28269+
2824428270
/**
2824528271
* Given a name and a list of symbols whose names are *not* equal to the name, return a spelling suggestion if there is one that is close enough.
2824628272
* Names less than length 3 only check for case-insensitive equality, not levenshtein distance.
@@ -38047,6 +38073,7 @@ namespace ts {
3804738073
function checkClassMember(member: ClassElement | ParameterPropertyDeclaration, memberIsParameterProperty?: boolean) {
3804838074
const hasOverride = hasOverrideModifier(member);
3804938075
const hasStatic = isStatic(member);
38076+
const isJs = isInJSFile(member);
3805038077
if (baseWithThis && (hasOverride || compilerOptions.noImplicitOverride)) {
3805138078
const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member);
3805238079
if (!declaredProp) {
@@ -38062,8 +38089,19 @@ namespace ts {
3806238089
if (prop && !baseProp && hasOverride) {
3806338090
const suggestion = getSuggestedSymbolForNonexistentClassMember(symbolName(declaredProp), baseType);
3806438091
suggestion ?
38065-
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1, baseClassName, symbolToString(suggestion)) :
38066-
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0, baseClassName);
38092+
error(
38093+
member,
38094+
isJs ?
38095+
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1 :
38096+
Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1,
38097+
baseClassName,
38098+
symbolToString(suggestion)) :
38099+
error(
38100+
member,
38101+
isJs ?
38102+
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0 :
38103+
Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0,
38104+
baseClassName);
3806738105
}
3806838106
else if (prop && baseProp?.declarations && compilerOptions.noImplicitOverride && !nodeInAmbientContext) {
3806938107
const baseHasAbstract = some(baseProp.declarations, hasAbstractModifier);
@@ -38073,8 +38111,12 @@ namespace ts {
3807338111

3807438112
if (!baseHasAbstract) {
3807538113
const diag = memberIsParameterProperty ?
38076-
Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0 :
38077-
Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0;
38114+
isJs ?
38115+
Diagnostics.This_parameter_property_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0 :
38116+
Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0 :
38117+
isJs ?
38118+
Diagnostics.This_member_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0 :
38119+
Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0;
3807838120
error(member, diag, baseClassName);
3807938121
}
3808038122
else if (hasAbstractModifier(member) && baseHasAbstract) {
@@ -38084,7 +38126,12 @@ namespace ts {
3808438126
}
3808538127
else if (hasOverride) {
3808638128
const className = typeToString(type);
38087-
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class, className);
38129+
error(
38130+
member,
38131+
isJs ?
38132+
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_its_containing_class_0_does_not_extend_another_class :
38133+
Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class,
38134+
className);
3808838135
}
3808938136
}
3809038137
}

src/compiler/diagnosticMessages.json

+26-3
Original file line numberDiff line numberDiff line change
@@ -3304,14 +3304,18 @@
33043304
"category": "Error",
33053305
"code": 2819
33063306
},
3307-
"Import assertions are only supported when the '--module' option is set to 'esnext'.": {
3307+
"Type '{0}' is not assignable to type '{1}'. Did you mean '{2}'?": {
33083308
"category": "Error",
33093309
"code": 2820
33103310
},
3311-
"Import assertions cannot be used with type-only imports or exports.": {
3311+
"Import assertions are only supported when the '--module' option is set to 'esnext'.": {
33123312
"category": "Error",
33133313
"code": 2821
33143314
},
3315+
"Import assertions cannot be used with type-only imports or exports.": {
3316+
"category": "Error",
3317+
"code": 2822
3318+
},
33153319

33163320
"Import declaration '{0}' is using private name '{1}'.": {
33173321
"category": "Error",
@@ -3717,7 +3721,26 @@
37173721
"category": "Error",
37183722
"code": 4118
37193723
},
3720-
3724+
"This member must have a JSDoc comment with an '@override' tag because it overrides a member in the base class '{0}'.": {
3725+
"category": "Error",
3726+
"code": 4119
3727+
},
3728+
"This parameter property must have a JSDoc comment with an '@override' tag because it overrides a member in the base class '{0}'.": {
3729+
"category": "Error",
3730+
"code": 4120
3731+
},
3732+
"This member cannot have a JSDoc comment with an '@override' tag because its containing class '{0}' does not extend another class.": {
3733+
"category": "Error",
3734+
"code": 4121
3735+
},
3736+
"This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'.": {
3737+
"category": "Error",
3738+
"code": 4122
3739+
},
3740+
"This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?": {
3741+
"category": "Error",
3742+
"code": 4123
3743+
},
37213744
"The current host does not support the '{0}' option.": {
37223745
"category": "Error",
37233746
"code": 5001

0 commit comments

Comments
 (0)