Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e25a4ee

Browse files
committed
fix(app): double layer spread support for modules
fix #979
1 parent 35401d9 commit e25a4ee

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

src/app/compiler/angular-dependencies.ts

+36-12
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,46 @@ export class AngularDependencies extends FrameworkDependencies {
120120
if (deps.miscellaneous.variables.length > 0) {
121121
deps.miscellaneous.variables.forEach(_variable => {
122122
let newVar = [];
123+
124+
// link ...VAR to VAR values, recursively
123125
((_var, _newVar) => {
124126
// getType pr reconstruire....
125-
if (_var.initializer) {
126-
if (_var.initializer.elements) {
127-
if (_var.initializer.elements.length > 0) {
128-
_var.initializer.elements.forEach(element => {
129-
if (element.text) {
130-
newVar.push({
131-
name: element.text,
132-
type: this.symbolHelper.getType(element.text)
133-
});
134-
}
135-
});
127+
const elementsMatcher = variabelToReplace => {
128+
if (variabelToReplace.initializer) {
129+
if (variabelToReplace.initializer.elements) {
130+
if (variabelToReplace.initializer.elements.length > 0) {
131+
variabelToReplace.initializer.elements.forEach(element => {
132+
// Direct value -> Kind 79
133+
if (
134+
element.text &&
135+
element.kind === SyntaxKind.Identifier
136+
) {
137+
newVar.push({
138+
name: element.text,
139+
type: this.symbolHelper.getType(element.text)
140+
});
141+
}
142+
// if _variable is ArrayLiteralExpression 203
143+
// and has SpreadElements in his elements
144+
// merge them
145+
if (
146+
element.kind === SyntaxKind.SpreadElement &&
147+
element.expression
148+
) {
149+
const el = deps.miscellaneous.variables.find(
150+
variable =>
151+
variable.name === element.expression.text
152+
);
153+
if (el) {
154+
elementsMatcher(el);
155+
}
156+
}
157+
});
158+
}
136159
}
137160
}
138-
}
161+
};
162+
elementsMatcher(_var);
139163
})(_variable, newVar);
140164

141165
const onLink = mod => {

test/fixtures/todomvc-ng2/src/app/header/header.module.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import { FormsModule } from '@angular/forms';
33

44
import { HeaderComponent } from './header.component';
55

6+
const COMPO = [HeaderComponent];
7+
8+
const COMPOS = [...COMPO];
9+
610
/**
711
* The header module
812
*/
913
@NgModule({
1014
imports: [FormsModule],
11-
declarations: [HeaderComponent],
15+
declarations: [...COMPOS],
1216
exports: [HeaderComponent]
1317
})
1418
export class HeaderModule {}

test/src/cli/cli-generation-big-app.spec.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const tmp = temporaryDir();
77

88
describe('CLI simple generation - big app', () => {
99
let stdoutString = undefined;
10-
let clockInterfaceFile;
1110
let interfaceIDATAFile;
1211
let searchFuncFile;
1312

@@ -45,7 +44,6 @@ describe('CLI simple generation - big app', () => {
4544
done('error');
4645
}
4746
stdoutString = ls.stdout.toString();
48-
clockInterfaceFile = read(`${distFolder}/interfaces/ClockInterface.html`);
4947
interfaceIDATAFile = read(`${distFolder}/interfaces/IDATA.html`);
5048
searchFuncFile = read(`${distFolder}/interfaces/SearchFunc.html`);
5149

@@ -873,34 +871,34 @@ describe('CLI simple generation - big app', () => {
873871
});
874872

875873
it('should support JSDoc @link in JSDoc @see tag', () => {
876-
let file = read(distFolder + '/injectables/TodoStore.html');
874+
const file = read(distFolder + '/injectables/TodoStore.html');
877875
expect(file).to.contain('See <a href="../classes/Todo.html">Todo</a> for details');
878876
});
879877

880878
it('should support JSDoc @link for setters and getters', () => {
881-
let file = read(distFolder + '/injectables/TodoStore.html');
879+
const file = read(distFolder + '/injectables/TodoStore.html');
882880
expect(file).to.contain('or link to <a href="../classes/Todo.html">Todo');
883881
expect(file).to.contain('ore link to <a href="../classes/Todo.html">Todo');
884882
});
885883

886884
it('should support JSDoc @link for inputs', () => {
887-
let file = read(distFolder + '/components/HeaderComponent.html');
885+
const file = read(distFolder + '/components/HeaderComponent.html');
888886
expect(file).to.contain('_fullName <a href="https://compodoc.app/">https://compodoc.app/');
889887
});
890888

891889
it('should not crash with invalid JSDoc @link tags', () => {
892-
let file = read(distFolder + '/components/AboutComponent.html');
890+
const file = read(distFolder + '/components/AboutComponent.html');
893891
expect(file).to.contain('if this {@link AboutComponent.fullName} does not crash');
894892
expect(file).to.contain('if this {@link undefined} does not crash');
895893
});
896894

897895
it('should support multiple decorators for component for example', () => {
898-
let file = read(distFolder + '/components/AboutComponent.html');
896+
const file = read(distFolder + '/components/AboutComponent.html');
899897
expect(file).to.contain('<code>src/app/about/about.component.ts</code>');
900898
});
901899

902900
it('should not have bootstraped component in components menu entry', () => {
903-
let file = read(distFolder + '/js/menu-wc.js');
901+
const file = read(distFolder + '/js/menu-wc.js');
904902
expect(file).to.not.contain(
905903
'<a href="components/AppComponent.html" data-type="entity-link" >AppComponent</a>'
906904
);
@@ -911,4 +909,9 @@ describe('CLI simple generation - big app', () => {
911909
'">&lt;todomvc&gt;The example of the component&lt;'
912910
);
913911
});
912+
913+
it('should support double layer spread for modules', () => {
914+
const file = read(distFolder + '/modules/HeaderModule.html');
915+
expect(file).to.contain('href="../components/HeaderComponent.html">HeaderComponent');
916+
});
914917
});

0 commit comments

Comments
 (0)