New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed bug - Certain static member names cannot be used due to non overridable member names on the constructor function type. #5396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,13 @@ namespace ts { | |
} | ||
}; | ||
|
||
const reservedStaticPropertyNames: { [key: string]: string } = { | ||
length: "length", | ||
arguments: "arguments", | ||
caller: "caller", | ||
name: "name" | ||
}; | ||
|
||
const JsxNames = { | ||
JSX: "JSX", | ||
IntrinsicElements: "IntrinsicElements", | ||
|
@@ -15082,6 +15089,9 @@ namespace ts { | |
break; | ||
|
||
case SyntaxKind.StaticKeyword: | ||
if (node.kind === SyntaxKind.Identifier && reservedStaticPropertyNames[node.symbol.name]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this makes static declarations with name "toString" for instance illegal, if you are using a map, use |
||
return grammarErrorOnNode(node, Diagnostics._0_cannot_be_used_as_a_static_member_identifier, node.symbol.name); | ||
} | ||
if (flags & NodeFlags.Static) { | ||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "static"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1724,6 +1724,10 @@ | |
"category": "Error", | ||
"code": 2657 | ||
}, | ||
"'{0}' cannot be used as a static member identifier.": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need a lit bit more information here; preferably something that will point that classes constructors are inherently functions. something like:
|
||
"category":"Error", | ||
"code": 2658 | ||
}, | ||
"Import declaration '{0}' is using private name '{1}'.": { | ||
"category": "Error", | ||
"code": 4000 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//// [reservedNameWithStaticProperty.ts] | ||
class Length { | ||
static length: string = "pizza"; | ||
} | ||
|
||
class Caller { | ||
static caller: string = "potatos"; | ||
} | ||
|
||
class Arguments { | ||
static arguments: string = "tomatoes" | ||
} | ||
|
||
class Name { | ||
static name: string = "name" | ||
} | ||
|
||
//// [reservedNameWithStaticProperty.js] | ||
var Length = (function () { | ||
function Length() { | ||
} | ||
Length.length = "pizza"; | ||
return Length; | ||
})(); | ||
var Caller = (function () { | ||
function Caller() { | ||
} | ||
Caller.caller = "potatos"; | ||
return Caller; | ||
})(); | ||
var Arguments = (function () { | ||
function Arguments() { | ||
} | ||
Arguments.arguments = "tomatoes"; | ||
return Arguments; | ||
})(); | ||
var Name = (function () { | ||
function Name() { | ||
} | ||
Name.name = "name"; | ||
return Name; | ||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
=== tests/cases/compiler/reservedNameWithStaticProperty.ts === | ||
class Length { | ||
>Length : Symbol(Length, Decl(reservedNameWithStaticProperty.ts, 0, 0)) | ||
|
||
static length: string = "pizza"; | ||
>length : Symbol(Length.length, Decl(reservedNameWithStaticProperty.ts, 0, 14)) | ||
} | ||
|
||
class Caller { | ||
>Caller : Symbol(Caller, Decl(reservedNameWithStaticProperty.ts, 2, 1)) | ||
|
||
static caller: string = "potatos"; | ||
>caller : Symbol(Caller.caller, Decl(reservedNameWithStaticProperty.ts, 4, 14)) | ||
} | ||
|
||
class Arguments { | ||
>Arguments : Symbol(Arguments, Decl(reservedNameWithStaticProperty.ts, 6, 1)) | ||
|
||
static arguments: string = "tomatoes" | ||
>arguments : Symbol(Arguments.arguments, Decl(reservedNameWithStaticProperty.ts, 8, 17)) | ||
} | ||
|
||
class Name { | ||
>Name : Symbol(Name, Decl(reservedNameWithStaticProperty.ts, 10, 1)) | ||
|
||
static name: string = "name" | ||
>name : Symbol(Name.name, Decl(reservedNameWithStaticProperty.ts, 12, 12)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/compiler/reservedNameWithStaticProperty.ts === | ||
class Length { | ||
>Length : Length | ||
|
||
static length: string = "pizza"; | ||
>length : string | ||
>"pizza" : string | ||
} | ||
|
||
class Caller { | ||
>Caller : Caller | ||
|
||
static caller: string = "potatos"; | ||
>caller : string | ||
>"potatos" : string | ||
} | ||
|
||
class Arguments { | ||
>Arguments : Arguments | ||
|
||
static arguments: string = "tomatoes" | ||
>arguments : string | ||
>"tomatoes" : string | ||
} | ||
|
||
class Name { | ||
>Name : Name | ||
|
||
static name: string = "name" | ||
>name : string | ||
>"name" : string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Length { | ||
static length: string = "pizza"; | ||
} | ||
|
||
class Caller { | ||
static caller: string = "potatos"; | ||
} | ||
|
||
class Arguments { | ||
static arguments: string = "tomatoes" | ||
} | ||
|
||
class Name { | ||
static name: string = "name" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map<string>