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.

stringify.js 708B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const utils = require('./utils');
  3. module.exports = (ast, options = {}) => {
  4. const stringify = (node, parent = {}) => {
  5. const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
  6. const invalidNode = node.invalid === true && options.escapeInvalid === true;
  7. let output = '';
  8. if (node.value) {
  9. if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
  10. return '\\' + node.value;
  11. }
  12. return node.value;
  13. }
  14. if (node.value) {
  15. return node.value;
  16. }
  17. if (node.nodes) {
  18. for (const child of node.nodes) {
  19. output += stringify(child);
  20. }
  21. }
  22. return output;
  23. };
  24. return stringify(ast);
  25. };