Skip to content

Commit e40a2bc

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/TypeScript into bug/38463
2 parents a7364bf + 45cf20c commit e40a2bc

29 files changed

+570
-41
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15367,7 +15367,9 @@ namespace ts {
1536715367
}
1536815368

1536915369
function isEmptyAnonymousObjectType(type: Type) {
15370-
return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type);
15370+
return !!(getObjectFlags(type) & ObjectFlags.Anonymous && (
15371+
(<ResolvedType>type).members && isEmptyResolvedType(<ResolvedType>type) ||
15372+
type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral && getMembersOfSymbol(type.symbol).size === 0));
1537115373
}
1537215374

1537315375
function isStringIndexSignatureOnlyType(type: Type): boolean {
@@ -26381,7 +26383,7 @@ namespace ts {
2638126383
return true;
2638226384
}
2638326385

26384-
function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
26386+
function invocationErrorDetails(errorTarget: Node, apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
2638526387
let errorInfo: DiagnosticMessageChain | undefined;
2638626388
const isCall = kind === SignatureKind.Call;
2638726389
const awaitedType = getAwaitedType(apparentType);
@@ -26450,16 +26452,24 @@ namespace ts {
2645026452
typeToString(apparentType)
2645126453
);
2645226454
}
26455+
26456+
let headMessage = isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable;
26457+
26458+
// Diagnose get accessors incorrectly called as functions
26459+
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
26460+
const { resolvedSymbol } = getNodeLinks(errorTarget);
26461+
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
26462+
headMessage = Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without;
26463+
}
26464+
}
26465+
2645326466
return {
26454-
messageChain: chainDiagnosticMessages(
26455-
errorInfo,
26456-
isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
26457-
),
26467+
messageChain: chainDiagnosticMessages(errorInfo, headMessage),
2645826468
relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined,
2645926469
};
2646026470
}
2646126471
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
26462-
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
26472+
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(errorTarget, apparentType, kind);
2646326473
const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
2646426474
if (relatedInfo) {
2646526475
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
@@ -26563,7 +26573,7 @@ namespace ts {
2656326573

2656426574
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
2656526575
if (!callSignatures.length) {
26566-
const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
26576+
const errorDetails = invocationErrorDetails(node.expression, apparentType, SignatureKind.Call);
2656726577
const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
2656826578
const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
2656926579
if (errorDetails.relatedMessage) {

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4416,6 +4416,10 @@
44164416
"category": "Error",
44174417
"code": 6233
44184418
},
4419+
"This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?": {
4420+
"category": "Error",
4421+
"code": 6234
4422+
},
44194423

44204424
"Projects to reference": {
44214425
"category": "Message",

src/compiler/emitter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,10 +4499,11 @@ namespace ts {
44994499
function getLiteralTextOfNode(node: LiteralLikeNode, neverAsciiEscape: boolean | undefined, jsxAttributeEscape: boolean): string {
45004500
if (node.kind === SyntaxKind.StringLiteral && (<StringLiteral>node).textSourceNode) {
45014501
const textSourceNode = (<StringLiteral>node).textSourceNode!;
4502-
if (isIdentifier(textSourceNode)) {
4503-
return jsxAttributeEscape ? `"${escapeJsxAttributeString(getTextOfNode(textSourceNode))}"` :
4504-
neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? `"${escapeString(getTextOfNode(textSourceNode))}"` :
4505-
`"${escapeNonAsciiString(getTextOfNode(textSourceNode))}"`;
4502+
if (isIdentifier(textSourceNode) || isNumericLiteral(textSourceNode)) {
4503+
const text = isNumericLiteral(textSourceNode) ? textSourceNode.text : getTextOfNode(textSourceNode);
4504+
return jsxAttributeEscape ? `"${escapeJsxAttributeString(text)}"` :
4505+
neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? `"${escapeString(text)}"` :
4506+
`"${escapeNonAsciiString(text)}"`;
45064507
}
45074508
else {
45084509
return getLiteralTextOfNode(textSourceNode, neverAsciiEscape, jsxAttributeEscape);

src/compiler/factoryPublic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,23 +2610,23 @@ namespace ts {
26102610
}
26112611

26122612
export function createJSDocAuthorTag(comment?: string) {
2613-
return createJSDocTag(SyntaxKind.JSDocAuthorTag, "author", comment);
2613+
return createJSDocTag<JSDocAuthorTag>(SyntaxKind.JSDocAuthorTag, "author", comment);
26142614
}
26152615

26162616
export function createJSDocPublicTag() {
2617-
return createJSDocTag(SyntaxKind.JSDocPublicTag, "public");
2617+
return createJSDocTag<JSDocPublicTag>(SyntaxKind.JSDocPublicTag, "public");
26182618
}
26192619

26202620
export function createJSDocPrivateTag() {
2621-
return createJSDocTag(SyntaxKind.JSDocPrivateTag, "private");
2621+
return createJSDocTag<JSDocPrivateTag>(SyntaxKind.JSDocPrivateTag, "private");
26222622
}
26232623

26242624
export function createJSDocProtectedTag() {
2625-
return createJSDocTag(SyntaxKind.JSDocProtectedTag, "protected");
2625+
return createJSDocTag<JSDocProtectedTag>(SyntaxKind.JSDocProtectedTag, "protected");
26262626
}
26272627

26282628
export function createJSDocReadonlyTag() {
2629-
return createJSDocTag(SyntaxKind.JSDocReadonlyTag, "readonly");
2629+
return createJSDocTag<JSDocReadonlyTag>(SyntaxKind.JSDocReadonlyTag, "readonly");
26302630
}
26312631

26322632
export function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc) {

src/compiler/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,12 @@ namespace ts {
30923092
else if (isStringOrNumericLiteralLike(nameExpression)) {
30933093
return escapeLeadingUnderscores(nameExpression.text);
30943094
}
3095+
else if (isSignedNumericLiteral(nameExpression)) {
3096+
if (nameExpression.operator === SyntaxKind.MinusToken) {
3097+
return tokenToString(nameExpression.operator) + nameExpression.operand.text as __String;
3098+
}
3099+
return nameExpression.operand.text as __String;
3100+
}
30953101
return undefined;
30963102
default:
30973103
return Debug.assertNever(name);

src/lib/es2017.sharedmemory.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ interface Atomics {
102102
/**
103103
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
104104
* number of agents that were awoken.
105+
* @param typedArray A shared Int32Array.
106+
* @param index The position in the typedArray to wake up on.
107+
* @param count The number of sleeping agents to notify. Defaults to +Infinity.
105108
*/
106-
notify(typedArray: Int32Array, index: number, count: number): number;
109+
notify(typedArray: Int32Array, index: number, count?: number): number;
107110

108111
/**
109112
* Stores the bitwise XOR of a value with the value at the given position in the array,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
2+
Type 'Number' has no call signatures.
3+
4+
5+
==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ====
6+
// https://github.com/microsoft/TypeScript/issues/24554
7+
class Test24554 {
8+
get property(): number { return 1; }
9+
}
10+
function test24554(x: Test24554) {
11+
return x.property();
12+
~~~~~~~~
13+
!!! error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
14+
!!! error TS6234: Type 'Number' has no call signatures.
15+
}
16+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [accessorAccidentalCallDiagnostic.ts]
2+
// https://github.com/microsoft/TypeScript/issues/24554
3+
class Test24554 {
4+
get property(): number { return 1; }
5+
}
6+
function test24554(x: Test24554) {
7+
return x.property();
8+
}
9+
10+
11+
//// [accessorAccidentalCallDiagnostic.js]
12+
// https://github.com/microsoft/TypeScript/issues/24554
13+
var Test24554 = /** @class */ (function () {
14+
function Test24554() {
15+
}
16+
Object.defineProperty(Test24554.prototype, "property", {
17+
get: function () { return 1; },
18+
enumerable: false,
19+
configurable: true
20+
});
21+
return Test24554;
22+
}());
23+
function test24554(x) {
24+
return x.property();
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/24554
3+
class Test24554 {
4+
>Test24554 : Symbol(Test24554, Decl(accessorAccidentalCallDiagnostic.ts, 0, 0))
5+
6+
get property(): number { return 1; }
7+
>property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17))
8+
}
9+
function test24554(x: Test24554) {
10+
>test24554 : Symbol(test24554, Decl(accessorAccidentalCallDiagnostic.ts, 3, 1))
11+
>x : Symbol(x, Decl(accessorAccidentalCallDiagnostic.ts, 4, 19))
12+
>Test24554 : Symbol(Test24554, Decl(accessorAccidentalCallDiagnostic.ts, 0, 0))
13+
14+
return x.property();
15+
>x.property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17))
16+
>x : Symbol(x, Decl(accessorAccidentalCallDiagnostic.ts, 4, 19))
17+
>property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17))
18+
}
19+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/24554
3+
class Test24554 {
4+
>Test24554 : Test24554
5+
6+
get property(): number { return 1; }
7+
>property : number
8+
>1 : 1
9+
}
10+
function test24554(x: Test24554) {
11+
>test24554 : (x: Test24554) => any
12+
>x : Test24554
13+
14+
return x.property();
15+
>x.property() : any
16+
>x.property : number
17+
>x : Test24554
18+
>property : number
19+
}
20+

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4272,11 +4272,11 @@ declare namespace ts {
42724272
function createJSDocParameterTag(typeExpression: JSDocTypeExpression | undefined, name: EntityName, isNameFirst: boolean, isBracketed: boolean, comment?: string): JSDocParameterTag;
42734273
function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral;
42744274
function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag;
4275-
function createJSDocAuthorTag(comment?: string): JSDocTag;
4276-
function createJSDocPublicTag(): JSDocTag;
4277-
function createJSDocPrivateTag(): JSDocTag;
4278-
function createJSDocProtectedTag(): JSDocTag;
4279-
function createJSDocReadonlyTag(): JSDocTag;
4275+
function createJSDocAuthorTag(comment?: string): JSDocAuthorTag;
4276+
function createJSDocPublicTag(): JSDocPublicTag;
4277+
function createJSDocPrivateTag(): JSDocPrivateTag;
4278+
function createJSDocProtectedTag(): JSDocProtectedTag;
4279+
function createJSDocReadonlyTag(): JSDocReadonlyTag;
42804280
function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc): JSDocContainer;
42814281
function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement;
42824282
function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4272,11 +4272,11 @@ declare namespace ts {
42724272
function createJSDocParameterTag(typeExpression: JSDocTypeExpression | undefined, name: EntityName, isNameFirst: boolean, isBracketed: boolean, comment?: string): JSDocParameterTag;
42734273
function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral;
42744274
function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag;
4275-
function createJSDocAuthorTag(comment?: string): JSDocTag;
4276-
function createJSDocPublicTag(): JSDocTag;
4277-
function createJSDocPrivateTag(): JSDocTag;
4278-
function createJSDocProtectedTag(): JSDocTag;
4279-
function createJSDocReadonlyTag(): JSDocTag;
4275+
function createJSDocAuthorTag(comment?: string): JSDocAuthorTag;
4276+
function createJSDocPublicTag(): JSDocPublicTag;
4277+
function createJSDocPrivateTag(): JSDocPrivateTag;
4278+
function createJSDocProtectedTag(): JSDocProtectedTag;
4279+
function createJSDocReadonlyTag(): JSDocReadonlyTag;
42804280
function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc): JSDocContainer;
42814281
function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement;
42824282
function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(3,5): error TS2300: Duplicate identifier '[1]'.
2+
tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(8,5): error TS2300: Duplicate identifier '[+1]'.
3+
tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(13,5): error TS2300: Duplicate identifier '[+1]'.
4+
tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(23,5): error TS2300: Duplicate identifier '["+1"]'.
5+
tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(28,5): error TS2300: Duplicate identifier '[-1]'.
6+
tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(33,5): error TS2300: Duplicate identifier '["-1"]'.
7+
8+
9+
==== tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts (6 errors) ====
10+
const t1 = {
11+
1: 1,
12+
[1]: 0 // duplicate
13+
~~~
14+
!!! error TS2300: Duplicate identifier '[1]'.
15+
}
16+
17+
const t2 = {
18+
1: 1,
19+
[+1]: 0 // duplicate
20+
~~~~
21+
!!! error TS2300: Duplicate identifier '[+1]'.
22+
}
23+
24+
const t3 = {
25+
"1": 1,
26+
[+1]: 0 // duplicate
27+
~~~~
28+
!!! error TS2300: Duplicate identifier '[+1]'.
29+
}
30+
31+
const t4 = {
32+
"+1": 1,
33+
[+1]: 0 // two different keys, "+1", "1"
34+
}
35+
36+
const t5 = {
37+
"+1": 1,
38+
["+1"]: 0 // duplicate
39+
~~~~~~
40+
!!! error TS2300: Duplicate identifier '["+1"]'.
41+
}
42+
43+
const t6 = {
44+
"-1": 1,
45+
[-1]: 0 // duplicate
46+
~~~~
47+
!!! error TS2300: Duplicate identifier '[-1]'.
48+
}
49+
50+
const t7 = {
51+
"-1": 1,
52+
["-1"]: 0 // duplicate
53+
~~~~~~
54+
!!! error TS2300: Duplicate identifier '["-1"]'.
55+
}
56+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//// [duplicateObjectLiteralProperty_computedName.ts]
2+
const t1 = {
3+
1: 1,
4+
[1]: 0 // duplicate
5+
}
6+
7+
const t2 = {
8+
1: 1,
9+
[+1]: 0 // duplicate
10+
}
11+
12+
const t3 = {
13+
"1": 1,
14+
[+1]: 0 // duplicate
15+
}
16+
17+
const t4 = {
18+
"+1": 1,
19+
[+1]: 0 // two different keys, "+1", "1"
20+
}
21+
22+
const t5 = {
23+
"+1": 1,
24+
["+1"]: 0 // duplicate
25+
}
26+
27+
const t6 = {
28+
"-1": 1,
29+
[-1]: 0 // duplicate
30+
}
31+
32+
const t7 = {
33+
"-1": 1,
34+
["-1"]: 0 // duplicate
35+
}
36+
37+
38+
//// [duplicateObjectLiteralProperty_computedName.js]
39+
var _a, _b, _c, _d, _e, _f, _g;
40+
var t1 = (_a = {
41+
1: 1
42+
},
43+
_a[1] = 0 // duplicate
44+
,
45+
_a);
46+
var t2 = (_b = {
47+
1: 1
48+
},
49+
_b[+1] = 0 // duplicate
50+
,
51+
_b);
52+
var t3 = (_c = {
53+
"1": 1
54+
},
55+
_c[+1] = 0 // duplicate
56+
,
57+
_c);
58+
var t4 = (_d = {
59+
"+1": 1
60+
},
61+
_d[+1] = 0 // two different keys, "+1", "1"
62+
,
63+
_d);
64+
var t5 = (_e = {
65+
"+1": 1
66+
},
67+
_e["+1"] = 0 // duplicate
68+
,
69+
_e);
70+
var t6 = (_f = {
71+
"-1": 1
72+
},
73+
_f[-1] = 0 // duplicate
74+
,
75+
_f);
76+
var t7 = (_g = {
77+
"-1": 1
78+
},
79+
_g["-1"] = 0 // duplicate
80+
,
81+
_g);

0 commit comments

Comments
 (0)