This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
[WIP] precompileTemplate with scope that has properties with different key and value #486
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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-hbmlbars-inline-precompile 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: