From 644b2c1745d250457d2f40eb1fe2b02ad816030b Mon Sep 17 00:00:00 2001 From: Andrew Yustyk Date: Wed, 31 Oct 2018 13:16:25 +0200 Subject: [PATCH] fix(core/common): allow to use symbol token in the module exports Symbol token can be used in the exports section as well as the string token. Closes #1246 --- packages/common/utils/shared.utils.ts | 2 +- packages/core/injector/module.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/common/utils/shared.utils.ts b/packages/common/utils/shared.utils.ts index 8ed1257ff2f..b736f142571 100644 --- a/packages/common/utils/shared.utils.ts +++ b/packages/common/utils/shared.utils.ts @@ -8,4 +8,4 @@ export const validatePath = (path): string => path.charAt(0) !== '/' ? '/' + path : path; export const isNil = (obj): boolean => isUndefined(obj) || obj === null; export const isEmpty = (array): boolean => !(array && array.length > 0); -export const isSymbol = (fn): boolean => typeof fn === 'symbol'; +export const isSymbol = (fn): fn is symbol => typeof fn === 'symbol'; diff --git a/packages/core/injector/module.ts b/packages/core/injector/module.ts index e42e0d72550..d7736215ff4 100644 --- a/packages/core/injector/module.ts +++ b/packages/core/injector/module.ts @@ -47,7 +47,7 @@ export class Module { private readonly _components = new Map>(); private readonly _injectables = new Map>(); private readonly _routes = new Map>(); - private readonly _exports = new Set(); + private readonly _exports = new Set(); constructor( private readonly _metatype: Type, @@ -82,7 +82,7 @@ export class Module { return this._routes; } - get exports(): Set { + get exports(): Set { return this._exports; } @@ -279,14 +279,14 @@ export class Module { } public addExportedComponent( - exportedComponent: ComponentMetatype | string | DynamicModule, + exportedComponent: ComponentMetatype | string | symbol | DynamicModule, ) { - const addExportedUnit = (token: string) => + const addExportedUnit = (token: string | symbol) => this._exports.add(this.validateExportedProvider(token)); if (this.isCustomProvider(exportedComponent as any)) { return this.addCustomExportedComponent(exportedComponent as any); - } else if (isString(exportedComponent)) { + } else if (isString(exportedComponent) || isSymbol(exportedComponent)) { return addExportedUnit(exportedComponent); } else if (this.isDynamicModule(exportedComponent)) { const { module } = exportedComponent; @@ -305,7 +305,7 @@ export class Module { this._exports.add(this.validateExportedProvider(provide.name)); } - public validateExportedProvider(token: string) { + public validateExportedProvider(token: string | symbol) { if (this._components.has(token)) { return token; } @@ -316,7 +316,7 @@ export class Module { .filter(metatype => metatype) .map(({ name }) => name); - if (!importedRefNames.includes(token)) { + if (!importedRefNames.includes(token as any)) { const { name } = this.metatype; throw new UnknownExportException(name); }