-
Notifications
You must be signed in to change notification settings - Fork 47
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
Class annotation support #270
Conversation
…s that appear before a class keyword
Good catch - though annotations shouldn't normally be added from inside the statement readers normally. I need to check. |
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.
Looks simple enough to me. I have requested two small changes, but then it's good to go..
src/parser/Parser.ts
Outdated
@@ -460,6 +463,12 @@ export class Parser { | |||
parentClassName, | |||
this.currentNamespaceName | |||
); | |||
|
|||
//attach annotations to statements | |||
if (classAnnotations?.length) { |
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.
While this technically works due to javascripts truthy/falsey, let's check for length > 0
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.
I got this from other code in the project.. I didn't like it; but I thought it was idiomatic
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.
Test should be
if (classAnnotations.length > 0) {
and we can merge - I'll complete some other things.
Got a couple of questions about this. @elsassph says this is working out the box as it stands. I didn't get that behaviour with the above unit test so I'm confused. Secondly I've been told that this should be implemented with refactoring the parser. Don't have time to do that. Can we just make it work for the time being for classes and class methods and do whatever refactoring later? The feature is half baked as it is imho. |
I think I've covered everything here - see tests. |
I think this is good to go now. I addressed both of your feedback and merged current master. |
Adds annotation support for classes, attaching any pending annotation…s that appear before a class keyword
@elsassph inspired (i.e goaded) me to add annotation support for maestro, perhaps knowing that this feature was missing and I would therefore have to write it :D Great delegation @elsassph 👏
Hopefully this approach is okay - I'm sure we all concur that annotations are just as usefu on classes as other statements.