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 1fade50
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
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]

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Floating dependencies

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Floating dependencies

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Linting

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Linting

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (18)

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (18)

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 14)

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 14)

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (20)

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 515 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (20)

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.
),
]);
}
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]

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Floating dependencies

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Floating dependencies

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Linting

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Linting

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (18)

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (18)

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 14)

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 14)

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (20)

Type 'string' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.

Check failure on line 636 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Tests (20)

Type 'string | null' is not assignable to type 'ArgumentPlaceholder | SpreadElement | Expression'.
),
])
);
Expand Down

0 comments on commit 1fade50

Please sign in to comment.