benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

recursiveScanScope fails with Error('')

KnisterPeter opened this issue · comments

Hi,

the recursiveScanScope function fails while visiting/scanning bunyan.js with an Error without error message in line 202.

} else if (Node.check(node) && !Expression.check(node)) {
    types.eachField(node, function(name, child) {
        var childPath = path.get(name);
        if (childPath.value !== child) {
            throw new Error("");
        }
        recursiveScanChild(childPath, bindings, scopeTypes);
    });
}

Currently I do not understand what is wrong here and why to throw an Error without message. Can you please try to explain it to me so I could provide a bug fix?

It used to be assert.strictEqual(childPath.value, child), but we removed the dependency on "assert" so that ast-types could be bundled more easily for the browser.

Try changing the code to print out childPath.value and child?

I've already done this. It prints out [] for each of this. But obviously they are not strict equal.

Ah, those []s are probably coming from a default function (defaults.emptyArray) that gets called when the property is undefined.

These assertions should be more forgiving.

Should I provide a bugfix?

Closed by #160