How to use the gonzales-pe.srcToAST function in gonzales-pe

To help you get started, we’ve selected a few gonzales-pe 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 lightningtgc / sublime-cssorder / node_modules / cssorder / node_modules / csscomb / lib / csscomb.js View on Github external
function cssToAST(text, syntax, filename) {
    var string = JSON.stringify;
    var fileInfo = filename ? ' at ' + filename : '';
    var tree;

    try {
        tree = gonzales.srcToAST({ syntax: syntax, src: text });
    } catch (e) {
        throw new Error('Parsing error' + fileInfo + ': ' + e.message);
    }

    // TODO: When can tree be undefined? 
    if (typeof tree === 'undefined') {
        throw new Error('Undefined tree' + fileInfo + ': ' + string(text) + ' => ' + string(tree));
    }

    return tree;
}
github lightningtgc / sublime-cssorder / node_modules / cssorder / node_modules / csscomb / node_modules / csscomb-core / lib / core.js View on Github external
this.processString = function processString(text, options) {
        var syntax = options && options.syntax;
        var filename = options && options.filename || '';
        var context = options && options.context;
        var tree;

        if (!text) return text;

        // TODO: Parse different syntaxes
        _this.syntax = syntax || 'css';

        try {
            tree = gonzales.srcToAST({ src: text, syntax: syntax, rule: context });
        } catch (e) {
            var version = require('../package.json').version;
            var message = [filename,
                           e.message,
                          'CSScomb Core version: ' + version];
            e.stack = e.message = message.join('\n');
            throw e;
        }

        tree = processTree(tree);
        return gonzales.astToSrc({ syntax: syntax, ast: tree });
    };