Skip to content

Commit

Permalink
fix(app): double layer spread support for modules
Browse files Browse the repository at this point in the history
fix #979
  • Loading branch information
vogloblinsky committed Feb 11, 2022
1 parent 35401d9 commit e25a4ee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
48 changes: 36 additions & 12 deletions src/app/compiler/angular-dependencies.ts
Expand Up @@ -120,22 +120,46 @@ export class AngularDependencies extends FrameworkDependencies {
if (deps.miscellaneous.variables.length > 0) {
deps.miscellaneous.variables.forEach(_variable => {
let newVar = [];

// link ...VAR to VAR values, recursively
((_var, _newVar) => {
// getType pr reconstruire....
if (_var.initializer) {
if (_var.initializer.elements) {
if (_var.initializer.elements.length > 0) {
_var.initializer.elements.forEach(element => {
if (element.text) {
newVar.push({
name: element.text,
type: this.symbolHelper.getType(element.text)
});
}
});
const elementsMatcher = variabelToReplace => {
if (variabelToReplace.initializer) {
if (variabelToReplace.initializer.elements) {
if (variabelToReplace.initializer.elements.length > 0) {
variabelToReplace.initializer.elements.forEach(element => {
// Direct value -> Kind 79
if (
element.text &&
element.kind === SyntaxKind.Identifier
) {
newVar.push({
name: element.text,
type: this.symbolHelper.getType(element.text)
});
}
// if _variable is ArrayLiteralExpression 203
// and has SpreadElements in his elements
// merge them
if (
element.kind === SyntaxKind.SpreadElement &&
element.expression
) {
const el = deps.miscellaneous.variables.find(
variable =>
variable.name === element.expression.text
);
if (el) {
elementsMatcher(el);
}
}
});
}
}
}
}
};
elementsMatcher(_var);
})(_variable, newVar);

const onLink = mod => {
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/todomvc-ng2/src/app/header/header.module.ts
Expand Up @@ -3,12 +3,16 @@ import { FormsModule } from '@angular/forms';

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

const COMPO = [HeaderComponent];

const COMPOS = [...COMPO];

/**
* The header module
*/
@NgModule({
imports: [FormsModule],
declarations: [HeaderComponent],
declarations: [...COMPOS],
exports: [HeaderComponent]
})
export class HeaderModule {}
19 changes: 11 additions & 8 deletions test/src/cli/cli-generation-big-app.spec.ts
Expand Up @@ -7,7 +7,6 @@ const tmp = temporaryDir();

describe('CLI simple generation - big app', () => {
let stdoutString = undefined;
let clockInterfaceFile;
let interfaceIDATAFile;
let searchFuncFile;

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

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

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

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

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

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

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

it('should not have bootstraped component in components menu entry', () => {
let file = read(distFolder + '/js/menu-wc.js');
const file = read(distFolder + '/js/menu-wc.js');
expect(file).to.not.contain(
'<a href="components/AppComponent.html" data-type="entity-link" >AppComponent</a>'
);
Expand All @@ -911,4 +909,9 @@ describe('CLI simple generation - big app', () => {
'">&lt;todomvc&gt;The example of the component&lt;'
);
});

it('should support double layer spread for modules', () => {
const file = read(distFolder + '/modules/HeaderModule.html');
expect(file).to.contain('href="../components/HeaderComponent.html">HeaderComponent');
});
});

0 comments on commit e25a4ee

Please sign in to comment.