Skip to content

Commit bd1f293

Browse files
committed
add template only name
1 parent 70b7fb4 commit bd1f293

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/plugin.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NodePath } from '@babel/traverse';
22
import type * as Babel from '@babel/core';
33
import type { types as t } from '@babel/core';
4-
import { ImportUtil, type Importer } from 'babel-import-util';
4+
import { ImportUtil, Importer } from 'babel-import-util';
55
import { ExpressionParser } from './expression-parser';
66
import { JSUtils, ExtendedPluginBuilder } from './js-utils';
77
import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template-compiler';
@@ -496,13 +496,23 @@ function insertCompiledTemplate<EnvSpecificOptions>(
496496

497497
let expression = t.callExpression(templateFactoryIdentifier, [templateExpression]);
498498

499+
let assignment = target.parent;
500+
let assignmentName: string | null = null;
501+
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
502+
assignmentName = assignment.left.name;
503+
}
504+
505+
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
506+
assignmentName = assignment.id.name;
507+
}
508+
499509
if (config.rfc931Support) {
500510
expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
501511
expression,
502512
backingClass?.node ??
503513
t.callExpression(
504514
i.import('@ember/component/template-only', 'default', 'templateOnly'),
505-
[]
515+
['@ember/component/template-only', assignmentName]
506516
),
507517
]);
508518
}
@@ -606,14 +616,24 @@ function updateCallForm<EnvSpecificOptions>(
606616
convertStrictMode(babel, target);
607617
removeEvalAndScope(target);
608618
target.node.arguments = target.node.arguments.slice(0, 2);
619+
let assignment = target.parent;
620+
let assignmentName: string | null = null;
621+
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
622+
assignmentName = assignment.left.name;
623+
}
624+
625+
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
626+
assignmentName = assignment.id.name;
627+
}
628+
609629
state.recursionGuard.add(target.node);
610630
state.util.replaceWith(target, (i) =>
611631
babel.types.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
612632
target.node,
613633
backingClass?.node ??
614634
babel.types.callExpression(
615635
i.import('@ember/component/template-only', 'default', 'templateOnly'),
616-
[]
636+
['@ember/component/template-only', assignmentName]
617637
),
618638
])
619639
);

0 commit comments

Comments
 (0)