mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
41 lines
975 B
JavaScript
41 lines
975 B
JavaScript
import cloneDeep from "../lib/transformation/util/clone-deep.js";
|
|
|
|
describe("util", () => {
|
|
it("deep clone", () => {
|
|
const circle = {};
|
|
circle.circle = circle;
|
|
const object = {};
|
|
|
|
const ast = {
|
|
type: "Program",
|
|
extra: {
|
|
circle,
|
|
circle2: circle,
|
|
},
|
|
object,
|
|
object2: object,
|
|
};
|
|
const cloned = cloneDeep(ast);
|
|
|
|
expect(cloned.object === ast.object).toBe(false);
|
|
expect(cloned.object === cloned.object2).toBe(false);
|
|
|
|
expect(cloned.extra.circle === ast.extra.circle).toBe(false);
|
|
expect(cloned.extra.circle === cloned.extra.circle2).toBe(true);
|
|
expect(cloned.extra.circle === cloned.extra.circle.circle).toBe(true);
|
|
});
|
|
|
|
it("deep clone circle", () => {
|
|
const circle = {};
|
|
circle.circle = circle;
|
|
|
|
const ast = {
|
|
type: "Program",
|
|
circle,
|
|
};
|
|
expect(() => {
|
|
cloneDeep(ast);
|
|
}).toThrow("Babel-deepClone: Cycles are not allowed in AST");
|
|
});
|
|
});
|