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