diff --git a/aio/tools/transforms/angular-api-package/index.js b/aio/tools/transforms/angular-api-package/index.js index 9882dad214..a8d731505d 100644 --- a/aio/tools/transforms/angular-api-package/index.js +++ b/aio/tools/transforms/angular-api-package/index.js @@ -179,7 +179,7 @@ module.exports = .config(function(filterMembers) { filterMembers.notAllowedPatterns.push( - /^ng[A-Z].*Def$/, /^ɵ/ + /^ɵ/ ); }) diff --git a/packages/bazel/test/ng_package/core_package.spec.ts b/packages/bazel/test/ng_package/core_package.spec.ts index 81f68ce93e..bbfe3594ac 100644 --- a/packages/bazel/test/ng_package/core_package.spec.ts +++ b/packages/bazel/test/ng_package/core_package.spec.ts @@ -126,9 +126,9 @@ describe('@angular/core ng_package', () => { }); if (ivyEnabled) { - it('should have decorators downleveled to static props e.g. ngInjectableDef', () => { + it('should have decorators downleveled to static props e.g. ɵprov', () => { expect(shx.cat('fesm5/core.js')).not.toContain('__decorate'); - expect(shx.cat('fesm5/core.js')).toContain('.ngInjectableDef = '); + expect(shx.cat('fesm5/core.js')).toContain('.ɵprov = '); }); } else { it('should have decorators', diff --git a/packages/common/src/viewport_scroller.ts b/packages/common/src/viewport_scroller.ts index 0e57c942d9..39044f51d9 100644 --- a/packages/common/src/viewport_scroller.ts +++ b/packages/common/src/viewport_scroller.ts @@ -21,7 +21,7 @@ export abstract class ViewportScroller { // De-sugared tree-shakable injection // See #23917 /** @nocollapse */ - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ViewportScroller, providedIn: 'root', factory: () => new BrowserViewportScroller(ɵɵinject(DOCUMENT), window, ɵɵinject(ErrorHandler)) diff --git a/packages/compiler-cli/integrationtest/bazel/injectable_def/app/test/app_spec.ts b/packages/compiler-cli/integrationtest/bazel/injectable_def/app/test/app_spec.ts index 3ac26c32f5..cf01fe5278 100644 --- a/packages/compiler-cli/integrationtest/bazel/injectable_def/app/test/app_spec.ts +++ b/packages/compiler-cli/integrationtest/bazel/injectable_def/app/test/app_spec.ts @@ -125,14 +125,14 @@ describe('ngInjectableDef Bazel Integration', () => { expect(TestBed.inject(Service).value).toEqual('overridden'); }); - it('does not override existing ngInjectableDef', () => { + it('does not override existing ɵprov', () => { @Injectable({ providedIn: 'root', useValue: new Service(false), }) class Service { constructor(public value: boolean) {} - static ngInjectableDef = { + static ɵprov = { providedIn: 'root', factory: () => new Service(true), token: Service, @@ -143,7 +143,7 @@ describe('ngInjectableDef Bazel Integration', () => { expect(TestBed.inject(Service).value).toEqual(true); }); - it('does not override existing ngInjectableDef in case of inheritance', () => { + it('does not override existing ɵprov in case of inheritance', () => { @Injectable({ providedIn: 'root', useValue: new ParentService(false), diff --git a/packages/compiler-cli/src/metadata/bundler.ts b/packages/compiler-cli/src/metadata/bundler.ts index 50be5c11e1..5c07de49c0 100644 --- a/packages/compiler-cli/src/metadata/bundler.ts +++ b/packages/compiler-cli/src/metadata/bundler.ts @@ -423,7 +423,7 @@ export class MetadataBundler { result[key] = this.convertFunction(moduleName, value); } else if (isMetadataSymbolicCallExpression(value)) { // Class members can also contain static members that call a function with module - // references. e.g. "static ngInjectableDef = ɵɵdefineInjectable(..)". We also need to + // references. e.g. "static ɵprov = ɵɵdefineInjectable(..)". We also need to // convert these module references because otherwise these resolve to non-existent files. result[key] = this.convertValue(moduleName, value); } else { diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts b/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts index 08cd1ded95..b2b6a4d583 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts @@ -92,7 +92,7 @@ export class InjectableDecoratorHandler implements } results.push({ - name: 'ngInjectableDef', + name: 'ɵprov', initializer: res.expression, statements, type: res.type, }); @@ -214,8 +214,7 @@ function extractInjectableCtorDeps( // Angular's DI. // // To deal with this, @Injectable() without an argument is more lenient, and if the - // constructor - // signature does not work for DI then an ngInjectableDef that throws. + // constructor signature does not work for DI then a provider def (ɵprov) that throws. if (strictCtorDeps) { ctorDeps = getValidConstructorDependencies(clazz, reflector, defaultImportRecorder, isCore); } else { diff --git a/packages/compiler-cli/src/transformers/nocollapse_hack.ts b/packages/compiler-cli/src/transformers/nocollapse_hack.ts index ba2389b642..d889704f9d 100644 --- a/packages/compiler-cli/src/transformers/nocollapse_hack.ts +++ b/packages/compiler-cli/src/transformers/nocollapse_hack.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -// Closure compiler transforms the form `Service.ngInjectableDef = X` into -// `Service$ngInjectableDef = X`. To prevent this transformation, such assignments need to be +// Closure compiler transforms the form `Service.ɵprov = X` into +// `Service$ɵprov = X`. To prevent this transformation, such assignments need to be // annotated with @nocollapse. Unfortunately, a bug in Typescript where comments aren't propagated // through the TS transformations precludes adding the comment via the AST. This workaround detects -// the static assignments to R3 properties such as ngInjectableDef using a regex, as output files +// the static assignments to R3 properties such as ɵprov using a regex, as output files // are written, and applies the annotation through regex replacement. // // TODO(alxhub): clean up once fix for TS transformers lands in upstream @@ -22,7 +22,7 @@ const R3_DEF_NAME_PATTERN = [ 'ngBaseDef', 'ɵcmp', 'ɵdir', - 'ngInjectableDef', + 'ɵprov', 'ɵinj', 'ɵmod', 'ɵpipe', diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_di_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_di_spec.ts index e4c7da3e98..2524f3575a 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_di_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_di_spec.ts @@ -88,7 +88,7 @@ describe('compiler compliance: dependency injection', () => { }`; const def = ` - MyService.ngInjectableDef = $r3$.ɵɵdefineInjectable({ + MyService.ɵprov = $r3$.ɵɵdefineInjectable({ token: MyService, factory: function(t) { return MyService.ɵfac(t); @@ -144,7 +144,7 @@ describe('compiler compliance: dependency injection', () => { }; const def = ` - MyService.ngInjectableDef = $r3$.ɵɵdefineInjectable({ + MyService.ɵprov = $r3$.ɵɵdefineInjectable({ token: MyService, factory: function() { return alternateFactory(); @@ -178,7 +178,7 @@ describe('compiler compliance: dependency injection', () => { }; const def = ` - MyService.ngInjectableDef = $r3$.ɵɵdefineInjectable({ + MyService.ɵprov = $r3$.ɵɵdefineInjectable({ token: MyService, factory: function MyService_Factory(t) { var r = null; @@ -217,7 +217,7 @@ describe('compiler compliance: dependency injection', () => { }; const factory = ` - MyService.ngInjectableDef = $r3$.ɵɵdefineInjectable({ + MyService.ɵprov = $r3$.ɵɵdefineInjectable({ token: MyService, factory: function(t) { return MyAlternateService.ɵfac(t); @@ -253,7 +253,7 @@ describe('compiler compliance: dependency injection', () => { }; const factory = ` - MyService.ngInjectableDef = $r3$.ɵɵdefineInjectable({ + MyService.ɵprov = $r3$.ɵɵdefineInjectable({ token: MyService, factory: function MyService_Factory(t) { var r = null; @@ -290,7 +290,7 @@ describe('compiler compliance: dependency injection', () => { }; const factory = ` - SomeProvider.ngInjectableDef = $r3$.ɵɵdefineInjectable({ + SomeProvider.ɵprov = $r3$.ɵɵdefineInjectable({ token: SomeProvider, factory: function(t) { return SomeProviderImpl.ɵfac(t); diff --git a/packages/compiler-cli/test/metadata/bundler_spec.ts b/packages/compiler-cli/test/metadata/bundler_spec.ts index a3df9d15ee..8e147e1a98 100644 --- a/packages/compiler-cli/test/metadata/bundler_spec.ts +++ b/packages/compiler-cli/test/metadata/bundler_spec.ts @@ -231,7 +231,7 @@ describe('metadata bundler', () => { import {sharedFn} from '../shared'; export class MyClass { - static ngInjectableDef = sharedFn(); + static ɵprov = sharedFn(); } `, } @@ -244,7 +244,7 @@ describe('metadata bundler', () => { // The unbundled metadata should reference symbols using the relative module path. expect(deepIndexMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining({ statics: { - ngInjectableDef: { + ɵprov: { __symbolic: 'call', expression: { __symbolic: 'reference', @@ -260,7 +260,7 @@ describe('metadata bundler', () => { // anywhere and it's not guaranteed that the relatively referenced files are present. expect(bundledMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining({ statics: { - ngInjectableDef: { + ɵprov: { __symbolic: 'call', expression: { __symbolic: 'reference', diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index 48bac17623..f9d7e4ed70 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -2082,7 +2082,7 @@ describe('ngc transformer command-line', () => { }) export class ServiceModule {} `); - expect(source).not.toMatch(/ngInjectableDef/); + expect(source).not.toMatch(/ɵprov/); }); it('on a service with a base class service', () => { const source = compileService(` @@ -2102,7 +2102,7 @@ describe('ngc transformer command-line', () => { }) export class ServiceModule {} `); - expect(source).not.toMatch(/ngInjectableDef/); + expect(source).not.toMatch(/ɵprov/); }); }); @@ -2116,21 +2116,20 @@ describe('ngc transformer command-line', () => { }) export class Service {} `); - expect(source).toMatch(/ngInjectableDef = .+\.ɵɵdefineInjectable\(/); - expect(source).toMatch(/ngInjectableDef.*token: Service/); - expect(source).toMatch(/ngInjectableDef.*providedIn: .+\.Module/); + expect(source).toMatch(/ɵprov = .+\.ɵɵdefineInjectable\(/); + expect(source).toMatch(/ɵprov.*token: Service/); + expect(source).toMatch(/ɵprov.*providedIn: .+\.Module/); }); - it('ngInjectableDef in es5 mode is annotated @nocollapse when closure options are enabled', - () => { - writeConfig(`{ + it('ɵprov in es5 mode is annotated @nocollapse when closure options are enabled', () => { + writeConfig(`{ "extends": "./tsconfig-base.json", "angularCompilerOptions": { "annotateForClosureCompiler": true }, "files": ["service.ts"] }`); - const source = compileService(` + const source = compileService(` import {Injectable} from '@angular/core'; import {Module} from './module'; @@ -2139,8 +2138,8 @@ describe('ngc transformer command-line', () => { }) export class Service {} `); - expect(source).toMatch(/\/\*\* @nocollapse \*\/ Service\.ngInjectableDef =/); - }); + expect(source).toMatch(/\/\*\* @nocollapse \*\/ Service\.ɵprov =/); + }); it('compiles a useValue InjectableDef', () => { const source = compileService(` @@ -2155,7 +2154,7 @@ describe('ngc transformer command-line', () => { }) export class Service {} `); - expect(source).toMatch(/ngInjectableDef.*return CONST_SERVICE/); + expect(source).toMatch(/ɵprov.*return CONST_SERVICE/); }); it('compiles a useExisting InjectableDef', () => { @@ -2172,7 +2171,7 @@ describe('ngc transformer command-line', () => { }) export class Service {} `); - expect(source).toMatch(/ngInjectableDef.*return ..\.ɵɵinject\(Existing\)/); + expect(source).toMatch(/ɵprov.*return ..\.ɵɵinject\(Existing\)/); }); it('compiles a useFactory InjectableDef with optional dep', () => { @@ -2192,7 +2191,7 @@ describe('ngc transformer command-line', () => { constructor(e: Existing|null) {} } `); - expect(source).toMatch(/ngInjectableDef.*return ..\(..\.ɵɵinject\(Existing, 8\)/); + expect(source).toMatch(/ɵprov.*return ..\(..\.ɵɵinject\(Existing, 8\)/); }); it('compiles a useFactory InjectableDef with skip-self dep', () => { @@ -2212,7 +2211,7 @@ describe('ngc transformer command-line', () => { constructor(e: Existing) {} } `); - expect(source).toMatch(/ngInjectableDef.*return ..\(..\.ɵɵinject\(Existing, 4\)/); + expect(source).toMatch(/ɵprov.*return ..\(..\.ɵɵinject\(Existing, 4\)/); }); it('compiles a service that depends on a token', () => { @@ -2229,9 +2228,9 @@ describe('ngc transformer command-line', () => { constructor(@Inject(TOKEN) value: boolean) {} } `); - expect(source).toMatch(/ngInjectableDef = .+\.ɵɵdefineInjectable\(/); - expect(source).toMatch(/ngInjectableDef.*token: Service/); - expect(source).toMatch(/ngInjectableDef.*providedIn: .+\.Module/); + expect(source).toMatch(/ɵprov = .+\.ɵɵdefineInjectable\(/); + expect(source).toMatch(/ɵprov.*token: Service/); + expect(source).toMatch(/ɵprov.*providedIn: .+\.Module/); }); it('generates exports.* references when outputting commonjs', () => { diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 0f0ad620d9..98a7be5acd 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -61,12 +61,12 @@ runInEachFileSystem(os => { const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('Dep.ngInjectableDef ='); - expect(jsContents).toContain('Service.ngInjectableDef ='); + expect(jsContents).toContain('Dep.ɵprov ='); + expect(jsContents).toContain('Service.ɵprov ='); expect(jsContents).not.toContain('__decorate'); const dtsContents = env.getContents('test.d.ts'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef;'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); }); @@ -83,10 +83,10 @@ runInEachFileSystem(os => { const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('Store.ngInjectableDef ='); + expect(jsContents).toContain('Store.ɵprov ='); const dtsContents = env.getContents('test.d.ts'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef>;'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef>;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef>;'); }); it('should compile Injectables with providedIn without errors', () => { @@ -106,16 +106,16 @@ runInEachFileSystem(os => { const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('Dep.ngInjectableDef ='); - expect(jsContents).toContain('Service.ngInjectableDef ='); + expect(jsContents).toContain('Dep.ɵprov ='); + expect(jsContents).toContain('Service.ɵprov ='); expect(jsContents) .toContain( 'Service.ɵfac = function Service_Factory(t) { return new (t || Service)(i0.ɵɵinject(Dep)); };'); expect(jsContents).toContain('providedIn: \'root\' })'); expect(jsContents).not.toContain('__decorate'); const dtsContents = env.getContents('test.d.ts'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef;'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); }); @@ -134,14 +134,14 @@ runInEachFileSystem(os => { const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('Service.ngInjectableDef ='); + expect(jsContents).toContain('Service.ɵprov ='); expect(jsContents) .toContain('factory: function () { return (function () { return new Service(); })(); }'); expect(jsContents).toContain('Service_Factory(t) { return new (t || Service)(); }'); expect(jsContents).toContain(', providedIn: \'root\' });'); expect(jsContents).not.toContain('__decorate'); const dtsContents = env.getContents('test.d.ts'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); }); @@ -162,7 +162,7 @@ runInEachFileSystem(os => { const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('Service.ngInjectableDef ='); + expect(jsContents).toContain('Service.ɵprov ='); expect(jsContents).toContain('factory: function Service_Factory(t) { var r = null; if (t) {'); expect(jsContents).toContain('return new (t || Service)(i0.ɵɵinject(Dep));'); expect(jsContents) @@ -170,7 +170,7 @@ runInEachFileSystem(os => { expect(jsContents).toContain('return r; }, providedIn: \'root\' });'); expect(jsContents).not.toContain('__decorate'); const dtsContents = env.getContents('test.d.ts'); - expect(dtsContents).toContain('static ngInjectableDef: i0.ɵɵInjectableDef;'); + expect(dtsContents).toContain('static ɵprov: i0.ɵɵInjectableDef;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); }); @@ -375,7 +375,7 @@ runInEachFileSystem(os => { expect(jsContents).toContain('TestComponent.ɵcmp = i0.ɵɵdefineComponent'); expect(jsContents).toContain('TestDirective.ɵdir = i0.ɵɵdefineDirective'); expect(jsContents).toContain('TestPipe.ɵpipe = i0.ɵɵdefinePipe'); - expect(jsContents).toContain('TestInjectable.ngInjectableDef = i0.ɵɵdefineInjectable'); + expect(jsContents).toContain('TestInjectable.ɵprov = i0.ɵɵdefineInjectable'); expect(jsContents).toContain('MyModule.ɵmod = i0.ɵɵdefineNgModule'); expect(jsContents).toContain('MyModule.ɵinj = i0.ɵɵdefineInjector'); expect(jsContents).toContain('inputs: { input: "input" }'); @@ -1183,10 +1183,10 @@ runInEachFileSystem(os => { expect(jsContents).toContain('TestNgModule.ɵmod ='); // Validate that each class also has an injectable definition. - expect(jsContents).toContain('TestCmp.ngInjectableDef ='); - expect(jsContents).toContain('TestDir.ngInjectableDef ='); - expect(jsContents).toContain('TestPipe.ngInjectableDef ='); - expect(jsContents).toContain('TestNgModule.ngInjectableDef ='); + expect(jsContents).toContain('TestCmp.ɵprov ='); + expect(jsContents).toContain('TestDir.ɵprov ='); + expect(jsContents).toContain('TestPipe.ɵprov ='); + expect(jsContents).toContain('TestNgModule.ɵprov ='); // Validate that each class's .d.ts declaration has the primary definition. expect(dtsContents).toContain('ComponentDefWithMeta('Inject', (token: any) => ({token})); export const createInjectionToken = makeMetadataFactory( - 'InjectionToken', (desc: string) => ({_desc: desc, ngInjectableDef: undefined})); + 'InjectionToken', (desc: string) => ({_desc: desc, ɵprov: undefined})); export interface Attribute { attributeName?: string; } export const createAttribute = diff --git a/packages/compiler/src/injectable_compiler.ts b/packages/compiler/src/injectable_compiler.ts index d915800852..6018fb8809 100644 --- a/packages/compiler/src/injectable_compiler.ts +++ b/packages/compiler/src/injectable_compiler.ts @@ -126,7 +126,7 @@ export class InjectableCompiler { className, null, [ new o.ClassField( - 'ngInjectableDef', o.INFERRED_TYPE, [o.StmtModifier.Static], + 'ɵprov', o.INFERRED_TYPE, [o.StmtModifier.Static], this.injectableDef(injectable, ctx)), ], [], new o.ClassMethod(null, [], []), []); diff --git a/packages/core/src/change_detection/differs/iterable_differs.ts b/packages/core/src/change_detection/differs/iterable_differs.ts index e81ba67413..e9f6f660d9 100644 --- a/packages/core/src/change_detection/differs/iterable_differs.ts +++ b/packages/core/src/change_detection/differs/iterable_differs.ts @@ -143,7 +143,7 @@ export interface IterableDifferFactory { */ export class IterableDiffers { /** @nocollapse */ - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: IterableDiffers, providedIn: 'root', factory: () => new IterableDiffers([new DefaultIterableDifferFactory()]) diff --git a/packages/core/src/change_detection/differs/keyvalue_differs.ts b/packages/core/src/change_detection/differs/keyvalue_differs.ts index 83c11b2ed8..953d787d36 100644 --- a/packages/core/src/change_detection/differs/keyvalue_differs.ts +++ b/packages/core/src/change_detection/differs/keyvalue_differs.ts @@ -118,7 +118,7 @@ export interface KeyValueDifferFactory { */ export class KeyValueDiffers { /** @nocollapse */ - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: KeyValueDiffers, providedIn: 'root', factory: () => new KeyValueDiffers([new DefaultKeyValueDifferFactory()]) diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 4cbd6e8882..eff2b5a2bc 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -229,7 +229,7 @@ export { } from './render3/fields'; export { - NG_INJECTABLE_DEF as ɵNG_INJECTABLE_DEF, + NG_PROV_DEF as ɵNG_PROV_DEF, NG_INJ_DEF as ɵNG_INJ_DEF, } from './di/interface/defs'; diff --git a/packages/core/src/di/injectable.ts b/packages/core/src/di/injectable.ts index 27feb21c4f..1c766a513e 100644 --- a/packages/core/src/di/injectable.ts +++ b/packages/core/src/di/injectable.ts @@ -91,7 +91,7 @@ export const Injectable: InjectableDecorator = makeDecorator( * * @publicApi */ -export interface InjectableType extends Type { ngInjectableDef: ɵɵInjectableDef; } +export interface InjectableType extends Type { ɵprov: ɵɵInjectableDef; } /** * Supports @Injectable() in JIT mode for Render2. @@ -100,7 +100,7 @@ function render2CompileInjectable(injectableType: Type, options?: { providedIn?: Type| 'root' | 'platform' | 'any' | null } & InjectableProvider): void { if (options && options.providedIn !== undefined && !getInjectableDef(injectableType)) { - (injectableType as InjectableType).ngInjectableDef = ɵɵdefineInjectable({ + (injectableType as InjectableType).ɵprov = ɵɵdefineInjectable({ token: injectableType, providedIn: options.providedIn, factory: convertInjectableProviderToFactory(injectableType, options), diff --git a/packages/core/src/di/injection_token.ts b/packages/core/src/di/injection_token.ts index 7552fc7e53..5a3a6feb4e 100644 --- a/packages/core/src/di/injection_token.ts +++ b/packages/core/src/di/injection_token.ts @@ -54,20 +54,20 @@ export class InjectionToken { /** @internal */ readonly ngMetadataName = 'InjectionToken'; - readonly ngInjectableDef: never|undefined; + readonly ɵprov: never|undefined; constructor(protected _desc: string, options?: { providedIn?: Type| 'root' | 'platform' | 'any' | null, factory: () => T }) { - this.ngInjectableDef = undefined; + this.ɵprov = undefined; if (typeof options == 'number') { // This is a special hack to assign __NG_ELEMENT_ID__ to this instance. // __NG_ELEMENT_ID__ is Used by Ivy to determine bloom filter id. // We are using it to assign `-1` which is used to identify `Injector`. (this as any).__NG_ELEMENT_ID__ = options; } else if (options !== undefined) { - this.ngInjectableDef = ɵɵdefineInjectable({ + this.ɵprov = ɵɵdefineInjectable({ token: this, providedIn: options.providedIn || 'root', factory: options.factory, @@ -78,4 +78,4 @@ export class InjectionToken { toString(): string { return `InjectionToken ${this._desc}`; } } -export interface InjectableDefToken extends InjectionToken { ngInjectableDef: never; } +export interface InjectableDefToken extends InjectionToken { ɵprov: never; } diff --git a/packages/core/src/di/injector.ts b/packages/core/src/di/injector.ts index 1bcb4d66f8..80395cf24a 100644 --- a/packages/core/src/di/injector.ts +++ b/packages/core/src/di/injector.ts @@ -90,7 +90,7 @@ export abstract class Injector { } /** @nocollapse */ - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: Injector, providedIn: 'any' as any, factory: () => ɵɵinject(INJECTOR), diff --git a/packages/core/src/di/interface/defs.ts b/packages/core/src/di/interface/defs.ts index 02aab567f3..ac99be13a0 100644 --- a/packages/core/src/di/interface/defs.ts +++ b/packages/core/src/di/interface/defs.ts @@ -71,7 +71,7 @@ export interface ɵɵInjectorDef { factory: () => T; // TODO(alxhub): Narrow down the type here once decorators properly change the return type of the - // class they are decorating (to add the ngInjectableDef property for example). + // class they are decorating (to add the ɵprov property for example). providers: (Type|ValueProvider|ExistingProvider|FactoryProvider|ConstructorProvider| StaticClassProvider|ClassProvider|any[])[]; @@ -90,7 +90,7 @@ export interface InjectableType extends Type { /** * Opaque type whose structure is highly version dependent. Do not rely on any properties. */ - ngInjectableDef: never; + ɵprov: never; } /** @@ -126,7 +126,7 @@ export interface InjectorTypeWithProviders { * Construct an `InjectableDef` which defines how a token will be constructed by the DI system, and * in which injectors (if any) it will be available. * - * This should be assigned to a static `ngInjectableDef` field on a type, which will then be an + * This should be assigned to a static `ɵprov` field on a type, which will then be an * `InjectableType`. * * Options: @@ -168,7 +168,7 @@ export const defineInjectable = ɵɵdefineInjectable; * create the type must be provided. If that factory function needs to inject arguments, it can * use the `inject` function. * * `providers`: an optional array of providers to add to the injector. Each provider must - * either have a factory or point to a type which has an `ngInjectableDef` static property (the + * either have a factory or point to a type which has a `ɵprov` static property (the * type must be an `InjectableType`). * * `imports`: an optional array of imports of other `InjectorType`s or `InjectorTypeWithModule`s * whose providers will also be added to the injector. Locally provided types will override @@ -184,39 +184,40 @@ export function ɵɵdefineInjector(options: {factory: () => any, providers?: any } /** - * Read the `ngInjectableDef` for `type` in a way which is immune to accidentally reading inherited - * value. + * Read the injectable def (`ɵprov`) for `type` in a way which is immune to accidentally reading + * inherited value. * - * @param type A type which may have its own (non-inherited) `ngInjectableDef`. + * @param type A type which may have its own (non-inherited) `ɵprov`. */ export function getInjectableDef(type: any): ɵɵInjectableDef|null { - const def = type[NG_INJECTABLE_DEF] as ɵɵInjectableDef; + const def = (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]) as ɵɵInjectableDef; // The definition read above may come from a base class. `hasOwnProperty` is not sufficient to // distinguish this case, as in older browsers (e.g. IE10) static property inheritance is // implemented by copying the properties. // - // Instead, the ngInjectableDef's token is compared to the type, and if they don't match then the + // Instead, the ɵprov's token is compared to the type, and if they don't match then the // property was not defined directly on the type itself, and was likely inherited. The definition // is only returned if the type matches the def.token. return def && def.token === type ? def : null; } /** - * Read the `ngInjectableDef` for `type` or read the `ngInjectableDef` from one of its ancestors. + * Read the injectable def (`ɵprov`) for `type` or read the `ɵprov` from one of its ancestors. * - * @param type A type which may have `ngInjectableDef`, via inheritance. + * @param type A type which may have `ɵprov`, via inheritance. * * @deprecated Will be removed in v10, where an error will occur in the scenario if we find the - * `ngInjectableDef` on an ancestor only. + * `ɵprov` on an ancestor only. */ export function getInheritedInjectableDef(type: any): ɵɵInjectableDef|null { - if (type && type[NG_INJECTABLE_DEF]) { + const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]); + if (def) { // TODO(FW-1307): Re-add ngDevMode when closure can handle it // ngDevMode && console.warn( `DEPRECATED: DI is instantiating a token "${type.name}" that inherits its @Injectable decorator but does not provide one itself.\n` + `This will become an error in v10. Please add @Injectable() to the "${type.name}" class.`); - return type[NG_INJECTABLE_DEF]; + return def; } else { return null; } @@ -228,8 +229,14 @@ export function getInheritedInjectableDef(type: any): ɵɵInjectableDef|nu * @param type type which may have an injector def (`ɵinj`) */ export function getInjectorDef(type: any): ɵɵInjectorDef|null { - return type && type.hasOwnProperty(NG_INJ_DEF) ? (type as any)[NG_INJ_DEF] : null; + return type && (type.hasOwnProperty(NG_INJ_DEF) || type.hasOwnProperty(NG_INJECTOR_DEF)) ? + (type as any)[NG_INJ_DEF] : + null; } -export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty}); +export const NG_PROV_DEF = getClosureSafeProperty({ɵprov: getClosureSafeProperty}); export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty}); + +// We need to keep these around so we can read off old defs if new defs are unavailable +export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty}); +export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty}); diff --git a/packages/core/src/di/jit/injectable.ts b/packages/core/src/di/jit/injectable.ts index 53fb9255c8..c22bf4f142 100644 --- a/packages/core/src/di/jit/injectable.ts +++ b/packages/core/src/di/jit/injectable.ts @@ -12,7 +12,7 @@ import {NG_FACTORY_DEF} from '../../render3/fields'; import {getClosureSafeProperty} from '../../util/property'; import {resolveForwardRef} from '../forward_ref'; import {Injectable} from '../injectable'; -import {NG_INJECTABLE_DEF} from '../interface/defs'; +import {NG_PROV_DEF} from '../interface/defs'; import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../interface/provider'; import {angularCoreDiEnv} from './environment'; @@ -22,19 +22,19 @@ import {convertDependencies, reflectDependencies} from './util'; /** * Compile an Angular injectable according to its `Injectable` metadata, and patch the resulting - * `ngInjectableDef` onto the injectable type. + * injectable def (`ɵprov`) onto the injectable type. */ export function compileInjectable(type: Type, srcMeta?: Injectable): void { let ngInjectableDef: any = null; let ngFactoryDef: any = null; - // if NG_INJECTABLE_DEF is already defined on this class then don't overwrite it - if (!type.hasOwnProperty(NG_INJECTABLE_DEF)) { - Object.defineProperty(type, NG_INJECTABLE_DEF, { + // if NG_PROV_DEF is already defined on this class then don't overwrite it + if (!type.hasOwnProperty(NG_PROV_DEF)) { + Object.defineProperty(type, NG_PROV_DEF, { get: () => { if (ngInjectableDef === null) { ngInjectableDef = getCompilerFacade().compileInjectable( - angularCoreDiEnv, `ng:///${type.name}/ngInjectableDef.js`, + angularCoreDiEnv, `ng:///${type.name}/ɵprov.js`, getInjectableMetadata(type, srcMeta)); } return ngInjectableDef; diff --git a/packages/core/src/di/r3_injector.ts b/packages/core/src/di/r3_injector.ts index 7d4fd59cbd..ab08322c81 100644 --- a/packages/core/src/di/r3_injector.ts +++ b/packages/core/src/di/r3_injector.ts @@ -176,11 +176,11 @@ export class R3Injector { // SkipSelf isn't set, check if the record belongs to this injector. let record: Record|undefined|null = this.records.get(token); if (record === undefined) { - // No record, but maybe the token is scoped to this injector. Look for an ngInjectableDef - // with a scope matching this injector. + // No record, but maybe the token is scoped to this injector. Look for an injectable + // def with a scope matching this injector. const def = couldBeInjectableType(token) && getInjectableDef(token); if (def && this.injectableDefInScope(def)) { - // Found an ngInjectableDef and it's scoped to this injector. Pretend as if it was here + // Found an injectable def and it's scoped to this injector. Pretend as if it was here // all along. record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET); } else { @@ -408,7 +408,7 @@ export class R3Injector { } function injectableDefOrInjectorDefFactory(token: Type| InjectionToken): () => any { - // Most tokens will have an ngInjectableDef directly on them, which specifies a factory directly. + // Most tokens will have an injectable def directly on them, which specifies a factory directly. const injectableDef = getInjectableDef(token); const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token); @@ -423,10 +423,10 @@ function injectableDefOrInjectorDefFactory(token: Type| InjectionToken return injectorDef.factory; } - // InjectionTokens should have an ngInjectableDef and thus should be handled above. + // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above. // If it's missing that, it's an error. if (token instanceof InjectionToken) { - throw new Error(`Token ${stringify(token)} is missing an ngInjectableDef definition.`); + throw new Error(`Token ${stringify(token)} is missing a ɵprov definition.`); } // Undecorated types can sometimes be created if they have no constructor arguments. @@ -447,8 +447,8 @@ function getUndecoratedInjectableFactory(token: Function) { } // The constructor function appears to have no parameters. - // This might be because it inherits from a super-class. In which case, use an ngInjectableDef - // from an ancestor if there is one. + // This might be because it inherits from a super-class. In which case, use an injectable + // def from an ancestor if there is one. // Otherwise this really is a simple class with no dependencies, so return a factory that // just instantiates the zero-arg constructor. const inheritedInjectableDef = getInheritedInjectableDef(token); diff --git a/packages/core/src/render3/VIEW_DATA.md b/packages/core/src/render3/VIEW_DATA.md index 2e47316a72..ffaced5fb0 100644 --- a/packages/core/src/render3/VIEW_DATA.md +++ b/packages/core/src/render3/VIEW_DATA.md @@ -331,9 +331,9 @@ The above will create the following layout: | `EXPANDO` | 11..18| cumulativeBloom | templateBloom | | *sub-section: `component` and `directives`* -| 19 | `factory(Child.ɵcmp.factory)`* | `Child` +| 19 | `factory(Child.ɵcmp.factory)`* | `Child` | | *sub-section: `providers`* -| 20 | `factory(ServiceA.ngInjectableDef.factory)`* | `ServiceA` +| 20 | `factory(ServiceA.ɵprov.factory)`* | `ServiceA` | 22 | `'someServiceBValue'`* | `ServiceB` | | *sub-section: `viewProviders`* | 22 | `factory(()=> new Service())`* | `ServiceC` @@ -420,7 +420,7 @@ A pseudo-implementation of `inject` function. ```typescript function inject(token: any): any { let injectableDef; - if (typeof token === 'function' && injectableDef = token.ngInjectableDef) { + if (typeof token === 'function' && injectableDef = token.ɵprov) { const provideIn = injectableDef.provideIn; if (provideIn === '__node_injector__') { // if we are injecting `Injector` than create a wrapper object around the inject but which diff --git a/packages/core/src/sanitization/sanitizer.ts b/packages/core/src/sanitization/sanitizer.ts index b7c21fa4d6..72e7989283 100644 --- a/packages/core/src/sanitization/sanitizer.ts +++ b/packages/core/src/sanitization/sanitizer.ts @@ -17,7 +17,7 @@ import {SecurityContext} from './security'; export abstract class Sanitizer { abstract sanitize(context: SecurityContext, value: {}|string|null): string|null; /** @nocollapse */ - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: Sanitizer, providedIn: 'root', factory: () => null, diff --git a/packages/core/test/bundling/injection/bundle.golden_symbols.json b/packages/core/test/bundling/injection/bundle.golden_symbols.json index b50e981c02..52891d4105 100644 --- a/packages/core/test/bundling/injection/bundle.golden_symbols.json +++ b/packages/core/test/bundling/injection/bundle.golden_symbols.json @@ -29,9 +29,15 @@ { "name": "NG_INJECTABLE_DEF" }, + { + "name": "NG_INJECTOR_DEF" + }, { "name": "NG_INJ_DEF" }, + { + "name": "NG_PROV_DEF" + }, { "name": "NG_TEMP_TOKEN_PATH" }, diff --git a/packages/core/test/bundling/injection/usage.ts b/packages/core/test/bundling/injection/usage.ts index af8d1db771..8b9aad4d78 100644 --- a/packages/core/test/bundling/injection/usage.ts +++ b/packages/core/test/bundling/injection/usage.ts @@ -9,7 +9,7 @@ import {Injector, ɵcreateInjector as createInjector, ɵɵdefineInjectable, ɵɵdefineInjector} from '@angular/core'; export class RootService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: RootService, providedIn: 'root', factory: () => new RootService(), @@ -17,7 +17,7 @@ export class RootService { } export class ScopedService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ScopedService, providedIn: null, factory: () => new ScopedService(), diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 443c9b5b7d..a03e73d82e 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -140,6 +140,9 @@ { "name": "NG_PIPE_DEF" }, + { + "name": "NG_PROV_DEF" + }, { "name": "NG_TEMPLATE_SELECTOR" }, diff --git a/packages/core/test/di/r3_injector_spec.ts b/packages/core/test/di/r3_injector_spec.ts index 171465bed3..292bd079d1 100644 --- a/packages/core/test/di/r3_injector_spec.ts +++ b/packages/core/test/di/r3_injector_spec.ts @@ -12,7 +12,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers'; describe('InjectorDef-based createInjector()', () => { class CircularA { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: CircularA, providedIn: null, factory: () => ɵɵinject(CircularB), @@ -20,7 +20,7 @@ describe('InjectorDef-based createInjector()', () => { } class CircularB { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: CircularB, providedIn: null, factory: () => ɵɵinject(CircularA), @@ -28,7 +28,7 @@ describe('InjectorDef-based createInjector()', () => { } class Service { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: Service, providedIn: null, factory: () => new Service(), @@ -36,7 +36,7 @@ describe('InjectorDef-based createInjector()', () => { } class OptionalService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: OptionalService, providedIn: null, factory: () => new OptionalService(), @@ -59,7 +59,7 @@ describe('InjectorDef-based createInjector()', () => { class ServiceWithDep { constructor(readonly service: Service) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ServiceWithDep, providedIn: null, // ChildService is derived from ServiceWithDep, so the factory function here must do the right @@ -71,7 +71,7 @@ describe('InjectorDef-based createInjector()', () => { class ServiceWithOptionalDep { constructor(@Optional() readonly service: OptionalService|null) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ServiceWithOptionalDep, providedIn: null, factory: () => new ServiceWithOptionalDep(ɵɵinject(OptionalService, InjectFlags.Optional)), @@ -81,7 +81,7 @@ describe('InjectorDef-based createInjector()', () => { class ServiceWithMissingDep { constructor(readonly service: Service) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ServiceWithMissingDep, providedIn: null, factory: () => new ServiceWithMissingDep(ɵɵinject(Service)), @@ -91,7 +91,7 @@ describe('InjectorDef-based createInjector()', () => { class ServiceWithMultiDep { constructor(readonly locale: string[]) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ServiceWithMultiDep, providedIn: null, factory: () => new ServiceWithMultiDep(ɵɵinject(LOCALE)), @@ -99,7 +99,7 @@ describe('InjectorDef-based createInjector()', () => { } class ServiceTwo { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ServiceTwo, providedIn: null, factory: () => new ServiceTwo(), @@ -108,7 +108,7 @@ describe('InjectorDef-based createInjector()', () => { let deepServiceDestroyed = false; class DeepService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: DeepService, providedIn: null, factory: () => new DeepService(), @@ -119,7 +119,7 @@ describe('InjectorDef-based createInjector()', () => { let eagerServiceCreated: boolean = false; class EagerService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: EagerService, providedIn: undefined, factory: () => new EagerService(), @@ -218,7 +218,7 @@ describe('InjectorDef-based createInjector()', () => { let scopedServiceDestroyed = false; class ScopedService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: ScopedService, providedIn: Module, factory: () => new ScopedService(), @@ -228,7 +228,7 @@ describe('InjectorDef-based createInjector()', () => { } class WrongScopeService { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: WrongScopeService, providedIn: OtherModule, factory: () => new WrongScopeService(), diff --git a/packages/core/test/linker/ng_module_integration_spec.ts b/packages/core/test/linker/ng_module_integration_spec.ts index fa1c8013bd..beef110c3a 100644 --- a/packages/core/test/linker/ng_module_integration_spec.ts +++ b/packages/core/test/linker/ng_module_integration_spec.ts @@ -1387,7 +1387,7 @@ function declareTests(config?: {useJit: boolean}) { } class Bar { - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: Bar, factory: () => new Bar(), providedIn: SomeModule, @@ -1420,7 +1420,7 @@ function declareTests(config?: {useJit: boolean}) { } class Bar { - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: Bar, factory: () => new Bar(), providedIn: SomeModule, diff --git a/packages/core/test/render3/component_spec.ts b/packages/core/test/render3/component_spec.ts index a8d801ed26..ded79d0183 100644 --- a/packages/core/test/render3/component_spec.ts +++ b/packages/core/test/render3/component_spec.ts @@ -63,7 +63,7 @@ describe('component', () => { class MyService { constructor(public value: string) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: MyService, providedIn: 'root', factory: () => new MyService('no-injector'), diff --git a/packages/core/test/render3/ivy/jit_spec.ts b/packages/core/test/render3/ivy/jit_spec.ts index 1f7e96cb8e..e335e429c5 100644 --- a/packages/core/test/render3/ivy/jit_spec.ts +++ b/packages/core/test/render3/ivy/jit_spec.ts @@ -43,8 +43,8 @@ ivyEnabled && describe('render3 jit', () => { } const ServiceAny = Service as any; - expect(ServiceAny.ngInjectableDef).toBeDefined(); - expect(ServiceAny.ngInjectableDef.providedIn).toBe('root'); + expect(ServiceAny.ɵprov).toBeDefined(); + expect(ServiceAny.ɵprov.providedIn).toBe('root'); expect(ɵɵinject(Service) instanceof Service).toBe(true); }); @@ -167,7 +167,7 @@ ivyEnabled && describe('render3 jit', () => { it('compiles a module to an ɵinj with the providers', () => { class Token { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: Token, providedIn: 'root', factory: () => 'default', diff --git a/packages/core/test/render3/providers_spec.ts b/packages/core/test/render3/providers_spec.ts index 1b4b800741..566bcd8538 100644 --- a/packages/core/test/render3/providers_spec.ts +++ b/packages/core/test/render3/providers_spec.ts @@ -58,7 +58,7 @@ describe('providers', () => { public greet: string; constructor(private provider: GreeterProvider) { this.greet = this.provider.provide(); } - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: GreeterInj, factory: () => new GreeterInj(ɵɵinject(GreeterProvider as any)), }); @@ -816,7 +816,7 @@ describe('providers', () => { it('should work with root', () => { @Injectable({providedIn: 'root'}) class FooForRoot { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: FooForRoot, factory: () => new FooForRoot(), providedIn: 'root', @@ -841,7 +841,7 @@ describe('providers', () => { @Injectable({providedIn: MyModule}) class FooForModule { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: FooForModule, factory: () => new FooForModule(), providedIn: MyModule, @@ -1168,7 +1168,7 @@ describe('providers', () => { class MyService { constructor(public value: String) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: MyService, factory: () => new MyService(ɵɵinject(String)), }); @@ -1188,7 +1188,7 @@ describe('providers', () => { it('should make sure that parent service does not see overrides in child directives', () => { class Greeter { - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: Greeter, factory: () => new Greeter(ɵɵinject(String)), }); @@ -1233,7 +1233,7 @@ describe('providers', () => { class SomeInj implements Some { constructor(public location: String) {} - static ngInjectableDef = ɵɵdefineInjectable({ + static ɵprov = ɵɵdefineInjectable({ token: SomeInj, factory: () => new SomeInj(ɵɵinject(String)), }); diff --git a/packages/core/test/view/ng_module_spec.ts b/packages/core/test/view/ng_module_spec.ts index c875e49e9c..249ecf5bbc 100644 --- a/packages/core/test/view/ng_module_spec.ts +++ b/packages/core/test/view/ng_module_spec.ts @@ -25,7 +25,7 @@ class MyChildModule {} class NotMyModule {} class Bar { - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: Bar, factory: () => new Bar(), providedIn: MyModule, @@ -33,7 +33,7 @@ class Bar { } class Baz { - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: Baz, factory: () => new Baz(), providedIn: NotMyModule, @@ -43,7 +43,7 @@ class Baz { class HasNormalDep { constructor(public foo: Foo) {} - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: HasNormalDep, factory: () => new HasNormalDep(inject(Foo)), providedIn: MyModule, @@ -53,7 +53,7 @@ class HasNormalDep { class HasDefinedDep { constructor(public bar: Bar) {} - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: HasDefinedDep, factory: () => new HasDefinedDep(inject(Bar)), providedIn: MyModule, @@ -63,7 +63,7 @@ class HasDefinedDep { class HasOptionalDep { constructor(public baz: Baz|null) {} - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: HasOptionalDep, factory: () => new HasOptionalDep(inject(Baz, InjectFlags.Optional)), providedIn: MyModule, @@ -71,7 +71,7 @@ class HasOptionalDep { } class ChildDep { - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: ChildDep, factory: () => new ChildDep(), providedIn: MyChildModule, @@ -80,7 +80,7 @@ class ChildDep { class FromChildWithOptionalDep { constructor(public baz: Baz|null) {} - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: FromChildWithOptionalDep, factory: () => new FromChildWithOptionalDep(inject(Baz, InjectFlags.Default)), providedIn: MyChildModule, @@ -91,7 +91,7 @@ class FromChildWithSkipSelfDep { constructor( public skipSelfChildDep: ChildDep|null, public selfChildDep: ChildDep|null, public optionalSelfBar: Bar|null) {} - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: FromChildWithSkipSelfDep, factory: () => new FromChildWithSkipSelfDep( inject(ChildDep, InjectFlags.SkipSelf|InjectFlags.Optional), @@ -215,7 +215,7 @@ describe('NgModuleRef_ injector', () => { ngOnDestroy(): void { Service.destroyed++; } - static ngInjectableDef: ɵɵInjectableDef = ɵɵdefineInjectable({ + static ɵprov: ɵɵInjectableDef = ɵɵdefineInjectable({ token: Service, factory: () => new Service(), providedIn: 'root', diff --git a/packages/examples/core/di/ts/injector_spec.ts b/packages/examples/core/di/ts/injector_spec.ts index 1a06c1c824..600bc132e8 100644 --- a/packages/examples/core/di/ts/injector_spec.ts +++ b/packages/examples/core/di/ts/injector_spec.ts @@ -14,10 +14,10 @@ class MockRootScopeInjector implements Injector { get( token: Type|InjectionToken, defaultValue?: any, flags: InjectFlags = InjectFlags.Default): T { - if ((token as any).ngInjectableDef && (token as any).ngInjectableDef.providedIn === 'root') { + if ((token as any).ɵprov && (token as any).ɵprov.providedIn === 'root') { const old = setCurrentInjector(this); try { - return (token as any).ngInjectableDef.factory(); + return (token as any).ɵprov.factory(); } finally { setCurrentInjector(old); } diff --git a/tools/public_api_guard/common/common.d.ts b/tools/public_api_guard/common/common.d.ts index 3672410f63..7ae6de68b3 100644 --- a/tools/public_api_guard/common/common.d.ts +++ b/tools/public_api_guard/common/common.d.ts @@ -446,7 +446,7 @@ export declare abstract class ViewportScroller { abstract scrollToPosition(position: [number, number]): void; abstract setHistoryScrollRestoration(scrollRestoration: 'auto' | 'manual'): void; abstract setOffset(offset: [number, number] | (() => [number, number])): void; - static ngInjectableDef: never; + static ɵprov: never; } export declare enum WeekDay { diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index 49d3fda9e2..2451c41339 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -428,7 +428,7 @@ export interface InjectableDecorator { export declare type InjectableProvider = ValueSansProvider | ExistingSansProvider | StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider; export interface InjectableType extends Type { - ngInjectableDef: never; + ɵprov: never; } export interface InjectDecorator { @@ -446,7 +446,7 @@ export declare enum InjectFlags { export declare class InjectionToken { protected _desc: string; - readonly ngInjectableDef: never | undefined; + readonly ɵprov: never | undefined; constructor(_desc: string, options?: { providedIn?: Type | 'root' | 'platform' | 'any' | null; factory: () => T; @@ -459,7 +459,7 @@ export declare abstract class Injector { /** @deprecated */ abstract get(token: any, notFoundValue?: any): any; static NULL: Injector; static THROW_IF_NOT_FOUND: Object; - static ngInjectableDef: never; + static ɵprov: never; /** @deprecated */ static create(providers: StaticProvider[], parent?: Injector): Injector; static create(options: { providers: StaticProvider[]; @@ -517,7 +517,7 @@ export declare class IterableDiffers { /** @deprecated */ factories: IterableDifferFactory[]; constructor(factories: IterableDifferFactory[]); find(iterable: any): IterableDifferFactory; - static ngInjectableDef: never; + static ɵprov: never; static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers; static extend(factories: IterableDifferFactory[]): StaticProvider; } @@ -552,7 +552,7 @@ export declare class KeyValueDiffers { /** @deprecated */ factories: KeyValueDifferFactory[]; constructor(factories: KeyValueDifferFactory[]); find(kv: any): KeyValueDifferFactory; - static ngInjectableDef: never; + static ɵprov: never; static create(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers; static extend(factories: KeyValueDifferFactory[]): StaticProvider; } @@ -1270,7 +1270,7 @@ export declare function resolveForwardRef(type: T): T; export declare abstract class Sanitizer { abstract sanitize(context: SecurityContext, value: {} | string | null): string | null; - static ngInjectableDef: never; + static ɵprov: never; } export interface SchemaMetadata {