Add support for preserving comments in babel-template. (#3689)
* Add support for preserving comments in babel-template. * Add an API section to babel-template.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
var generator = require('../../babel-generator').default;
|
||||
var template = require("../lib");
|
||||
var chai = require("chai");
|
||||
|
||||
var comments = "// Sum two numbers\nconst add = (a, b) => a + b;";
|
||||
|
||||
suite("templating", function () {
|
||||
test("import statement will cause parser to throw by default", function () {
|
||||
chai.expect(function () {
|
||||
@@ -13,4 +16,15 @@ suite("templating", function () {
|
||||
template("import foo from 'foo'", {sourceType: 'module'})({});
|
||||
}).not.to.throw();
|
||||
});
|
||||
|
||||
test("should strip comments by default", function () {
|
||||
var code = "const add = (a, b) => a + b;"
|
||||
var output = template(comments)();
|
||||
chai.expect(generator(output).code).to.be.equal(code);
|
||||
});
|
||||
|
||||
test("should preserve comments with a flag", function () {
|
||||
var output = template(comments, {preserveComments: true})();
|
||||
chai.expect(generator(output).code).to.be.equal(comments);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user