fix(compiler): allow tree-shakeable injectables to depend on string tokens (#22376)
Previously the injectable compiler assumed all tree-shakeable injectables would have dependencies that were injectables or InjectionTokens. However old code still uses string tokens (e.g. NgUpgrade and '$injector'). Using such tokens would cause the injectable compiler to crash. Now, the injectable compiler can properly generate a dependency on such a string token. PR Close #22376
This commit is contained in:

committed by
Alex Eagle

parent
8bb2f5c71d
commit
dd534471ec
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @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 {Component, Inject, Injectable, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {ServerModule} from '@angular/platform-server';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'string-app',
|
||||
template: '{{data}}',
|
||||
})
|
||||
export class AppComponent {
|
||||
data: string;
|
||||
constructor(service: Service) { this.data = service.data; }
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule.withServerTransition({appId: 'id-app'}),
|
||||
ServerModule,
|
||||
],
|
||||
declarations: [AppComponent],
|
||||
bootstrap: [AppComponent],
|
||||
providers: [{provide: 'someStringToken', useValue: 'works'}],
|
||||
})
|
||||
export class StringAppModule {
|
||||
}
|
||||
|
||||
@Injectable({scope: StringAppModule})
|
||||
export class Service {
|
||||
constructor(@Inject('someStringToken') readonly data: string) {}
|
||||
}
|
Reference in New Issue
Block a user