angular-cn/packages/compiler-cli/test
Alex Rickabaugh d2742cf473 feat(ivy): compile @Injectable on classes not meant for DI (#28523)
In the past, @Injectable had no side effects and existing Angular code is
therefore littered with @Injectable usage on classes which are not intended
to be injected.

A common example is:

@Injectable()
class Foo {
  constructor(private notInjectable: string) {}
}

and somewhere else:

providers: [{provide: Foo, useFactory: ...})

Here, there is no need for Foo to be injectable - indeed, it's impossible
for the DI system to create an instance of it, as it has a non-injectable
constructor. The provider configures a factory for the DI system to be
able to create instances of Foo.

Adding @Injectable in Ivy signifies that the class's own constructor, and
not a provider, determines how the class will be created.

This commit adds logic to compile classes which are marked with @Injectable
but are otherwise not injectable, and create an ngInjectableDef field with
a factory function that throws an error. This way, existing code in the wild
continues to compile, but if someone attempts to use the injectable it will
fail with a useful error message.

In the case where strictInjectionParameters is set to true, a compile-time
error is thrown instead of the runtime error, as ngtsc has enough
information to determine when injection couldn't possibly be valid.

PR Close #28523
2019-02-13 19:13:10 -08:00
..
compliance refactor(ivy): combine contentQueries and contentQueriesRefresh functions (#28503) 2019-02-13 12:01:32 -08:00
diagnostics refactor(compiler): use `options` argument for parsers (#28055) 2019-02-12 20:58:27 -08:00
metadata test(ivy): mark failing test targets with fixme-ivy-jit and fixme-ivy-local tags (#26471) 2018-10-23 08:57:42 -07:00
ngcc build: support running compiler-cli tests on windows (#28352) 2019-02-05 14:31:10 -05:00
ngtsc feat(ivy): compile @Injectable on classes not meant for DI (#28523) 2019-02-13 19:13:10 -08:00
transformers build: fix failing compiler-cli tests on windows (#28352) 2019-02-05 14:31:10 -05:00
BUILD.bazel build: support running compiler-cli tests on windows (#28352) 2019-02-05 14:31:10 -05:00
extract_i18n_spec.ts build: remove unused "test.sh" leftover code in compiler-cli (#28352) 2019-02-05 14:31:10 -05:00
mocks.ts fix(compiler-cli): Use typescript to resolve modules for metadata (#22856) 2018-07-10 11:11:48 -07:00
ngc_spec.ts feat(compiler-cli): no longer re-export external symbols by default (#28633) 2019-02-13 09:49:51 -08:00
ngtools_api_spec.ts fix(ivy): support listing lazy route for project-root-relative entry point in `ngtsc` (#28542) 2019-02-11 16:23:30 -08:00
perform_compile_spec.ts feat(compiler-cli): add support to extend `angularCompilerOptions` (#22717) 2018-09-19 16:17:28 -07:00
perform_watch_spec.ts build: fix failing compiler-cli tests on windows (#28352) 2019-02-05 14:31:10 -05:00
runfile_helpers.ts build: support running compiler-cli tests on windows (#28352) 2019-02-05 14:31:10 -05:00
test_support.ts test(ivy): test listing lazy routes to different root directories (#28542) 2019-02-11 16:23:30 -08:00