1 | "use strict";
|
---|
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 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.Migration = void 0;
|
---|
11 | const ts = require("typescript");
|
---|
12 | class Migration {
|
---|
13 | constructor(
|
---|
14 | /** TypeScript program for the migration. */
|
---|
15 | program,
|
---|
16 | /** TypeChecker instance for the analysis program. */
|
---|
17 | typeChecker,
|
---|
18 | /** Version for which the migration rule should run. */
|
---|
19 | targetVersion,
|
---|
20 | /** Context data for the migration. */
|
---|
21 | context,
|
---|
22 | /** Upgrade data passed to the migration. */
|
---|
23 | upgradeData,
|
---|
24 | /** File system that can be used for modifying files. */
|
---|
25 | fileSystem,
|
---|
26 | /** Logger that can be used to print messages as part of the migration. */
|
---|
27 | logger) {
|
---|
28 | this.program = program;
|
---|
29 | this.typeChecker = typeChecker;
|
---|
30 | this.targetVersion = targetVersion;
|
---|
31 | this.context = context;
|
---|
32 | this.upgradeData = upgradeData;
|
---|
33 | this.fileSystem = fileSystem;
|
---|
34 | this.logger = logger;
|
---|
35 | /** List of migration failures that need to be reported. */
|
---|
36 | this.failures = [];
|
---|
37 | }
|
---|
38 | /** Method can be used to perform global analysis of the program. */
|
---|
39 | init() { }
|
---|
40 | /**
|
---|
41 | * Method that will be called once all nodes, templates and stylesheets
|
---|
42 | * have been visited.
|
---|
43 | */
|
---|
44 | postAnalysis() { }
|
---|
45 | /**
|
---|
46 | * Method that will be called for each node in a given source file. Unlike tslint, this
|
---|
47 | * function will only retrieve TypeScript nodes that need to be casted manually. This
|
---|
48 | * allows us to only walk the program source files once per program and not per
|
---|
49 | * migration rule (significant performance boost).
|
---|
50 | */
|
---|
51 | visitNode(node) { }
|
---|
52 | /** Method that will be called for each Angular template in the program. */
|
---|
53 | visitTemplate(template) { }
|
---|
54 | /** Method that will be called for each stylesheet in the program. */
|
---|
55 | visitStylesheet(stylesheet) { }
|
---|
56 | /** Creates a failure with a specified message at the given node location. */
|
---|
57 | createFailureAtNode(node, message) {
|
---|
58 | const sourceFile = node.getSourceFile();
|
---|
59 | this.failures.push({
|
---|
60 | filePath: this.fileSystem.resolve(sourceFile.fileName),
|
---|
61 | position: ts.getLineAndCharacterOfPosition(sourceFile, node.getStart()),
|
---|
62 | message: message,
|
---|
63 | });
|
---|
64 | }
|
---|
65 | }
|
---|
66 | exports.Migration = Migration;
|
---|
67 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlncmF0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL3VwZGF0ZS10b29sL21pZ3JhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCxpQ0FBaUM7QUF1QmpDLE1BQXNCLFNBQVM7SUFPN0I7SUFDSSw0Q0FBNEM7SUFDckMsT0FBbUI7SUFDMUIscURBQXFEO0lBQzlDLFdBQTJCO0lBQ2xDLHVEQUF1RDtJQUNoRCxhQUE0QjtJQUNuQyxzQ0FBc0M7SUFDL0IsT0FBZ0I7SUFDdkIsNENBQTRDO0lBQ3JDLFdBQWlCO0lBQ3hCLHdEQUF3RDtJQUNqRCxVQUFzQjtJQUM3QiwwRUFBMEU7SUFDbkUsTUFBb0I7UUFacEIsWUFBTyxHQUFQLE9BQU8sQ0FBWTtRQUVuQixnQkFBVyxHQUFYLFdBQVcsQ0FBZ0I7UUFFM0Isa0JBQWEsR0FBYixhQUFhLENBQWU7UUFFNUIsWUFBTyxHQUFQLE9BQU8sQ0FBUztRQUVoQixnQkFBVyxHQUFYLFdBQVcsQ0FBTTtRQUVqQixlQUFVLEdBQVYsVUFBVSxD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