Skip to content

Commit 4359785

Browse files
author
Patrick Housley
committed
fix(core): support symbols
Support for the use of symbols as the provided in modules exports was broken as a result of nestjs/nest@v4.5.5...master#diff-f52585e35398d156c2cd41f3863d4c52R184. This bugfix corrects the issue by updating the changed code to test for and support symbols.
1 parent ceb0ecb commit 4359785

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/common/utils/shared.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export const validatePath = (path): string =>
88
path.charAt(0) !== '/' ? '/' + path : path;
99
export const isNil = (obj): boolean => isUndefined(obj) || obj === null;
1010
export const isEmpty = (array): boolean => !(array && array.length > 0);
11+
export const isSymbol = (fn): boolean => typeof fn === 'symbol';

src/core/injector/module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isNil,
1010
isUndefined,
1111
isString,
12+
isSymbol,
1213
} from '@nestjs/common/utils/shared.utils';
1314
import { RuntimeException } from '../errors/exceptions/runtime.exception';
1415
import { Reflector } from '../services/reflector.service';
@@ -255,7 +256,7 @@ export class Module {
255256
exportedComponent: CustomFactory | CustomValue | CustomClass,
256257
) {
257258
const provide = exportedComponent.provide;
258-
if (isString(provide)) {
259+
if (isString(provide) || isSymbol(provide)) {
259260
return this._exports.add(provide);
260261
}
261262
this._exports.add(provide.name);

src/core/test/injector/module.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ describe('Module', () => {
222222
module.addExportedComponent({ provide: 'test' } as any);
223223
expect(addCustomExportedComponentSpy.called).to.be.true;
224224
});
225+
it('should support symbols', () => {
226+
const addCustomExportedComponentSpy = sinon.spy(
227+
module,
228+
'addCustomExportedComponent',
229+
);
230+
const symb = Symbol('test');
231+
module.addExportedComponent({ provide: symb } as any);
232+
expect(addCustomExportedComponentSpy.called).to.be.true;
233+
expect((module as any)._exports.has(symb)).to.be.true;
234+
});
225235
});
226236

227237
describe('replace', () => {

0 commit comments

Comments
 (0)