Skip to content

Commit

Permalink
fix(core): getExpectExportedComponent without example name
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Mar 15, 2022
1 parent fb74b39 commit c3171cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
21 changes: 8 additions & 13 deletions packages/core/src/builders/library-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,23 @@ export class LibraryComponentImpl extends FileEmitter implements LibraryComponen

// build example source files
const exampleSourceFiles = await this.buildExampleSourceFiles(absComponentExamplePath);
if (
!exampleSourceFiles.find(item => {
return item.name === `${exampleName}.component.ts`;
})
) {
return {
order: 0,
liveExample: undefined
};
}
liveExample.sourceFiles = exampleSourceFiles;

// try extract component name from example entry ts file
const entrySourceFile = exampleSourceFiles.find(sourceFile => {
return sourceFile.name === `${exampleName}.component.ts`;
});

if (entrySourceFile) {
const component = createNgSourceFile(entrySourceFile.name, entrySourceFile.content).getExpectExportedComponent(exampleName);
const component = createNgSourceFile(entrySourceFile.name, entrySourceFile.content).getExpectExportedComponent();
if (component) {
liveExample.componentName = component.name;
}
} else {
return {
order: 0,
liveExample: undefined
};
}
liveExample.sourceFiles = exampleSourceFiles;

// build order, title from FrontMatter
let exampleOrder = Number.MAX_SAFE_INTEGER;
Expand Down
6 changes: 3 additions & 3 deletions packages/ngdoc/src/ng-source-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('#ng-source-file', () => {

it('should get exported components', () => {
const sourceText = `
@Component({selector: "my-component"})
export class MyComponent {}
export class NotComponent {}
@Component({selector: "internal-component"})
class InternalComponent {}
@Component({selector: "my-component"})
export class MyComponent {}
`;
const ngSourceFile = createNgSourceFile('test.ts', sourceText);
expect(ngSourceFile.getExportedComponents()).toEqual([jasmine.objectContaining({ name: 'MyComponent', selector: 'my-component' })]);
Expand Down

0 comments on commit c3171cc

Please sign in to comment.