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 trivago / melody / packages / melody-compiler / src / index.js View on Github external
export function toString(jsAst, code) {
    const g = new CodeGenerator(jsAst, {}, code);
    // Babel sanitises strings to not contain complex characters
    // however we need them in order to be able to render complex strings
    g._generator.StringLiteral = function(node, parent) {
        var raw = this.getPossibleRaw(node);
        if (!this.format.minified && raw != null) {
            this.token(raw);
            return;
        }

        return this.token(JSON.stringify(node.value));
    };
    return g.generate();
}

babel-generator

Turns an AST into code.

MIT
Latest version published 7 years ago

Package Health Score

88 / 100
Full package analysis

Similar packages