Skip to content

Commit

Permalink
fix: fix babel requirement: instance should be instanceof constructor…
Browse files Browse the repository at this point in the history
…, even if constructor was repla

fix #55
  • Loading branch information
k1r0s committed Dec 10, 2017
1 parent e3aa468 commit 16bd8d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ function applyReflect (target, advices, methodName, keyJoinPoint, original) {
if (methodName === "constructor") {
const keyBeforeInstance = generateKey(KEY_BEFORE_INSTANCE, methodName)
const keyAfterInstance = generateKey(KEY_AFTER_INSTANCE, methodName)
return wrapMethod(target, methodName, keyBeforeInstance, keyAfterInstance)
// this is only needed to avoid babel's TypeError https://github.com/babel/babel/issues/682
// and should be removed in the future when babel isn't no longer needed to transpile ES6 classes
const result = wrapMethod(target, methodName, keyBeforeInstance, keyAfterInstance)
result.prototype = target.prototype
return result

} else {
const keyBeforeMethod = generateKey(KEY_BEFORE_METHOD, methodName)
const keyAfterMethod = generateKey(KEY_AFTER_METHOD, methodName)
Expand Down
4 changes: 4 additions & 0 deletions test/inject.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe("inject specs", () => {
model = new DummyModel()
})

it("Instance decorators do not broke protoChain", () => {
expect(test).toBeInstanceOf(Test)
})

it("should be able to inject dependencies", () => {
expect(model.$ser).toBeInstanceOf(SomeService)
expect(test.$ser).toBeInstanceOf(SomeService)
Expand Down

0 comments on commit 16bd8d3

Please sign in to comment.