-
Notifications
You must be signed in to change notification settings - Fork 378
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
Add "doc" origin to the boolean, string, number type which was created by JSDoc. #542
Conversation
This PR gives the capability to know if a type is created from a comment or not. In my case I need this information to support validation with comments angelozerr/tern-lint#30
This PR add the doc origin to the bool, string and number type, to know that boolean, string, number type type comes the JSDoc. This PR should be improved with typedef type.
This is not a solution to the problem you are trying to solve. You'll have the same issue with other types that the JSDoc module does not own -- types are shared, and stuffing properties in them is a bad idea. You'll also prevent the inferer from noticing that your number type and the built-in one are the same, resulting in types like Also, if you can't even bother to make the test suite run before submitting a pull request, please don't submit it at all. |
My main need is to improve tern-lint validation by using JSDoc like angelozerr/tern-lint#31 When I wish to validate a node, I have an array of types which comes from JSDoc, JSON Type Definition or from JS code, so I don't know how to know if type comes from JSDoc or other mean. If you have time, could you give me some directive please, thanks!
I agree with you, I have done that, because I'm experimenting a solution to know the origin of the type. But I will do it next time. |
Tern has no framework for doing what you are trying to do here, and I can't think of a solution that wouldn't require big changes to the way it works. |
Ok that's very shame -( Thanks for your answer. |
@marijnh I disturb you again and I after I stop it. In my case I need to have the result type computed by your jsdocInterpretComments function of doc_comments.js stored in the aval. In other words I need to store a new docTypes field in the aval target : function propagateWithWeight(type, target) {
target.docTypes = type;
var weight = infer.cx().parent._docComment.weight;
type.type.propagate(target, weight || (type.madeUp ? WG_MADEUP : undefined));
} Are you agree to do add this new docTypes field according a new option. If you are OK, I will do a patch. |
That looks harmless enough. If you make it an option to the doc_comment mode, I'd accept such a pull request. |
Thanks @marijnh! Before doing that, I must investigate if it will work for my case. I find limitation with this solution when variable is assigned. /**
* @type {Boolean}
*/
var test
test = 'hello' // here I can retrieve that test has JSDoc boolean /**
* @type {Boolean}
*/
var test
var test1 = test
test1 = 'hello' // here I can NOT retrieve that test1 has JSDoc boolean |
@marijnh for your information, since I have discovered the I will able to support multiple types validation if #557 could be fixed ( a strong option for JSON Type Definition like JSDoc). |
This PR add the "doc" origin to the bool, string and number type, to know that boolean, string, number type was created by the JSDoc.
This PR should be improved for @typedef.
This info can be very helpfull for :