Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/core/src/di/create_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export function createInjectorWithoutInjectorInstances(
scopes = new Set<InjectorScope>(),
): R3Injector {
const providers = [additionalProviders || EMPTY_ARRAY, importProvidersFrom(defType)];
name = name || (typeof defType === 'object' ? undefined : stringify(defType));
let source: string | undefined = undefined;
if (ngDevMode) {
source = name || (typeof defType === 'object' ? undefined : stringify(defType));
}

return new R3Injector(providers, parent || getNullInjector(), name || null, scopes);
return new R3Injector(providers, parent || getNullInjector(), source || null, scopes);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value, as I understand it, is only used in dev

if (ngDevMode) {
prependTokenToDependencyPath(error, token);
if (previousInjector) {
// We still have a parent injector, keep throwing
throw error;
} else {
// Format & throw the final error message when we don't have any previous injector
throw augmentRuntimeError(error, this.source);
}

}
9 changes: 6 additions & 3 deletions packages/core/src/di/forward_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ const __forward_ref__ = getClosureSafeProperty({__forward_ref__: getClosureSafeP
*/
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
(<any>forwardRefFn).__forward_ref__ = forwardRef;
(<any>forwardRefFn).toString = function () {
return stringify(this());
};
if (ngDevMode) {
(<any>forwardRefFn).toString = function () {
return stringify(this());
};
}

return <Type<any>>(<any>forwardRefFn);
}

Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/di/r3_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,16 @@ export class R3Injector extends EnvironmentInjector implements PrimitivesInjecto
}

override toString() {
const tokens: string[] = [];
const records = this.records;
for (const token of records.keys()) {
tokens.push(stringify(token));
if (ngDevMode) {
const tokens: string[] = [];
const records = this.records;
for (const token of records.keys()) {
tokens.push(stringify(token));
}
return `R3Injector[${tokens.join(', ')}]`;
}
return `R3Injector[${tokens.join(', ')}]`;

return 'R3Injector[...]';
}

/**
Expand Down Expand Up @@ -521,7 +525,7 @@ export class R3Injector extends EnvironmentInjector implements PrimitivesInjecto
const prevConsumer = setActiveConsumer(null);
try {
if (record.value === CIRCULAR) {
throw cyclicDependencyError(stringify(token));
throw cyclicDependencyError(ngDevMode ? stringify(token) : '');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a similar case here; the value is only used for dev mode.

export function cyclicDependencyError(token: string, path?: string[]): Error {
const message = ngDevMode ? `Circular dependency detected for \`${token}\`.` : '';
return createRuntimeError(message, RuntimeErrorCode.CYCLIC_DI_DEPENDENCY, path);
}

} else if (record.value === NOT_YET) {
record.value = CIRCULAR;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@
"shouldBeIgnoredByZone",
"shouldSearchParent",
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"stringifyCSSSelectorList",
"style",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,6 @@
"stashEventListenerImpl",
"storeLViewOnDestroy",
"storeListenerCleanup",
"stringify",
"stringifyCSSSelector",
"stringifyCSSSelectorList",
"syncViewWithBlueprint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@
"shouldTriggerDeferBlock",
"storeLViewOnDestroy",
"storeTriggerCleanupFn",
"stringify",
"stringifyCSSSelector",
"stringifyCSSSelectorList",
"syncViewWithBlueprint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@
"skipTextNodes",
"sortAndConcatParams",
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"stringifyCSSSelectorList",
"subscribeOn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@
"shouldBeIgnoredByZone",
"shouldSearchParent",
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"stringifyCSSSelectorList",
"syncViewWithBlueprint",
Expand Down