|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | function stringifyNode(node, custom) {
|
|---|
| 2 | var type = node.type
|
|---|
| 3 | var value = node.value
|
|---|
| 4 | var buf
|
|---|
| 5 | var customResult
|
|---|
| 6 |
|
|---|
| 7 | if (custom && (customResult = custom(node)) !== undefined) {
|
|---|
| 8 | return customResult
|
|---|
| 9 | } else if (type === 'word' || type === 'space') {
|
|---|
| 10 | return value
|
|---|
| 11 | } else if (type === 'string') {
|
|---|
| 12 | buf = node.quote || ''
|
|---|
| 13 | return buf + value + (node.unclosed ? '' : buf)
|
|---|
| 14 | } else if (type === 'comment') {
|
|---|
| 15 | return '/*' + value + (node.unclosed ? '' : '*/')
|
|---|
| 16 | } else if (type === 'div') {
|
|---|
| 17 | return (node.before || '') + value + (node.after || '')
|
|---|
| 18 | } else if (Array.isArray(node.nodes)) {
|
|---|
| 19 | buf = stringify(node.nodes, custom)
|
|---|
| 20 | if (type !== 'function') {
|
|---|
| 21 | return buf
|
|---|
| 22 | }
|
|---|
| 23 | return value + '(' + (node.before || '') + buf + (node.after || '') + (node.unclosed ? '' : ')')
|
|---|
| 24 | }
|
|---|
| 25 | return value
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | function stringify(nodes, custom) {
|
|---|
| 29 | var result, i
|
|---|
| 30 |
|
|---|
| 31 | if (Array.isArray(nodes)) {
|
|---|
| 32 | result = ''
|
|---|
| 33 | for (i = nodes.length - 1; ~i; i -= 1) {
|
|---|
| 34 | result = stringifyNode(nodes[i], custom) + result
|
|---|
| 35 | }
|
|---|
| 36 | return result
|
|---|
| 37 | }
|
|---|
| 38 | return stringifyNode(nodes, custom)
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | module.exports = stringify
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.