refactor(core): remove disabled injectable-pipe migration (#32184)
Initially the plan was to have a migration that adds `@Injectable()` to
all pipes in a CLI project so that the pipes can be injected in Ivy
similarly to how it worked in view engine.
Due to the planned refactorings which ensure that `@Directive`, `@Component`
and `@Pipe` also have a factory definition, this migration is no longer
needed for Ivy. Additionally since it is already disabled (due to
572b54967c
) and we have a more generic
migration (known as `missing-injectable)` that could do the same as
`injectable-pipe`, we remove the migration from the code-base.
PR Close #32184
This commit is contained in:

committed by
Andrew Kushnir

parent
5da5ca5c23
commit
639b732024
@ -6,7 +6,6 @@ ts_library(
|
||||
tsconfig = "//packages/core/schematics:tsconfig.json",
|
||||
visibility = ["//packages/core/schematics/test/google3:__pkg__"],
|
||||
deps = [
|
||||
"//packages/core/schematics/migrations/injectable-pipe",
|
||||
"//packages/core/schematics/migrations/missing-injectable",
|
||||
"//packages/core/schematics/migrations/missing-injectable/google3",
|
||||
"//packages/core/schematics/migrations/renderer-to-renderer2",
|
||||
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Replacement, RuleFailure, Rules} from 'tslint';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {InjectablePipeVisitor} from '../injectable-pipe/angular/injectable_pipe_visitor';
|
||||
import {INJECTABLE_DECORATOR_NAME, addImport, getNamedImports} from '../injectable-pipe/util';
|
||||
|
||||
|
||||
/**
|
||||
* TSLint rule that flags `@Pipe` classes that haven't been marked as `@Injectable`.
|
||||
*/
|
||||
export class Rule extends Rules.TypedRule {
|
||||
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[] {
|
||||
const visitor = new InjectablePipeVisitor(program.getTypeChecker());
|
||||
const printer = ts.createPrinter();
|
||||
const failures: RuleFailure[] = [];
|
||||
|
||||
visitor.visitNode(sourceFile);
|
||||
|
||||
visitor.missingInjectablePipes.forEach(data => {
|
||||
const {pipeDecorator, importDeclarationMissingImport} = data;
|
||||
const fixes = [new Replacement(
|
||||
pipeDecorator.getStart(), pipeDecorator.getWidth(),
|
||||
`@${INJECTABLE_DECORATOR_NAME}()\n${pipeDecorator.getText()}`)];
|
||||
|
||||
if (importDeclarationMissingImport) {
|
||||
const namedImports = getNamedImports(importDeclarationMissingImport);
|
||||
|
||||
// Add another fix that'll add the missing import.
|
||||
if (namedImports) {
|
||||
fixes.push(new Replacement(
|
||||
namedImports.getStart(), namedImports.getWidth(),
|
||||
printer.printNode(
|
||||
ts.EmitHint.Unspecified, addImport(namedImports, INJECTABLE_DECORATOR_NAME),
|
||||
sourceFile)));
|
||||
}
|
||||
}
|
||||
|
||||
// Add a failure on Pipe decorators that are missing the Injectable decorator.
|
||||
failures.push(new RuleFailure(
|
||||
sourceFile, pipeDecorator.getStart(), pipeDecorator.getWidth(),
|
||||
'Classes with @Pipe should be decorated with @Injectable so that they can be injected.',
|
||||
this.ruleName, fixes));
|
||||
});
|
||||
|
||||
return failures;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user