Skip to content

Commit b67a261

Browse files
committed
Merge branch 'master' into typedBindCallApply
# Conflicts: # src/compiler/diagnosticMessages.json
2 parents 91123fc + ba8595b commit b67a261

File tree

318 files changed

+3566
-860
lines changed

Some content is hidden

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

318 files changed

+3566
-860
lines changed

src/compiler/checker.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,12 +2295,12 @@ namespace ts {
22952295
? chainDiagnosticMessages(
22962296
/*details*/ undefined,
22972297
Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1,
2298-
packageId.name, getMangledNameForScopedPackage(packageId.name))
2298+
packageId.name, mangleScopedPackageName(packageId.name))
22992299
: chainDiagnosticMessages(
23002300
/*details*/ undefined,
23012301
Diagnostics.Try_npm_install_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
23022302
moduleReference,
2303-
getMangledNameForScopedPackage(packageId.name))
2303+
mangleScopedPackageName(packageId.name))
23042304
: undefined;
23052305
errorOrSuggestion(isError, errorNode, chainDiagnosticMessages(
23062306
errorInfo,
@@ -5910,9 +5910,9 @@ namespace ts {
59105910
for (const declaration of symbol.declarations) {
59115911
if (declaration.kind === SyntaxKind.EnumDeclaration) {
59125912
for (const member of (<EnumDeclaration>declaration).members) {
5913-
const memberType = getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member)); // TODO: GH#18217
5913+
const memberType = getFreshTypeOfLiteralType(getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member))); // TODO: GH#18217
59145914
getSymbolLinks(getSymbolOfNode(member)).declaredType = memberType;
5915-
memberTypeList.push(memberType);
5915+
memberTypeList.push(getRegularTypeOfLiteralType(memberType));
59165916
}
59175917
}
59185918
}
@@ -8249,7 +8249,7 @@ namespace ts {
82498249
const res = tryGetDeclaredTypeOfSymbol(symbol);
82508250
if (res) {
82518251
return checkNoTypeArguments(node, symbol) ?
8252-
res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : res :
8252+
res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : getRegularTypeOfLiteralType(res) :
82538253
errorType;
82548254
}
82558255

@@ -12743,7 +12743,7 @@ namespace ts {
1274312743
}
1274412744

1274512745
function getWidenedLiteralType(type: Type): Type {
12746-
return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
12746+
return type.flags & TypeFlags.EnumLiteral && type.flags & TypeFlags.FreshLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
1274712747
type.flags & TypeFlags.StringLiteral && type.flags & TypeFlags.FreshLiteral ? stringType :
1274812748
type.flags & TypeFlags.NumberLiteral && type.flags & TypeFlags.FreshLiteral ? numberType :
1274912749
type.flags & TypeFlags.BooleanLiteral ? booleanType :
@@ -19217,12 +19217,16 @@ namespace ts {
1921719217
let aboveArgCount = Number.POSITIVE_INFINITY;
1921819218

1921919219
let argCount = args.length;
19220+
let closestSignature: Signature | undefined;
1922019221
for (const sig of signatures) {
1922119222
const minCount = getMinArgumentCount(sig);
1922219223
const maxCount = getParameterCount(sig);
1922319224
if (minCount < argCount && minCount > belowArgCount) belowArgCount = minCount;
1922419225
if (argCount < maxCount && maxCount < aboveArgCount) aboveArgCount = maxCount;
19225-
min = Math.min(min, minCount);
19226+
if (minCount < min) {
19227+
min = minCount;
19228+
closestSignature = sig;
19229+
}
1922619230
max = Math.max(max, maxCount);
1922719231
}
1922819232

@@ -19235,16 +19239,29 @@ namespace ts {
1923519239
argCount--;
1923619240
}
1923719241

19242+
let related: DiagnosticWithLocation | undefined;
19243+
if (closestSignature && getMinArgumentCount(closestSignature) > argCount && closestSignature.declaration) {
19244+
const paramDecl = closestSignature.declaration.parameters[closestSignature.thisParameter ? argCount + 1 : argCount];
19245+
if (paramDecl) {
19246+
related = createDiagnosticForNode(
19247+
paramDecl,
19248+
isBindingPattern(paramDecl.name) ? Diagnostics.An_argument_matching_this_binding_pattern_was_not_provided : Diagnostics.An_argument_for_0_was_not_provided,
19249+
!paramDecl.name ? argCount : !isBindingPattern(paramDecl.name) ? idText(getFirstIdentifier(paramDecl.name)) : undefined
19250+
);
19251+
}
19252+
}
1923819253
if (hasRestParameter || hasSpreadArgument) {
1923919254
const error = hasRestParameter && hasSpreadArgument ? Diagnostics.Expected_at_least_0_arguments_but_got_1_or_more :
1924019255
hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1 :
1924119256
Diagnostics.Expected_0_arguments_but_got_1_or_more;
19242-
return createDiagnosticForNode(node, error, paramRange, argCount);
19257+
const diagnostic = createDiagnosticForNode(node, error, paramRange, argCount);
19258+
return related ? addRelatedInfo(diagnostic, related) : diagnostic;
1924319259
}
1924419260
if (min < argCount && argCount < max) {
1924519261
return createDiagnosticForNode(node, Diagnostics.No_overload_expects_0_arguments_but_overloads_do_exist_that_expect_either_1_or_2_arguments, argCount, belowArgCount, aboveArgCount);
1924619262
}
19247-
return createDiagnosticForNode(node, Diagnostics.Expected_0_arguments_but_got_1, paramRange, argCount);
19263+
const diagnostic = createDiagnosticForNode(node, Diagnostics.Expected_0_arguments_but_got_1, paramRange, argCount);
19264+
return related ? addRelatedInfo(diagnostic, related) : diagnostic;
1924819265
}
1924919266

1925019267
function getTypeArgumentArityError(node: Node, signatures: ReadonlyArray<Signature>, typeArguments: NodeArray<TypeNode>) {
@@ -28286,13 +28303,14 @@ namespace ts {
2828628303
return false;
2828728304
}
2828828305

28289-
function literalTypeToNode(type: LiteralType): Expression {
28290-
return createLiteral(type.value);
28306+
function literalTypeToNode(type: LiteralType, enclosing: Node): Expression {
28307+
const enumResult = type.flags & TypeFlags.EnumLiteral && nodeBuilder.symbolToExpression(type.symbol, SymbolFlags.Value, enclosing);
28308+
return enumResult || createLiteral(type.value);
2829128309
}
2829228310

2829328311
function createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
2829428312
const type = getTypeOfSymbol(getSymbolOfNode(node));
28295-
return literalTypeToNode(<LiteralType>type);
28313+
return literalTypeToNode(<LiteralType>type, node);
2829628314
}
2829728315

2829828316
function createResolver(): EmitResolver {
@@ -29657,13 +29675,20 @@ namespace ts {
2965729675
(<PrefixUnaryExpression>expr).operand.kind === SyntaxKind.NumericLiteral;
2965829676
}
2965929677

29678+
function isSimpleLiteralEnumReference(expr: Expression) {
29679+
if (
29680+
(isPropertyAccessExpression(expr) || (isElementAccessExpression(expr) && isStringOrNumberLiteralExpression(expr.argumentExpression))) &&
29681+
isEntityNameExpression(expr.expression)
29682+
) return !!(checkExpressionCached(expr).flags & TypeFlags.EnumLiteral);
29683+
}
29684+
2966029685
function checkAmbientInitializer(node: VariableDeclaration | PropertyDeclaration | PropertySignature) {
2966129686
if (node.initializer) {
29662-
const isInvalidInitializer = !isStringOrNumberLiteralExpression(node.initializer);
29687+
const isInvalidInitializer = !(isStringOrNumberLiteralExpression(node.initializer) || isSimpleLiteralEnumReference(node.initializer));
2966329688
const isConstOrReadonly = isDeclarationReadonly(node) || isVariableDeclaration(node) && isVarConst(node);
2966429689
if (isConstOrReadonly && !node.type) {
2966529690
if (isInvalidInitializer) {
29666-
return grammarErrorOnNode(node.initializer!, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal);
29691+
return grammarErrorOnNode(node.initializer!, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal_or_literal_enum_reference);
2966729692
}
2966829693
}
2966929694
else {

src/compiler/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace ts {
6565

6666
/* @internal */
6767
namespace ts {
68+
export const emptyArray: never[] = [] as never[];
6869

6970
/** Create a MapLike with good performance. */
7071
function createDictionaryObject<T>(): MapLike<T> {

src/compiler/diagnosticMessages.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@
835835
"category": "Error",
836836
"code": 1253
837837
},
838-
"A 'const' initializer in an ambient context must be a string or numeric literal.": {
838+
"A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.": {
839839
"category": "Error",
840840
"code": 1254
841841
},
@@ -3294,7 +3294,7 @@
32943294
"category": "Message",
32953295
"code": 6104
32963296
},
3297-
"Expected type of '{0}' field in 'package.json' to be 'string', got '{1}'.": {
3297+
"Expected type of '{0}' field in 'package.json' to be '{1}', got '{2}'.": {
32983298
"category": "Message",
32993299
"code": 6105
33003300
},
@@ -3692,10 +3692,34 @@
36923692
"category": "Error",
36933693
"code": 6205
36943694
},
3695-
"Enable strict 'bind', 'call', and 'apply' methods on functions.": {
3695+
"'package.json' has a 'typesVersions' field with version-specific path mappings.": {
36963696
"category": "Message",
36973697
"code": 6206
36983698
},
3699+
"'package.json' does not have a 'typesVersions' entry that matches version '{0}'.": {
3700+
"category": "Message",
3701+
"code": 6207
3702+
},
3703+
"'package.json' has a 'typesVersions' entry '{0}' that matches compiler version '{1}', looking for a pattern to match module name '{2}'.": {
3704+
"category": "Message",
3705+
"code": 6208
3706+
},
3707+
"'package.json' has a 'typesVersions' entry '{0}' that is not a valid semver range.": {
3708+
"category": "Message",
3709+
"code": 6209
3710+
},
3711+
"An argument for '{0}' was not provided.": {
3712+
"category": "Message",
3713+
"code": 6210
3714+
},
3715+
"An argument matching this binding pattern was not provided.": {
3716+
"category": "Message",
3717+
"code": 6211
3718+
},
3719+
"Enable strict 'bind', 'call', and 'apply' methods on functions.": {
3720+
"category": "Message",
3721+
"code": 6212
3722+
},
36993723

37003724
"Projects to reference": {
37013725
"category": "Message",

src/compiler/emitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,8 @@ namespace ts {
28182818
const parameter = singleOrUndefined(parameters);
28192819
return parameter
28202820
&& parameter.pos === parentNode.pos // may not have parsed tokens between parent and parameter
2821-
&& !(isArrowFunction(parentNode) && parentNode.type) // arrow function may not have return type annotation
2821+
&& isArrowFunction(parentNode) // only arrow functions may have simple arrow head
2822+
&& !parentNode.type // arrow function may not have return type annotation
28222823
&& !some(parentNode.decorators) // parent may not have decorators
28232824
&& !some(parentNode.modifiers) // parent may not have modifiers
28242825
&& !some(parentNode.typeParameters) // parent may not have type parameters

0 commit comments

Comments
 (0)