Skip to content

Commit

Permalink
fix babel plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Jun 10, 2024
1 parent 4696562 commit 850e915
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions lib/babel-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ class HotAstProcessor {
return;
if (original?.includes('.')) return;
if (!original) return;
const param = glimmer.builders.path(`${importVar}.${original}`);
parent.params.splice(0, 1, param);
importBindings.add(original);

if (findImport(original)) {
const param = glimmer.builders.path(`${importVar}.${original}`);
parent.params.splice(0, 1, param);
importBindings.add(original);
}
return;
}
if (importVar) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-vite-hmr",
"version": "1.4.9",
"version": "1.4.10",
"keywords": [
"ember-addon"
],
Expand Down
11 changes: 7 additions & 4 deletions tests/babel-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('convert template with hot reload helpers', () => {
it('should convert hbs correctly', () => {
const code = `
{{(myhelper)}}
<this.X />
{{component this.X}}
<SomeComponent />
<NamedComponent />
`;
Expand Down Expand Up @@ -71,7 +73,7 @@ describe('convert template with hot reload helpers', () => {
SomeComponent = _init_SomeComponent(this, SomeComponent);
myhelper = _init_myhelper(this, myhelper);
}()
export default precompileTemplate("\\n {{(template__imports__.myhelper)}}\\n <template__imports__.SomeComponent />\\n <template__imports__.NamedComponent />\\n ", {
export default precompileTemplate("\\n {{(template__imports__.myhelper)}}\\n <this.X />\\n {{component this.X}}\\n <template__imports__.SomeComponent />\\n <template__imports__.NamedComponent />\\n ", {
moduleName: 'a.hbs',
scope: () => ({
template__imports__
Expand Down Expand Up @@ -126,13 +128,15 @@ describe('convert template with hot reload helpers', () => {
/*
{{(myhelper)}}
<this.X />
{{component this.X}}
<SomeComponent />
<NamedComponent />
*/
{
"id": "--id--",
"block": "[[[1,\\"\\\\n \\"],[1,[28,[32,0,[\\"myhelper\\"]],null,null]],[1,\\"\\\\n \\"],[8,[32,0,[\\"SomeComponent\\"]],null,null,null],[1,\\"\\\\n \\"],[8,[32,0,[\\"NamedComponent\\"]],null,null,null],[1,\\"\\\\n \\"]],[],false,[]]",
"block": "[[[1,\\"\\\\n \\"],[1,[28,[32,0,[\\"myhelper\\"]],null,null]],[1,\\"\\\\n \\"],[8,[30,0,[\\"X\\"]],null,null,null],[1,\\"\\\\n \\"],[46,[30,0,[\\"X\\"]],null,null,null],[1,\\"\\\\n \\"],[8,[32,0,[\\"SomeComponent\\"]],null,null,null],[1,\\"\\\\n \\"],[8,[32,0,[\\"NamedComponent\\"]],null,null,null],[1,\\"\\\\n \\"]],[],false,[\\"component\\"]]",
"moduleName": "a.hbs",
"scope": () => [template__imports__],
"isStrictMode": false
Expand All @@ -152,8 +156,7 @@ describe('convert template with hot reload helpers', () => {
const T = <template>
<Other />
</template>;
</template>;
<template>
{{(myhelper)}}
{{component SomeComponent}}
Expand Down

0 comments on commit 850e915

Please sign in to comment.