Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b05da49
commit af1a93e
Showing
4 changed files
with
42 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
import assert from "assert"; | ||
import { transformSync } from "@babel/core"; | ||
import { Hub } from "../lib/index.js"; | ||
|
||
describe("hub", function () { | ||
it("default buildError should return TypeError", function () { | ||
const hub = new Hub(); | ||
const msg = "test_msg"; | ||
assert.deepEqual(hub.buildError(null, msg), new TypeError(msg)); | ||
expect(hub.buildError(null, msg)).toEqual(new TypeError(msg)); | ||
}); | ||
|
||
it("should be preserved across nested traversals", function () { | ||
let origHub; | ||
let innerHub = {}; | ||
let exprHub; | ||
function plugin({ types: t, traverse }) { | ||
return { | ||
visitor: { | ||
Identifier(path) { | ||
if (path.node.name !== "foo") return; | ||
origHub = path.hub; | ||
|
||
const mem = t.memberExpression( | ||
t.identifier("property"), | ||
t.identifier("access"), | ||
); | ||
traverse(mem, { | ||
noScope: true, | ||
Identifier(path) { | ||
if (path.node.name === "property") innerHub = path.hub; | ||
}, | ||
}); | ||
const [p2] = path.insertAfter(mem); | ||
|
||
exprHub = p2.get("expression").hub; | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
transformSync("foo;", { configFile: false, plugins: [plugin] }); | ||
|
||
expect(origHub).toBeInstanceOf(Object); | ||
expect(exprHub).toBe(origHub); | ||
expect(innerHub).toBeUndefined(); | ||
}); | ||
}); |
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