How to use the @babel/generator.CodeGenerator function in @babel/generator

To help you get started, we’ve selected a few @babel/generator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github power-assert-js / babel-plugin-espower / lib / babel-assertion-visitor.js View on Github external
BabelAssertionVisitor.prototype.generateCanonicalCode = function (nodePath, node) {
    var file = nodePath.hub.file;
    var gen = new babelgen.CodeGenerator(node, { concise: true, comments: false });
    var output = gen.generate();
    this.canonicalCode = output.code;
    if (!this.options.embedAst) {
        return;
    }
    var astAndTokens = this.parseCanonicalCode(file, this.canonicalCode);
    this.ast = JSON.stringify(this.purifyAst(astAndTokens.expression));
    this.tokens = JSON.stringify(astAndTokens.tokens);
    var _this = this;
    var types = this.babel.types;
    this.visitorKeys = this.getOrCreateNode(nodePath, 'powerAssertVisitorKeys', function () {
        return types.stringLiteral(JSON.stringify(_this.options.visitorKeys));
    });
};
github wq / wq.app / rollup-utils.js View on Github external
function generator(ast, opts, code) {
    var generator = new CodeGenerator(ast, opts, code);
    generator._generator.format.indent.style = '    ';
    return generator.generate();
}

@babel/generator

Turns an AST into code.

MIT
Latest version published 18 days ago

Package Health Score

95 / 100
Full package analysis

Similar packages