Skip to content

Commit c6f3da0

Browse files
authored
Merge pull request #144 from Turbo87/link-to
Fix inline link-to with subexpression caption crash
2 parents 3f17c21 + 14b9d58 commit c6f3da0

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

transforms/angle-brackets/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ test('link-to-inline', () => {
370370
segment
371371
class="t__em-link"
372372
}}
373+
{{link-to (t "show") "flight" event.flight.id class="btn btn-default btn-sm pull-right"}}
373374
`;
374375

375376
/**
@@ -383,6 +384,7 @@ test('link-to-inline', () => {
383384
<LinkTo @route=\\"apps.segments\\" class=\\"tabs__discrete-tab\\" @activeClass=\\"o__selected\\" @current-when=\\"apps.segments\\" data-test-segment-link=\\"segments\\">Segments</LinkTo>
384385
<LinkTo @route={{this.dynamicPath}} class=\\"tabs__discrete-tab\\" @activeClass=\\"o__selected\\" @current-when=\\"apps.segments\\" data-test-segment-link=\\"segments\\">Segments</LinkTo>
385386
<LinkTo @route=\\"apps.app.companies.segments.segment\\" @model={{segment}} class=\\"t__em-link\\">{{segment.name}}</LinkTo>
387+
<LinkTo @route=\\"flight\\" @model={{event.flight.id}} class=\\"btn btn-default btn-sm pull-right\\">{{t \\"show\\"}}</LinkTo>
386388
"
387389
`);
388390
});

transforms/angle-brackets/transform.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ function transformToAngleBracket(env, fileInfo, config) {
303303
}
304304

305305
function transformLinkToTextParam(textParam) {
306-
if (textParam.type.includes('Literal')) {
306+
if (textParam.type === 'SubExpression') {
307+
return subExpressionToMustacheStatement(textParam);
308+
} else if (textParam.type.includes('Literal')) {
307309
return b.text(textParam.value);
308310
} else {
309311
return b.mustache(textParam.original);
@@ -466,12 +468,16 @@ function transformToAngleBracket(env, fileInfo, config) {
466468
);
467469
}
468470

471+
function subExpressionToMustacheStatement(subExpression) {
472+
return b.mustache(subExpression.path, subExpression.params, subExpression.hash);
473+
}
474+
469475
return {
470476
MustacheStatement(node) {
471477
// Don't change attribute statements
472478
const isValidMustache =
473479
node.loc.source !== '(synthetic)' && !shouldIgnoreMustacheStatement(node.path.original);
474-
const tagName = node.path.original;
480+
const tagName = node.path && node.path.original;
475481
const isNestedComponent = isNestedComponentTagName(tagName);
476482

477483
if (

0 commit comments

Comments
 (0)