Skip to content

Commit

Permalink
add template only name
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Jun 25, 2024
1 parent 70b7fb4 commit bd1f293
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NodePath } from '@babel/traverse';
import type * as Babel from '@babel/core';
import type { types as t } from '@babel/core';
import { ImportUtil, type Importer } from 'babel-import-util';
import { ImportUtil, Importer } from 'babel-import-util';
import { ExpressionParser } from './expression-parser';
import { JSUtils, ExtendedPluginBuilder } from './js-utils';
import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template-compiler';
Expand Down Expand Up @@ -496,13 +496,23 @@ function insertCompiledTemplate<EnvSpecificOptions>(

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

let assignment = target.parent;
let assignmentName: string | null = null;
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
assignmentName = assignment.left.name;
}

if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
assignmentName = assignment.id.name;
}

if (config.rfc931Support) {
expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
expression,
backingClass?.node ??
t.callExpression(
i.import('@ember/component/template-only', 'default', 'templateOnly'),
[]
['@ember/component/template-only', assignmentName]
),
]);
}
Expand Down Expand Up @@ -606,14 +616,24 @@ function updateCallForm<EnvSpecificOptions>(
convertStrictMode(babel, target);
removeEvalAndScope(target);
target.node.arguments = target.node.arguments.slice(0, 2);
let assignment = target.parent;
let assignmentName: string | null = null;
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {
assignmentName = assignment.left.name;
}

if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {
assignmentName = assignment.id.name;
}

state.recursionGuard.add(target.node);
state.util.replaceWith(target, (i) =>
babel.types.callExpression(i.import('@ember/component', 'setComponentTemplate'), [
target.node,
backingClass?.node ??
babel.types.callExpression(
i.import('@ember/component/template-only', 'default', 'templateOnly'),
[]
['@ember/component/template-only', assignmentName]
),
])
);
Expand Down

0 comments on commit bd1f293

Please sign in to comment.