refactor(core): rename ngInjectableDef to ɵprov (#33151)
Injectable defs are not considered public API, so the property that contains them should be prefixed with Angular's marker for "private" ('ɵ') to discourage apps from relying on def APIs directly. This commit adds the prefix and shortens the name from ngInjectableDef to "prov" (for "provider", since injector defs are known as "inj"). This is because property names cannot be minified by Uglify without turning on property mangling (which most apps have turned off) and are thus size-sensitive. PR Close #33151
This commit is contained in:

committed by
Matias Niemelä

parent
cda9248b33
commit
86104b82b8
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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',
|
||||
|
Reference in New Issue
Block a user