UNPKG

3.88 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. 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.io/license
7 */
8import { ImportGenerator } from '@angular/compiler';
9import { AngularCompilerOptions, MetadataCollector, ModuleMetadata } from '@angular/tsc-wrapped';
10import * as ts from 'typescript';
11import { StaticReflectorHost, StaticSymbol } from './static_reflector';
12export interface ReflectorHostContext {
13 fileExists(fileName: string): boolean;
14 directoryExists(directoryName: string): boolean;
15 readFile(fileName: string): string;
16 assumeFileExists(fileName: string): void;
17}
18export declare class ReflectorHost implements StaticReflectorHost, ImportGenerator {
19 protected program: ts.Program;
20 protected compilerHost: ts.CompilerHost;
21 protected options: AngularCompilerOptions;
22 protected metadataCollector: MetadataCollector;
23 protected context: ReflectorHostContext;
24 private isGenDirChildOfRootDir;
25 protected basePath: string;
26 private genDir;
27 constructor(program: ts.Program, compilerHost: ts.CompilerHost, options: AngularCompilerOptions, context?: ReflectorHostContext);
28 angularImportLocations(): {
29 coreDecorators: string;
30 diDecorators: string;
31 diMetadata: string;
32 diOpaqueToken: string;
33 animationMetadata: string;
34 provider: string;
35 };
36 getCanonicalFileName(fileName: string): string;
37 protected resolve(m: string, containingFile: string): string;
38 protected normalizeAssetUrl(url: string): string;
39 protected resolveAssetUrl(url: string, containingFile: string): string;
40 /**
41 * We want a moduleId that will appear in import statements in the generated code.
42 * These need to be in a form that system.js can load, so absolute file paths don't work.
43 *
44 * The `containingFile` is always in the `genDir`, where as the `importedFile` can be in
45 * `genDir`, `node_module` or `basePath`. The `importedFile` is either a generated file or
46 * existing file.
47 *
48 * | genDir | node_module | rootDir
49 * --------------+----------+-------------+----------
50 * generated | relative | relative | n/a
51 * existing file | n/a | absolute | relative(*)
52 *
53 * NOTE: (*) the relative path is computed depending on `isGenDirChildOfRootDir`.
54 */
55 getImportPath(containingFile: string, importedFile: string): string;
56 private dotRelative(from, to);
57 /**
58 * Moves the path into `genDir` folder while preserving the `node_modules` directory.
59 */
60 private rewriteGenDirPath(filepath);
61 findDeclaration(module: string, symbolName: string, containingFile: string, containingModule?: string): StaticSymbol;
62 private typeCache;
63 private resolverCache;
64 /**
65 * getStaticSymbol produces a Type whose metadata is known but whose implementation is not loaded.
66 * All types passed to the StaticResolver should be pseudo-types returned by this method.
67 *
68 * @param declarationFile the absolute path of the file where the symbol is declared
69 * @param name the name of the type.
70 */
71 getStaticSymbol(declarationFile: string, name: string, members?: string[]): StaticSymbol;
72 getMetadataFor(filePath: string): ModuleMetadata;
73 readMetadata(filePath: string): any;
74 private getResolverMetadata(filePath);
75 protected resolveExportedSymbol(filePath: string, symbolName: string): StaticSymbol;
76}
77export declare class NodeReflectorHostContext implements ReflectorHostContext {
78 private host;
79 constructor(host: ts.CompilerHost);
80 private assumedExists;
81 fileExists(fileName: string): boolean;
82 directoryExists(directoryName: string): boolean;
83 readFile(fileName: string): string;
84 assumeFileExists(fileName: string): void;
85}