diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2dd567cbe90..8a81ac167b0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7095,7 +7095,7 @@ namespace ts { if (container.parent.kind === SyntaxKind.ObjectLiteralExpression) { if (languageVersion < ScriptTarget.ES6) { - error(node, Diagnostics.super_in_members_of_object_literal_expressions_is_only_allowed_when_option_target_is_ES2015_or_higher); + error(node, Diagnostics.super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher); return unknownType; } else { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 30b46e5cde2..34552a26b20 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1759,7 +1759,7 @@ "category": "Error", "code": 2658 }, - "'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.": { + "'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.": { "category": "Error", "code": 2659 }, diff --git a/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt b/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt index 944766cb5ae..a3149ce8cd5 100644 --- a/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt +++ b/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/superInObjectLiterals_ES5.ts(7,9): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. -tests/cases/compiler/superInObjectLiterals_ES5.ts(10,9): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. -tests/cases/compiler/superInObjectLiterals_ES5.ts(14,9): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(7,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(10,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(14,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. tests/cases/compiler/superInObjectLiterals_ES5.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superInObjectLiterals_ES5.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superInObjectLiterals_ES5.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. -tests/cases/compiler/superInObjectLiterals_ES5.ts(39,17): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. -tests/cases/compiler/superInObjectLiterals_ES5.ts(42,17): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. -tests/cases/compiler/superInObjectLiterals_ES5.ts(46,17): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(39,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(42,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(46,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. tests/cases/compiler/superInObjectLiterals_ES5.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superInObjectLiterals_ES5.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. @@ -20,18 +20,18 @@ tests/cases/compiler/superInObjectLiterals_ES5.ts(52,17): error TS2660: 'super' method() { super.method(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, get prop() { super.method(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. return 10; }, set prop(value) { super.method(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, p1: function () { super.method(); @@ -64,18 +64,18 @@ tests/cases/compiler/superInObjectLiterals_ES5.ts(52,17): error TS2660: 'super' method() { super.method(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, get prop() { super.method(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. return 10; }, set prop(value) { super.method(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, p1: function () { super.method(); diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt index 16a66bf6fa4..5fe7fa59ff6 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt @@ -1,10 +1,10 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(20,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. ==== tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts (7 errors) ==== @@ -16,14 +16,14 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return super._foo; ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, set foo(value: string) { ~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super._foo = value; ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, test: function () { return super._foo; @@ -42,7 +42,7 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return super.test(); ~~~~~ -!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. } }; } diff --git a/tests/cases/fourslash/getOccurrencesSuper3.ts b/tests/cases/fourslash/getOccurrencesSuper3.ts new file mode 100644 index 00000000000..bceac02a392 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesSuper3.ts @@ -0,0 +1,34 @@ +/// + +////let x = { +//// a() { +//// return [|s/**/uper|].b(); +//// }, +//// b() { +//// return [|super|].a(); +//// }, +//// c: function () { +//// return [|super|].a(); +//// } +//// d: () => [|super|].b(); +////} + +function checkRange(r: FourSlashInterface.Range, expectedOccurences: FourSlashInterface.Range[]): void { + goTo.position(r.start); + if (expectedOccurences.length) { + for (const expected of expectedOccurences) { + verify.occurrencesAtPositionContains(expected); + } + } + else { + verify.occurrencesAtPositionCount(0); + } +} + +let [r0, r1, r2, r3] = test.ranges(); + +checkRange(r0, [r0, r1]); +checkRange(r1, [r0, r1]); +checkRange(r0, [r0, r1]); +checkRange(r2, []); +checkRange(r3, []); \ No newline at end of file