fix: cloneNode(deep, withoutLoc) handles absent comments (#12602)
This fragment (maybe all fragments?) throw during cloning, as 'comments' is unset here. Handle it being unset, by returning undefined.
This commit is contained in:
@@ -42,6 +42,14 @@ describe("cloneNode", function () {
|
||||
expect(t.isNodesEquivalent(node, cloned)).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle deep cloning without loc of fragments", function () {
|
||||
const program = "foo();";
|
||||
const node = parse(program);
|
||||
const cloned = t.cloneNode(node, /* deep */ true, /* withoutLoc */ true);
|
||||
expect(node).not.toBe(cloned);
|
||||
expect(t.isNodesEquivalent(node, cloned)).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle missing array element", function () {
|
||||
const node = parse("[,0]");
|
||||
const cloned = t.cloneNode(node);
|
||||
|
||||
Reference in New Issue
Block a user