From 850e915df7fa171f0bef001cebf10db198f4ded0 Mon Sep 17 00:00:00 2001 From: patrick Date: Mon, 10 Jun 2024 13:32:45 +0200 Subject: [PATCH] fix babel plugin --- lib/babel-plugin.ts | 9 +++++---- package.json | 2 +- tests/babel-plugin.test.js | 11 +++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/babel-plugin.ts b/lib/babel-plugin.ts index c4af1fb..de955c6 100644 --- a/lib/babel-plugin.ts +++ b/lib/babel-plugin.ts @@ -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) { diff --git a/package.json b/package.json index 48b531e..74971da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-vite-hmr", - "version": "1.4.9", + "version": "1.4.10", "keywords": [ "ember-addon" ], diff --git a/tests/babel-plugin.test.js b/tests/babel-plugin.test.js index 440ae92..c098e0a 100644 --- a/tests/babel-plugin.test.js +++ b/tests/babel-plugin.test.js @@ -13,6 +13,8 @@ describe('convert template with hot reload helpers', () => { it('should convert hbs correctly', () => { const code = ` {{(myhelper)}} + + {{component this.X}} `; @@ -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 \\n \\n ", { + export default precompileTemplate("\\n {{(template__imports__.myhelper)}}\\n \\n {{component this.X}}\\n \\n \\n ", { moduleName: 'a.hbs', scope: () => ({ template__imports__ @@ -126,13 +128,15 @@ describe('convert template with hot reload helpers', () => { /* {{(myhelper)}} + + {{component this.X}} */ { "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 @@ -152,8 +156,7 @@ describe('convert template with hot reload helpers', () => { const T = ; - + ;