component-resource-collector.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.dev/license
  7. */
  8. import * as ts from 'typescript';
  9. import { FileSystem, WorkspacePath } from './file-system';
  10. import { LineAndCharacter } from './utils/line-mappings';
  11. export interface ResolvedResource {
  12. /** Class declaration that contains this resource. */
  13. container: ts.ClassDeclaration | null;
  14. /** File content of the given template. */
  15. content: string;
  16. /** Start offset of the resource content (e.g. in the inline source file) */
  17. start: number;
  18. /** Whether the given resource is inline or not. */
  19. inline: boolean;
  20. /** Path to the file that contains this resource. */
  21. filePath: WorkspacePath;
  22. /**
  23. * Gets the character and line of a given position index in the resource.
  24. * If the resource is declared inline within a TypeScript source file, the line and
  25. * character are based on the full source file content.
  26. */
  27. getCharacterAndLineOfPosition: (pos: number) => LineAndCharacter;
  28. }
  29. /**
  30. * Collector that can be used to find Angular templates and stylesheets referenced within
  31. * given TypeScript source files (inline or external referenced files)
  32. */
  33. export declare class ComponentResourceCollector {
  34. typeChecker: ts.TypeChecker;
  35. private _fileSystem;
  36. resolvedTemplates: ResolvedResource[];
  37. resolvedStylesheets: ResolvedResource[];
  38. constructor(typeChecker: ts.TypeChecker, _fileSystem: FileSystem);
  39. visitNode(node: ts.Node): void;
  40. private _visitClassDeclaration;
  41. /** Resolves an external stylesheet by reading its content and computing line mappings. */
  42. resolveExternalStylesheet(filePath: WorkspacePath, container: ts.ClassDeclaration | null): ResolvedResource | null;
  43. private _trackExternalStylesheet;
  44. }