Skip to content

Commit 79d7044

Browse files
committed
fix(cli): resolve namespace barrel spread declarations
closes #623
1 parent eb34354 commit 79d7044

7 files changed

Lines changed: 115 additions & 0 deletions

File tree

‎src/app/compiler/angular/deps/helpers/symbol-helper.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ export class SymbolHelper {
190190
if (node.expression && node.expression.text) {
191191
return node.expression.text;
192192
}
193+
// parse expressions such as: ...fromComponents.components
194+
if (
195+
node.expression &&
196+
ts.isPropertyAccessExpression(node.expression)
197+
) {
198+
return node.expression.name.text;
199+
}
193200
}
194201

195202
return node.text ? node.text : this.parseProviderConfiguration(node);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as fromComponents from "./components";
2+
3+
function NgModule(_: any) {
4+
return function (_target: any) {};
5+
}
6+
7+
@NgModule({
8+
declarations: [...fromComponents.components],
9+
exports: [...fromComponents.components]
10+
})
11+
export class AppModule {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from "@angular/core";
2+
3+
@Component({
4+
selector: "app-account-type",
5+
template: "<p>AccountTypeComponent</p>"
6+
})
7+
export class AccountTypeComponent {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RegistrationRootComponent } from "./registration-root.component";
2+
import { AccountTypeComponent } from "./account-type.component";
3+
4+
export const components = [RegistrationRootComponent, AccountTypeComponent];
5+
6+
export * from "./registration-root.component";
7+
export * from "./account-type.component";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from "@angular/core";
2+
3+
@Component({
4+
selector: "app-registration-root",
5+
template: "<p>RegistrationRootComponent</p>"
6+
})
7+
export class RegistrationRootComponent {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"module": "commonjs",
5+
"experimentalDecorators": true,
6+
"emitDecoratorMetadata": false,
7+
"strict": false,
8+
"skipLibCheck": true
9+
},
10+
"include": ["src/**/*.ts"]
11+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { expect } from 'chai';
2+
import { temporaryDir, shell, exists, read } from '../helpers';
3+
4+
const tmp = temporaryDir();
5+
6+
describe('CLI issue #623 - barrel spread declarations', () => {
7+
const distFolder = tmp.name + '-issue-623-barrel-spread';
8+
let documentation: any;
9+
10+
before(function (done) {
11+
tmp.create(distFolder);
12+
const ls = shell('node', [
13+
'./bin/index-cli.js',
14+
'-p',
15+
'./test/fixtures/issue623-barrel-spread/tsconfig.json',
16+
'-e',
17+
'json',
18+
'-d',
19+
distFolder,
20+
]);
21+
22+
if (ls.stderr.toString() !== '') {
23+
console.error(`shell error: ${ls.stderr.toString()}`);
24+
done('error');
25+
return;
26+
}
27+
28+
documentation = JSON.parse(read(`${distFolder}/documentation.json`));
29+
done();
30+
});
31+
32+
after(() => tmp.clean(distFolder));
33+
34+
it('should generate documentation successfully', () => {
35+
expect(exists(distFolder)).to.be.true;
36+
});
37+
38+
it('should resolve declarations from namespace barrel spread', () => {
39+
const appModule = documentation.modules.find(
40+
(module) => module.name === 'AppModule',
41+
);
42+
const declarations = appModule.children.find(
43+
(child) => child.type === 'declarations',
44+
).elements;
45+
46+
const declarationNames = declarations.map((entry) => entry.name);
47+
48+
expect(declarationNames).to.include('RegistrationRootComponent');
49+
expect(declarationNames).to.include('AccountTypeComponent');
50+
});
51+
52+
it('should resolve exports from namespace barrel spread', () => {
53+
const appModule = documentation.modules.find(
54+
(module) => module.name === 'AppModule',
55+
);
56+
const exportsElements = appModule.children.find(
57+
(child) => child.type === 'exports',
58+
).elements;
59+
60+
const exportNames = exportsElements.map((entry) => entry.name);
61+
62+
expect(exportNames).to.include('RegistrationRootComponent');
63+
expect(exportNames).to.include('AccountTypeComponent');
64+
});
65+
});

0 commit comments

Comments
 (0)