From 61f60057f1798cae92781a1f2d6521a5f378a1a1 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Sun, 5 Apr 2020 15:17:14 -0700 Subject: [PATCH 01/11] Better error message for accidental calls to get-accessors --- src/compiler/checker.ts | 23 +++++++++++------ src/compiler/diagnosticMessages.json | 4 +++ ...ccessorAccidentalCallDiagnostic.errors.txt | 17 +++++++++++++ .../accessorAccidentalCallDiagnostic.js | 25 +++++++++++++++++++ .../accessorAccidentalCallDiagnostic.symbols | 19 ++++++++++++++ .../accessorAccidentalCallDiagnostic.types | 20 +++++++++++++++ ...ropertiesInheritedIntoClassType.errors.txt | 2 ++ .../instancePropertyInClassType.errors.txt | 2 ++ .../accessorAccidentalCallDiagnostic.ts | 9 +++++++ 9 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt create mode 100644 tests/baselines/reference/accessorAccidentalCallDiagnostic.js create mode 100644 tests/baselines/reference/accessorAccidentalCallDiagnostic.symbols create mode 100644 tests/baselines/reference/accessorAccidentalCallDiagnostic.types create mode 100644 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5cab127293b..79a5d93f3bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25851,14 +25851,21 @@ namespace ts { error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType)); } else { - let relatedInformation: DiagnosticRelatedInformation | undefined; - if (node.arguments.length === 1) { - const text = getSourceFileOfNode(node).text; - if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) { - relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon); + const relatedInformation: DiagnosticRelatedInformation[] = []; + if (node.arguments.length === 0) { + // Diagnose get accessors incorrectly called as functions + const { resolvedSymbol } = getNodeLinks(node.expression); + if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) { + relatedInformation.push(createDiagnosticForNode(node.expression, Diagnostics._0_is_a_get_accessor_did_you_mean_to_use_it_without, getTextOfNode(node.expression))); } } - invocationError(node.expression, apparentType, SignatureKind.Call, relatedInformation); + else if (node.arguments.length === 1) { + const text = getSourceFileOfNode(node).text; + if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) { + relatedInformation.push(createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon)); + } + } + invocationError(node.expression, apparentType, SignatureKind.Call, ...relatedInformation); } return resolveErrorCall(node); } @@ -26126,7 +26133,7 @@ namespace ts { relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined, }; } - function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) { + function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, ...relatedInformation: DiagnosticRelatedInformation[]) { const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind); const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain); if (relatedInfo) { @@ -26138,7 +26145,7 @@ namespace ts { diagnostic.length = length; } diagnostics.add(diagnostic); - invocationErrorRecovery(apparentType, kind, relatedInformation ? addRelatedInfo(diagnostic, relatedInformation) : diagnostic); + invocationErrorRecovery(apparentType, kind, addRelatedInfo(diagnostic, ...relatedInformation)); } function invocationErrorRecovery(apparentType: Type, kind: SignatureKind, diagnostic: Diagnostic) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 29bf61b2f75..9046f05de63 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4384,6 +4384,10 @@ "category": "Error", "code": 6231 }, + "'{0}' is a 'get' accessor; did you mean to use it without '()'?": { + "category": "Message", + "code": 6232 + }, "Projects to reference": { "category": "Message", diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt new file mode 100644 index 00000000000..f2bf6b4cf18 --- /dev/null +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: This expression is not callable. + Type 'Number' has no call signatures. + + +==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ==== + // https://github.com/microsoft/TypeScript/issues/24554 + class Test24554 { + get property(): number { return 1; } + } + function test24554(x: Test24554) { + return x.property(); + ~~~~~~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'Number' has no call signatures. +!!! related TS6232 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:6:12: 'x.property' is a 'get' accessor; did you mean to use it without '()'? + } + \ No newline at end of file diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.js b/tests/baselines/reference/accessorAccidentalCallDiagnostic.js new file mode 100644 index 00000000000..6d5ae04ad52 --- /dev/null +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.js @@ -0,0 +1,25 @@ +//// [accessorAccidentalCallDiagnostic.ts] +// https://github.com/microsoft/TypeScript/issues/24554 +class Test24554 { + get property(): number { return 1; } +} +function test24554(x: Test24554) { + return x.property(); +} + + +//// [accessorAccidentalCallDiagnostic.js] +// https://github.com/microsoft/TypeScript/issues/24554 +var Test24554 = /** @class */ (function () { + function Test24554() { + } + Object.defineProperty(Test24554.prototype, "property", { + get: function () { return 1; }, + enumerable: false, + configurable: true + }); + return Test24554; +}()); +function test24554(x) { + return x.property(); +} diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.symbols b/tests/baselines/reference/accessorAccidentalCallDiagnostic.symbols new file mode 100644 index 00000000000..d60d466e4cd --- /dev/null +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts === +// https://github.com/microsoft/TypeScript/issues/24554 +class Test24554 { +>Test24554 : Symbol(Test24554, Decl(accessorAccidentalCallDiagnostic.ts, 0, 0)) + + get property(): number { return 1; } +>property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17)) +} +function test24554(x: Test24554) { +>test24554 : Symbol(test24554, Decl(accessorAccidentalCallDiagnostic.ts, 3, 1)) +>x : Symbol(x, Decl(accessorAccidentalCallDiagnostic.ts, 4, 19)) +>Test24554 : Symbol(Test24554, Decl(accessorAccidentalCallDiagnostic.ts, 0, 0)) + + return x.property(); +>x.property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17)) +>x : Symbol(x, Decl(accessorAccidentalCallDiagnostic.ts, 4, 19)) +>property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17)) +} + diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.types b/tests/baselines/reference/accessorAccidentalCallDiagnostic.types new file mode 100644 index 00000000000..17a59da43c8 --- /dev/null +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts === +// https://github.com/microsoft/TypeScript/issues/24554 +class Test24554 { +>Test24554 : Test24554 + + get property(): number { return 1; } +>property : number +>1 : 1 +} +function test24554(x: Test24554) { +>test24554 : (x: Test24554) => any +>x : Test24554 + + return x.property(); +>x.property() : any +>x.property : number +>x : Test24554 +>property : number +} + diff --git a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt index 3b39bdc8e78..33d34d8db6e 100644 --- a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt +++ b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt @@ -35,6 +35,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn ~ !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'Number' has no call signatures. +!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:19:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'? } @@ -64,4 +65,5 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn ~ !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'String' has no call signatures. +!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:41:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'? } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertyInClassType.errors.txt b/tests/baselines/reference/instancePropertyInClassType.errors.txt index aa5f4eaa8d6..c09527fd123 100644 --- a/tests/baselines/reference/instancePropertyInClassType.errors.txt +++ b/tests/baselines/reference/instancePropertyInClassType.errors.txt @@ -33,6 +33,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t ~ !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'Number' has no call signatures. +!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:17:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'? } @@ -60,4 +61,5 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t ~ !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'String' has no call signatures. +!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:37:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'? } \ No newline at end of file diff --git a/tests/cases/compiler/accessorAccidentalCallDiagnostic.ts b/tests/cases/compiler/accessorAccidentalCallDiagnostic.ts new file mode 100644 index 00000000000..a616fabe8ab --- /dev/null +++ b/tests/cases/compiler/accessorAccidentalCallDiagnostic.ts @@ -0,0 +1,9 @@ +// @target: es5 + +// https://github.com/microsoft/TypeScript/issues/24554 +class Test24554 { + get property(): number { return 1; } +} +function test24554(x: Test24554) { + return x.property(); +} From d00a5c954f3a032226a7249e3e97f93bc9060986 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Sat, 11 Apr 2020 15:52:03 -0700 Subject: [PATCH 02/11] Add _0_is_declared_here pointing to accessor declaration --- src/compiler/checker.ts | 5 ++++- .../reference/accessorAccidentalCallDiagnostic.errors.txt | 1 + .../instancePropertiesInheritedIntoClassType.errors.txt | 2 ++ .../reference/instancePropertyInClassType.errors.txt | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 79a5d93f3bd..a7d623cb567 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25856,7 +25856,10 @@ namespace ts { // Diagnose get accessors incorrectly called as functions const { resolvedSymbol } = getNodeLinks(node.expression); if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) { - relatedInformation.push(createDiagnosticForNode(node.expression, Diagnostics._0_is_a_get_accessor_did_you_mean_to_use_it_without, getTextOfNode(node.expression))); + relatedInformation.push( + createDiagnosticForNode(node.expression, Diagnostics._0_is_a_get_accessor_did_you_mean_to_use_it_without, getTextOfNode(node.expression)), + createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol)) + ); } } else if (node.arguments.length === 1) { diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt index f2bf6b4cf18..50faf9dc98d 100644 --- a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt @@ -13,5 +13,6 @@ tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: Th !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'Number' has no call signatures. !!! related TS6232 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:6:12: 'x.property' is a 'get' accessor; did you mean to use it without '()'? +!!! related TS2728 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:3:9: 'property' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt index 33d34d8db6e..87a2ec97a4f 100644 --- a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt +++ b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt @@ -36,6 +36,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'Number' has no call signatures. !!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:19:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'? +!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:4:13: 'y' is declared here. } @@ -66,4 +67,5 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'String' has no call signatures. !!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:41:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'? +!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:26:13: 'y' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertyInClassType.errors.txt b/tests/baselines/reference/instancePropertyInClassType.errors.txt index c09527fd123..f4bdd129256 100644 --- a/tests/baselines/reference/instancePropertyInClassType.errors.txt +++ b/tests/baselines/reference/instancePropertyInClassType.errors.txt @@ -34,6 +34,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'Number' has no call signatures. !!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:17:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'? +!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:4:13: 'y' is declared here. } @@ -62,4 +63,5 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t !!! error TS2349: This expression is not callable. !!! error TS2349: Type 'String' has no call signatures. !!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:37:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'? +!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:24:13: 'y' is declared here. } \ No newline at end of file From d00f2b53adb1dafbba33ac07227b21a62d4acb53 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Sat, 18 Apr 2020 21:23:31 -0700 Subject: [PATCH 03/11] replace the original not-callable error --- src/compiler/checker.ts | 41 ++++++++++--------- src/compiler/diagnosticMessages.json | 4 +- ...ccessorAccidentalCallDiagnostic.errors.txt | 7 +--- ...ropertiesInheritedIntoClassType.errors.txt | 14 ++----- .../instancePropertyInClassType.errors.txt | 14 ++----- 5 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a7d623cb567..543188c6f85 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25851,24 +25851,14 @@ namespace ts { error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType)); } else { - const relatedInformation: DiagnosticRelatedInformation[] = []; - if (node.arguments.length === 0) { - // Diagnose get accessors incorrectly called as functions - const { resolvedSymbol } = getNodeLinks(node.expression); - if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) { - relatedInformation.push( - createDiagnosticForNode(node.expression, Diagnostics._0_is_a_get_accessor_did_you_mean_to_use_it_without, getTextOfNode(node.expression)), - createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol)) - ); - } - } - else if (node.arguments.length === 1) { + let relatedInformation: DiagnosticRelatedInformation | undefined; + if (node.arguments.length === 1) { const text = getSourceFileOfNode(node).text; if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) { - relatedInformation.push(createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon)); + relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon); } } - invocationError(node.expression, apparentType, SignatureKind.Call, ...relatedInformation); + invocationError(node.expression, apparentType, SignatureKind.Call, relatedInformation); } return resolveErrorCall(node); } @@ -26136,11 +26126,22 @@ namespace ts { 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 diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain); - if (relatedInfo) { - addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo)); + function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) { + let diagnostic; + if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) { + // Diagnose get accessors incorrectly called as functions + const { resolvedSymbol } = getNodeLinks(errorTarget); + if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) { + diagnostic = createDiagnosticForNode(errorTarget, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without); + addRelatedInfo(diagnostic, createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol))); + } + } + if (!diagnostic) { + const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind); + diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain); + if (relatedInfo) { + addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo)); + } } if (isCallExpression(errorTarget.parent)) { const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true); @@ -26148,7 +26149,7 @@ namespace ts { diagnostic.length = length; } diagnostics.add(diagnostic); - invocationErrorRecovery(apparentType, kind, addRelatedInfo(diagnostic, ...relatedInformation)); + invocationErrorRecovery(apparentType, kind, relatedInformation ? addRelatedInfo(diagnostic, relatedInformation) : diagnostic); } function invocationErrorRecovery(apparentType: Type, kind: SignatureKind, diagnostic: Diagnostic) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9046f05de63..9c1fa1adfa2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4384,7 +4384,7 @@ "category": "Error", "code": 6231 }, - "'{0}' is a 'get' accessor; did you mean to use it without '()'?": { + "This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?": { "category": "Message", "code": 6232 }, @@ -5645,7 +5645,7 @@ "category": "Message", "code": 95116 }, - + "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", "code": 18004 diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt index 50faf9dc98d..f5e0afe4bdc 100644 --- a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt @@ -1,5 +1,4 @@ -tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: This expression is not callable. - Type 'Number' has no call signatures. +tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? ==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ==== @@ -10,9 +9,7 @@ tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: Th function test24554(x: Test24554) { return x.property(); ~~~~~~~~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Type 'Number' has no call signatures. -!!! related TS6232 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:6:12: 'x.property' is a 'get' accessor; did you mean to use it without '()'? +!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? !!! related TS2728 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:3:9: 'property' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt index 87a2ec97a4f..31190afaf04 100644 --- a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt +++ b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt @@ -1,11 +1,9 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): error TS2349: This expression is not callable. - Type 'Number' has no call signatures. +tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(26,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(29,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): error TS2349: This expression is not callable. - Type 'String' has no call signatures. +tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? ==== tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts (6 errors) ==== @@ -33,9 +31,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = 4; var r6 = d.y(); // error ~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Type 'Number' has no call signatures. -!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:19:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'? +!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? !!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:4:13: 'y' is declared here. } @@ -64,8 +60,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = ''; var r6 = d.y(); // error ~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Type 'String' has no call signatures. -!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:41:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'? +!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? !!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:26:13: 'y' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertyInClassType.errors.txt b/tests/baselines/reference/instancePropertyInClassType.errors.txt index f4bdd129256..62241900abd 100644 --- a/tests/baselines/reference/instancePropertyInClassType.errors.txt +++ b/tests/baselines/reference/instancePropertyInClassType.errors.txt @@ -1,11 +1,9 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): error TS2349: This expression is not callable. - Type 'Number' has no call signatures. +tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(24,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(27,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): error TS2349: This expression is not callable. - Type 'String' has no call signatures. +tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? ==== tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts (6 errors) ==== @@ -31,9 +29,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = 4; var r6 = c.y(); // error ~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Type 'Number' has no call signatures. -!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:17:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'? +!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? !!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:4:13: 'y' is declared here. } @@ -60,8 +56,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = ''; var r6 = c.y(); // error ~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Type 'String' has no call signatures. -!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:37:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'? +!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? !!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:24:13: 'y' is declared here. } \ No newline at end of file From 6051fc1814e9344c5c0f35eec9bac325822ea23a Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Wed, 29 Apr 2020 22:58:18 -0700 Subject: [PATCH 04/11] move to invocationErrorDetails --- src/compiler/checker.ts | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 543188c6f85..90f31841ab5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26049,7 +26049,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); @@ -26118,6 +26118,15 @@ namespace ts { typeToString(apparentType) ); } + + // 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) { + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without); + } + } + return { messageChain: chainDiagnosticMessages( errorInfo, @@ -26127,21 +26136,10 @@ namespace ts { }; } function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) { - let diagnostic; - if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) { - // Diagnose get accessors incorrectly called as functions - const { resolvedSymbol } = getNodeLinks(errorTarget); - if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) { - diagnostic = createDiagnosticForNode(errorTarget, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without); - addRelatedInfo(diagnostic, createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol))); - } - } - if (!diagnostic) { - const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind); - diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain); - if (relatedInfo) { - addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo)); - } + const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(errorTarget, apparentType, kind); + const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain); + if (relatedInfo) { + addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo)); } if (isCallExpression(errorTarget.parent)) { const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true); @@ -26242,7 +26240,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) { From 0b1cb745301e2582d6ba18fd3817d40f6d4b13a4 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Wed, 29 Apr 2020 23:04:24 -0700 Subject: [PATCH 05/11] fix order and tests --- src/compiler/checker.ts | 9 ++++----- .../accessorAccidentalCallDiagnostic.errors.txt | 7 ++++--- ...ancePropertiesInheritedIntoClassType.errors.txt | 14 ++++++++------ .../instancePropertyInClassType.errors.txt | 14 ++++++++------ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 897654e3363..191764c92a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26324,19 +26324,18 @@ namespace ts { ); } + 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) { - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without); + 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, }; } diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt index f5e0afe4bdc..0b3e5df31ad 100644 --- a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt @@ -1,4 +1,5 @@ -tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'Number' has no call signatures. ==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ==== @@ -9,7 +10,7 @@ tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6232: function test24554(x: Test24554) { return x.property(); ~~~~~~~~ -!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! related TS2728 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:3:9: 'property' is declared here. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'Number' has no call signatures. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt index 31190afaf04..fab7ccc6e5d 100644 --- a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt +++ b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt @@ -1,9 +1,11 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'Number' has no call signatures. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(26,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(29,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'String' has no call signatures. ==== tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts (6 errors) ==== @@ -31,8 +33,8 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = 4; var r6 = d.y(); // error ~ -!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:4:13: 'y' is declared here. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'Number' has no call signatures. } @@ -60,6 +62,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = ''; var r6 = d.y(); // error ~ -!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:26:13: 'y' is declared here. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'String' has no call signatures. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertyInClassType.errors.txt b/tests/baselines/reference/instancePropertyInClassType.errors.txt index 62241900abd..2921b375681 100644 --- a/tests/baselines/reference/instancePropertyInClassType.errors.txt +++ b/tests/baselines/reference/instancePropertyInClassType.errors.txt @@ -1,9 +1,11 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'Number' has no call signatures. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(24,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(27,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'String' has no call signatures. ==== tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts (6 errors) ==== @@ -29,8 +31,8 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = 4; var r6 = c.y(); // error ~ -!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:4:13: 'y' is declared here. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'Number' has no call signatures. } @@ -56,6 +58,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = ''; var r6 = c.y(); // error ~ -!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:24:13: 'y' is declared here. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'String' has no call signatures. } \ No newline at end of file From 84f89f8702cc4472b949eb980db23fef564936a6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 8 May 2020 12:26:50 -0400 Subject: [PATCH 06/11] Fix some JSDoc factory function return types. --- src/compiler/factoryPublic.ts | 10 +++++----- tests/baselines/reference/api/tsserverlibrary.d.ts | 10 +++++----- tests/baselines/reference/api/typescript.d.ts | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/compiler/factoryPublic.ts b/src/compiler/factoryPublic.ts index ac1dcbb0435..38bca657c66 100644 --- a/src/compiler/factoryPublic.ts +++ b/src/compiler/factoryPublic.ts @@ -2592,23 +2592,23 @@ namespace ts { } export function createJSDocAuthorTag(comment?: string) { - return createJSDocTag(SyntaxKind.JSDocAuthorTag, "author", comment); + return createJSDocTag(SyntaxKind.JSDocAuthorTag, "author", comment); } export function createJSDocPublicTag() { - return createJSDocTag(SyntaxKind.JSDocPublicTag, "public"); + return createJSDocTag(SyntaxKind.JSDocPublicTag, "public"); } export function createJSDocPrivateTag() { - return createJSDocTag(SyntaxKind.JSDocPrivateTag, "private"); + return createJSDocTag(SyntaxKind.JSDocPrivateTag, "private"); } export function createJSDocProtectedTag() { - return createJSDocTag(SyntaxKind.JSDocProtectedTag, "protected"); + return createJSDocTag(SyntaxKind.JSDocProtectedTag, "protected"); } export function createJSDocReadonlyTag() { - return createJSDocTag(SyntaxKind.JSDocReadonlyTag, "readonly"); + return createJSDocTag(SyntaxKind.JSDocReadonlyTag, "readonly"); } export function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc) { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index cd164686ae2..32bb724d735 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4268,11 +4268,11 @@ declare namespace ts { function createJSDocParameterTag(typeExpression: JSDocTypeExpression | undefined, name: EntityName, isNameFirst: boolean, isBracketed: boolean, comment?: string): JSDocParameterTag; function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral; function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag; - function createJSDocAuthorTag(comment?: string): JSDocTag; - function createJSDocPublicTag(): JSDocTag; - function createJSDocPrivateTag(): JSDocTag; - function createJSDocProtectedTag(): JSDocTag; - function createJSDocReadonlyTag(): JSDocTag; + function createJSDocAuthorTag(comment?: string): JSDocAuthorTag; + function createJSDocPublicTag(): JSDocPublicTag; + function createJSDocPrivateTag(): JSDocPrivateTag; + function createJSDocProtectedTag(): JSDocProtectedTag; + function createJSDocReadonlyTag(): JSDocReadonlyTag; function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc): JSDocContainer; function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement; function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f1a808da728..f17543b362c 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4268,11 +4268,11 @@ declare namespace ts { function createJSDocParameterTag(typeExpression: JSDocTypeExpression | undefined, name: EntityName, isNameFirst: boolean, isBracketed: boolean, comment?: string): JSDocParameterTag; function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral; function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag; - function createJSDocAuthorTag(comment?: string): JSDocTag; - function createJSDocPublicTag(): JSDocTag; - function createJSDocPrivateTag(): JSDocTag; - function createJSDocProtectedTag(): JSDocTag; - function createJSDocReadonlyTag(): JSDocTag; + function createJSDocAuthorTag(comment?: string): JSDocAuthorTag; + function createJSDocPublicTag(): JSDocPublicTag; + function createJSDocPrivateTag(): JSDocPrivateTag; + function createJSDocProtectedTag(): JSDocProtectedTag; + function createJSDocReadonlyTag(): JSDocReadonlyTag; function appendJSDocToContainer(node: JSDocContainer, jsdoc: JSDoc): JSDocContainer; function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement; function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement; From df772327fe2f9089bcc534eccbf36026b69db03d Mon Sep 17 00:00:00 2001 From: Song Gao Date: Tue, 12 May 2020 16:55:36 +0800 Subject: [PATCH 07/11] make last para of Actomics.notify optional. --- src/lib/es2017.sharedmemory.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/es2017.sharedmemory.d.ts b/src/lib/es2017.sharedmemory.d.ts index 1d052d6a988..441e1ab55e2 100644 --- a/src/lib/es2017.sharedmemory.d.ts +++ b/src/lib/es2017.sharedmemory.d.ts @@ -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, From e04ab6938a9ad017f9c71e40553455a440e1a5b3 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Sat, 16 May 2020 11:56:07 +0300 Subject: [PATCH 08/11] fix(38295): handle duplicate object literal keys which contain '+' and '-' tokens --- src/compiler/utilities.ts | 6 + ...ectLiteralProperty_computedName.errors.txt | 56 ++++++++++ ...icateObjectLiteralProperty_computedName.js | 81 ++++++++++++++ ...ObjectLiteralProperty_computedName.symbols | 74 +++++++++++++ ...teObjectLiteralProperty_computedName.types | 103 ++++++++++++++++++ ...icateObjectLiteralProperty_computedName.ts | 34 ++++++ 6 files changed, 354 insertions(+) create mode 100644 tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt create mode 100644 tests/baselines/reference/duplicateObjectLiteralProperty_computedName.js create mode 100644 tests/baselines/reference/duplicateObjectLiteralProperty_computedName.symbols create mode 100644 tests/baselines/reference/duplicateObjectLiteralProperty_computedName.types create mode 100644 tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 17ce0562122..06d4c902014 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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); diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt new file mode 100644 index 00000000000..84fae4c8fbe --- /dev/null +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt @@ -0,0 +1,56 @@ +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(3,5): error TS2300: Duplicate identifier '[1]'. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(8,5): error TS2300: Duplicate identifier '[+1]'. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(13,5): error TS2300: Duplicate identifier '[+1]'. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(23,5): error TS2300: Duplicate identifier '["+1"]'. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(28,5): error TS2300: Duplicate identifier '[-1]'. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(33,5): error TS2300: Duplicate identifier '["-1"]'. + + +==== tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts (6 errors) ==== + const t1 = { + 1: 1, + [1]: 0 // duplicate + ~~~ +!!! error TS2300: Duplicate identifier '[1]'. + } + + const t2 = { + 1: 1, + [+1]: 0 // duplicate + ~~~~ +!!! error TS2300: Duplicate identifier '[+1]'. + } + + const t3 = { + "1": 1, + [+1]: 0 // duplicate + ~~~~ +!!! error TS2300: Duplicate identifier '[+1]'. + } + + const t4 = { + "+1": 1, + [+1]: 0 // two different keys, "+1", "1" + } + + const t5 = { + "+1": 1, + ["+1"]: 0 // duplicate + ~~~~~~ +!!! error TS2300: Duplicate identifier '["+1"]'. + } + + const t6 = { + "-1": 1, + [-1]: 0 // duplicate + ~~~~ +!!! error TS2300: Duplicate identifier '[-1]'. + } + + const t7 = { + "-1": 1, + ["-1"]: 0 // duplicate + ~~~~~~ +!!! error TS2300: Duplicate identifier '["-1"]'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.js b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.js new file mode 100644 index 00000000000..2eedb465be5 --- /dev/null +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.js @@ -0,0 +1,81 @@ +//// [duplicateObjectLiteralProperty_computedName.ts] +const t1 = { + 1: 1, + [1]: 0 // duplicate +} + +const t2 = { + 1: 1, + [+1]: 0 // duplicate +} + +const t3 = { + "1": 1, + [+1]: 0 // duplicate +} + +const t4 = { + "+1": 1, + [+1]: 0 // two different keys, "+1", "1" +} + +const t5 = { + "+1": 1, + ["+1"]: 0 // duplicate +} + +const t6 = { + "-1": 1, + [-1]: 0 // duplicate +} + +const t7 = { + "-1": 1, + ["-1"]: 0 // duplicate +} + + +//// [duplicateObjectLiteralProperty_computedName.js] +var _a, _b, _c, _d, _e, _f, _g; +var t1 = (_a = { + 1: 1 + }, + _a[1] = 0 // duplicate +, + _a); +var t2 = (_b = { + 1: 1 + }, + _b[+1] = 0 // duplicate +, + _b); +var t3 = (_c = { + "1": 1 + }, + _c[+1] = 0 // duplicate +, + _c); +var t4 = (_d = { + "+1": 1 + }, + _d[+1] = 0 // two different keys, "+1", "1" +, + _d); +var t5 = (_e = { + "+1": 1 + }, + _e["+1"] = 0 // duplicate +, + _e); +var t6 = (_f = { + "-1": 1 + }, + _f[-1] = 0 // duplicate +, + _f); +var t7 = (_g = { + "-1": 1 + }, + _g["-1"] = 0 // duplicate +, + _g); diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.symbols b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.symbols new file mode 100644 index 00000000000..9ed2226656d --- /dev/null +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.symbols @@ -0,0 +1,74 @@ +=== tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts === +const t1 = { +>t1 : Symbol(t1, Decl(duplicateObjectLiteralProperty_computedName.ts, 0, 5)) + + 1: 1, +>1 : Symbol(1, Decl(duplicateObjectLiteralProperty_computedName.ts, 0, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 1, 9)) + + [1]: 0 // duplicate +>[1] : Symbol(1, Decl(duplicateObjectLiteralProperty_computedName.ts, 0, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 1, 9)) +>1 : Symbol(1, Decl(duplicateObjectLiteralProperty_computedName.ts, 0, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 1, 9)) +} + +const t2 = { +>t2 : Symbol(t2, Decl(duplicateObjectLiteralProperty_computedName.ts, 5, 5)) + + 1: 1, +>1 : Symbol(1, Decl(duplicateObjectLiteralProperty_computedName.ts, 5, 12)) + + [+1]: 0 // duplicate +>[+1] : Symbol([+1], Decl(duplicateObjectLiteralProperty_computedName.ts, 6, 9)) +} + +const t3 = { +>t3 : Symbol(t3, Decl(duplicateObjectLiteralProperty_computedName.ts, 10, 5)) + + "1": 1, +>"1" : Symbol("1", Decl(duplicateObjectLiteralProperty_computedName.ts, 10, 12)) + + [+1]: 0 // duplicate +>[+1] : Symbol([+1], Decl(duplicateObjectLiteralProperty_computedName.ts, 11, 11)) +} + +const t4 = { +>t4 : Symbol(t4, Decl(duplicateObjectLiteralProperty_computedName.ts, 15, 5)) + + "+1": 1, +>"+1" : Symbol("+1", Decl(duplicateObjectLiteralProperty_computedName.ts, 15, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 16, 12)) + + [+1]: 0 // two different keys, "+1", "1" +>[+1] : Symbol("+1", Decl(duplicateObjectLiteralProperty_computedName.ts, 15, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 16, 12)) +} + +const t5 = { +>t5 : Symbol(t5, Decl(duplicateObjectLiteralProperty_computedName.ts, 20, 5)) + + "+1": 1, +>"+1" : Symbol("+1", Decl(duplicateObjectLiteralProperty_computedName.ts, 20, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 21, 12)) + + ["+1"]: 0 // duplicate +>["+1"] : Symbol("+1", Decl(duplicateObjectLiteralProperty_computedName.ts, 20, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 21, 12)) +>"+1" : Symbol("+1", Decl(duplicateObjectLiteralProperty_computedName.ts, 20, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 21, 12)) +} + +const t6 = { +>t6 : Symbol(t6, Decl(duplicateObjectLiteralProperty_computedName.ts, 25, 5)) + + "-1": 1, +>"-1" : Symbol("-1", Decl(duplicateObjectLiteralProperty_computedName.ts, 25, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 26, 12)) + + [-1]: 0 // duplicate +>[-1] : Symbol("-1", Decl(duplicateObjectLiteralProperty_computedName.ts, 25, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 26, 12)) +} + +const t7 = { +>t7 : Symbol(t7, Decl(duplicateObjectLiteralProperty_computedName.ts, 30, 5)) + + "-1": 1, +>"-1" : Symbol("-1", Decl(duplicateObjectLiteralProperty_computedName.ts, 30, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 31, 12)) + + ["-1"]: 0 // duplicate +>["-1"] : Symbol("-1", Decl(duplicateObjectLiteralProperty_computedName.ts, 30, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 31, 12)) +>"-1" : Symbol("-1", Decl(duplicateObjectLiteralProperty_computedName.ts, 30, 12), Decl(duplicateObjectLiteralProperty_computedName.ts, 31, 12)) +} + diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.types b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.types new file mode 100644 index 00000000000..e597508a0c9 --- /dev/null +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.types @@ -0,0 +1,103 @@ +=== tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts === +const t1 = { +>t1 : { 1: number; } +>{ 1: 1, [1]: 0 // duplicate} : { 1: number; } + + 1: 1, +>1 : number +>1 : 1 + + [1]: 0 // duplicate +>[1] : number +>1 : 1 +>0 : 0 +} + +const t2 = { +>t2 : { 1: number; } +>{ 1: 1, [+1]: 0 // duplicate} : { 1: number; } + + 1: 1, +>1 : number +>1 : 1 + + [+1]: 0 // duplicate +>[+1] : number +>+1 : 1 +>1 : 1 +>0 : 0 +} + +const t3 = { +>t3 : { 1: number; } +>{ "1": 1, [+1]: 0 // duplicate} : { 1: number; } + + "1": 1, +>"1" : number +>1 : 1 + + [+1]: 0 // duplicate +>[+1] : number +>+1 : 1 +>1 : 1 +>0 : 0 +} + +const t4 = { +>t4 : { "+1": number; 1: number; } +>{ "+1": 1, [+1]: 0 // two different keys, "+1", "1"} : { "+1": number; 1: number; } + + "+1": 1, +>"+1" : number +>1 : 1 + + [+1]: 0 // two different keys, "+1", "1" +>[+1] : number +>+1 : 1 +>1 : 1 +>0 : 0 +} + +const t5 = { +>t5 : { "+1": number; } +>{ "+1": 1, ["+1"]: 0 // duplicate} : { "+1": number; } + + "+1": 1, +>"+1" : number +>1 : 1 + + ["+1"]: 0 // duplicate +>["+1"] : number +>"+1" : "+1" +>0 : 0 +} + +const t6 = { +>t6 : { [-1]: number; } +>{ "-1": 1, [-1]: 0 // duplicate} : { [-1]: number; } + + "-1": 1, +>"-1" : number +>1 : 1 + + [-1]: 0 // duplicate +>[-1] : number +>-1 : -1 +>1 : 1 +>0 : 0 +} + +const t7 = { +>t7 : { [-1]: number; } +>{ "-1": 1, ["-1"]: 0 // duplicate} : { [-1]: number; } + + "-1": 1, +>"-1" : number +>1 : 1 + + ["-1"]: 0 // duplicate +>["-1"] : number +>"-1" : "-1" +>0 : 0 +} + diff --git a/tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts b/tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts new file mode 100644 index 00000000000..9bc5e2e3d93 --- /dev/null +++ b/tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts @@ -0,0 +1,34 @@ +const t1 = { + 1: 1, + [1]: 0 // duplicate +} + +const t2 = { + 1: 1, + [+1]: 0 // duplicate +} + +const t3 = { + "1": 1, + [+1]: 0 // duplicate +} + +const t4 = { + "+1": 1, + [+1]: 0 // two different keys, "+1", "1" +} + +const t5 = { + "+1": 1, + ["+1"]: 0 // duplicate +} + +const t6 = { + "-1": 1, + [-1]: 0 // duplicate +} + +const t7 = { + "-1": 1, + ["-1"]: 0 // duplicate +} From a56960303d18eae609493b4225f4c7de5e87c89d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 20 May 2020 10:56:14 -0700 Subject: [PATCH 09/11] Intersection check for empty object type shouldn't cause circularities (#38673) * isEmptyAnonymousObjectType shouldn't require full member resolution * Add regression test --- src/compiler/checker.ts | 4 +++- .../reference/intersectionsAndEmptyObjects.js | 5 +++++ .../reference/intersectionsAndEmptyObjects.symbols | 14 ++++++++++++++ .../reference/intersectionsAndEmptyObjects.types | 11 +++++++++++ .../intersection/intersectionsAndEmptyObjects.ts | 5 +++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bd58c379ea..e333b031c6d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15367,7 +15367,9 @@ namespace ts { } function isEmptyAnonymousObjectType(type: Type) { - return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type); + return !!(getObjectFlags(type) & ObjectFlags.Anonymous && ( + (type).members && isEmptyResolvedType(type) || + type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral && getMembersOfSymbol(type.symbol).size === 0)); } function isStringIndexSignatureOnlyType(type: Type): boolean { diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.js b/tests/baselines/reference/intersectionsAndEmptyObjects.js index 4c4161e9544..4ff24248f46 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.js +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.js @@ -75,6 +75,11 @@ var myChoicesAndEmpty: choices; var unknownChoices: choices; var unknownChoicesAndEmpty: choices; + +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +type Foo2 = { x: string } & { [K in number]: Foo2 }; //// [intersectionsAndEmptyObjects.js] diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.symbols b/tests/baselines/reference/intersectionsAndEmptyObjects.symbols index 50fb6f866e7..39131564a59 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.symbols +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.symbols @@ -246,3 +246,17 @@ var unknownChoicesAndEmpty: choices; >choices : Symbol(choices, Decl(intersectionsAndEmptyObjects.ts, 51, 19)) >IUnknownChoiceList : Symbol(IUnknownChoiceList, Decl(intersectionsAndEmptyObjects.ts, 64, 2)) +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +>Foo1 : Symbol(Foo1, Decl(intersectionsAndEmptyObjects.ts, 75, 61)) +>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 79, 13)) +>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 79, 31)) +>Foo1 : Symbol(Foo1, Decl(intersectionsAndEmptyObjects.ts, 75, 61)) + +type Foo2 = { x: string } & { [K in number]: Foo2 }; +>Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50)) +>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 80, 13)) +>K : Symbol(K, Decl(intersectionsAndEmptyObjects.ts, 80, 31)) +>Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50)) + diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.types b/tests/baselines/reference/intersectionsAndEmptyObjects.types index 1dcc904a435..889ee33d378 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.types +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.types @@ -206,3 +206,14 @@ var unknownChoices: choices; var unknownChoicesAndEmpty: choices; >unknownChoicesAndEmpty : { shoes: boolean; food: boolean; } +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +>Foo1 : Foo1 +>x : string +>x : number + +type Foo2 = { x: string } & { [K in number]: Foo2 }; +>Foo2 : Foo2 +>x : string + diff --git a/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts b/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts index 2832a3f36bf..00db917b967 100644 --- a/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts +++ b/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts @@ -76,3 +76,8 @@ var myChoicesAndEmpty: choices; var unknownChoices: choices; var unknownChoicesAndEmpty: choices; + +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +type Foo2 = { x: string } & { [K in number]: Foo2 }; From 4e945fbc98451ea5e2b627c2dfff2edea1c7aacd Mon Sep 17 00:00:00 2001 From: Alexander T Date: Wed, 20 May 2020 23:52:52 +0300 Subject: [PATCH 10/11] fix(38299): use string literals as keys to creating rest result (#38600) --- src/compiler/emitter.ts | 9 +++++---- .../restElementWithNumberPropertyName.js | 17 +++++++++++++++++ .../restElementWithNumberPropertyName.symbols | 5 +++++ .../restElementWithNumberPropertyName.types | 9 +++++++++ .../restParameterWithBindingPattern3.js | 2 +- .../restElementWithNumberPropertyName.ts | 2 ++ 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/restElementWithNumberPropertyName.js create mode 100644 tests/baselines/reference/restElementWithNumberPropertyName.symbols create mode 100644 tests/baselines/reference/restElementWithNumberPropertyName.types create mode 100644 tests/cases/compiler/restElementWithNumberPropertyName.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b2325d2e3e6..10b6f7b786d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4499,10 +4499,11 @@ namespace ts { function getLiteralTextOfNode(node: LiteralLikeNode, neverAsciiEscape: boolean | undefined, jsxAttributeEscape: boolean): string { if (node.kind === SyntaxKind.StringLiteral && (node).textSourceNode) { const textSourceNode = (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); diff --git a/tests/baselines/reference/restElementWithNumberPropertyName.js b/tests/baselines/reference/restElementWithNumberPropertyName.js new file mode 100644 index 00000000000..d0829998eb9 --- /dev/null +++ b/tests/baselines/reference/restElementWithNumberPropertyName.js @@ -0,0 +1,17 @@ +//// [restElementWithNumberPropertyName.ts] +const { 0: a, ...b } = [0, 1, 2]; + + +//// [restElementWithNumberPropertyName.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a = [0, 1, 2], a = _a[0], b = __rest(_a, ["0"]); diff --git a/tests/baselines/reference/restElementWithNumberPropertyName.symbols b/tests/baselines/reference/restElementWithNumberPropertyName.symbols new file mode 100644 index 00000000000..da804ef7014 --- /dev/null +++ b/tests/baselines/reference/restElementWithNumberPropertyName.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/restElementWithNumberPropertyName.ts === +const { 0: a, ...b } = [0, 1, 2]; +>a : Symbol(a, Decl(restElementWithNumberPropertyName.ts, 0, 7)) +>b : Symbol(b, Decl(restElementWithNumberPropertyName.ts, 0, 13)) + diff --git a/tests/baselines/reference/restElementWithNumberPropertyName.types b/tests/baselines/reference/restElementWithNumberPropertyName.types new file mode 100644 index 00000000000..a39a1ac5c24 --- /dev/null +++ b/tests/baselines/reference/restElementWithNumberPropertyName.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/restElementWithNumberPropertyName.ts === +const { 0: a, ...b } = [0, 1, 2]; +>a : number +>b : { [n: number]: number; 0: number; 1: number; 2: number; length: 3; toString(): string; toLocaleString(): string; pop(): number; push(...items: number[]): number; concat(...items: ConcatArray[]): number[]; concat(...items: (number | ConcatArray)[]): number[]; join(separator?: string): string; reverse(): number[]; shift(): number; slice(start?: number, end?: number): number[]; sort(compareFn?: (a: number, b: number) => number): [number, number, number]; splice(start: number, deleteCount?: number): number[]; splice(start: number, deleteCount: number, ...items: number[]): number[]; unshift(...items: number[]): number; indexOf(searchElement: number, fromIndex?: number): number; lastIndexOf(searchElement: number, fromIndex?: number): number; every(callbackfn: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: number, index: number, array: number[]) => void, thisArg?: any): void; map(callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: number, index: number, array: number[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: number, index: number, array: number[]) => unknown, thisArg?: any): number[]; reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>[0, 1, 2] : [number, number, number] +>0 : 0 +>1 : 1 +>2 : 2 + diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.js b/tests/baselines/reference/restParameterWithBindingPattern3.js index 9f52594f7cb..3894d0f3400 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.js +++ b/tests/baselines/reference/restParameterWithBindingPattern3.js @@ -54,5 +54,5 @@ function e() { for (var _i = 0; _i < arguments.length; _i++) { _a[_i] = arguments[_i]; } - var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c, rest = __rest(_a, [0, 1]); + var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c, rest = __rest(_a, ["0", "1"]); } diff --git a/tests/cases/compiler/restElementWithNumberPropertyName.ts b/tests/cases/compiler/restElementWithNumberPropertyName.ts new file mode 100644 index 00000000000..778a968c54f --- /dev/null +++ b/tests/cases/compiler/restElementWithNumberPropertyName.ts @@ -0,0 +1,2 @@ +// @target: es5 +const { 0: a, ...b } = [0, 1, 2]; From 0b531720d48e3ae67a3bda8d4c363324c2f6ac93 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 20 May 2020 16:53:17 -0700 Subject: [PATCH 11/11] Make new error an error, not message --- src/compiler/diagnosticMessages.json | 2 +- .../accessorAccidentalCallDiagnostic.errors.txt | 6 +++--- ...stancePropertiesInheritedIntoClassType.errors.txt | 12 ++++++------ .../reference/instancePropertyInClassType.errors.txt | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 362fb805a0e..ef46447faac 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4417,7 +4417,7 @@ "code": 6233 }, "This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?": { - "category": "Message", + "category": "Error", "code": 6234 }, diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt index 0b3e5df31ad..ee57be17427 100644 --- a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +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 '()'? Type 'Number' has no call signatures. @@ -10,7 +10,7 @@ tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6234: function test24554(x: Test24554) { return x.property(); ~~~~~~~~ -!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! message TS6234: Type 'Number' has no call signatures. +!!! error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! error TS6234: Type 'Number' has no call signatures. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt index fab7ccc6e5d..e7584c3d831 100644 --- a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt +++ b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt @@ -1,10 +1,10 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? Type 'Number' has no call signatures. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(26,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(29,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? Type 'String' has no call signatures. @@ -33,8 +33,8 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = 4; var r6 = d.y(); // error ~ -!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! message TS6234: Type 'Number' has no call signatures. +!!! error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! error TS6234: Type 'Number' has no call signatures. } @@ -62,6 +62,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = ''; var r6 = d.y(); // error ~ -!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! message TS6234: Type 'String' has no call signatures. +!!! error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! error TS6234: Type 'String' has no call signatures. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertyInClassType.errors.txt b/tests/baselines/reference/instancePropertyInClassType.errors.txt index 2921b375681..224290a4c00 100644 --- a/tests/baselines/reference/instancePropertyInClassType.errors.txt +++ b/tests/baselines/reference/instancePropertyInClassType.errors.txt @@ -1,10 +1,10 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? Type 'Number' has no call signatures. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(24,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(27,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? Type 'String' has no call signatures. @@ -31,8 +31,8 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = 4; var r6 = c.y(); // error ~ -!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! message TS6234: Type 'Number' has no call signatures. +!!! error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! error TS6234: Type 'Number' has no call signatures. } @@ -58,6 +58,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = ''; var r6 = c.y(); // error ~ -!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? -!!! message TS6234: Type 'String' has no call signatures. +!!! error TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! error TS6234: Type 'String' has no call signatures. } \ No newline at end of file