angular/packages/core/src
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
..
change_detection refactor(ivy): Add newer, smaller NgOnChangesFeature (#28187) 2019-01-23 10:59:34 -08:00
compiler fix(ivy): verify Host Bindings and Host Listeners before compiling them (#28356) 2019-01-29 16:36:22 -08:00
debug refactor(ivy): remove unused notImplement function (#28630) 2019-02-12 21:56:09 -08:00
di feat(ivy): compile @Injectable on classes not meant for DI (#28523) 2019-02-13 19:13:10 -08:00
i18n docs: convert all @experimental tags to @publicApi tags (#26595) 2018-10-19 14:35:52 -07:00
interface refactor(ivy): Add newer, smaller NgOnChangesFeature (#28187) 2019-01-23 10:59:34 -08:00
linker docs: add api doc to template_ref (#27380) 2019-01-22 12:13:50 -08:00
metadata docs: add di-related api doc (#27731) 2019-02-13 11:57:37 -08:00
profile build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
reflection build: set a default module_name for ts_library rules (#28051) 2019-01-18 10:16:39 -08:00
render fix(ivy): ensure element removal triggers host removal animations (#28162) 2019-01-17 09:58:50 -08:00
render3 fix(ivy): should mark OnPush ancestor of dynamically created views as dirty (#28687) 2019-02-13 12:12:45 -08:00
sanitization fix(ivy): throw on bindings to unknown properties (#28537) 2019-02-07 12:37:32 -08:00
testability build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
util fix(core): improve global variable detection (#28679) 2019-02-13 12:05:41 -08:00
view perf(core): be more consistent about typeof checks (#28400) 2019-01-29 11:50:47 -08:00
zone docs: convert all @experimental tags to @publicApi tags (#26595) 2018-10-19 14:35:52 -07:00
application_init.ts docs: update core to use @publicApi tags (#26595) 2018-10-19 14:35:53 -07:00
application_module.ts fix(ivy): use NgZone.onStable when bootstraped using PlatformRef (#27898) 2019-01-08 14:10:53 -08:00
application_ref.ts docs(core): document isStable traps (#28102) 2019-02-06 15:13:19 -05:00
application_tokens.ts docs: convert all @experimental tags to @publicApi tags (#26595) 2018-10-19 14:35:52 -07:00
change_detection.ts refactor(core): remove deprecated TrackByFn (#18757) 2017-08-18 13:23:46 -05:00
codegen_private_exports.ts refactor(compiler): don’t rely on global reflector (#16832) 2017-05-23 10:41:23 -06:00
console.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
core.externs.js fix: don’t use the global ng at all with closure enhanced optimizations 2017-09-27 10:09:56 -07:00
core.ts build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
core_private_export.ts feat(ivy): implement compileComponents method for TestBedRender3 (#27778) 2019-01-15 14:08:20 -08:00
core_render3_private_export.ts fix(core): remove createInjector() from public API (#28509) 2019-02-04 16:54:26 -05:00
di.ts refactor(ivy): create Injector interface; remove dependency on Ivy (#28066) 2019-01-11 16:24:03 -08:00
error_handler.ts refactor(ivy): refactor more files in DI to prepare it for bazel packages (#28098) 2019-01-14 09:55:30 -08:00
errors.ts build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
event_emitter.ts refactor(core): improve type for EventEmitter (#27228) 2019-01-10 17:02:52 -08:00
ivy_switch.ts refactor(ivy): obviate the Bazel component of the ivy_switch (#26550) 2018-10-19 09:23:05 -07:00
linker.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
metadata.ts refactor(ivy): refactor more files in DI to prepare it for bazel packages (#28098) 2019-01-14 09:55:30 -08:00
platform_core_providers.ts docs: convert all @experimental tags to @publicApi tags (#26595) 2018-10-19 14:35:52 -07:00
r3_symbols.ts build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
render.ts refactor(core): use flags in Renderer2.setStyle instead of booleans (#15045) 2017-03-13 09:45:04 -07:00
version.ts docs: update core to use @publicApi tags (#26595) 2018-10-19 14:35:53 -07:00
zone.ts feat(router): warn if navigation triggered outside Angular zone (#24959) 2018-09-05 09:35:14 -07:00