-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
PrecompileTemplate with scope that has properties with different key and value #17
Conversation
92b02a9
to
37ae38a
Compare
edb3829
to
25a6b1e
Compare
I agree we need to make this case legal. I don't think this is the right implementation. We should be able to handle the remapping entirely at build time with no runtime closure. Since we already parse the ember template compiler's output expression into an AST, we could precisely modify that AST to replace the inner identifiers with the outer identifiers. |
src/ember-template-compiler.ts
Outdated
@@ -21,6 +21,7 @@ export interface PreprocessOptions { | |||
mode?: 'codemod' | 'precompile'; | |||
strictMode?: boolean; | |||
locals?: string[]; | |||
localsWithNames?: { [key: string]: string }; |
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.
The intent of this type was to reflect the real params that the ember template compiler accepts. We can't just add new stuff here.
It's fine to introduce a new type instead for stuff that we handle entirely in this project and never pass into ember-template-compiler.
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, I am going to address this issue.
Thank you for the suggestion. I am going to modify that AST. |
03bf8d2
to
6936f1e
Compare
Thanks. I made three changes on top of yours.
|
Released in 2.0.1 |
Background
This PR solves a bug in
precompileTemplate
scope.precompileTemplate
expects that the scope is a function that returns an object with a few properties where keys and values are equal, as in the following example.But when the project is built with the rollup, imports can be renamed. For example,
Select
can be renamed toSelect$1
, as shown in the following example.From a javascript point of view, everything is correct, and both examples are equivalent. But the second example will fail with an error.
I have created a simple example where you can see how an import is renamed by rollup and then there is a problem
Solution
When a GJS component is built in V2 addon, there is precompileTemplate function in the file in the dist dir. Imported components used in scope can be renamed by Rollup and then properties have different keys and values as shown below:
When the application is built, the ember-auto-import loads V2 addons with babel-plugin-ember-template-compilation and replaces the precompileTemplate with _createTemplateFactory as shown below:
The problem is that the scope arrow function returns the original names of the properties. It can be solved by wrapping glimmer wire format in a closure function shown below: