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:
Ben Briggs
2016-09-01 15:50:25 +01:00
committed by Henry Zhu
parent 23ea626241
commit c94abcc170
5 changed files with 74 additions and 20 deletions

View File

@@ -24,16 +24,19 @@ export default function (code: string, opts?: Object): Function {
}
}
opts = assign({
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
preserveComments: false,
}, opts);
let getAst = function () {
let ast;
try {
ast = babylon.parse(code, assign({
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true
}, opts));
ast = babylon.parse(code, opts);
ast = traverse.removeProperties(ast);
ast = traverse.removeProperties(ast, {preserveComments: opts.preserveComments});
traverse.cheap(ast, function (node) {
node[FROM_TEMPLATE] = true;