2018-07-16 08:51:14 +01:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
import * as ts from 'typescript';
|
2019-06-03 18:41:47 +02:00
|
|
|
import {ClassDeclaration, ClassSymbol, Declaration, Decorator, ReflectionHost} from '../../../src/ngtsc/reflection';
|
2018-07-16 08:51:14 +01:00
|
|
|
|
2018-10-15 11:48:03 +01:00
|
|
|
export const PRE_R3_MARKER = '__PRE_R3__';
|
|
|
|
|
export const POST_R3_MARKER = '__POST_R3__';
|
2018-08-17 07:50:55 +01:00
|
|
|
|
|
|
|
|
export type SwitchableVariableDeclaration = ts.VariableDeclaration & {initializer: ts.Identifier};
|
|
|
|
|
export function isSwitchableVariableDeclaration(node: ts.Node):
|
|
|
|
|
node is SwitchableVariableDeclaration {
|
|
|
|
|
return ts.isVariableDeclaration(node) && !!node.initializer &&
|
2018-10-15 11:48:03 +01:00
|
|
|
ts.isIdentifier(node.initializer) && node.initializer.text.endsWith(PRE_R3_MARKER);
|
2018-08-17 07:50:55 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 13:10:52 +00:00
|
|
|
/**
|
|
|
|
|
* A structure returned from `getModuleWithProviderInfo` that describes functions
|
|
|
|
|
* that return ModuleWithProviders objects.
|
|
|
|
|
*/
|
|
|
|
|
export interface ModuleWithProvidersFunction {
|
2019-03-20 13:47:58 +00:00
|
|
|
/**
|
|
|
|
|
* The name of the declared function.
|
|
|
|
|
*/
|
|
|
|
|
name: string;
|
2018-12-07 13:10:52 +00:00
|
|
|
/**
|
|
|
|
|
* The declaration of the function that returns the `ModuleWithProviders` object.
|
|
|
|
|
*/
|
|
|
|
|
declaration: ts.SignatureDeclaration;
|
2019-03-20 13:47:58 +00:00
|
|
|
/**
|
|
|
|
|
* Declaration of the containing class (if this is a method)
|
|
|
|
|
*/
|
|
|
|
|
container: ts.Declaration|null;
|
2018-12-07 13:10:52 +00:00
|
|
|
/**
|
2019-03-05 23:29:28 +01:00
|
|
|
* The declaration of the class that the `ngModule` property on the `ModuleWithProviders` object
|
|
|
|
|
* refers to.
|
2018-12-07 13:10:52 +00:00
|
|
|
*/
|
2019-03-05 23:29:28 +01:00
|
|
|
ngModule: Declaration<ClassDeclaration>;
|
2018-12-07 13:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-16 08:51:14 +01:00
|
|
|
/**
|
|
|
|
|
* A reflection host that has extra methods for looking at non-Typescript package formats
|
|
|
|
|
*/
|
|
|
|
|
export interface NgccReflectionHost extends ReflectionHost {
|
2018-08-17 07:50:55 +01:00
|
|
|
/**
|
|
|
|
|
* Find a symbol for a declaration that we think is a class.
|
|
|
|
|
* @param declaration The declaration whose symbol we are finding
|
|
|
|
|
* @returns the symbol for the declaration or `undefined` if it is not
|
|
|
|
|
* a "class" or has no symbol.
|
|
|
|
|
*/
|
2019-03-20 12:10:57 +02:00
|
|
|
getClassSymbol(node: ts.Node): ClassSymbol|undefined;
|
2018-08-17 07:50:55 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Search the given module for variable declarations in which the initializer
|
2018-10-15 11:48:03 +01:00
|
|
|
* is an identifier marked with the `PRE_R3_MARKER`.
|
2018-08-17 07:50:55 +01:00
|
|
|
* @param module The module in which to search for switchable declarations.
|
|
|
|
|
* @returns An array of variable declarations that match.
|
|
|
|
|
*/
|
|
|
|
|
getSwitchableDeclarations(module: ts.Node): SwitchableVariableDeclaration[];
|
2018-09-26 17:24:43 +01:00
|
|
|
|
|
|
|
|
/**
|
2019-06-03 18:41:47 +02:00
|
|
|
* Retrieves all decorators of a given class symbol.
|
|
|
|
|
* @param symbol Class symbol that can refer to a declaration which can hold decorators.
|
|
|
|
|
* @returns An array of decorators or null if none are declared.
|
2018-09-26 17:24:43 +01:00
|
|
|
*/
|
2019-06-03 18:41:47 +02:00
|
|
|
getDecoratorsOfSymbol(symbol: ClassSymbol): Decorator[]|null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves all class symbols of a given source file.
|
|
|
|
|
* @param sourceFile The source file to search for classes.
|
|
|
|
|
* @returns An array of found class symbols.
|
|
|
|
|
*/
|
|
|
|
|
findClassSymbols(sourceFile: ts.SourceFile): ClassSymbol[];
|
2018-12-07 13:10:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Search the given source file for exported functions and static class methods that return
|
|
|
|
|
* ModuleWithProviders objects.
|
|
|
|
|
* @param f The source file to search for these functions
|
|
|
|
|
* @returns An array of info items about each of the functions that return ModuleWithProviders
|
|
|
|
|
* objects.
|
|
|
|
|
*/
|
|
|
|
|
getModuleWithProvidersFunctions(f: ts.SourceFile): ModuleWithProvidersFunction[];
|
2018-07-16 08:51:14 +01:00
|
|
|
}
|