Skip to content

Commit

Permalink
fix(core/common): allow to use symbol token in the module exports
Browse files Browse the repository at this point in the history
Symbol token can be used in the exports section as well as the string token.

Closes nestjs#1246
  • Loading branch information
Andrew Yustyk committed Oct 31, 2018
1 parent 47f0fa0 commit 644b2c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/common/utils/shared.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
14 changes: 7 additions & 7 deletions packages/core/injector/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Module {
private readonly _components = new Map<any, InstanceWrapper<Injectable>>();
private readonly _injectables = new Map<any, InstanceWrapper<Injectable>>();
private readonly _routes = new Map<string, InstanceWrapper<Controller>>();
private readonly _exports = new Set<string>();
private readonly _exports = new Set<string | symbol>();

constructor(
private readonly _metatype: Type<any>,
Expand Down Expand Up @@ -82,7 +82,7 @@ export class Module {
return this._routes;
}

get exports(): Set<string> {
get exports(): Set<string | symbol> {
return this._exports;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 644b2c1

Please sign in to comment.