From 38c08d0155d1ca8df619de237e38b26a06af5a41 Mon Sep 17 00:00:00 2001 From: void_malex Date: Tue, 24 Jun 2025 16:07:24 +0100 Subject: [PATCH 1/2] allow setting moduleName from caller context use shortened value as fallback make comment be true --- src/plugin.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index cb9e5e4..853fea2 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -8,6 +8,7 @@ import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template- import { LegacyModuleName } from './public-types.js'; import { ScopeLocals } from './scope-locals.js'; import { type ASTPluginBuilder, preprocess, print } from '@glimmer/syntax'; +import { basename, extname } from 'node:path'; export * from './public-types.js'; @@ -143,6 +144,7 @@ interface State { program: NodePath; lastInsertedPath: NodePath | undefined; filename: string; + moduleName?: string; recursionGuard: Set; } @@ -408,7 +410,7 @@ function buildPrecompileOptions( // TODO: embroider's template-compiler allows this to be overriden to get // backward-compatible module names that don't match the real name of the // on-disk file. What's our plan for migrating people away from that? - moduleName: state.filename, + moduleName: state.moduleName || basename(state.filename, extname(state.filename)), // This is here so it's *always* the real filename. Historically, there is // also `moduleName` but that did not match the real on-disk filename, it @@ -514,10 +516,10 @@ function insertCompiledTemplate( expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [ expression, backingClass?.node ?? - t.callExpression( - i.import('@ember/component/template-only', 'default', 'templateOnly'), - [] - ), + t.callExpression( + i.import('@ember/component/template-only', 'default', 'templateOnly'), + [] + ), ]); } return expression; @@ -627,10 +629,10 @@ function updateCallForm( babel.types.callExpression(i.import('@ember/component', 'setComponentTemplate'), [ target.node, backingClass?.node ?? - babel.types.callExpression( - i.import('@ember/component/template-only', 'default', 'templateOnly'), - [] - ), + babel.types.callExpression( + i.import('@ember/component/template-only', 'default', 'templateOnly'), + [] + ), ]) ); // we just wrapped the target callExpression in the call to From 38086a2812de76bc8db3232ab44f8251b0bd08fe Mon Sep 17 00:00:00 2001 From: void_malex Date: Tue, 24 Jun 2025 16:35:33 +0100 Subject: [PATCH 2/2] lint fix --- src/plugin.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 853fea2..0bb39a5 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -516,10 +516,10 @@ function insertCompiledTemplate( expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [ expression, backingClass?.node ?? - t.callExpression( - i.import('@ember/component/template-only', 'default', 'templateOnly'), - [] - ), + t.callExpression( + i.import('@ember/component/template-only', 'default', 'templateOnly'), + [] + ), ]); } return expression; @@ -629,10 +629,10 @@ function updateCallForm( babel.types.callExpression(i.import('@ember/component', 'setComponentTemplate'), [ target.node, backingClass?.node ?? - babel.types.callExpression( - i.import('@ember/component/template-only', 'default', 'templateOnly'), - [] - ), + babel.types.callExpression( + i.import('@ember/component/template-only', 'default', 'templateOnly'), + [] + ), ]) ); // we just wrapped the target callExpression in the call to