* Lint against CJS globals in modules * Use `import.meta.url` instead of `__filename` in `src` files * Prepare fixtures runner for `import.meta.url` * Use `import.meta.url` instead of `__filename` in `test/index` files * Remove `__dirname` from remaining test files dirname * Avoid using `module` in `src` files * Avoid using `require` in `src` files * Avoid using `require` in `test` files * Update `@types/node` * Compile dynamic import in `@babel/node` * Fix windows * Use `@babel/plugin-proposal-dynamic-import` from npm
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import * as babel from "@babel/core";
|
|
import { fileURLToPath } from "url";
|
|
import path from "path";
|
|
|
|
import transformCommonJS from "..";
|
|
|
|
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,
|
|
);
|
|
});
|