Adds a schematic and tslint rule that automatically migrate the consumer from `Renderer` to `Renderer2`. Supports: * Renaming imports. * Renaming property and method argument types. * Casting to `Renderer`. * Mapping all of the methods from the `Renderer` to `Renderer2`. Note that some of the `Renderer` methods don't map cleanly between renderers. In these cases the migration adds a helper function at the bottom of the file which ensures that we generate valid code with the same return value as before. E.g. here's what the migration for `createText` looks like. Before: ``` class SomeComponent { createAndAddText() { const node = this._renderer.createText(this._element.nativeElement, 'hello'); node.textContent += ' world'; } } ``` After: ``` class SomeComponent { createAndAddText() { const node = __rendererCreateTextHelper(this._renderer, this._element.nativeElement, 'hello'); node.textContent += ' world'; } } function __rendererCreateTextHelper(renderer: any, parent: any, value: any) { const node = renderer.createText(value); if (parent) { renderer.appendChild(parent, node); } return node; } ``` This PR resolves FW-1344. PR Close #30936
19 lines
558 B
Python
19 lines
558 B
Python
load("//tools:defaults.bzl", "ts_library")
|
|
|
|
ts_library(
|
|
name = "renderer-to-renderer2",
|
|
srcs = glob(["**/*.ts"]),
|
|
tsconfig = "//packages/core/schematics:tsconfig.json",
|
|
visibility = [
|
|
"//packages/core/schematics:__pkg__",
|
|
"//packages/core/schematics/migrations/renderer-to-renderer2/google3:__pkg__",
|
|
"//packages/core/schematics/test:__pkg__",
|
|
],
|
|
deps = [
|
|
"//packages/core/schematics/utils",
|
|
"@npm//@angular-devkit/schematics",
|
|
"@npm//@types/node",
|
|
"@npm//typescript",
|
|
],
|
|
)
|