Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
fix(Core): correctly treat optional pipe dependencies as optional
Browse files Browse the repository at this point in the history
Previously the `@Optional()` annotation used to mark injected dependencies as
optional was ignored on pipes, meaning a "No provider found ..." error would be
thrown when attempting to instantiate a pipe with a missing optional dependency.

Fixes #1665.

PiperOrigin-RevId: 222314430
  • Loading branch information
leonsenft authored and alorenzen committed Nov 30, 2018
1 parent b06a160 commit 0c16f9e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
33 changes: 33 additions & 0 deletions _tests/test/regression/1665_optional_pipe_dependency_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@TestOn('browser')
import 'package:test/test.dart';
import 'package:angular/angular.dart';
import 'package:angular_test/angular_test.dart';

import '1665_optional_pipe_dependency_test.template.dart' as ng;

void main() {
tearDown(disposeAnyRunningTest);

test('a missing @Optional() pipe dependency does not throw', () async {
var testBed = NgTestBed.forComponent(ng.TestComponentNgFactory);
expect(testBed.create(), completes);
});
}

abstract class TestService {}

@Pipe('test')
class TestPipe {
TestPipe(@Optional() TestService _);

dynamic transform(dynamic value) => value;
}

@Component(
selector: 'test',
template: '{{value | test}}',
pipes: [TestPipe],
)
class TestComponent {
var value = 'Hello world!';
}
6 changes: 6 additions & 0 deletions angular/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@
Previously, this would build successfully but emit code that instantiated
the directive with `dynamic` in place of the private type.

* [#1665][]: `@Optional()` dependencies of pipes are now correctly treated as
optional. Previously the annotation was ignored, and attempting to
instantiate the pipe with a missing optional dependency would throw an error
for the missing dependency.

[#1653]: https://github.com/dart-lang/angular/issues/1653
[#1665]: https://github.com/dart-lang/angular/issues/1665

## 5.1.0

Expand Down
2 changes: 1 addition & 1 deletion angular/lib/src/compiler/view_compiler/compile_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ class CompileView implements AppViewBuilder {
return o.ReadClassMemberExpr('ref');
}
usesInjectorGet = true;
return injectFromViewParentInjector(this, diDep.token, false);
return injectFromViewParentInjector(this, diDep.token, diDep.isOptional);
}).toList();
final pipeInstance = storage.allocate(
name,
Expand Down

0 comments on commit 0c16f9e

Please sign in to comment.