-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
index.js
30 lines (25 loc) 路 1008 Bytes
/
index.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
import generator from "../../babel-generator";
import template from "../lib";
import chai from "chai";
const comments = "// Sum two numbers\nconst add = (a, b) => a + b;";
describe("templating", function () {
it("import statement will cause parser to throw by default", function () {
chai.expect(function () {
template("import foo from 'foo'")({});
}).to.throw();
});
it("import statements are allowed with sourceType: module", function () {
chai.expect(function () {
template("import foo from 'foo'", { sourceType: "module" })({});
}).not.to.throw();
});
it("should strip comments by default", function () {
const code = "const add = (a, b) => a + b;";
const output = template(comments)();
chai.expect(generator(output).code).to.be.equal(code);
});
it("should preserve comments with a flag", function () {
const output = template(comments, { preserveComments: true })();
chai.expect(generator(output).code).to.be.equal(comments);
});
});