Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
700 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | const utils = require('./utils');
|
---|
| 4 |
|
---|
| 5 | module.exports = (ast, options = {}) => {
|
---|
| 6 | let stringify = (node, parent = {}) => {
|
---|
| 7 | let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
---|
| 8 | let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
---|
| 9 | let output = '';
|
---|
| 10 |
|
---|
| 11 | if (node.value) {
|
---|
| 12 | if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
---|
| 13 | return '\\' + node.value;
|
---|
| 14 | }
|
---|
| 15 | return node.value;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | if (node.value) {
|
---|
| 19 | return node.value;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | if (node.nodes) {
|
---|
| 23 | for (let child of node.nodes) {
|
---|
| 24 | output += stringify(child);
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 | return output;
|
---|
| 28 | };
|
---|
| 29 |
|
---|
| 30 | return stringify(ast);
|
---|
| 31 | };
|
---|
| 32 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.