Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/resolver/template-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ function readGts(
for (const block of templates) {
if (!block.range) continue;
const start = block.range.startUtf16Codepoint;
const end = block.range.endUtf16Codepoint;
if (start >= resolvedRange.start && end <= resolvedRange.end) {
if (start < resolvedRange.start) continue;
// `const X = <template>` without a semicolon: the blanked initializer
// leaves the statement ending at `=`, so the block follows the range
// across whitespace only.
if (start < resolvedRange.end || /^\s*$/.test(contents.slice(resolvedRange.end, start))) {
return { content: block.contents, origin: file, kind };
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/glint-fixtures/toc-expression-no-semicolon.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Two template-only components in expression form without a trailing
// semicolon. Blanking the templates before the TS parse leaves each
// `export const X = ` with no initializer, so the statement's range
// ends before its template block.
export const Bar = <template>
<div class='bar'>{{yield}}</div>
</template>

export const Baz = <template>
<span class='baz'>{{yield}}</span>
</template>
8 changes: 8 additions & 0 deletions test/resolver/template-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ describe('findTemplateSource', () => {
expect(result?.content).not.toContain('<div ...attributes');
});

test('multi-template file: expression-form TOCs without semicolons resolve by name', () => {
const declFile = path.join(FIXTURES, 'toc-expression-no-semicolon.gts');
const bar = findTemplateSource({ declFile, componentName: 'Bar', ts });
expect(bar?.content).toContain("<div class='bar'>");
const baz = findTemplateSource({ declFile, componentName: 'Baz', ts });
expect(baz?.content).toContain("<span class='baz'>");
});

test('reads .hbs source directly', () => {
const declFile = path.join(FIXTURES, 'node_modules/classic-card-addon/addon/components/classic-card.hbs');
const result = findTemplateSource({ declFile, ts });
Expand Down
Loading