Impossible to define static 'length' function on class#9215
Impossible to define static 'length' function on class#9215plantain-00 wants to merge 2 commits into
Conversation
| checkNameOfStaticMethodOrPropertyInClass(node); | ||
| } | ||
|
|
||
| function checkNameOfStaticMethodOrPropertyInClass(node: ClassElement) { |
There was a problem hiding this comment.
I would consider this as grammar check -> like call it checkGrammarStaticPropertyName
There was a problem hiding this comment.
We should do this in a more generic fashion and not hard code the names. we should use the Function type and make sure we are not redefining any of the properties there. possibly readonly ones only. this way users can add/remove some of these checks.
|
Thank you for the PR @plantain-00 ! Additional comment is that I believe there need to be distinction between static property and static method declaration when users target ES5, ES6
EDIT: i make an inline edit, as my original comment is incorrect |
|
Regardless of the previous comment, @vladima points out that this rule should be extended to "ComputedProperty" with string literal of the value: length, name, arguments, caller Could you add additional tests for such case? |
|
@yuit class C {
static caller = { // error: caller
[name]: "abc", // error: name
[length]: 1, // error: length
};
} |
|
@plantain-00 almost but using string literal instead. In your example, it is an expression class C {
static caller = { // error: caller
["name"]: "abc", // error: name
["length"]: 1, // error: length
};
} |
6d94928 to
12e2118
Compare
|
any comments? |
|
@yuit sorry I missed my ping. Confirming that this change is correct, length, arguments, caller, and name are all valid static method names in ES6. |
| !!! error TS2690: 'caller' is not allowed to be used as a name of a static property or method in a class. | ||
| static foo = { | ||
| ["length"]: 1, | ||
| ~~~~~~~~~~ |
There was a problem hiding this comment.
There is a comment(above) from yuit:
this rule should be extended to "ComputedProperty" with string literal of the value: length, name, arguments, caller
dceba92 to
f8366b6
Compare
|
any comments? |
|
Fixed by #12065 |
Fixes #442