-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix null property access at getBaseClassDependencyCount (#1665)
* refactor: add getBaseType * fix: update getBaseClassDependencyCount to rely on getBaseType * fix: update rollup config to patch wrong sourcemap links on ESM build * fix: update Prototype with mandatory constructor
- Loading branch information
1 parent
f7dd2c8
commit d787b8f
Showing
5 changed files
with
105 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Newable } from '@inversifyjs/common'; | ||
import { expect } from 'chai'; | ||
|
||
import { getBaseType } from '../../utils/get_base_type'; | ||
|
||
describe(getBaseType.name, () => { | ||
describe('having a type with base type', () => { | ||
let baseTypeFixture: Newable; | ||
let typeFixture: Newable; | ||
|
||
before(() => { | ||
class BaseType {} | ||
|
||
baseTypeFixture = BaseType; | ||
typeFixture = class extends BaseType {}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
before(() => { | ||
result = getBaseType(typeFixture); | ||
}); | ||
|
||
it('should return base type', () => { | ||
expect(result).to.eq(baseTypeFixture); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('having a type with no base type', () => { | ||
let typeFixture: Newable; | ||
|
||
before(() => { | ||
typeFixture = Object; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
before(() => { | ||
result = getBaseType(typeFixture); | ||
}); | ||
|
||
it('should return undefined', () => { | ||
expect(result).to.eq(undefined); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Newable } from '@inversifyjs/common'; | ||
|
||
interface Prototype { | ||
constructor: Newable; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type | ||
export function getBaseType(type: Function): Newable | undefined { | ||
const prototype: Prototype | null = Object.getPrototypeOf( | ||
type.prototype, | ||
) as Prototype | null; | ||
|
||
const baseType: Newable | undefined = prototype?.constructor; | ||
|
||
return baseType; | ||
} |