(compiler: NgCompiler, fileName: string)
| 26 | import {getFirstComponentForTemplateFile, isTypeScriptFile, toTextSpan} from './utils'; |
| 27 | |
| 28 | export function getOutliningSpans(compiler: NgCompiler, fileName: string): ts.OutliningSpan[] { |
| 29 | if (isTypeScriptFile(fileName)) { |
| 30 | const sf = compiler.getCurrentProgram().getSourceFile(fileName); |
| 31 | if (sf === undefined) { |
| 32 | return []; |
| 33 | } |
| 34 | |
| 35 | const templatesInFile: Array<TmplAstNode[]> = []; |
| 36 | for (const stmt of sf.statements) { |
| 37 | if (isNamedClassDeclaration(stmt)) { |
| 38 | const resources = compiler.getDirectiveResources(stmt); |
| 39 | if ( |
| 40 | resources === null || |
| 41 | resources.template === null || |
| 42 | isExternalResource(resources.template) |
| 43 | ) { |
| 44 | continue; |
| 45 | } |
| 46 | const template = compiler.getTemplateTypeChecker().getTemplate(stmt); |
| 47 | if (template === null) { |
| 48 | continue; |
| 49 | } |
| 50 | templatesInFile.push(template); |
| 51 | } |
| 52 | } |
| 53 | return templatesInFile.map((template) => BlockVisitor.getBlockSpans(template)).flat(); |
| 54 | } else { |
| 55 | const typeCheckInfo = getFirstComponentForTemplateFile(fileName, compiler); |
| 56 | return typeCheckInfo === undefined ? [] : BlockVisitor.getBlockSpans(typeCheckInfo.nodes); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | class BlockVisitor extends TmplAstRecursiveVisitor { |
| 61 | readonly blocks = [] as Array<TmplAstBlockNode>; |
no test coverage detected