* Migrate the following packages' tests:
* babel-helper-annotate-as-pure
* babel-helper-module-imports
* babel-helper-transform-fixture-test-runner
* babel-highlight
* babel-node
* babel-plugin-transform-modules-commonjs
* babel-preset-env-standalone
* babel-preset-env
* babel-preset-es2015
* babel-preset-react
* babel-standalone
* babel-template
* babel-traverse
* babel-types
37 lines
755 B
JavaScript
37 lines
755 B
JavaScript
import traverse from "../lib";
|
|
import { parse } from "babylon";
|
|
import generate from "@babel/generator";
|
|
|
|
function getPath(code) {
|
|
const ast = parse(code);
|
|
let path;
|
|
traverse(ast, {
|
|
Program: function(_path) {
|
|
path = _path;
|
|
_path.stop();
|
|
},
|
|
});
|
|
|
|
return path;
|
|
}
|
|
|
|
function generateCode(path) {
|
|
return generate(path.node).code;
|
|
}
|
|
|
|
describe("removal", function() {
|
|
describe("ArrowFunction", function() {
|
|
it("remove body", function() {
|
|
const rootPath = getPath("x = () => b;");
|
|
const path = rootPath
|
|
.get("body")[0]
|
|
.get("expression")
|
|
.get("right");
|
|
const body = path.get("body");
|
|
body.remove();
|
|
|
|
expect(generateCode(rootPath)).toBe("x = () => {};");
|
|
});
|
|
});
|
|
});
|