@@ -2142,24 +2142,25 @@ namespace ts {
2142
2142
return type.flags & TypeFlags.StringLiteral ? `"${escapeString((<LiteralType>type).text)}"` : (<LiteralType>type).text;
2143
2143
}
2144
2144
2145
- function getSymbolDisplayBuilder(): SymbolDisplayBuilder {
2146
2145
2147
- function getNameOfSymbol(symbol: Symbol): string {
2148
- if (symbol.declarations && symbol.declarations.length) {
2149
- const declaration = symbol.declarations[0];
2150
- if (declaration.name) {
2151
- return declarationNameToString(declaration.name);
2152
- }
2153
- switch (declaration.kind) {
2154
- case SyntaxKind.ClassExpression:
2155
- return "(Anonymous class)";
2156
- case SyntaxKind.FunctionExpression:
2157
- case SyntaxKind.ArrowFunction:
2158
- return "(Anonymous function)";
2159
- }
2146
+ function getNameOfSymbol(symbol: Symbol): string {
2147
+ if (symbol.declarations && symbol.declarations.length) {
2148
+ const declaration = symbol.declarations[0];
2149
+ if (declaration.name) {
2150
+ return declarationNameToString(declaration.name);
2151
+ }
2152
+ switch (declaration.kind) {
2153
+ case SyntaxKind.ClassExpression:
2154
+ return "(Anonymous class)";
2155
+ case SyntaxKind.FunctionExpression:
2156
+ case SyntaxKind.ArrowFunction:
2157
+ return "(Anonymous function)";
2160
2158
}
2161
- return symbol.name;
2162
2159
}
2160
+ return symbol.name;
2161
+ }
2162
+
2163
+ function getSymbolDisplayBuilder(): SymbolDisplayBuilder {
2163
2164
2164
2165
/**
2165
2166
* Writes only the name of the symbol out to the writer. Uses the original source text
@@ -15647,20 +15648,27 @@ namespace ts {
15647
15648
}
15648
15649
}
15649
15650
15650
- // Static members may conflict with non-configurable non-writable built-in Function object properties
15651
- // see https://github.com/microsoft/typescript/issues/442.
15651
+ /**
15652
+ * Static members being set on a constructor function may conflict with built-in Function
15653
+ * object properties. Esp. in ECMAScript 5 there are non-configurable and non-writable
15654
+ * built-in properties. This check issues a transpile error when a class has a static
15655
+ * member with the same name as a non-writable built-in property.
15656
+ *
15657
+ * @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3
15658
+ * @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5
15659
+ * @see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor
15660
+ * @see http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances
15661
+ */
15652
15662
function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) {
15653
15663
const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1;
15654
- const className = getSymbolOfNode(node).name ;
15664
+ const className = getNameOfSymbol( getSymbolOfNode(node)) ;
15655
15665
for (const member of node.members) {
15656
- const isStatic = forEach (member.modifiers, (m: Modifier) => m.kind === SyntaxKind.StaticKeyword) ;
15666
+ const isStatic = getModifierFlags (member) & ModifierFlags.Static ;
15657
15667
const isMethod = member.kind === SyntaxKind.MethodDeclaration;
15658
15668
const memberNameNode = member.name;
15659
15669
if (isStatic && memberNameNode) {
15660
15670
const memberName = getPropertyNameForPropertyNameNode(memberNameNode);
15661
15671
if (languageVersion <= ScriptTarget.ES5) { // ES3, ES5
15662
- // see also http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3
15663
- // see also http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5
15664
15672
if (memberName === "prototype" ||
15665
15673
memberName === "name" ||
15666
15674
memberName === "length" ||
@@ -15671,8 +15679,6 @@ namespace ts {
15671
15679
}
15672
15680
}
15673
15681
else { // ES6+
15674
- // see also http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor
15675
- // see also http://www.ecma-international.org/ecma-262/6.0/#sec-function-instances
15676
15682
if (memberName === "prototype") {
15677
15683
error(memberNameNode, message, memberName, className);
15678
15684
}
0 commit comments