Skip to content

Commit

Permalink
[Bug] Fix #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed May 4, 2020
1 parent e0b4c23 commit f567e79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/evaluate/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function createFunc(
/*<remove>*/
if (node.async && node.generator) {
func = function (): AsyncIterator<any> {
const iterator = tmpFunc.apply(void 0, arguments)
const iterator = tmpFunc.apply(this, arguments)
let last: Promise<any> = Promise.resolve()
let hasCatch = false
const run = (opts: runAsyncOptions) =>
Expand All @@ -198,7 +198,7 @@ export function createFunc(
return asyncIterator
}
} else if (node.async) {
func = function () { return runAsync(tmpFunc.apply(void 0, arguments)) }
func = function () { return runAsync(tmpFunc.apply(this, arguments)) }
} else {
func = tmpFunc
}
Expand Down
18 changes: 18 additions & 0 deletions tests/class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,24 @@ describe('testing src/index.ts', () => {
expect(interpreter.exports.target).toEqual(interpreter.exports.actual)
})

it('should support async method', () => {
const interpreter = new Sval()
interpreter.run(`
class Foo {
constructor() {
this.a = 1
}
async getA() {
return this.a
}
}
exports.Foo = Foo
`)

const instance = new interpreter.exports.Foo();
expect(instance.getA()).resolves.toBe(1);
})

it('should support property accessing between parent and child class', () => {
const interpreter = new Sval()
interpreter.run(`
Expand Down

0 comments on commit f567e79

Please sign in to comment.