From fc5b2e524de5e6118970ab8b0f7eb4e1dfb2445f Mon Sep 17 00:00:00 2001 From: about-code Date: Sun, 16 Oct 2016 18:34:57 +0200 Subject: [PATCH 01/11] Fix for issue #442 --- .../staticPropertyNameConflictsEs5.ts | 26 +++++++++++++++++++ .../staticPropertyNameConflictsEs6.ts | 25 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts new file mode 100644 index 00000000000..0f260673d9d --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts @@ -0,0 +1,26 @@ +// @target: es5 + +// static name +class A { + static name: number; // error + name: string; // ok +} + +class B { + static name() {} // error + name() {} // ok +} + + + +// static length... +class C { + static length: number; // error + length: string; // ok +} + +class D { + static length() {} // error + length() {} // ok +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts new file mode 100644 index 00000000000..47c7dbbde25 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts @@ -0,0 +1,25 @@ +// @target: es6 + + +// static name +class A { + static name: string; // ok + name: string; // ok +} + +class B { + static name() {}; // ok + name() {}; // ok +} + + +// static length +class C { + static length: number; // ok + length: string; // ok +} + +class D { + static length() {} // ok + length() {} // ok +} From 8a37a162b2d15fd04d3f8961269e66951bda1343 Mon Sep 17 00:00:00 2001 From: about-code Date: Sun, 16 Oct 2016 18:43:55 +0200 Subject: [PATCH 02/11] Fix for issue #442 --- src/compiler/checker.ts | 45 +++++++ src/compiler/diagnosticMessages.json | 5 +- .../propertyNamedPrototype.errors.txt | 10 ++ ...cMemberOfAnotherClassAssignment.errors.txt | 30 ++--- ...AndPublicMemberOfAnotherClassAssignment.js | 26 ++-- .../staticPropertyNameConflictsEs5.errors.txt | 92 ++++++++++++++ .../staticPropertyNameConflictsEs5.js | 120 ++++++++++++++++++ .../staticPropertyNameConflictsEs6.errors.txt | 80 ++++++++++++ .../staticPropertyNameConflictsEs6.js | 89 +++++++++++++ .../staticPrototypeProperty.errors.txt | 8 +- ...AndPublicMemberOfAnotherClassAssignment.ts | 14 +- .../staticPropertyNameConflictsEs5.ts | 42 +++++- .../staticPropertyNameConflictsEs6.ts | 49 +++++-- 13 files changed, 558 insertions(+), 52 deletions(-) create mode 100644 tests/baselines/reference/propertyNamedPrototype.errors.txt create mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt create mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs5.js create mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt create mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs6.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8568cd5feed..f4f3a77e9be 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13922,6 +13922,50 @@ namespace ts { } } + // Static members may conflict with non-configurable non-writable built-in Function.prototype properties + // see https://github.com/microsoft/typescript/issues/442. + function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { + const es5_descriptors: PropertyDescriptorMap = { + // see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3 + // see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5 + "name": {configurable: false, writable: false}, + "length": {configurable: false, writable: false}, + "prototype": {configurable: false, writable: false}, + + // see https://github.com/microsoft/typescript/issues/442 + "caller": {configurable: false, writable: false}, + "arguments": {configurable: false, writable: false} + }; + const post_es5_descriptors: PropertyDescriptorMap = { + // see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor + // see http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances + "name": {configurable: true, writable: false}, + "length": {configurable: true, writable: false}, + "prototype": {configurable: false, writable: false}, + "caller": {configurable: false, writable: false}, + "arguments": {configurable: false, writable: false} + }; + const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1; + const className = getSymbolOfNode(node).name; + + for (let member of node.members) { + let isStatic = forEach(member.modifiers, (m:Modifier) => m.kind === SyntaxKind.StaticKeyword); + if (isStatic) { + let memberNameNode = member.name; + let memberName = getPropertyNameForPropertyNameNode(memberNameNode); + let descriptor: PropertyDescriptor = null; + if (languageVersion <= ScriptTarget.ES5) { + descriptor = es5_descriptors.hasOwnProperty(memberName) ? es5_descriptors[memberName] : null; + } else if (languageVersion > ScriptTarget.ES5) { + descriptor = post_es5_descriptors.hasOwnProperty(memberName) ? post_es5_descriptors[memberName] : null; + } + if (descriptor && descriptor.configurable === false && descriptor.writable === false) { + error(memberNameNode, message, memberName, className); + } + } + } + } + function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) { const names = createMap(); for (const member of node.members) { @@ -16423,6 +16467,7 @@ namespace ts { const staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); checkClassForDuplicateDeclarations(node); + checkClassForStaticPropertyNameConflicts(node); const baseTypeNode = getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6210a20afa6..6b0a6d6dfb7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1955,6 +1955,10 @@ "category": "Error", "code": 2691 }, + "Static property '{0}' conflicts with built-in property 'Function.{0}' of constructor function '{1}'.": { + "category": "Error", + "code": 2692 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 @@ -2239,7 +2243,6 @@ "category": "Message", "code": 4090 }, - "The current host does not support the '{0}' option.": { "category": "Error", "code": 5001 diff --git a/tests/baselines/reference/propertyNamedPrototype.errors.txt b/tests/baselines/reference/propertyNamedPrototype.errors.txt new file mode 100644 index 00000000000..6ddd8390720 --- /dev/null +++ b/tests/baselines/reference/propertyNamedPrototype.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts(3,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts (1 errors) ==== + class C { + prototype: number; // ok + static prototype: C; // error + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. + } \ No newline at end of file diff --git a/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt b/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt index 59626540806..36ead708331 100644 --- a/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt +++ b/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt @@ -1,43 +1,43 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(12,1): error TS2322: Type 'C' is not assignable to type 'A'. - Property 'name' is missing in type 'C'. + Property 'prop' is missing in type 'C'. tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(13,1): error TS2322: Type 'typeof B' is not assignable to type 'A'. - Property 'name' is missing in type 'typeof B'. + Property 'prop' is missing in type 'typeof B'. tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(16,5): error TS2322: Type 'C' is not assignable to type 'B'. - Property 'name' is missing in type 'C'. + Property 'prop' is missing in type 'C'. tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(17,1): error TS2322: Type 'typeof B' is not assignable to type 'B'. - Property 'name' is missing in type 'typeof B'. + Property 'prop' is missing in type 'typeof B'. ==== tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts (4 errors) ==== interface A { - name(); + prop(); } class B { - public name() { } + public prop() { } } class C { - public static name() { } + public static prop() { } } var a: A = new B(); - a = new C(); // error name is missing + a = new C(); // error prop is missing ~ !!! error TS2322: Type 'C' is not assignable to type 'A'. -!!! error TS2322: Property 'name' is missing in type 'C'. - a = B; // error name is missing +!!! error TS2322: Property 'prop' is missing in type 'C'. + a = B; // error prop is missing ~ !!! error TS2322: Type 'typeof B' is not assignable to type 'A'. -!!! error TS2322: Property 'name' is missing in type 'typeof B'. +!!! error TS2322: Property 'prop' is missing in type 'typeof B'. a = C; - var b: B = new C(); // error name is missing + var b: B = new C(); // error prop is missing ~ !!! error TS2322: Type 'C' is not assignable to type 'B'. -!!! error TS2322: Property 'name' is missing in type 'C'. - b = B; // error name is missing +!!! error TS2322: Property 'prop' is missing in type 'C'. + b = B; // error prop is missing ~ !!! error TS2322: Type 'typeof B' is not assignable to type 'B'. -!!! error TS2322: Property 'name' is missing in type 'typeof B'. +!!! error TS2322: Property 'prop' is missing in type 'typeof B'. b = C; b = a; diff --git a/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.js b/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.js index 1b98daa226d..00de82a4f6d 100644 --- a/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.js +++ b/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.js @@ -1,21 +1,21 @@ //// [staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts] interface A { - name(); + prop(); } class B { - public name() { } + public prop() { } } class C { - public static name() { } + public static prop() { } } var a: A = new B(); -a = new C(); // error name is missing -a = B; // error name is missing +a = new C(); // error prop is missing +a = B; // error prop is missing a = C; -var b: B = new C(); // error name is missing -b = B; // error name is missing +var b: B = new C(); // error prop is missing +b = B; // error prop is missing b = C; b = a; @@ -29,21 +29,21 @@ c = a; var B = (function () { function B() { } - B.prototype.name = function () { }; + B.prototype.prop = function () { }; return B; }()); var C = (function () { function C() { } - C.name = function () { }; + C.prop = function () { }; return C; }()); var a = new B(); -a = new C(); // error name is missing -a = B; // error name is missing +a = new C(); // error prop is missing +a = B; // error prop is missing a = C; -var b = new C(); // error name is missing -b = B; // error name is missing +var b = new C(); // error prop is missing +b = B; // error prop is missing b = C; b = a; var c = new B(); diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt new file mode 100644 index 00000000000..182b1628522 --- /dev/null +++ b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt @@ -0,0 +1,92 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(4,12): error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(9,12): error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(15,12): error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(20,12): error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(26,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2300: Duplicate identifier 'prototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(37,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(42,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(48,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(53,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts (11 errors) ==== + + // static name + class StaticName { + static name: number; // error + ~~~~ +!!! error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. + name: string; // ok + } + + class StaticNameFn { + static name() {} // error + ~~~~ +!!! error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. + name() {} // ok + } + + + class StaticLength { + static length: number; // error + ~~~~~~ +!!! error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. + length: string; // ok + } + + class StaticLengthFn { + static length() {} // error + ~~~~~~ +!!! error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. + length() {} // ok + } + + + class StaticPrototype { + static prototype: number; // error + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. + prototype: string; // ok + } + + class StaticPrototypeFn { + static prototype() {} // error + ~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'prototype'. + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. + prototype() {} // ok + } + + + class StaticCaller { + static caller: number; // error + ~~~~~~ +!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. + caller: string; // ok + } + + class StaticCallerFn { + static caller() {} // error + ~~~~~~ +!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. + caller() {} // ok + } + + + class StaticArguments { + static arguments: number; // error + ~~~~~~~~~ +!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. + arguments: string; // ok + } + + class StaticArgumentsFn { + static arguments() {} // error + ~~~~~~~~~ +!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + arguments() {} // ok + } + \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs5.js b/tests/baselines/reference/staticPropertyNameConflictsEs5.js new file mode 100644 index 00000000000..06d4a011a8e --- /dev/null +++ b/tests/baselines/reference/staticPropertyNameConflictsEs5.js @@ -0,0 +1,120 @@ +//// [staticPropertyNameConflictsEs5.ts] + +// static name +class StaticName { + static name: number; // error + name: string; // ok +} + +class StaticNameFn { + static name() {} // error + name() {} // ok +} + + +class StaticLength { + static length: number; // error + length: string; // ok +} + +class StaticLengthFn { + static length() {} // error + length() {} // ok +} + + +class StaticPrototype { + static prototype: number; // error + prototype: string; // ok +} + +class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok +} + + +class StaticCaller { + static caller: number; // error + caller: string; // ok +} + +class StaticCallerFn { + static caller() {} // error + caller() {} // ok +} + + +class StaticArguments { + static arguments: number; // error + arguments: string; // ok +} + +class StaticArgumentsFn { + static arguments() {} // error + arguments() {} // ok +} + + +//// [staticPropertyNameConflictsEs5.js] +// static name +var StaticName = (function () { + function StaticName() { + } + return StaticName; +}()); +var StaticNameFn = (function () { + function StaticNameFn() { + } + StaticNameFn.name = function () { }; // error + StaticNameFn.prototype.name = function () { }; // ok + return StaticNameFn; +}()); +var StaticLength = (function () { + function StaticLength() { + } + return StaticLength; +}()); +var StaticLengthFn = (function () { + function StaticLengthFn() { + } + StaticLengthFn.length = function () { }; // error + StaticLengthFn.prototype.length = function () { }; // ok + return StaticLengthFn; +}()); +var StaticPrototype = (function () { + function StaticPrototype() { + } + return StaticPrototype; +}()); +var StaticPrototypeFn = (function () { + function StaticPrototypeFn() { + } + StaticPrototypeFn.prototype = function () { }; // error + StaticPrototypeFn.prototype.prototype = function () { }; // ok + return StaticPrototypeFn; +}()); +var StaticCaller = (function () { + function StaticCaller() { + } + return StaticCaller; +}()); +var StaticCallerFn = (function () { + function StaticCallerFn() { + } + StaticCallerFn.caller = function () { }; // error + StaticCallerFn.prototype.caller = function () { }; // ok + return StaticCallerFn; +}()); +var StaticArguments = (function () { + function StaticArguments() { + } + return StaticArguments; +}()); +var StaticArgumentsFn = (function () { + function StaticArgumentsFn() { + } + StaticArgumentsFn.arguments = function () { }; // error + StaticArgumentsFn.prototype.arguments = function () { }; // ok + return StaticArgumentsFn; +}()); diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt new file mode 100644 index 00000000000..b76b7e02b76 --- /dev/null +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt @@ -0,0 +1,80 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(42,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(53,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== + + + class StaticName { + static name: number; // ok + name: string; // ok + } + + class StaticNameFn { + static name() {} // ok + name() {} // ok + } + + + class StaticLength { + static length: number; // ok + length: string; // ok + } + + class StaticLengthFn { + static length() {} // ok + length() {} // ok + } + + + class StaticPrototype { + static prototype: number; // error + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. + prototype: string; // ok + } + + class StaticPrototypeFn { + static prototype() {} // error + ~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'prototype'. + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. + prototype() {} // ok + } + + + class StaticCaller { + static caller: number; // // error + ~~~~~~ +!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. + caller: string; // ok + } + + class StaticCallerFn { + static caller() {} // // error + ~~~~~~ +!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. + caller() {} // ok + } + + + class StaticArguments { + static arguments: number; // // error + ~~~~~~~~~ +!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. + arguments: string; // ok + } + + class StaticArgumentsFn { + static arguments() {} // // error + ~~~~~~~~~ +!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + arguments() {} // ok + } + \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.js b/tests/baselines/reference/staticPropertyNameConflictsEs6.js new file mode 100644 index 00000000000..67756c37a92 --- /dev/null +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.js @@ -0,0 +1,89 @@ +//// [staticPropertyNameConflictsEs6.ts] + + +class StaticName { + static name: number; // ok + name: string; // ok +} + +class StaticNameFn { + static name() {} // ok + name() {} // ok +} + + +class StaticLength { + static length: number; // ok + length: string; // ok +} + +class StaticLengthFn { + static length() {} // ok + length() {} // ok +} + + +class StaticPrototype { + static prototype: number; // error + prototype: string; // ok +} + +class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok +} + + +class StaticCaller { + static caller: number; // // error + caller: string; // ok +} + +class StaticCallerFn { + static caller() {} // // error + caller() {} // ok +} + + +class StaticArguments { + static arguments: number; // // error + arguments: string; // ok +} + +class StaticArgumentsFn { + static arguments() {} // // error + arguments() {} // ok +} + + +//// [staticPropertyNameConflictsEs6.js] +class StaticName { +} +class StaticNameFn { + static name() { } // ok + name() { } // ok +} +class StaticLength { +} +class StaticLengthFn { + static length() { } // ok + length() { } // ok +} +class StaticPrototype { +} +class StaticPrototypeFn { + static prototype() { } // error + prototype() { } // ok +} +class StaticCaller { +} +class StaticCallerFn { + static caller() { } // // error + caller() { } // ok +} +class StaticArguments { +} +class StaticArgumentsFn { + static arguments() { } // // error + arguments() { } // ok +} diff --git a/tests/baselines/reference/staticPrototypeProperty.errors.txt b/tests/baselines/reference/staticPrototypeProperty.errors.txt index c3f5cb99c96..b2f36a40bed 100644 --- a/tests/baselines/reference/staticPrototypeProperty.errors.txt +++ b/tests/baselines/reference/staticPrototypeProperty.errors.txt @@ -1,13 +1,19 @@ tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2300: Duplicate identifier 'prototype'. +tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. -==== tests/cases/compiler/staticPrototypeProperty.ts (1 errors) ==== +==== tests/cases/compiler/staticPrototypeProperty.ts (3 errors) ==== class C { static prototype() { } ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. } class C2 { static prototype; + ~~~~~~~~~ +!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. } \ No newline at end of file diff --git a/tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts b/tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts index c8ebc312104..aa78d4333c6 100644 --- a/tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts +++ b/tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts @@ -1,20 +1,20 @@ interface A { - name(); + prop(); } class B { - public name() { } + public prop() { } } class C { - public static name() { } + public static prop() { } } var a: A = new B(); -a = new C(); // error name is missing -a = B; // error name is missing +a = new C(); // error prop is missing +a = B; // error prop is missing a = C; -var b: B = new C(); // error name is missing -b = B; // error name is missing +var b: B = new C(); // error prop is missing +b = B; // error prop is missing b = C; b = a; diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts index 0f260673d9d..5eb09ddb2d3 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts @@ -1,26 +1,56 @@ // @target: es5 // static name -class A { +class StaticName { static name: number; // error name: string; // ok } -class B { +class StaticNameFn { static name() {} // error name() {} // ok } - -// static length... -class C { +class StaticLength { static length: number; // error length: string; // ok } -class D { +class StaticLengthFn { static length() {} // error length() {} // ok } + +class StaticPrototype { + static prototype: number; // error + prototype: string; // ok +} + +class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok +} + + +class StaticCaller { + static caller: number; // error + caller: string; // ok +} + +class StaticCallerFn { + static caller() {} // error + caller() {} // ok +} + + +class StaticArguments { + static arguments: number; // error + arguments: string; // ok +} + +class StaticArgumentsFn { + static arguments() {} // error + arguments() {} // ok +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts index 47c7dbbde25..2122e183ff2 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts @@ -1,25 +1,56 @@ // @target: es6 -// static name -class A { - static name: string; // ok +class StaticName { + static name: number; // ok name: string; // ok } -class B { - static name() {}; // ok - name() {}; // ok +class StaticNameFn { + static name() {} // ok + name() {} // ok } -// static length -class C { +class StaticLength { static length: number; // ok length: string; // ok } -class D { +class StaticLengthFn { static length() {} // ok length() {} // ok } + + +class StaticPrototype { + static prototype: number; // error + prototype: string; // ok +} + +class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok +} + + +class StaticCaller { + static caller: number; // // error + caller: string; // ok +} + +class StaticCallerFn { + static caller() {} // // error + caller() {} // ok +} + + +class StaticArguments { + static arguments: number; // // error + arguments: string; // ok +} + +class StaticArgumentsFn { + static arguments() {} // // error + arguments() {} // ok +} From 45e8a5b54d0e3fe8deb1f412436a9defad0ff04e Mon Sep 17 00:00:00 2001 From: about-code Date: Mon, 17 Oct 2016 19:22:40 +0200 Subject: [PATCH 03/11] Accepting new baseline. Format code to fit linter rules. --- src/compiler/checker.ts | 53 ++++++++++--------- .../propertyNamedPrototype.errors.txt | 4 +- .../staticPropertyNameConflictsEs5.errors.txt | 40 +++++++------- .../staticPropertyNameConflictsEs6.errors.txt | 24 ++++----- .../staticPrototypeProperty.errors.txt | 8 +-- 5 files changed, 66 insertions(+), 63 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2412faed6ad..9e8c92309b0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14554,43 +14554,46 @@ namespace ts { // Static members may conflict with non-configurable non-writable built-in Function.prototype properties // see https://github.com/microsoft/typescript/issues/442. - function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { + function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { const es5_descriptors: PropertyDescriptorMap = { // see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3 // see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5 - "name": {configurable: false, writable: false}, - "length": {configurable: false, writable: false}, - "prototype": {configurable: false, writable: false}, + "name": { configurable: false, writable: false }, + "length": { configurable: false, writable: false }, + "prototype": { configurable: false, writable: false }, // see https://github.com/microsoft/typescript/issues/442 - "caller": {configurable: false, writable: false}, - "arguments": {configurable: false, writable: false} - }; + "caller": { configurable: false, writable: false }, + "arguments": { configurable: false, writable: false } + }; const post_es5_descriptors: PropertyDescriptorMap = { // see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor // see http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances - "name": {configurable: true, writable: false}, - "length": {configurable: true, writable: false}, - "prototype": {configurable: false, writable: false}, - "caller": {configurable: false, writable: false}, - "arguments": {configurable: false, writable: false} + "name": { configurable: true, writable: false }, + "length": { configurable: true, writable: false }, + "prototype": { configurable: false, writable: false }, + "caller": { configurable: false, writable: false }, + "arguments": { configurable: false, writable: false } }; const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1; const className = getSymbolOfNode(node).name; - - for (let member of node.members) { - let isStatic = forEach(member.modifiers, (m:Modifier) => m.kind === SyntaxKind.StaticKeyword); + + for (const member of node.members) { + const isStatic = forEach(member.modifiers, (m: Modifier) => m.kind === SyntaxKind.StaticKeyword); if (isStatic) { - let memberNameNode = member.name; - let memberName = getPropertyNameForPropertyNameNode(memberNameNode); - let descriptor: PropertyDescriptor = null; - if (languageVersion <= ScriptTarget.ES5) { - descriptor = es5_descriptors.hasOwnProperty(memberName) ? es5_descriptors[memberName] : null; - } else if (languageVersion > ScriptTarget.ES5) { - descriptor = post_es5_descriptors.hasOwnProperty(memberName) ? post_es5_descriptors[memberName] : null; - } - if (descriptor && descriptor.configurable === false && descriptor.writable === false) { - error(memberNameNode, message, memberName, className); + const memberNameNode = member.name; + if (memberNameNode) { + const memberName = getPropertyNameForPropertyNameNode(memberNameNode); + let descriptor: PropertyDescriptor = undefined; + if (languageVersion <= ScriptTarget.ES5) { + descriptor = es5_descriptors.hasOwnProperty(memberName) ? es5_descriptors[memberName] : undefined; + } + else if (languageVersion > ScriptTarget.ES5) { + descriptor = post_es5_descriptors.hasOwnProperty(memberName) ? post_es5_descriptors[memberName] : undefined; + } + if (descriptor && descriptor.configurable === false && descriptor.writable === false) { + error(memberNameNode, message, memberName, className); + } } } } diff --git a/tests/baselines/reference/propertyNamedPrototype.errors.txt b/tests/baselines/reference/propertyNamedPrototype.errors.txt index 6ddd8390720..2c0c8f30f76 100644 --- a/tests/baselines/reference/propertyNamedPrototype.errors.txt +++ b/tests/baselines/reference/propertyNamedPrototype.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts(3,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts(3,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts (1 errors) ==== @@ -6,5 +6,5 @@ tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototyp prototype: number; // ok static prototype: C; // error ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt index 182b1628522..5c3f3b3f7dc 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(4,12): error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(9,12): error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(15,12): error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(20,12): error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(26,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(4,12): error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(9,12): error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(15,12): error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(20,12): error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(26,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2300: Duplicate identifier 'prototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(37,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(42,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(48,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(53,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(37,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(42,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(48,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(53,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts (11 errors) ==== @@ -17,14 +17,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticName { static name: number; // error ~~~~ -!!! error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +!!! error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. name: string; // ok } class StaticNameFn { static name() {} // error ~~~~ -!!! error TS2692: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +!!! error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. name() {} // ok } @@ -32,14 +32,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticLength { static length: number; // error ~~~~~~ -!!! error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +!!! error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. length: string; // ok } class StaticLengthFn { static length() {} // error ~~~~~~ -!!! error TS2692: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +!!! error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. length() {} // ok } @@ -47,7 +47,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticPrototype { static prototype: number; // error ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. prototype: string; // ok } @@ -56,7 +56,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. prototype() {} // ok } @@ -64,14 +64,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticCaller { static caller: number; // error ~~~~~~ -!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. caller: string; // ok } class StaticCallerFn { static caller() {} // error ~~~~~~ -!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. caller() {} // ok } @@ -79,14 +79,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticArguments { static arguments: number; // error ~~~~~~~~~ -!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. arguments: string; // ok } class StaticArgumentsFn { static arguments() {} // error ~~~~~~~~~ -!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. arguments() {} // ok } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt index b76b7e02b76..0c65494c7bc 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(42,12): error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(53,12): error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(42,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(53,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== @@ -35,7 +35,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticPrototype { static prototype: number; // error ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. prototype: string; // ok } @@ -44,7 +44,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. prototype() {} // ok } @@ -52,14 +52,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticCaller { static caller: number; // // error ~~~~~~ -!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. caller: string; // ok } class StaticCallerFn { static caller() {} // // error ~~~~~~ -!!! error TS2692: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. caller() {} // ok } @@ -67,14 +67,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticArguments { static arguments: number; // // error ~~~~~~~~~ -!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. arguments: string; // ok } class StaticArgumentsFn { static arguments() {} // // error ~~~~~~~~~ -!!! error TS2692: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. arguments() {} // ok } \ No newline at end of file diff --git a/tests/baselines/reference/staticPrototypeProperty.errors.txt b/tests/baselines/reference/staticPrototypeProperty.errors.txt index b2f36a40bed..44b6980cb91 100644 --- a/tests/baselines/reference/staticPrototypeProperty.errors.txt +++ b/tests/baselines/reference/staticPrototypeProperty.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2300: Duplicate identifier 'prototype'. -tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. -tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. +tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. ==== tests/cases/compiler/staticPrototypeProperty.ts (3 errors) ==== @@ -9,11 +9,11 @@ tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2692: Static prop ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. } class C2 { static prototype; ~~~~~~~~~ -!!! error TS2692: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. +!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. } \ No newline at end of file From 189dbddb101a0d5acaa612013d8cdd07ece78344 Mon Sep 17 00:00:00 2001 From: about-code Date: Sat, 5 Nov 2016 18:42:53 +0100 Subject: [PATCH 04/11] Accept baseline tests. Fixing `diagnosticMessages.json` (merge result not included in prior commit). --- src/compiler/diagnosticMessages.json | 12 ++---- .../propertyNamedPrototype.errors.txt | 4 +- .../staticPropertyNameConflictsEs5.errors.txt | 40 +++++++++---------- .../staticPropertyNameConflictsEs6.errors.txt | 32 +++++++-------- .../staticPropertyNameConflictsEs6.js | 12 +++--- .../staticPrototypeProperty.errors.txt | 8 ++-- ...ariableDeclarationInStrictMode1.errors.txt | 2 +- .../staticPropertyNameConflictsEs6.ts | 8 ++-- 8 files changed, 57 insertions(+), 61 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 77df2489fe5..4bb683865a8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1979,18 +1979,14 @@ "category": "Error", "code": 2696 }, -<<<<<<< HEAD - "Static property '{0}' conflicts with built-in property 'Function.{0}' of constructor function '{1}'.": { - "category": "Error", - "code": 2699 - }, -======= "An async function or method must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { "category": "Error", "code": 2697 }, - ->>>>>>> upstream/master + "Static property '{0}' conflicts with built-in property 'Function.{0}' of constructor function '{1}'.": { + "category": "Error", + "code": 2699 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/propertyNamedPrototype.errors.txt b/tests/baselines/reference/propertyNamedPrototype.errors.txt index 2c0c8f30f76..d80e1c95c8d 100644 --- a/tests/baselines/reference/propertyNamedPrototype.errors.txt +++ b/tests/baselines/reference/propertyNamedPrototype.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts(3,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts(3,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototype.ts (1 errors) ==== @@ -6,5 +6,5 @@ tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedPrototyp prototype: number; // ok static prototype: C; // error ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt index 5c3f3b3f7dc..004365d3e76 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(4,12): error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(9,12): error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(15,12): error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(20,12): error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(26,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(4,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(9,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(15,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(20,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(26,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2300: Duplicate identifier 'prototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(37,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(42,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(48,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(53,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(37,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(42,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(53,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts (11 errors) ==== @@ -17,14 +17,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticName { static name: number; // error ~~~~ -!!! error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. name: string; // ok } class StaticNameFn { static name() {} // error ~~~~ -!!! error TS2697: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. name() {} // ok } @@ -32,14 +32,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticLength { static length: number; // error ~~~~~~ -!!! error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. length: string; // ok } class StaticLengthFn { static length() {} // error ~~~~~~ -!!! error TS2697: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. length() {} // ok } @@ -47,7 +47,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticPrototype { static prototype: number; // error ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. prototype: string; // ok } @@ -56,7 +56,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. prototype() {} // ok } @@ -64,14 +64,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticCaller { static caller: number; // error ~~~~~~ -!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. caller: string; // ok } class StaticCallerFn { static caller() {} // error ~~~~~~ -!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. caller() {} // ok } @@ -79,14 +79,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticArguments { static arguments: number; // error ~~~~~~~~~ -!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. arguments: string; // ok } class StaticArgumentsFn { static arguments() {} // error ~~~~~~~~~ -!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. arguments() {} // ok } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt index 0c65494c7bc..ef83151aa3d 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(42,12): error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(53,12): error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(42,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(53,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== @@ -35,7 +35,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon class StaticPrototype { static prototype: number; // error ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. prototype: string; // ok } @@ -44,37 +44,37 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. prototype() {} // ok } class StaticCaller { - static caller: number; // // error + static caller: number; // error ~~~~~~ -!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. caller: string; // ok } class StaticCallerFn { - static caller() {} // // error + static caller() {} // error ~~~~~~ -!!! error TS2697: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. caller() {} // ok } class StaticArguments { - static arguments: number; // // error + static arguments: number; // error ~~~~~~~~~ -!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. arguments: string; // ok } class StaticArgumentsFn { - static arguments() {} // // error + static arguments() {} // error ~~~~~~~~~ -!!! error TS2697: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. arguments() {} // ok } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.js b/tests/baselines/reference/staticPropertyNameConflictsEs6.js index 67756c37a92..48e8b7a063d 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.js +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.js @@ -35,23 +35,23 @@ class StaticPrototypeFn { class StaticCaller { - static caller: number; // // error + static caller: number; // error caller: string; // ok } class StaticCallerFn { - static caller() {} // // error + static caller() {} // error caller() {} // ok } class StaticArguments { - static arguments: number; // // error + static arguments: number; // error arguments: string; // ok } class StaticArgumentsFn { - static arguments() {} // // error + static arguments() {} // error arguments() {} // ok } @@ -78,12 +78,12 @@ class StaticPrototypeFn { class StaticCaller { } class StaticCallerFn { - static caller() { } // // error + static caller() { } // error caller() { } // ok } class StaticArguments { } class StaticArgumentsFn { - static arguments() { } // // error + static arguments() { } // error arguments() { } // ok } diff --git a/tests/baselines/reference/staticPrototypeProperty.errors.txt b/tests/baselines/reference/staticPrototypeProperty.errors.txt index 44b6980cb91..c131b7a774d 100644 --- a/tests/baselines/reference/staticPrototypeProperty.errors.txt +++ b/tests/baselines/reference/staticPrototypeProperty.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2300: Duplicate identifier 'prototype'. -tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. -tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. +tests/cases/compiler/staticPrototypeProperty.ts(2,11): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. ==== tests/cases/compiler/staticPrototypeProperty.ts (3 errors) ==== @@ -9,11 +9,11 @@ tests/cases/compiler/staticPrototypeProperty.ts(6,11): error TS2697: Static prop ~~~~~~~~~ !!! error TS2300: Duplicate identifier 'prototype'. ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C'. } class C2 { static prototype; ~~~~~~~~~ -!!! error TS2697: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'C2'. } \ No newline at end of file diff --git a/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt b/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt index 46782aaa1d6..9dd9a8d41a1 100644 --- a/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt +++ b/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt @@ -1,4 +1,4 @@ -lib.d.ts(32,18): error TS2300: Duplicate identifier 'eval'. +lib.d.ts(28,18): error TS2300: Duplicate identifier 'eval'. tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS1100: Invalid use of 'eval' in strict mode. tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS2300: Duplicate identifier 'eval'. diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts index 2122e183ff2..412833791b4 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts @@ -35,22 +35,22 @@ class StaticPrototypeFn { class StaticCaller { - static caller: number; // // error + static caller: number; // error caller: string; // ok } class StaticCallerFn { - static caller() {} // // error + static caller() {} // error caller() {} // ok } class StaticArguments { - static arguments: number; // // error + static arguments: number; // error arguments: string; // ok } class StaticArgumentsFn { - static arguments() {} // // error + static arguments() {} // error arguments() {} // ok } From d58b5c807cffd71e65d6c26ac45e1858427f062c Mon Sep 17 00:00:00 2001 From: about-code Date: Sun, 6 Nov 2016 00:36:41 +0100 Subject: [PATCH 05/11] Fixing wrong line number in tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt after rebuilding and testing compiler. --- .../reference/variableDeclarationInStrictMode1.errors.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt b/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt index 9dd9a8d41a1..46782aaa1d6 100644 --- a/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt +++ b/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt @@ -1,4 +1,4 @@ -lib.d.ts(28,18): error TS2300: Duplicate identifier 'eval'. +lib.d.ts(32,18): error TS2300: Duplicate identifier 'eval'. tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS1100: Invalid use of 'eval' in strict mode. tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS2300: Duplicate identifier 'eval'. From d9a46e1ae6877e4fe806fe2592d043d330ea2893 Mon Sep 17 00:00:00 2001 From: about-code Date: Sun, 6 Nov 2016 17:59:38 +0100 Subject: [PATCH 06/11] Allowing `static arguments()` and `static caller()` for target `"es6"`. Disallow non-function properties `static arguments` and `static caller`, though. --- src/compiler/checker.ts | 64 +++++++++---------- .../staticPropertyNameConflictsEs6.errors.txt | 12 +--- .../staticPropertyNameConflictsEs6.js | 8 +-- .../staticPropertyNameConflictsEs6.ts | 4 +- 4 files changed, 38 insertions(+), 50 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6524a69f13f..d756f215ac3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14764,49 +14764,43 @@ namespace ts { } } - // Static members may conflict with non-configurable non-writable built-in Function.prototype properties + // Static members may conflict with non-configurable non-writable built-in Function object properties // see https://github.com/microsoft/typescript/issues/442. function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { - const es5_descriptors: PropertyDescriptorMap = { - // see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3 - // see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5 - "name": { configurable: false, writable: false }, - "length": { configurable: false, writable: false }, - "prototype": { configurable: false, writable: false }, - - // see https://github.com/microsoft/typescript/issues/442 - "caller": { configurable: false, writable: false }, - "arguments": { configurable: false, writable: false } - }; - const post_es5_descriptors: PropertyDescriptorMap = { - // see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor - // see http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances - "name": { configurable: true, writable: false }, - "length": { configurable: true, writable: false }, - "prototype": { configurable: false, writable: false }, - "caller": { configurable: false, writable: false }, - "arguments": { configurable: false, writable: false } - }; const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1; const className = getSymbolOfNode(node).name; - for (const member of node.members) { - const isStatic = forEach(member.modifiers, (m: Modifier) => m.kind === SyntaxKind.StaticKeyword); - if (isStatic) { - const memberNameNode = member.name; - if (memberNameNode) { - const memberName = getPropertyNameForPropertyNameNode(memberNameNode); - let descriptor: PropertyDescriptor = undefined; - if (languageVersion <= ScriptTarget.ES5) { - descriptor = es5_descriptors.hasOwnProperty(memberName) ? es5_descriptors[memberName] : undefined; - } - else if (languageVersion > ScriptTarget.ES5) { - descriptor = post_es5_descriptors.hasOwnProperty(memberName) ? post_es5_descriptors[memberName] : undefined; - } - if (descriptor && descriptor.configurable === false && descriptor.writable === false) { + const isStatic = forEach(member.modifiers, (m: Modifier) => m.kind === SyntaxKind.StaticKeyword); + const isMethod = member.kind === SyntaxKind.MethodDeclaration; + const memberNameNode = member.name; + if (isStatic && memberNameNode) { + const memberName = getPropertyNameForPropertyNameNode(memberNameNode); + if (languageVersion <= ScriptTarget.ES5) { // ES3, ES5 + // see also http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3 + // see also http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5 + if (memberName === "prototype" || + memberName === "name" || + memberName === "length" || + memberName === "caller" || + memberName === "arguments" + ) { error(memberNameNode, message, memberName, className); } } + else { // ES6+ + // see also http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor + // see also http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances + if (memberName === "prototype") { + error(memberNameNode, message, memberName, className); + } + else if (( + memberName === "caller" || + memberName === "arguments" ) && + isMethod === false + ) { + error(memberNameNode, message, memberName, className); + } + } } } } diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt index ef83151aa3d..b73b01abbbe 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt @@ -2,12 +2,10 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(42,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(53,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. -==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (5 errors) ==== class StaticName { @@ -57,9 +55,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon } class StaticCallerFn { - static caller() {} // error - ~~~~~~ -!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. + static caller() {} // ok caller() {} // ok } @@ -72,9 +68,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon } class StaticArgumentsFn { - static arguments() {} // error - ~~~~~~~~~ -!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + static arguments() {} // ok arguments() {} // ok } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.js b/tests/baselines/reference/staticPropertyNameConflictsEs6.js index 48e8b7a063d..8d96c73d4c5 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.js +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.js @@ -40,7 +40,7 @@ class StaticCaller { } class StaticCallerFn { - static caller() {} // error + static caller() {} // ok caller() {} // ok } @@ -51,7 +51,7 @@ class StaticArguments { } class StaticArgumentsFn { - static arguments() {} // error + static arguments() {} // ok arguments() {} // ok } @@ -78,12 +78,12 @@ class StaticPrototypeFn { class StaticCaller { } class StaticCallerFn { - static caller() { } // error + static caller() { } // ok caller() { } // ok } class StaticArguments { } class StaticArgumentsFn { - static arguments() { } // error + static arguments() { } // ok arguments() { } // ok } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts index 412833791b4..01db0c27872 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts @@ -40,7 +40,7 @@ class StaticCaller { } class StaticCallerFn { - static caller() {} // error + static caller() {} // ok caller() {} // ok } @@ -51,6 +51,6 @@ class StaticArguments { } class StaticArgumentsFn { - static arguments() {} // error + static arguments() {} // ok arguments() {} // ok } From b623f3771e91f5fe31c498c9a5defc4172b567bd Mon Sep 17 00:00:00 2001 From: about-code Date: Wed, 9 Nov 2016 21:08:56 +0100 Subject: [PATCH 07/11] Fix #442: (es3, es5, es6+) Show compiler errors for conflicting properties. --- src/compiler/checker.ts | 6 ++++-- .../staticPropertyNameConflictsEs6.errors.txt | 14 ++++++++++---- .../reference/staticPropertyNameConflictsEs6.js | 6 +++--- .../staticPropertyNameConflictsEs6.ts | 6 +++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d756f215ac3..de82ee004e8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14794,11 +14794,13 @@ namespace ts { error(memberNameNode, message, memberName, className); } else if (( + memberName === "name" || + memberName === "length" || memberName === "caller" || - memberName === "arguments" ) && + memberName === "arguments") && isMethod === false ) { - error(memberNameNode, message, memberName, className); + error(memberNameNode, message, memberName, className); } } } diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt index b73b01abbbe..607735bb12f 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt @@ -1,3 +1,5 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(4,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(15,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. @@ -5,22 +7,26 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (5 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== class StaticName { - static name: number; // ok + static name: number; // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. name: string; // ok } class StaticNameFn { - static name() {} // ok + static name() {} // ok name() {} // ok } class StaticLength { - static length: number; // ok + static length: number; // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. length: string; // ok } diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.js b/tests/baselines/reference/staticPropertyNameConflictsEs6.js index 8d96c73d4c5..7adef10b141 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.js +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.js @@ -2,18 +2,18 @@ class StaticName { - static name: number; // ok + static name: number; // error name: string; // ok } class StaticNameFn { - static name() {} // ok + static name() {} // ok name() {} // ok } class StaticLength { - static length: number; // ok + static length: number; // error length: string; // ok } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts index 01db0c27872..1b93e98dae8 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts @@ -2,18 +2,18 @@ class StaticName { - static name: number; // ok + static name: number; // error name: string; // ok } class StaticNameFn { - static name() {} // ok + static name() {} // ok name() {} // ok } class StaticLength { - static length: number; // ok + static length: number; // error length: string; // ok } From 544d0a43880b3ee6043aae28f8f09210221f60c4 Mon Sep 17 00:00:00 2001 From: about-code Date: Fri, 30 Dec 2016 13:03:20 +0100 Subject: [PATCH 08/11] Incorporate changes proposed by @sandersn --- src/compiler/checker.ts | 52 ++++++++++++++++------------ src/compiler/diagnosticMessages.json | 8 ++--- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b3820bc0970..4395e852ebc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2142,24 +2142,25 @@ namespace ts { return type.flags & TypeFlags.StringLiteral ? `"${escapeString((type).text)}"` : (type).text; } - function getSymbolDisplayBuilder(): SymbolDisplayBuilder { - function getNameOfSymbol(symbol: Symbol): string { - if (symbol.declarations && symbol.declarations.length) { - const declaration = symbol.declarations[0]; - if (declaration.name) { - return declarationNameToString(declaration.name); - } - switch (declaration.kind) { - case SyntaxKind.ClassExpression: - return "(Anonymous class)"; - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - return "(Anonymous function)"; - } + function getNameOfSymbol(symbol: Symbol): string { + if (symbol.declarations && symbol.declarations.length) { + const declaration = symbol.declarations[0]; + if (declaration.name) { + return declarationNameToString(declaration.name); + } + switch (declaration.kind) { + case SyntaxKind.ClassExpression: + return "(Anonymous class)"; + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + return "(Anonymous function)"; } - return symbol.name; } + return symbol.name; + } + + function getSymbolDisplayBuilder(): SymbolDisplayBuilder { /** * Writes only the name of the symbol out to the writer. Uses the original source text @@ -15647,20 +15648,27 @@ namespace ts { } } - // Static members may conflict with non-configurable non-writable built-in Function object properties - // see https://github.com/microsoft/typescript/issues/442. + /** + * Static members being set on a constructor function may conflict with built-in Function + * object properties. Esp. in ECMAScript 5 there are non-configurable and non-writable + * built-in properties. This check issues a transpile error when a class has a static + * member with the same name as a non-writable built-in property. + * + * @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3 + * @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5 + * @see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor + * @see http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances + */ function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1; - const className = getSymbolOfNode(node).name; + const className = getNameOfSymbol(getSymbolOfNode(node)); for (const member of node.members) { - const isStatic = forEach(member.modifiers, (m: Modifier) => m.kind === SyntaxKind.StaticKeyword); + const isStatic = getModifierFlags(member) & ModifierFlags.Static; const isMethod = member.kind === SyntaxKind.MethodDeclaration; const memberNameNode = member.name; if (isStatic && memberNameNode) { const memberName = getPropertyNameForPropertyNameNode(memberNameNode); if (languageVersion <= ScriptTarget.ES5) { // ES3, ES5 - // see also http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3 - // see also http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5 if (memberName === "prototype" || memberName === "name" || memberName === "length" || @@ -15671,8 +15679,6 @@ namespace ts { } } else { // ES6+ - // see also http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor - // see also http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances if (memberName === "prototype") { error(memberNameNode, message, memberName, className); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0c9bb74f781..476cced3732 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2011,14 +2011,14 @@ "category": "Error", "code": 2697 }, - "Static property '{0}' conflicts with built-in property 'Function.{0}' of constructor function '{1}'.": { - "category": "Error", - "code": 2699 - }, "Spread types may only be created from object types.": { "category": "Error", "code": 2698 }, + "Static property '{0}' conflicts with built-in property 'Function.{0}' of constructor function '{1}'.": { + "category": "Error", + "code": 2699 + }, "Rest types may only be created from object types.": { "category": "Error", "code": 2700 From 244db70730e90bcfa69b00c8f8b8f6973d641bda Mon Sep 17 00:00:00 2001 From: about-code Date: Tue, 3 Jan 2017 14:06:10 +0100 Subject: [PATCH 09/11] Incorporating changes to `checkClassForDuplicateDeclarations` in `checker.ts` as proposed by @sandersn --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4395e852ebc..d6df79e3bbc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15610,7 +15610,7 @@ namespace ts { } } else { - const isStatic = forEach(member.modifiers, m => m.kind === SyntaxKind.StaticKeyword); + const isStatic = getModifierFlags(member) & ModifierFlags.Static; const names = isStatic ? staticNames : instanceNames; const memberName = member.name && getPropertyNameForPropertyNameNode(member.name); From 4718efd181c2ddcc7d1203cb6ec13367ab4537b3 Mon Sep 17 00:00:00 2001 From: about-code Date: Sat, 14 Jan 2017 16:06:13 +0100 Subject: [PATCH 10/11] Removing es6 method/property distinction. Adding tests with default export and anonymous class expressions. --- .../staticPropertyNameConflicts.errors.txt | 293 ++++++++++++ .../reference/staticPropertyNameConflicts.js | 429 ++++++++++++++++++ ...sEs5.ts => staticPropertyNameConflicts.ts} | 0 .../staticPropertyNameConflictsEs6.ts | 56 --- 4 files changed, 722 insertions(+), 56 deletions(-) create mode 100644 tests/baselines/reference/staticPropertyNameConflicts.errors.txt create mode 100644 tests/baselines/reference/staticPropertyNameConflicts.js rename tests/cases/conformance/classes/propertyMemberDeclarations/{staticPropertyNameConflictsEs5.ts => staticPropertyNameConflicts.ts} (100%) delete mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts diff --git a/tests/baselines/reference/staticPropertyNameConflicts.errors.txt b/tests/baselines/reference/staticPropertyNameConflicts.errors.txt new file mode 100644 index 00000000000..4c051ace0ac --- /dev/null +++ b/tests/baselines/reference/staticPropertyNameConflicts.errors.txt @@ -0,0 +1,293 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(3,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(8,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(14,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(19,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(25,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(30,12): error TS2300: Duplicate identifier 'prototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(30,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(36,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(41,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(47,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(52,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(62,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(67,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(73,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(78,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(84,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(89,12): error TS2300: Duplicate identifier 'prototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(89,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(95,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(100,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(106,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(111,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function '(Anonymous class)'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(121,16): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(128,16): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(136,16): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(143,16): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(151,16): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(158,16): error TS2300: Duplicate identifier 'prototype'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(158,16): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(166,16): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(173,16): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(181,16): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts(188,16): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts (33 errors) ==== + // name + class StaticName { + static name: number; // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. + name: string; // ok + } + + class StaticNameFn { + static name() {} // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. + name() {} // ok + } + + // length + class StaticLength { + static length: number; // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. + length: string; // ok + } + + class StaticLengthFn { + static length() {} // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. + length() {} // ok + } + + // prototype + class StaticPrototype { + static prototype: number; // error + ~~~~~~~~~ +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. + prototype: string; // ok + } + + class StaticPrototypeFn { + static prototype() {} // error + ~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'prototype'. + ~~~~~~~~~ +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. + prototype() {} // ok + } + + // caller + class StaticCaller { + static caller: number; // error + ~~~~~~ +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. + caller: string; // ok + } + + class StaticCallerFn { + static caller() {} // error + ~~~~~~ +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. + caller() {} // ok + } + + // arguments + class StaticArguments { + static arguments: number; // error + ~~~~~~~~~ +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. + arguments: string; // ok + } + + class StaticArgumentsFn { + static arguments() {} // error + ~~~~~~~~~ +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + arguments() {} // ok + } + + + + // === Static properties on anonymous classes === + + // name + var StaticName_Anonymous = class { + static name: number; // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function '(Anonymous class)'. + name: string; // ok + } + + var StaticNameFn_Anonymous = class { + static name() {} // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function '(Anonymous class)'. + name() {} // ok + } + + // length + var StaticLength_Anonymous = class { + static length: number; // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function '(Anonymous class)'. + length: string; // ok + } + + var StaticLengthFn_Anonymous = class { + static length() {} // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function '(Anonymous class)'. + length() {} // ok + } + + // prototype + var StaticPrototype_Anonymous = class { + static prototype: number; // error + ~~~~~~~~~ +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function '(Anonymous class)'. + prototype: string; // ok + } + + var StaticPrototypeFn_Anonymous = class { + static prototype() {} // error + ~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'prototype'. + ~~~~~~~~~ +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function '(Anonymous class)'. + prototype() {} // ok + } + + // caller + var StaticCaller_Anonymous = class { + static caller: number; // error + ~~~~~~ +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function '(Anonymous class)'. + caller: string; // ok + } + + var StaticCallerFn_Anonymous = class { + static caller() {} // error + ~~~~~~ +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function '(Anonymous class)'. + caller() {} // ok + } + + // arguments + var StaticArguments_Anonymous = class { + static arguments: number; // error + ~~~~~~~~~ +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function '(Anonymous class)'. + arguments: string; // ok + } + + var StaticArgumentsFn_Anonymous = class { + static arguments() {} // error + ~~~~~~~~~ +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function '(Anonymous class)'. + arguments() {} // ok + } + + + // === Static properties on default exported classes === + + // name + module TestOnDefaultExportedClass_1 { + class StaticName { + static name: number; // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. + name: string; // ok + } + } + + module TestOnDefaultExportedClass_2 { + class StaticNameFn { + static name() {} // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. + name() {} // ok + } + } + + // length + module TestOnDefaultExportedClass_3 { + export default class StaticLength { + static length: number; // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. + length: string; // ok + } + } + + module TestOnDefaultExportedClass_4 { + export default class StaticLengthFn { + static length() {} // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. + length() {} // ok + } + } + + // prototype + module TestOnDefaultExportedClass_5 { + export default class StaticPrototype { + static prototype: number; // error + ~~~~~~~~~ +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. + prototype: string; // ok + } + } + + module TestOnDefaultExportedClass_6 { + export default class StaticPrototypeFn { + static prototype() {} // error + ~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'prototype'. + ~~~~~~~~~ +!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. + prototype() {} // ok + } + } + + // caller + module TestOnDefaultExportedClass_7 { + export default class StaticCaller { + static caller: number; // error + ~~~~~~ +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. + caller: string; // ok + } + } + + module TestOnDefaultExportedClass_8 { + export default class StaticCallerFn { + static caller() {} // error + ~~~~~~ +!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. + caller() {} // ok + } + } + + // arguments + module TestOnDefaultExportedClass_9 { + export default class StaticArguments { + static arguments: number; // error + ~~~~~~~~~ +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. + arguments: string; // ok + } + } + + module TestOnDefaultExportedClass_10 { + export default class StaticArgumentsFn { + static arguments() {} // error + ~~~~~~~~~ +!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. + arguments() {} // ok + } + } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflicts.js b/tests/baselines/reference/staticPropertyNameConflicts.js new file mode 100644 index 00000000000..b93b16550f0 --- /dev/null +++ b/tests/baselines/reference/staticPropertyNameConflicts.js @@ -0,0 +1,429 @@ +//// [staticPropertyNameConflicts.ts] +// name +class StaticName { + static name: number; // error + name: string; // ok +} + +class StaticNameFn { + static name() {} // error + name() {} // ok +} + +// length +class StaticLength { + static length: number; // error + length: string; // ok +} + +class StaticLengthFn { + static length() {} // error + length() {} // ok +} + +// prototype +class StaticPrototype { + static prototype: number; // error + prototype: string; // ok +} + +class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok +} + +// caller +class StaticCaller { + static caller: number; // error + caller: string; // ok +} + +class StaticCallerFn { + static caller() {} // error + caller() {} // ok +} + +// arguments +class StaticArguments { + static arguments: number; // error + arguments: string; // ok +} + +class StaticArgumentsFn { + static arguments() {} // error + arguments() {} // ok +} + + + +// === Static properties on anonymous classes === + +// name +var StaticName_Anonymous = class { + static name: number; // error + name: string; // ok +} + +var StaticNameFn_Anonymous = class { + static name() {} // error + name() {} // ok +} + +// length +var StaticLength_Anonymous = class { + static length: number; // error + length: string; // ok +} + +var StaticLengthFn_Anonymous = class { + static length() {} // error + length() {} // ok +} + +// prototype +var StaticPrototype_Anonymous = class { + static prototype: number; // error + prototype: string; // ok +} + +var StaticPrototypeFn_Anonymous = class { + static prototype() {} // error + prototype() {} // ok +} + +// caller +var StaticCaller_Anonymous = class { + static caller: number; // error + caller: string; // ok +} + +var StaticCallerFn_Anonymous = class { + static caller() {} // error + caller() {} // ok +} + +// arguments +var StaticArguments_Anonymous = class { + static arguments: number; // error + arguments: string; // ok +} + +var StaticArgumentsFn_Anonymous = class { + static arguments() {} // error + arguments() {} // ok +} + + +// === Static properties on default exported classes === + +// name +module TestOnDefaultExportedClass_1 { + class StaticName { + static name: number; // error + name: string; // ok + } +} + +module TestOnDefaultExportedClass_2 { + class StaticNameFn { + static name() {} // error + name() {} // ok + } +} + +// length +module TestOnDefaultExportedClass_3 { + export default class StaticLength { + static length: number; // error + length: string; // ok + } +} + +module TestOnDefaultExportedClass_4 { + export default class StaticLengthFn { + static length() {} // error + length() {} // ok + } +} + +// prototype +module TestOnDefaultExportedClass_5 { + export default class StaticPrototype { + static prototype: number; // error + prototype: string; // ok + } +} + +module TestOnDefaultExportedClass_6 { + export default class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok + } +} + +// caller +module TestOnDefaultExportedClass_7 { + export default class StaticCaller { + static caller: number; // error + caller: string; // ok + } +} + +module TestOnDefaultExportedClass_8 { + export default class StaticCallerFn { + static caller() {} // error + caller() {} // ok + } +} + +// arguments +module TestOnDefaultExportedClass_9 { + export default class StaticArguments { + static arguments: number; // error + arguments: string; // ok + } +} + +module TestOnDefaultExportedClass_10 { + export default class StaticArgumentsFn { + static arguments() {} // error + arguments() {} // ok + } +} + +//// [staticPropertyNameConflicts.js] +// name +var StaticName = (function () { + function StaticName() { + } + return StaticName; +}()); +var StaticNameFn = (function () { + function StaticNameFn() { + } + StaticNameFn.name = function () { }; // error + StaticNameFn.prototype.name = function () { }; // ok + return StaticNameFn; +}()); +// length +var StaticLength = (function () { + function StaticLength() { + } + return StaticLength; +}()); +var StaticLengthFn = (function () { + function StaticLengthFn() { + } + StaticLengthFn.length = function () { }; // error + StaticLengthFn.prototype.length = function () { }; // ok + return StaticLengthFn; +}()); +// prototype +var StaticPrototype = (function () { + function StaticPrototype() { + } + return StaticPrototype; +}()); +var StaticPrototypeFn = (function () { + function StaticPrototypeFn() { + } + StaticPrototypeFn.prototype = function () { }; // error + StaticPrototypeFn.prototype.prototype = function () { }; // ok + return StaticPrototypeFn; +}()); +// caller +var StaticCaller = (function () { + function StaticCaller() { + } + return StaticCaller; +}()); +var StaticCallerFn = (function () { + function StaticCallerFn() { + } + StaticCallerFn.caller = function () { }; // error + StaticCallerFn.prototype.caller = function () { }; // ok + return StaticCallerFn; +}()); +// arguments +var StaticArguments = (function () { + function StaticArguments() { + } + return StaticArguments; +}()); +var StaticArgumentsFn = (function () { + function StaticArgumentsFn() { + } + StaticArgumentsFn.arguments = function () { }; // error + StaticArgumentsFn.prototype.arguments = function () { }; // ok + return StaticArgumentsFn; +}()); +// === Static properties on anonymous classes === +// name +var StaticName_Anonymous = (function () { + function class_1() { + } + return class_1; +}()); +var StaticNameFn_Anonymous = (function () { + function class_2() { + } + class_2.name = function () { }; // error + class_2.prototype.name = function () { }; // ok + return class_2; +}()); +// length +var StaticLength_Anonymous = (function () { + function class_3() { + } + return class_3; +}()); +var StaticLengthFn_Anonymous = (function () { + function class_4() { + } + class_4.length = function () { }; // error + class_4.prototype.length = function () { }; // ok + return class_4; +}()); +// prototype +var StaticPrototype_Anonymous = (function () { + function class_5() { + } + return class_5; +}()); +var StaticPrototypeFn_Anonymous = (function () { + function class_6() { + } + class_6.prototype = function () { }; // error + class_6.prototype.prototype = function () { }; // ok + return class_6; +}()); +// caller +var StaticCaller_Anonymous = (function () { + function class_7() { + } + return class_7; +}()); +var StaticCallerFn_Anonymous = (function () { + function class_8() { + } + class_8.caller = function () { }; // error + class_8.prototype.caller = function () { }; // ok + return class_8; +}()); +// arguments +var StaticArguments_Anonymous = (function () { + function class_9() { + } + return class_9; +}()); +var StaticArgumentsFn_Anonymous = (function () { + function class_10() { + } + class_10.arguments = function () { }; // error + class_10.prototype.arguments = function () { }; // ok + return class_10; +}()); +// === Static properties on default exported classes === +// name +var TestOnDefaultExportedClass_1; +(function (TestOnDefaultExportedClass_1) { + var StaticName = (function () { + function StaticName() { + } + return StaticName; + }()); +})(TestOnDefaultExportedClass_1 || (TestOnDefaultExportedClass_1 = {})); +var TestOnDefaultExportedClass_2; +(function (TestOnDefaultExportedClass_2) { + var StaticNameFn = (function () { + function StaticNameFn() { + } + StaticNameFn.name = function () { }; // error + StaticNameFn.prototype.name = function () { }; // ok + return StaticNameFn; + }()); +})(TestOnDefaultExportedClass_2 || (TestOnDefaultExportedClass_2 = {})); +// length +var TestOnDefaultExportedClass_3; +(function (TestOnDefaultExportedClass_3) { + var StaticLength = (function () { + function StaticLength() { + } + return StaticLength; + }()); + TestOnDefaultExportedClass_3.StaticLength = StaticLength; +})(TestOnDefaultExportedClass_3 || (TestOnDefaultExportedClass_3 = {})); +var TestOnDefaultExportedClass_4; +(function (TestOnDefaultExportedClass_4) { + var StaticLengthFn = (function () { + function StaticLengthFn() { + } + StaticLengthFn.length = function () { }; // error + StaticLengthFn.prototype.length = function () { }; // ok + return StaticLengthFn; + }()); + TestOnDefaultExportedClass_4.StaticLengthFn = StaticLengthFn; +})(TestOnDefaultExportedClass_4 || (TestOnDefaultExportedClass_4 = {})); +// prototype +var TestOnDefaultExportedClass_5; +(function (TestOnDefaultExportedClass_5) { + var StaticPrototype = (function () { + function StaticPrototype() { + } + return StaticPrototype; + }()); + TestOnDefaultExportedClass_5.StaticPrototype = StaticPrototype; +})(TestOnDefaultExportedClass_5 || (TestOnDefaultExportedClass_5 = {})); +var TestOnDefaultExportedClass_6; +(function (TestOnDefaultExportedClass_6) { + var StaticPrototypeFn = (function () { + function StaticPrototypeFn() { + } + StaticPrototypeFn.prototype = function () { }; // error + StaticPrototypeFn.prototype.prototype = function () { }; // ok + return StaticPrototypeFn; + }()); + TestOnDefaultExportedClass_6.StaticPrototypeFn = StaticPrototypeFn; +})(TestOnDefaultExportedClass_6 || (TestOnDefaultExportedClass_6 = {})); +// caller +var TestOnDefaultExportedClass_7; +(function (TestOnDefaultExportedClass_7) { + var StaticCaller = (function () { + function StaticCaller() { + } + return StaticCaller; + }()); + TestOnDefaultExportedClass_7.StaticCaller = StaticCaller; +})(TestOnDefaultExportedClass_7 || (TestOnDefaultExportedClass_7 = {})); +var TestOnDefaultExportedClass_8; +(function (TestOnDefaultExportedClass_8) { + var StaticCallerFn = (function () { + function StaticCallerFn() { + } + StaticCallerFn.caller = function () { }; // error + StaticCallerFn.prototype.caller = function () { }; // ok + return StaticCallerFn; + }()); + TestOnDefaultExportedClass_8.StaticCallerFn = StaticCallerFn; +})(TestOnDefaultExportedClass_8 || (TestOnDefaultExportedClass_8 = {})); +// arguments +var TestOnDefaultExportedClass_9; +(function (TestOnDefaultExportedClass_9) { + var StaticArguments = (function () { + function StaticArguments() { + } + return StaticArguments; + }()); + TestOnDefaultExportedClass_9.StaticArguments = StaticArguments; +})(TestOnDefaultExportedClass_9 || (TestOnDefaultExportedClass_9 = {})); +var TestOnDefaultExportedClass_10; +(function (TestOnDefaultExportedClass_10) { + var StaticArgumentsFn = (function () { + function StaticArgumentsFn() { + } + StaticArgumentsFn.arguments = function () { }; // error + StaticArgumentsFn.prototype.arguments = function () { }; // ok + return StaticArgumentsFn; + }()); + TestOnDefaultExportedClass_10.StaticArgumentsFn = StaticArgumentsFn; +})(TestOnDefaultExportedClass_10 || (TestOnDefaultExportedClass_10 = {})); diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts similarity index 100% rename from tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts rename to tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts deleted file mode 100644 index 1b93e98dae8..00000000000 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts +++ /dev/null @@ -1,56 +0,0 @@ -// @target: es6 - - -class StaticName { - static name: number; // error - name: string; // ok -} - -class StaticNameFn { - static name() {} // ok - name() {} // ok -} - - -class StaticLength { - static length: number; // error - length: string; // ok -} - -class StaticLengthFn { - static length() {} // ok - length() {} // ok -} - - -class StaticPrototype { - static prototype: number; // error - prototype: string; // ok -} - -class StaticPrototypeFn { - static prototype() {} // error - prototype() {} // ok -} - - -class StaticCaller { - static caller: number; // error - caller: string; // ok -} - -class StaticCallerFn { - static caller() {} // ok - caller() {} // ok -} - - -class StaticArguments { - static arguments: number; // error - arguments: string; // ok -} - -class StaticArgumentsFn { - static arguments() {} // ok - arguments() {} // ok -} From 9b217e31df0898c229619f1e7465225f97ed5720 Mon Sep 17 00:00:00 2001 From: about-code Date: Sat, 14 Jan 2017 16:30:12 +0100 Subject: [PATCH 11/11] Removing es6 method/property distinction. Adding tests with default export and anonymous class expressions. --- src/compiler/checker.ts | 40 ++--- .../staticPropertyNameConflictsEs5.errors.txt | 92 ----------- .../staticPropertyNameConflictsEs5.js | 120 -------------- .../staticPropertyNameConflictsEs6.errors.txt | 80 ---------- .../staticPropertyNameConflictsEs6.js | 89 ----------- .../staticPropertyNameConflicts.ts | 150 +++++++++++++++++- 6 files changed, 155 insertions(+), 416 deletions(-) delete mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt delete mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs5.js delete mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt delete mode 100644 tests/baselines/reference/staticPropertyNameConflictsEs6.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 884860d6b14..da6235b6d1c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15694,8 +15694,8 @@ namespace ts { } /** - * Static members being set on a constructor function may conflict with built-in Function - * object properties. Esp. in ECMAScript 5 there are non-configurable and non-writable + * Static members being set on a constructor function may conflict with built-in properties + * of Function. Esp. in ECMAScript 5 there are non-configurable and non-writable * built-in properties. This check issues a transpile error when a class has a static * member with the same name as a non-writable built-in property. * @@ -15705,37 +15705,21 @@ namespace ts { * @see http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances */ function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { - const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1; - const className = getNameOfSymbol(getSymbolOfNode(node)); for (const member of node.members) { - const isStatic = getModifierFlags(member) & ModifierFlags.Static; - const isMethod = member.kind === SyntaxKind.MethodDeclaration; const memberNameNode = member.name; + const isStatic = getModifierFlags(member) & ModifierFlags.Static; if (isStatic && memberNameNode) { const memberName = getPropertyNameForPropertyNameNode(memberNameNode); - if (languageVersion <= ScriptTarget.ES5) { // ES3, ES5 - if (memberName === "prototype" || - memberName === "name" || - memberName === "length" || - memberName === "caller" || - memberName === "arguments" - ) { + switch (memberName) { + case "name": + case "length": + case "caller": + case "arguments": + case "prototype": + const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1; + const className = getNameOfSymbol(getSymbolOfNode(node)); error(memberNameNode, message, memberName, className); - } - } - else { // ES6+ - if (memberName === "prototype") { - error(memberNameNode, message, memberName, className); - } - else if (( - memberName === "name" || - memberName === "length" || - memberName === "caller" || - memberName === "arguments") && - isMethod === false - ) { - error(memberNameNode, message, memberName, className); - } + break; } } } diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt deleted file mode 100644 index 004365d3e76..00000000000 --- a/tests/baselines/reference/staticPropertyNameConflictsEs5.errors.txt +++ /dev/null @@ -1,92 +0,0 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(4,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(9,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(15,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(20,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(26,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2300: Duplicate identifier 'prototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(37,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(42,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts(53,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. - - -==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs5.ts (11 errors) ==== - - // static name - class StaticName { - static name: number; // error - ~~~~ -!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. - name: string; // ok - } - - class StaticNameFn { - static name() {} // error - ~~~~ -!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'. - name() {} // ok - } - - - class StaticLength { - static length: number; // error - ~~~~~~ -!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. - length: string; // ok - } - - class StaticLengthFn { - static length() {} // error - ~~~~~~ -!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'. - length() {} // ok - } - - - class StaticPrototype { - static prototype: number; // error - ~~~~~~~~~ -!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. - prototype: string; // ok - } - - class StaticPrototypeFn { - static prototype() {} // error - ~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'prototype'. - ~~~~~~~~~ -!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. - prototype() {} // ok - } - - - class StaticCaller { - static caller: number; // error - ~~~~~~ -!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. - caller: string; // ok - } - - class StaticCallerFn { - static caller() {} // error - ~~~~~~ -!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'. - caller() {} // ok - } - - - class StaticArguments { - static arguments: number; // error - ~~~~~~~~~ -!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. - arguments: string; // ok - } - - class StaticArgumentsFn { - static arguments() {} // error - ~~~~~~~~~ -!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'. - arguments() {} // ok - } - \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs5.js b/tests/baselines/reference/staticPropertyNameConflictsEs5.js deleted file mode 100644 index 06d4a011a8e..00000000000 --- a/tests/baselines/reference/staticPropertyNameConflictsEs5.js +++ /dev/null @@ -1,120 +0,0 @@ -//// [staticPropertyNameConflictsEs5.ts] - -// static name -class StaticName { - static name: number; // error - name: string; // ok -} - -class StaticNameFn { - static name() {} // error - name() {} // ok -} - - -class StaticLength { - static length: number; // error - length: string; // ok -} - -class StaticLengthFn { - static length() {} // error - length() {} // ok -} - - -class StaticPrototype { - static prototype: number; // error - prototype: string; // ok -} - -class StaticPrototypeFn { - static prototype() {} // error - prototype() {} // ok -} - - -class StaticCaller { - static caller: number; // error - caller: string; // ok -} - -class StaticCallerFn { - static caller() {} // error - caller() {} // ok -} - - -class StaticArguments { - static arguments: number; // error - arguments: string; // ok -} - -class StaticArgumentsFn { - static arguments() {} // error - arguments() {} // ok -} - - -//// [staticPropertyNameConflictsEs5.js] -// static name -var StaticName = (function () { - function StaticName() { - } - return StaticName; -}()); -var StaticNameFn = (function () { - function StaticNameFn() { - } - StaticNameFn.name = function () { }; // error - StaticNameFn.prototype.name = function () { }; // ok - return StaticNameFn; -}()); -var StaticLength = (function () { - function StaticLength() { - } - return StaticLength; -}()); -var StaticLengthFn = (function () { - function StaticLengthFn() { - } - StaticLengthFn.length = function () { }; // error - StaticLengthFn.prototype.length = function () { }; // ok - return StaticLengthFn; -}()); -var StaticPrototype = (function () { - function StaticPrototype() { - } - return StaticPrototype; -}()); -var StaticPrototypeFn = (function () { - function StaticPrototypeFn() { - } - StaticPrototypeFn.prototype = function () { }; // error - StaticPrototypeFn.prototype.prototype = function () { }; // ok - return StaticPrototypeFn; -}()); -var StaticCaller = (function () { - function StaticCaller() { - } - return StaticCaller; -}()); -var StaticCallerFn = (function () { - function StaticCallerFn() { - } - StaticCallerFn.caller = function () { }; // error - StaticCallerFn.prototype.caller = function () { }; // ok - return StaticCallerFn; -}()); -var StaticArguments = (function () { - function StaticArguments() { - } - return StaticArguments; -}()); -var StaticArgumentsFn = (function () { - function StaticArgumentsFn() { - } - StaticArgumentsFn.arguments = function () { }; // error - StaticArgumentsFn.prototype.arguments = function () { }; // ok - return StaticArgumentsFn; -}()); diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt deleted file mode 100644 index 607735bb12f..00000000000 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt +++ /dev/null @@ -1,80 +0,0 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(4,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(15,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. -tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. - - -==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== - - - class StaticName { - static name: number; // error - ~~~~ -!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. - name: string; // ok - } - - class StaticNameFn { - static name() {} // ok - name() {} // ok - } - - - class StaticLength { - static length: number; // error - ~~~~~~ -!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. - length: string; // ok - } - - class StaticLengthFn { - static length() {} // ok - length() {} // ok - } - - - class StaticPrototype { - static prototype: number; // error - ~~~~~~~~~ -!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. - prototype: string; // ok - } - - class StaticPrototypeFn { - static prototype() {} // error - ~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'prototype'. - ~~~~~~~~~ -!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. - prototype() {} // ok - } - - - class StaticCaller { - static caller: number; // error - ~~~~~~ -!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'. - caller: string; // ok - } - - class StaticCallerFn { - static caller() {} // ok - caller() {} // ok - } - - - class StaticArguments { - static arguments: number; // error - ~~~~~~~~~ -!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. - arguments: string; // ok - } - - class StaticArgumentsFn { - static arguments() {} // ok - arguments() {} // ok - } - \ No newline at end of file diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.js b/tests/baselines/reference/staticPropertyNameConflictsEs6.js deleted file mode 100644 index 7adef10b141..00000000000 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.js +++ /dev/null @@ -1,89 +0,0 @@ -//// [staticPropertyNameConflictsEs6.ts] - - -class StaticName { - static name: number; // error - name: string; // ok -} - -class StaticNameFn { - static name() {} // ok - name() {} // ok -} - - -class StaticLength { - static length: number; // error - length: string; // ok -} - -class StaticLengthFn { - static length() {} // ok - length() {} // ok -} - - -class StaticPrototype { - static prototype: number; // error - prototype: string; // ok -} - -class StaticPrototypeFn { - static prototype() {} // error - prototype() {} // ok -} - - -class StaticCaller { - static caller: number; // error - caller: string; // ok -} - -class StaticCallerFn { - static caller() {} // ok - caller() {} // ok -} - - -class StaticArguments { - static arguments: number; // error - arguments: string; // ok -} - -class StaticArgumentsFn { - static arguments() {} // ok - arguments() {} // ok -} - - -//// [staticPropertyNameConflictsEs6.js] -class StaticName { -} -class StaticNameFn { - static name() { } // ok - name() { } // ok -} -class StaticLength { -} -class StaticLengthFn { - static length() { } // ok - length() { } // ok -} -class StaticPrototype { -} -class StaticPrototypeFn { - static prototype() { } // error - prototype() { } // ok -} -class StaticCaller { -} -class StaticCallerFn { - static caller() { } // ok - caller() { } // ok -} -class StaticArguments { -} -class StaticArgumentsFn { - static arguments() { } // ok - arguments() { } // ok -} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts index 5eb09ddb2d3..86755cb016d 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts @@ -1,6 +1,5 @@ -// @target: es5 - -// static name +// @target: es5 +// name class StaticName { static name: number; // error name: string; // ok @@ -11,7 +10,7 @@ class StaticNameFn { name() {} // ok } - +// length class StaticLength { static length: number; // error length: string; // ok @@ -22,7 +21,7 @@ class StaticLengthFn { length() {} // ok } - +// prototype class StaticPrototype { static prototype: number; // error prototype: string; // ok @@ -33,7 +32,7 @@ class StaticPrototypeFn { prototype() {} // ok } - +// caller class StaticCaller { static caller: number; // error caller: string; // ok @@ -44,7 +43,7 @@ class StaticCallerFn { caller() {} // ok } - +// arguments class StaticArguments { static arguments: number; // error arguments: string; // ok @@ -54,3 +53,140 @@ class StaticArgumentsFn { static arguments() {} // error arguments() {} // ok } + + + +// === Static properties on anonymous classes === + +// name +var StaticName_Anonymous = class { + static name: number; // error + name: string; // ok +} + +var StaticNameFn_Anonymous = class { + static name() {} // error + name() {} // ok +} + +// length +var StaticLength_Anonymous = class { + static length: number; // error + length: string; // ok +} + +var StaticLengthFn_Anonymous = class { + static length() {} // error + length() {} // ok +} + +// prototype +var StaticPrototype_Anonymous = class { + static prototype: number; // error + prototype: string; // ok +} + +var StaticPrototypeFn_Anonymous = class { + static prototype() {} // error + prototype() {} // ok +} + +// caller +var StaticCaller_Anonymous = class { + static caller: number; // error + caller: string; // ok +} + +var StaticCallerFn_Anonymous = class { + static caller() {} // error + caller() {} // ok +} + +// arguments +var StaticArguments_Anonymous = class { + static arguments: number; // error + arguments: string; // ok +} + +var StaticArgumentsFn_Anonymous = class { + static arguments() {} // error + arguments() {} // ok +} + + +// === Static properties on default exported classes === + +// name +module TestOnDefaultExportedClass_1 { + class StaticName { + static name: number; // error + name: string; // ok + } +} + +module TestOnDefaultExportedClass_2 { + class StaticNameFn { + static name() {} // error + name() {} // ok + } +} + +// length +module TestOnDefaultExportedClass_3 { + export default class StaticLength { + static length: number; // error + length: string; // ok + } +} + +module TestOnDefaultExportedClass_4 { + export default class StaticLengthFn { + static length() {} // error + length() {} // ok + } +} + +// prototype +module TestOnDefaultExportedClass_5 { + export default class StaticPrototype { + static prototype: number; // error + prototype: string; // ok + } +} + +module TestOnDefaultExportedClass_6 { + export default class StaticPrototypeFn { + static prototype() {} // error + prototype() {} // ok + } +} + +// caller +module TestOnDefaultExportedClass_7 { + export default class StaticCaller { + static caller: number; // error + caller: string; // ok + } +} + +module TestOnDefaultExportedClass_8 { + export default class StaticCallerFn { + static caller() {} // error + caller() {} // ok + } +} + +// arguments +module TestOnDefaultExportedClass_9 { + export default class StaticArguments { + static arguments: number; // error + arguments: string; // ok + } +} + +module TestOnDefaultExportedClass_10 { + export default class StaticArgumentsFn { + static arguments() {} // error + arguments() {} // ok + } +} \ No newline at end of file