Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderBodurri committed Sep 25, 2023
1 parent cbd7950 commit a542baa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions devtools/projects/ng-devtools-backend/src/lib/component-tree.ts
Expand Up @@ -170,7 +170,7 @@ export interface ProviderRecord {
}

const getInjectorProviders = (injector: Injector): ProviderRecord[] => {
if (injector instanceof EnvironmentInjector && injector['scopes'] instanceof Set &&
if (isEnvironmentInjector(injector) && injector['scopes'] instanceof Set &&
injector['scopes'].has('platform')) {
return [];
}
Expand Down Expand Up @@ -218,9 +218,9 @@ const getDependenciesForDirective =
.map(node => ({type: 'ImportedModule', name: valueToLabel(node)}))
];

if (dependency.token instanceof InjectionToken) {
if (dependency.token && isInjectionToken(dependency.token)) {
serializedInjectedServices.push({
token: dependency.token.toString(),
token: dependency.token!.toString(),
value: valueToLabel(dependency.value),
flags: dependency.flags,
resolutionPath: dependencyResolutionPath
Expand Down Expand Up @@ -253,7 +253,7 @@ const valueToLabel = (value: any) => {
export const serializeInjector = (injector: Injector): {type: string; name: string;} => {
let serializedInjector: {type: string; name: string}|undefined;

if (injector instanceof EnvironmentInjector) {
if (isEnvironmentInjector(injector)) {
serializedInjector = {type: 'Environment', name: injector['source']};
}

Expand Down Expand Up @@ -304,6 +304,14 @@ export function getNodeInjectorTNode(nodeInjector) {
return (nodeInjector as any)._tNode;
}

export const isInjectionToken = (token: Type<unknown>|InjectionToken<unknown>): boolean => {
return token.constructor.name === 'InjectionToken';
}

export const isEnvironmentInjector = (injector: Injector) => {
return injector.constructor.name === 'EnvironmentInjector' || injector.constructor.name === 'R3Injector';
};

export const isNodeInjector = (injector: Injector) => {
return injector.constructor.name === 'NodeInjector';
};
Expand Down

0 comments on commit a542baa

Please sign in to comment.