Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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 });
};