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
15 changes: 15 additions & 0 deletions src/parser/component/component.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,19 @@ describe('ComponentParser', () => {

expect(parseComponent(ast, 'foo.component.ts').cva).toBeTruthy();
});

it('should be able to parse a component with an empty template', () => {
const ast = tsquery.ast(`
@Component({
selector: 'my-test-comp',
template: '',
styles: []
})
export class MyTestComponent implements ControlValueAccessor{}
`);

jest.spyOn(fs, 'readFileSync').mockReturnValue('');

expect(parseComponent(ast, 'foo.component.ts').template).toBe('');
});
});
5 changes: 4 additions & 1 deletion src/parser/component/component.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ function isCva(ast: ts.SourceFile): boolean {
);
}

function fetchFileContent(filePath: string, componentFilePath: string): string {
function fetchFileContent(filePath: string | undefined, componentFilePath: string): string {
if (!filePath) {
return '';
}
const filePathFragements = componentFilePath.split('/');
filePathFragements.pop();
const componentDirectory = filePathFragements.join('/');
Expand Down
Loading