/
migration.ts
65 lines (59 loc) 路 2.79 KB
/
migration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @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';
import {MetadataReader} from '../../../src/ngtsc/metadata';
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
import {ClassDeclaration, Decorator} from '../../../src/ngtsc/reflection';
import {HandlerFlags} from '../../../src/ngtsc/transform';
import {NgccReflectionHost} from '../host/ngcc_host';
/**
* Implement this interface and add it to the `DecorationAnalyzer.migrations` collection to get ngcc
* to modify the analysis of the decorators in the program in order to migrate older code to work
* with Ivy.
*
* `Migration.apply()` is called for every class in the program being compiled by ngcc.
*
* Note that the underlying program could be in a variety of different formats, e.g. ES2015, ES5,
* UMD, CommonJS etc. This means that an author of a `Migration` should not attempt to navigate and
* manipulate the AST nodes directly. Instead, the `MigrationHost` interface, passed to the
* `Migration`, provides access to a `MetadataReader`, `ReflectionHost` and `PartialEvaluator`
* interfaces, which should be used.
*/
export interface Migration {
apply(clazz: ClassDeclaration, host: MigrationHost): ts.Diagnostic|null;
}
export interface MigrationHost {
/** Provides access to the decorator information associated with classes. */
readonly metadata: MetadataReader;
/** Provides access to navigate the AST in a format-agnostic manner. */
readonly reflectionHost: NgccReflectionHost;
/** Enables expressions to be statically evaluated in the context of the program. */
readonly evaluator: PartialEvaluator;
/**
* Associate a new synthesized decorator, which did not appear in the original source, with a
* given class.
* @param clazz the class to receive the new decorator.
* @param decorator the decorator to inject.
*/
injectSyntheticDecorator(clazz: ClassDeclaration, decorator: Decorator, flags?: HandlerFlags):
void;
/**
* Retrieves all decorators that are associated with the class, including synthetic decorators
* that have been injected before.
* @param clazz the class for which all decorators are retrieved.
* @returns the list of the decorators, or null if the class was not decorated.
*/
getAllDecorators(clazz: ClassDeclaration): Decorator[]|null;
/**
* Determines whether the provided class in within scope of the entry-point that is currently
* being compiled.
* @param clazz the class for which to determine whether it is within the current entry-point.
* @returns true if the file is part of the compiled entry-point, false otherwise.
*/
isInScope(clazz: ClassDeclaration): boolean;
}