angular-docs-cn/packages/core/schematics/migrations/injectable-pipe
Alan Agius 80394ce08b fix(core): TypeScript related migrations should cater for BOM (#30719)
fix(@schematics/angular): TypeScript related migrations should cater for BOM

In the CLI `UpdateRecorder` methods such as `insertLeft`, `remove` etc.. accepts positions which are not offset by a BOM. This is because when a file has a BOM a different recorder will be used https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/src/tree/recorder.ts#L72 which caters for an addition offset/delta.

The main reason for this is that when a developer is writing a schematic they shouldn't need to compute the offset based if a file has a BOM or not and is handled out of the box.

Example
```ts
recorder.insertLeft(5, 'true');
```

However this is unfortunate in the case if a ts SourceFile is used and one uses `getWidth` and `getStart` method they will already be offset by 1, which at the end it results in a double offset and hence the problem.

Fixes #30713

PR Close #30719
2019-05-30 20:48:45 -07:00
..
angular feat(ivy): add injectable-pipe schematic (#29847) 2019-04-23 15:12:19 -07:00
google3 build: update rules_nodejs and clean up bazel warnings (#30370) 2019-05-14 10:08:45 -07:00
BUILD.bazel feat(ivy): add injectable-pipe schematic (#29847) 2019-04-23 15:12:19 -07:00
README.md feat(ivy): add injectable-pipe schematic (#29847) 2019-04-23 15:12:19 -07:00
index.ts fix(core): TypeScript related migrations should cater for BOM (#30719) 2019-05-30 20:48:45 -07:00
util.ts fix(ivy): injectable pipe schematic generating incorrect import statements (#30170) 2019-04-29 09:39:11 -07:00

README.md

Injectable annotation on pipes

In ViewEngine it was possible to inject a class that was annotated as a Pipe, however this no longer works in Ivy if the class also doesn't have the Injectable decorator. This migration adds Injectable automatically to all Pipe classes.

Before

import { Pipe } from '@angular/core';

@Pipe({ name: 'myPipe' })
class MyPipe {}

After

import { Pipe, Injectable } from '@angular/core';

@Injectable()
@Pipe({ name: 'myPipe' })
class MyPipe {}