-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement this-fallback-plugin #1
Conversation
820fa6a
to
5d45656
Compare
7108521
to
624006e
Compare
1a167b7
to
18e04c1
Compare
03d45eb
to
b8c84a9
Compare
@@ -78,10 +83,12 @@ | |||
"eslint-plugin-n": "^15.7.0", | |||
"eslint-plugin-qunit": "^7.3.4", | |||
"eslint-plugin-unicorn": "^46.0.0", | |||
"jest": "^29.5.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 tried vitest first but the types in the current version are whack and I got impatient waiting for them to fix it.
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.
Interesting! You found the types in jest
to be better than vitest
?
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.
Not really. The latest vitest
version had a bunch of type bugs in it (I found related issues but don't remember what it was now) and rather than wait for them to fix and ship, I just switched to jest
since the API is basically the same. Might be fixed now. I just put this comment here bc I knew you were going to suggest trying vitest
. :-P
a976f74
to
14ffb36
Compare
14ffb36
to
05e5a9c
Compare
8846032
to
d3afa64
Compare
d3afa64
to
f81eb6b
Compare
3887d0c
to
bf9bc75
Compare
app/is-helper.js
Outdated
@@ -0,0 +1 @@ | |||
export { default } from 'ember-this-fallback/is-helper'; |
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'm not sure if these re-exports are:
- used, or
- correct
bf9bc75
to
fcc4589
Compare
fcc4589
to
ea2a614
Compare
await render( | ||
hbs`{{if (this-fallback/is-helper "global-helper") "true" "false"}}` | ||
); | ||
await render(<template> |
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.
IDK how I would have tested this w/o ember-template-imports...fun stuff
"test:ember": "yarn build:ts && ember test && yarn clean", | ||
"test:ember-compatibility": "yarn build:ts && ember try:each", | ||
"prepack": "yarn build:ts && ember ts:precompile", | ||
"postpack": "yarn clean && ember ts:clean" | ||
}, | ||
"dependencies": { | ||
"babel-plugin-ember-template-compilation": "^2.0.2", |
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 only use this for types. devDependency?
@@ -70,6 +77,7 @@ | |||
"ember-resolver": "^10.0.0", | |||
"ember-source": "~4.11.0", | |||
"ember-source-channel-url": "^3.0.0", | |||
"ember-template-imports": "^3.4.2", |
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.
only used in tests
3ac6df3
to
0da7935
Compare
0da7935
to
6bfdc5c
Compare
How It Works
The addon registers an ember-cli-htmlbars plugin that traverses the nodes in your Ember templates and transforms them using the following logic:
For each
PathExpression
with aVarHead
that is NOT in the local template scope:If it is within
node.params
or anode.hash
value for aCallNode
(MustacheStatement | BlockStatement | ElementModifierStatement | SubExpression
):Prefix the
head
withthis
, making it aThisHead
("expression fallback").For example:
If is the
path
for aMustacheStatement
with NO params or hash:If there is a
tail
:Prefix the
head
withthis
, making it aThisHead
("expression fallback").If there is NO
tail
:If the
MustacheStatement
is the child of anAttrNode
with a name NOT starting with@
:Wrap the invocation with the
tryLookupHelper
helper to determine if it is a helper at runtime and fall back to thethis
property if not ("ambiguous attribute fallback").Otherwise:
Wrap the invocation with the
isComponent
helper to determine if it is a component at runtime and invoke it as a component if so. If not, wrap the invocation with thetryLookupHelper
helper to determine if it is a helper ad runtime and fall back to thethis
property if not ("ambiguous statement fallback").Caveats
Runtime implications
The
isComponent
andtryLookupHelper
helpers have runtime implications that may have performance impacts. Thus, we recommend relying on this addon only temporarily to unblock 4.0+ upgrades while continuing to migrate away from reliance on the Property Fallback Lookup feature.Embroider compatibility
In the "ambiguous attribute fallback" and "ambiguous statement fallback" cases shown above, we fall back to dynamic resolution at runtime to determine if the contents of the mustache statement point to a helper, a component, or a property on
this
. This technique is fundamentally incompatible with Embroider "optimized" mode, specifically thestaticHelpers
andstaticComponents
configs (and thus,splitAtRoutes
), which requires that helpers are resolvable at build-time.Thus, in these cases, we log a warning to
ember-this-fallback-plugin.log
. If you wish to use Embroider's "optimized" mode, we recommend manually updating the code in these cases to either:or
or
In the future, we could resolve this incompatibility if we had access to Embroider's static resolution.