/** * @author linhuiw * @desc AST 处理相关帮助方法 */ import * as ts from 'typescript'; /** * 去掉文件中的注释 * @param code * @param fileName */ export function removeFileComment(code: string, fileName: string) { const printer: ts.Printer = ts.createPrinter({ removeComments: true }); const sourceFile: ts.SourceFile = ts.createSourceFile( '', code, ts.ScriptTarget.ES2015, true, fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS ); return printer.printFile(sourceFile); }