You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
708 B
33 lines
708 B
4 weeks ago
|
'use strict';
|
||
|
|
||
|
const utils = require('./utils');
|
||
|
|
||
|
module.exports = (ast, options = {}) => {
|
||
|
const stringify = (node, parent = {}) => {
|
||
|
const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
||
|
const invalidNode = node.invalid === true && options.escapeInvalid === true;
|
||
|
let output = '';
|
||
|
|
||
|
if (node.value) {
|
||
|
if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
||
|
return '\\' + node.value;
|
||
|
}
|
||
|
return node.value;
|
||
|
}
|
||
|
|
||
|
if (node.value) {
|
||
|
return node.value;
|
||
|
}
|
||
|
|
||
|
if (node.nodes) {
|
||
|
for (const child of node.nodes) {
|
||
|
output += stringify(child);
|
||
|
}
|
||
|
}
|
||
|
return output;
|
||
|
};
|
||
|
|
||
|
return stringify(ast);
|
||
|
};
|
||
|
|