Merge branch 'master' of https://github.com/microsoft/TypeScript into bug/38463

This commit is contained in:
Alexander T
2020-05-21 16:33:35 +03:00
29 changed files with 570 additions and 41 deletions
+18 -8
View File
@@ -15367,7 +15367,9 @@ namespace ts {
}
function isEmptyAnonymousObjectType(type: Type) {
return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type);
return !!(getObjectFlags(type) & ObjectFlags.Anonymous && (
(<ResolvedType>type).members && isEmptyResolvedType(<ResolvedType>type) ||
type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral && getMembersOfSymbol(type.symbol).size === 0));
}
function isStringIndexSignatureOnlyType(type: Type): boolean {
@@ -26381,7 +26383,7 @@ namespace ts {
return true;
}
function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
function invocationErrorDetails(errorTarget: Node, apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
let errorInfo: DiagnosticMessageChain | undefined;
const isCall = kind === SignatureKind.Call;
const awaitedType = getAwaitedType(apparentType);
@@ -26450,16 +26452,24 @@ namespace ts {
typeToString(apparentType)
);
}
let headMessage = isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable;
// Diagnose get accessors incorrectly called as functions
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
const { resolvedSymbol } = getNodeLinks(errorTarget);
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
headMessage = Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without;
}
}
return {
messageChain: chainDiagnosticMessages(
errorInfo,
isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
),
messageChain: chainDiagnosticMessages(errorInfo, headMessage),
relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined,
};
}
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(errorTarget, apparentType, kind);
const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
if (relatedInfo) {
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
@@ -26563,7 +26573,7 @@ namespace ts {
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
if (!callSignatures.length) {
const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
const errorDetails = invocationErrorDetails(node.expression, apparentType, SignatureKind.Call);
const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
if (errorDetails.relatedMessage) {
+4
View File
@@ -4416,6 +4416,10 @@
"category": "Error",
"code": 6233
},
"This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?": {
"category": "Error",
"code": 6234
},
"Projects to reference": {
"category": "Message",
+5 -4
View File
@@ -4499,10 +4499,11 @@ namespace ts {
function getLiteralTextOfNode(node: LiteralLikeNode, neverAsciiEscape: boolean | undefined, jsxAttributeEscape: boolean): string {
if (node.kind === SyntaxKind.StringLiteral && (<StringLiteral>node).textSourceNode) {
const textSourceNode = (<StringLiteral>node).textSourceNode!;
if (isIdentifier(textSourceNode)) {
return jsxAttributeEscape ? `"${escapeJsxAttributeString(getTextOfNode(textSourceNode))}"` :
neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? `"${escapeString(getTextOfNode(textSourceNode))}"` :
`"${escapeNonAsciiString(getTextOfNode(textSourceNode))}"`;
if (isIdentifier(textSourceNode) || isNumericLiteral(textSourceNode)) {
const text = isNumericLiteral(textSourceNode) ? textSourceNode.text : getTextOfNode(textSourceNode);
return jsxAttributeEscape ? `"${escapeJsxAttributeString(text)}"` :
neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? `"${escapeString(text)}"` :
`"${escapeNonAsciiString(text)}"`;
}
else {
return getLiteralTextOfNode(textSourceNode, neverAsciiEscape, jsxAttributeEscape);
+5 -5
View File
@@ -2610,23 +2610,23 @@ namespace ts {
}
export function createJSDocAuthorTag(comment?: string) {
return createJSDocTag(SyntaxKind.JSDocAuthorTag, "author", comment);
return createJSDocTag<JSDocAuthorTag>(SyntaxKind.JSDocAuthorTag, "author", comment);
}
export function createJSDocPublicTag() {
return createJSDocTag(SyntaxKind.JSDocPublicTag, "public");
return createJSDocTag<JSDocPublicTag>(SyntaxKind.JSDocPublicTag, "public");
}
export function createJSDocPrivateTag() {
return createJSDocTag(SyntaxKind.JSDocPrivateTag, "private");
return createJSDocTag<JSDocPrivateTag>(SyntaxKind.JSDocPrivateTag, "private");
}
export function createJSDocProtectedTag() {
return createJSDocTag(SyntaxKind.JSDocProtectedTag, "protected");
return createJSDocTag<JSDocProtectedTag>(SyntaxKind.JSDocProtectedTag, "protected");
}
export function createJSDocReadonlyTag() {
return createJSDocTag(SyntaxKind.JSDocReadonlyTag, "readonly");
return createJSDocTag<JSDocReadonlyTag>(SyntaxKind.JSDocReadonlyTag, "readonly");
}
export function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc) {
+6
View File
@@ -3092,6 +3092,12 @@ namespace ts {
else if (isStringOrNumericLiteralLike(nameExpression)) {
return escapeLeadingUnderscores(nameExpression.text);
}
else if (isSignedNumericLiteral(nameExpression)) {
if (nameExpression.operator === SyntaxKind.MinusToken) {
return tokenToString(nameExpression.operator) + nameExpression.operand.text as __String;
}
return nameExpression.operand.text as __String;
}
return undefined;
default:
return Debug.assertNever(name);
+4 -1
View File
@@ -102,8 +102,11 @@ interface Atomics {
/**
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
* number of agents that were awoken.
* @param typedArray A shared Int32Array.
* @param index The position in the typedArray to wake up on.
* @param count The number of sleeping agents to notify. Defaults to +Infinity.
*/
notify(typedArray: Int32Array, index: number, count: number): number;
notify(typedArray: Int32Array, index: number, count?: number): number;
/**
* Stores the bitwise XOR of a value with the value at the given position in the array,