Skip to content

fails with es6 class member functionsΒ #26

@psnider

Description

@psnider

version 0.4.0
node v6.9.1

When I enter this code in the node REPL:

var promisify = require("promisify-node");
class C {
    constructor() {
        this.promisified_connect = promisify(this.connect);
    }
    connect(done) {
        if (done) {
            done();
        } else {
            return this.promisified_connect();
        }
    }
}
var c = new C()

promisify-node throws this error:

TypeError: Cannot read property '1' of null
    at module.exports (./node_modules/promisify-node/utils/args.js:9:63)
    at processExports (./node_modules/promisify-node/index.js:61:29)
    at module.exports (./node_modules/promisify-node/index.js:164:10)

so I updated the RegExp in https://github.com/nodegit/promisify-node/blob/master/utils/args.js#L9 from:

/function\s.*?\(([^)]*)\)/

to:

/\(([^)]*)\)/

Then re-running the above test code produced another error:

TypeError: Cannot convert undefined or null to object
    at processExports (./node_modules/promisify-node/index.js:86:16)
    at module.exports (./node_modules/promisify-node/index.js:164:10)
    at new C (repl:3:28)

I was able to get past this by modifying https://github.com/nodegit/promisify-node/blob/master/index.js#L86 to guard the checking of the keys of the prototype to:

    if (exports.prototype) {
      if (Object.keys(exports.prototype).length) {

I believe there are likely other changes required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions