malinajs 0.7.2-a11 → 0.7.2-a12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/malina.js +58 -25
- package/package.json +1 -1
package/malina.js
CHANGED
|
@@ -671,6 +671,42 @@
|
|
|
671
671
|
}
|
|
672
672
|
};
|
|
673
673
|
|
|
674
|
+
const walk = (node, fn) => {
|
|
675
|
+
switch(node.type) {
|
|
676
|
+
case 'node':
|
|
677
|
+
case 'slot':
|
|
678
|
+
case 'block':
|
|
679
|
+
case 'fragment':
|
|
680
|
+
case 'root':
|
|
681
|
+
if(node.body) fn(node.body, node);
|
|
682
|
+
break
|
|
683
|
+
case 'each':
|
|
684
|
+
if(node.mainBlock) fn(node.mainBlock, node);
|
|
685
|
+
if(node.elseBlock) fn(node.elseBlock, node);
|
|
686
|
+
break
|
|
687
|
+
case 'await':
|
|
688
|
+
if(node.parts.main) fn(node.parts.main, node);
|
|
689
|
+
if(node.parts.then) fn(node.parts.then, node);
|
|
690
|
+
if(node.parts.catch) fn(node.parts.catch, node);
|
|
691
|
+
break
|
|
692
|
+
case 'if':
|
|
693
|
+
node.parts.forEach(p => {
|
|
694
|
+
if(p.body) fn(p.body, node);
|
|
695
|
+
});
|
|
696
|
+
if(node.elsePart) fn(node.elsePart, node);
|
|
697
|
+
break
|
|
698
|
+
case 'text':
|
|
699
|
+
case 'comment':
|
|
700
|
+
case 'script':
|
|
701
|
+
case 'style':
|
|
702
|
+
case 'systag':
|
|
703
|
+
case 'template':
|
|
704
|
+
break
|
|
705
|
+
default:
|
|
706
|
+
throw `Not implemented: ${node.type}`;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
674
710
|
function compactDOM() {
|
|
675
711
|
let data = this.DOM;
|
|
676
712
|
|
|
@@ -710,29 +746,7 @@
|
|
|
710
746
|
}
|
|
711
747
|
} else {
|
|
712
748
|
if(node.type == 'node' && (node.name == 'pre' || node.name == 'textarea')) continue;
|
|
713
|
-
|
|
714
|
-
case 'node':
|
|
715
|
-
case 'slot':
|
|
716
|
-
case 'block':
|
|
717
|
-
case 'fragment':
|
|
718
|
-
if(node.body) go(node.body, node);
|
|
719
|
-
break
|
|
720
|
-
case 'each':
|
|
721
|
-
if(node.mainBlock) go(node.mainBlock, node);
|
|
722
|
-
if(node.elseBlock) go(node.elseBlock, node);
|
|
723
|
-
break
|
|
724
|
-
case 'await':
|
|
725
|
-
if(node.parts.main) go(node.parts.main, node);
|
|
726
|
-
if(node.parts.then) go(node.parts.then, node);
|
|
727
|
-
if(node.parts.catch) go(node.parts.catch, node);
|
|
728
|
-
break
|
|
729
|
-
case 'if':
|
|
730
|
-
node.parts.forEach(p => {
|
|
731
|
-
if(p.body) go(p.body, node);
|
|
732
|
-
});
|
|
733
|
-
if(node.elsePart) go(node.elsePart, node);
|
|
734
|
-
break
|
|
735
|
-
}
|
|
749
|
+
walk(node, go);
|
|
736
750
|
}
|
|
737
751
|
}
|
|
738
752
|
|
|
@@ -841,6 +855,25 @@
|
|
|
841
855
|
go(data.body);
|
|
842
856
|
}
|
|
843
857
|
|
|
858
|
+
function compactFull() {
|
|
859
|
+
const go = (body) => {
|
|
860
|
+
let i = 0;
|
|
861
|
+
while (i < body.length) {
|
|
862
|
+
let n = body[i];
|
|
863
|
+
if(n.type == 'text') {
|
|
864
|
+
n.value = n.value.trim();
|
|
865
|
+
if(!n.value) {
|
|
866
|
+
body.splice(i, 1);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
} else walk(n, go);
|
|
870
|
+
i++;
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
walk(this.DOM, go);
|
|
875
|
+
}
|
|
876
|
+
|
|
844
877
|
class Reader {
|
|
845
878
|
constructor(source) {
|
|
846
879
|
if(source instanceof Reader) return source;
|
|
@@ -6833,7 +6866,7 @@
|
|
|
6833
6866
|
});
|
|
6834
6867
|
}
|
|
6835
6868
|
|
|
6836
|
-
const version = '0.7.2-
|
|
6869
|
+
const version = '0.7.2-a12';
|
|
6837
6870
|
|
|
6838
6871
|
|
|
6839
6872
|
async function compile(source, config = {}) {
|
|
@@ -6913,7 +6946,7 @@
|
|
|
6913
6946
|
parseHTML: function() {
|
|
6914
6947
|
this.DOM = parseHTML(this.source);
|
|
6915
6948
|
},
|
|
6916
|
-
compactDOM,
|
|
6949
|
+
compactDOM: config.compact == 'full' ? compactFull : compactDOM,
|
|
6917
6950
|
|
|
6918
6951
|
script: null,
|
|
6919
6952
|
scriptNodes: null,
|