angular-docs-cn/packages/core/schematics/test
crisbeto c0955975f4 feat(core): add automatic migration from Renderer to Renderer2 (#30936)
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
2019-07-03 09:03:37 -07:00
..
google3 feat(core): add automatic migration from Renderer to Renderer2 (#30936) 2019-07-03 09:03:37 -07:00
BUILD.bazel feat(core): add automatic migration from Renderer to Renderer2 (#30936) 2019-07-03 09:03:37 -07:00
injectable_pipe_migration_spec.ts test: resotre "async" around tests where "await" is used (#30762) 2019-05-30 23:14:16 -07:00
line_mappings_spec.ts feat(core): template-var-assignment update schematic (#29608) 2019-04-02 15:47:32 -07:00
move_document_migration_spec.ts test: resotre "async" around tests where "await" is used (#30762) 2019-05-30 23:14:16 -07:00
project_tsconfig_paths_spec.ts refactor(core): migrations should parse cli workspace config as json5 (#30582) 2019-05-21 17:26:22 -07:00
renderer_to_renderer2_migration_spec.ts feat(core): add automatic migration from Renderer to Renderer2 (#30936) 2019-07-03 09:03:37 -07:00
static_queries_migration_template_spec.ts fix(core): TypeScript related migrations should cater for BOM (#30719) 2019-05-30 20:48:45 -07:00
static_queries_migration_usage_spec.ts fix(core): TypeScript related migrations should cater for BOM (#30719) 2019-05-30 20:48:45 -07:00
template_var_assignment_migration_spec.ts refactor(compiler): recursive ast expression visitor not passing context (#31085) 2019-06-20 11:12:16 -07:00
test-migrations.json test(core): run schematic tests with public migration collection (#30198) 2019-05-08 09:23:28 -07:00