-
Notifications
You must be signed in to change notification settings - Fork 25
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
Rewrite PathExpression
visitor code
#62
Conversation
Instead of having a single visitor for `PathExpression` it is more useful to know if it is the path of a simple mustache, a block, a modifier, etc. Depending on the parent element we can assume certain things, e.g. inside an `AttrNode` the mustache path can't be a component invocation. This rewrite also fixes the wrong priority order where properties had priority over components and helpers, which is different in an actual app. If a component/helper with a corresponding name is found than the prefixing will be skipped. This removes the reliance on `getTelemetryFor()` which helps bring us closer to "pods" support. Due to the different implementation this also removes the `dontAssumeThis` option from the codemod.
@@ -1,3 +0,0 @@ | |||
{ | |||
"dontAssumeThis": true |
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.
why remove this behavior/test?
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.
a path can only be either:
- a property
- a scoped variable
- a component invocation
- a helper invocation
if it is not a component/helper invocation and not a scoped variable then there is only "property" left. if we use dontAssumeThis: true
in what case would we then prefix the path with this.
?
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.
good point. that would be confusing. I think I'll have to do a major bump, just in case though.
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 think I'll have to do a major bump, just in case though.
yeah, totally agree. I'd wait a bit though so that people can try it out from master
, and I might have a few more PRs coming in... 😅
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'd wait a bit though
too late!
I have no problem with multiple releases or multiple breaking releases even.
release-it is my favorite tool for this stuff. so easy.
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.
So we were actually using this functionality 😬 but if it's not deemed useful then 🔪
For our use case, while we know that passed in args are reflected onto a classic component and all its properties can be referenced using this.
, we actually didn't want to do just migrate all properties in our templates to this.
. We wanted to try and semantically migrate our templates to properly disambiguate between this.
vs @
properties.
Our process for this was
- Run this codemod on said template
- Turn on
no-implicit-this
ember-template-lint rule - Any properties which didn't have
this.
prepended to them we'd manually fix on a case-by-case basis depending on whether the property existing in the JS (i.e.this.set('someProperty', ...)
) or just passed directly in.
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 think that's def a valid workflow, and should maybe be called out in the readme on this repo. @patocallaghan (or really anyone), a PR to add don't-assume-this back in would be worthwhile.
however, I keep forgetting, if you don't-assume-this, does the codemod do anything?
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.
no, in that case the codemod would literally do nothing, so I'm not sure if it's actually that useful 🤔
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.
So when we say it literally did nothing, before the default behaviour was always to append this.
but with this option it just opted you out of that and it left the property as is if it didn't find it in the component's telemetry. It was then on you to manually figure out if it was this.
or @
.
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.
that makes sense. We've had some issues with getting property information in telemetry from all the different types of classes / ember versions / ways of constructing "Meta". :(
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 good to me, just a couple questions.
Instead of having a single visitor for
PathExpression
it is more useful to know if it is the path of a simple mustache, a block, a modifier, etc.Depending on the parent element we can assume certain things, e.g. inside an
AttrNode
the mustache path can't be a component invocation.This rewrite also fixes the wrong priority order where properties had priority over components and helpers, which is different in an actual app. If a component/helper with a corresponding name is found than the prefixing will be skipped. This removes the reliance on
getTelemetryFor()
which helps bring us closer to "pods" support.Due to the different implementation this also removes the
dontAssumeThis
option from the codemod.