-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
copied-nodes.js
32 lines (26 loc) 路 1.12 KB
/
copied-nodes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as babel from "@babel/core";
import { fileURLToPath } from "url";
import path from "path";
import transformCommonJS from "../lib/index.js";
test("Doesn't use the same object for two different nodes in the AST", function () {
const code = 'import Foo from "bar"; Foo; Foo;';
const ast = babel.transform(code, {
cwd: path.dirname(fileURLToPath(import.meta.url)),
ast: true,
plugins: [[transformCommonJS, { loose: true }]],
}).ast;
expect(ast.program.body[0].declarations[0].id.type).toBe("Identifier");
expect(ast.program.body[2].expression.type).toBe("MemberExpression");
expect(ast.program.body[2].expression.object.type).toBe("Identifier");
expect(ast.program.body[3].expression.type).toBe("MemberExpression");
expect(ast.program.body[3].expression.object.type).toBe("Identifier");
expect(ast.program.body[2].expression.object).not.toBe(
ast.program.body[3].expression.object,
);
expect(ast.program.body[0].declarations[0].id).not.toBe(
ast.program.body[3].expression.object,
);
expect(ast.program.body[0].declarations[0].id).not.toBe(
ast.program.body[2].expression.object,
);
});