1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC 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 | */
|
---|
8 | (function (factory) {
|
---|
9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
10 | var v = factory(require, exports);
|
---|
11 | if (v !== undefined) module.exports = v;
|
---|
12 | }
|
---|
13 | else if (typeof define === "function" && define.amd) {
|
---|
14 | define("@angular/core/schematics/migrations/renderer-to-renderer2", ["require", "exports", "@angular-devkit/schematics", "path", "typescript", "@angular/core/schematics/utils/project_tsconfig_paths", "@angular/core/schematics/utils/typescript/compiler_host", "@angular/core/schematics/utils/typescript/imports", "@angular/core/schematics/utils/typescript/nodes", "@angular/core/schematics/migrations/renderer-to-renderer2/helpers", "@angular/core/schematics/migrations/renderer-to-renderer2/migration", "@angular/core/schematics/migrations/renderer-to-renderer2/util"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | const schematics_1 = require("@angular-devkit/schematics");
|
---|
20 | const path_1 = require("path");
|
---|
21 | const ts = require("typescript");
|
---|
22 | const project_tsconfig_paths_1 = require("@angular/core/schematics/utils/project_tsconfig_paths");
|
---|
23 | const compiler_host_1 = require("@angular/core/schematics/utils/typescript/compiler_host");
|
---|
24 | const imports_1 = require("@angular/core/schematics/utils/typescript/imports");
|
---|
25 | const nodes_1 = require("@angular/core/schematics/utils/typescript/nodes");
|
---|
26 | const helpers_1 = require("@angular/core/schematics/migrations/renderer-to-renderer2/helpers");
|
---|
27 | const migration_1 = require("@angular/core/schematics/migrations/renderer-to-renderer2/migration");
|
---|
28 | const util_1 = require("@angular/core/schematics/migrations/renderer-to-renderer2/util");
|
---|
29 | const MODULE_AUGMENTATION_FILENAME = 'ɵɵRENDERER_MIGRATION_CORE_AUGMENTATION.d.ts';
|
---|
30 | /**
|
---|
31 | * Migration that switches from `Renderer` to `Renderer2`. More information on how it works:
|
---|
32 | * https://hackmd.angular.io/UTzUZTnPRA-cSa_4mHyfYw
|
---|
33 | */
|
---|
34 | function default_1() {
|
---|
35 | return (tree) => {
|
---|
36 | const { buildPaths, testPaths } = project_tsconfig_paths_1.getProjectTsConfigPaths(tree);
|
---|
37 | const basePath = process.cwd();
|
---|
38 | const allPaths = [...buildPaths, ...testPaths];
|
---|
39 | if (!allPaths.length) {
|
---|
40 | throw new schematics_1.SchematicsException('Could not find any tsconfig file. Cannot migrate Renderer usages to Renderer2.');
|
---|
41 | }
|
---|
42 | for (const tsconfigPath of allPaths) {
|
---|
43 | runRendererToRenderer2Migration(tree, tsconfigPath, basePath);
|
---|
44 | }
|
---|
45 | };
|
---|
46 | }
|
---|
47 | exports.default = default_1;
|
---|
48 | function runRendererToRenderer2Migration(tree, tsconfigPath, basePath) {
|
---|
49 | // Technically we can get away with using `MODULE_AUGMENTATION_FILENAME` as the path, but as of
|
---|
50 | // TS 4.2, the module resolution caching seems to be more aggressive which causes the file to be
|
---|
51 | // retained between test runs. We can avoid it by using the full path.
|
---|
52 | const augmentedFilePath = path_1.join(basePath, MODULE_AUGMENTATION_FILENAME);
|
---|
53 | const { program } = compiler_host_1.createMigrationProgram(tree, tsconfigPath, basePath, fileName => {
|
---|
54 | // In case the module augmentation file has been requested, we return a source file that
|
---|
55 | // augments "@angular/core" to include a named export called "Renderer". This ensures that
|
---|
56 | // we can rely on the type checker for this migration in v9 where "Renderer" has been removed.
|
---|
57 | if (path_1.basename(fileName) === MODULE_AUGMENTATION_FILENAME) {
|
---|
58 | return `
|
---|
59 | import '@angular/core';
|
---|
60 | declare module "@angular/core" {
|
---|
61 | class Renderer {}
|
---|
62 | }
|
---|
63 | `;
|
---|
64 | }
|
---|
65 | return undefined;
|
---|
66 | }, [augmentedFilePath]);
|
---|
67 | const typeChecker = program.getTypeChecker();
|
---|
68 | const printer = ts.createPrinter();
|
---|
69 | const sourceFiles = program.getSourceFiles().filter(sourceFile => compiler_host_1.canMigrateFile(basePath, sourceFile, program));
|
---|
70 | sourceFiles.forEach(sourceFile => {
|
---|
71 | const rendererImportSpecifier = imports_1.getImportSpecifier(sourceFile, '@angular/core', 'Renderer');
|
---|
72 | const rendererImport = rendererImportSpecifier ?
|
---|
73 | nodes_1.closestNode(rendererImportSpecifier, ts.SyntaxKind.NamedImports) :
|
---|
74 | null;
|
---|
75 | // If there are no imports for the `Renderer`, we can exit early.
|
---|
76 | if (!rendererImportSpecifier || !rendererImport) {
|
---|
77 | return;
|
---|
78 | }
|
---|
79 | const { typedNodes, methodCalls, forwardRefs } = util_1.findRendererReferences(sourceFile, typeChecker, rendererImportSpecifier);
|
---|
80 | const update = tree.beginUpdate(path_1.relative(basePath, sourceFile.fileName));
|
---|
81 | const helpersToAdd = new Set();
|
---|
82 | // Change the `Renderer` import to `Renderer2`.
|
---|
83 | update.remove(rendererImport.getStart(), rendererImport.getWidth());
|
---|
84 | update.insertRight(rendererImport.getStart(), printer.printNode(ts.EmitHint.Unspecified, imports_1.replaceImport(rendererImport, 'Renderer', 'Renderer2'), sourceFile));
|
---|
85 | // Change the method parameter and property types to `Renderer2`.
|
---|
86 | typedNodes.forEach(node => {
|
---|
87 | const type = node.type;
|
---|
88 | if (type) {
|
---|
89 | update.remove(type.getStart(), type.getWidth());
|
---|
90 | update.insertRight(type.getStart(), 'Renderer2');
|
---|
91 | }
|
---|
92 | });
|
---|
93 | // Change all identifiers inside `forwardRef` referring to the `Renderer`.
|
---|
94 | forwardRefs.forEach(identifier => {
|
---|
95 | update.remove(identifier.getStart(), identifier.getWidth());
|
---|
96 | update.insertRight(identifier.getStart(), 'Renderer2');
|
---|
97 | });
|
---|
98 | // Migrate all of the method calls.
|
---|
99 | methodCalls.forEach(call => {
|
---|
100 | const { node, requiredHelpers } = migration_1.migrateExpression(call, typeChecker);
|
---|
101 | if (node) {
|
---|
102 | // If we migrated the node to a new expression, replace only the call expression.
|
---|
103 | update.remove(call.getStart(), call.getWidth());
|
---|
104 | update.insertRight(call.getStart(), printer.printNode(ts.EmitHint.Unspecified, node, sourceFile));
|
---|
105 | }
|
---|
106 | else if (call.parent && ts.isExpressionStatement(call.parent)) {
|
---|
107 | // Otherwise if the call is inside an expression statement, drop the entire statement.
|
---|
108 | // This takes care of any trailing semicolons. We only need to drop nodes for cases like
|
---|
109 | // `setBindingDebugInfo` which have been noop for a while so they can be removed safely.
|
---|
110 | update.remove(call.parent.getStart(), call.parent.getWidth());
|
---|
111 | }
|
---|
112 | if (requiredHelpers) {
|
---|
113 | requiredHelpers.forEach(helperName => helpersToAdd.add(helperName));
|
---|
114 | }
|
---|
115 | });
|
---|
116 | // Some of the methods can't be mapped directly to `Renderer2` and need extra logic around them.
|
---|
117 | // The safest way to do so is to declare helper functions similar to the ones emitted by TS
|
---|
118 | // which encapsulate the extra "glue" logic. We should only emit these functions once per file.
|
---|
119 | helpersToAdd.forEach(helperName => {
|
---|
120 | update.insertLeft(sourceFile.endOfFileToken.getStart(), helpers_1.getHelper(helperName, sourceFile, printer));
|
---|
121 | });
|
---|
122 | tree.commitUpdate(update);
|
---|
123 | });
|
---|
124 | }
|
---|
125 | });
|
---|
126 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb3JlL3NjaGVtYXRpY3MvbWlncmF0aW9ucy9yZW5kZXJlci10by1yZW5kZXJlcjIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOzs7Ozs7Ozs7Ozs7SUFFSCwyREFBMkU7SUFDM0UsK0JBQThDO0lBQzlDLGlDQUFpQztJQUVqQyxrR0FBMkU7SUFDM0UsMkZBQTRGO0lBQzVGLCtFQUFpRjtJQUNqRiwyRUFB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