UI: Resources service - avoid modules scan recursion. Update markdown template sanitize according to the latest angular template requirements.

This commit is contained in:
Igor Kulikov 2024-10-08 14:02:39 +03:00
parent 1d6b6a3f40
commit 4ca215fdee
2 changed files with 25 additions and 27 deletions

View File

@ -237,34 +237,32 @@ export class ResourcesService {
standaloneComponents: []
},
visitedModules: Set<any> = new Set<any>()): ModulesWithComponents {
if (module && ['object', 'function'].includes(typeof module)) {
if (module && ['object', 'function'].includes(typeof module) && !visitedModules.has(module)) {
visitedModules.add(module);
if (ɵNG_MOD_DEF in module) {
const moduleDef: ɵNgModuleDef<any> = module[ɵNG_MOD_DEF];
if (!visitedModules.has(moduleDef.type)) {
visitedModules.add(moduleDef.type);
const moduleInfo: ModuleInfo = {
module: moduleDef,
components: []
}
modulesWithComponents.modules.push(moduleInfo);
const exportsDecl = moduleDef.exports;
let exports: Type<any>[];
if (Array.isArray(exportsDecl)) {
exports = exportsDecl;
} else {
exports = exportsDecl();
}
for (const element of exports) {
if (ɵNG_COMP_DEF in element) {
const component: ɵComponentDef<any> = element[ɵNG_COMP_DEF];
if (!component.standalone) {
moduleInfo.components.push(component);
} else {
modulesWithComponents.standaloneComponents.push(component);
}
const moduleInfo: ModuleInfo = {
module: moduleDef,
components: []
}
modulesWithComponents.modules.push(moduleInfo);
const exportsDecl = moduleDef.exports;
let exports: Type<any>[];
if (Array.isArray(exportsDecl)) {
exports = exportsDecl;
} else {
exports = exportsDecl();
}
for (const element of exports) {
if (ɵNG_COMP_DEF in element) {
const component: ɵComponentDef<any> = element[ɵNG_COMP_DEF];
if (!component.standalone) {
moduleInfo.components.push(component);
} else {
this.extractModulesWithComponents(module, modulesWithComponents, visitedModules);
modulesWithComponents.standaloneComponents.push(component);
}
} else {
this.extractModulesWithComponents(module, modulesWithComponents, visitedModules);
}
}
} else if (ɵNG_COMP_DEF in module) {

View File

@ -127,7 +127,7 @@ export class TbMarkdownComponent implements OnChanges {
const preHtml = preElements.item(i).outerHTML.replace('ngnonbindable=""', 'ngNonBindable');
template = template.replace(matches[i][0], preHtml);
}
template = this.sanitizeCurlyBraces(template);
template = this.sanitize(template);
this.markdownContainer.clear();
let styles: string[] = [];
let readyObservable: Observable<void>;
@ -259,8 +259,8 @@ export class TbMarkdownComponent implements OnChanges {
}
}
private sanitizeCurlyBraces(template: string): string {
return template.replace(/{/g, '&#123;').replace(/}/g, '&#125;');
private sanitize(template: string): string {
return template.replace(/{/g, '&#123;').replace(/}/g, '&#125;').replace(/@/g, '&#64;');
}
private destroyMarkdownInstanceResources() {