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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[[FIX]] Computed names for object getters and setters #2993
base: main
Are you sure you want to change the base?
Conversation
src/jshint.js
Outdated
@@ -3236,7 +3236,13 @@ var JSHINT = (function() { | |||
error("E034"); | |||
} | |||
|
|||
i = propertyName(); | |||
// Checks if the getter and/or setter is a computed name by | |||
// checking that the next value of the getter and/or setter is a [. |
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.
This comment is a bit literal; on its own, the code already communicates this information.
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.
Thank you, will remove.
Thanks for the patch! In // jshint esversion: 6
var o = {
get [1](),
get [2]()
}; ...but the proposed solution triggers the following:
Relatedly, the following code produces the expected errors, but the messages // jshint esversion: 6
var o = {
get [2](x) {},
set [2]() {}
}; Errors:
We should also make sure that the long-deprecated |
c221d41
to
521ef75
Compare
@jugglinmike took some thought with your comments and this is what I have came up with and would like your feedback.
When running this snippet of code, I am now only getting these errors which is I believe the correct implementation and expected result.
I changed the logic a bit around in order to give QUESTION: Your last comment asks to make sure with this path we continue to support the members functionality, which is deprecated. I cannot find anywhere online where people are using examples of members to ensure this is accounted for correctly. In addition, the docs specify Thank you and let me know your thoughts. |
@jugglinmike was just checking in to see if you had any additional feedback for this PR. Thank you |
Not yet :) |
This is closer, but it's still not quite done. Take a closer look at the return ({
get [a]() {},
get a() {},
get [1 + 2]() {},
get '+'() {}
}); This code does not necessarily produce any duplicate keys, so JSHint should not Basically, if We'll also need dedicated tests for the edge cases I've mentioned so far. Would As for /* members abc */
({
get ['a' + 'b' + 'c'](), // <-- this is fine: no warning
get ['d'](), // <-- violation: warn about "d"
get [a]() // <-- we can't know if this is okay: no warning
}); Thanks for your hard work and your patience! |
@jugglinmike thanks for the input, will continue on with your feedback and yes will write tests for the edge cases we have been discussing. Will let you know if I have any questions while looking into updating my changes |
@jugglinmike been looking into This makes me think I'll need to adjust the Also, in my most recent code push, I tried assigning I am just confirming that I am thinking about this correctly and not overthinking this because having Thanks you for working through this. |
You're right; some of the previously-existing call sites for
Really, though, I think we can tackle this through I haven't dug into this very deeply, though, so there may be some requirement If this has become more than you have time for, then don't hesitate to let me |
@jugglinmike Think I got it! Writing tests and comments, will have the updated PR ready for review tomorrow! thanks |
Added logic in src/jshint.js that checks the next value of a getter and/or setter in ES6, if the next value is an open bracket [, then we assign a variable to the already implemented computedPropertyName, and if thats not the next character we call propertyName(), which was originally the only function call that was being assigned to i.
521ef75
to
1a2661d
Compare
@jugglinmike updated with most recent changes, comments, member support, and testing. In my PR, on line 4923, I checked if the type of value is not a string and then, assigned
I checked if
That being said, i dont know if its wise to allow users to have numbers or numeric string values as getter or setter properties without a warning or error. Per the MDN documentation, it seems like the only values given as examples are strings with chars Please let me know your thoughts on the PR and if you have any feedback on the implementation, tests, or JSDoc comments. Thank you! |
The logic that evaluates the expression in this latest patch isn't quite right: if (value.right.type !== "(string)" && value.left.type !== "(string)") {
var currValue = value;
value.value = value.left + currValue.value + value.right;
} In the above code, We could continue to refine this approach to allow JSHint to statically I'm sticking with the recommendation in my previous comments: when It's great to see more documentation! However, JSDoc comments such as the ones |
Thanks, removed the logic and just have:
inside of I have adjusted the comments, now I have a few tests breaking because I am returning null if it is not a string literal and then JS throws an error because it cannot read property Ill work through this and make sure I have all tests passing then I will repush. Thank you for your patience and working through this with me. |
Added logic in src/jshint.js that checks the next value of a getter and/or setter in ES6 so errors will not be thrown if a developer writes getters and/or setters in their JS file, if the next value is an open bracket [, then we assign a variable to the already implemented computedPropertyName, and if thats not the next character we call propertyName(), which was originally the only function call that was being assigned to i.
This issue fixes #2871