source: frontend/node_modules/strip-comments/lib/compile.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3const compile = (cst, options = {}) => {
4 const keepProtected = options.safe === true || options.keepProtected === true;
5 let firstSeen = false;
6
7 const walk = (node, parent) => {
8 let output = '';
9 let inner;
10 let lines;
11
12 for (const child of node.nodes) {
13 switch (child.type) {
14 case 'block':
15 if (options.first && firstSeen === true) {
16 output += walk(child, node);
17 break;
18 }
19
20 if (options.preserveNewlines === true) {
21 inner = walk(child, node);
22 lines = inner.split('\n');
23 output += '\n'.repeat(lines.length - 1);
24 break;
25 }
26
27 if (keepProtected === true && child.protected === true) {
28 output += walk(child, node);
29 break;
30 }
31
32 firstSeen = true;
33 break;
34 case 'line':
35 if (options.first && firstSeen === true) {
36 output += child.value;
37 break;
38 }
39
40 if (keepProtected === true && child.protected === true) {
41 output += child.value;
42 }
43
44 firstSeen = true;
45 break;
46 case 'open':
47 case 'close':
48 case 'text':
49 case 'newline':
50 default: {
51 output += child.value || '';
52 break;
53 }
54 }
55 }
56
57 return output;
58 };
59
60 return walk(cst);
61};
62
63module.exports = compile;
Note: See TracBrowser for help on using the repository browser.