1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.preprocessor;
16
17 import org.htmlunit.ScriptPreProcessor;
18 import org.htmlunit.html.HtmlElement;
19 import org.htmlunit.html.HtmlPage;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class HtmxTwoZeroSevenScriptPreProcessor implements ScriptPreProcessor {
52
53 private final ScriptPreProcessor nextScriptPreProcessor_;
54
55
56
57
58 public HtmxTwoZeroSevenScriptPreProcessor() {
59 nextScriptPreProcessor_ = null;
60 }
61
62
63
64
65
66 public HtmxTwoZeroSevenScriptPreProcessor(final ScriptPreProcessor nextScriptPreProcessor) {
67 nextScriptPreProcessor_ = nextScriptPreProcessor;
68 }
69
70
71
72
73 @Override
74 public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName,
75 final int lineNumber, final HtmlElement htmlElement) {
76
77 String patchedSourceCode = sourceCode;
78
79 if (sourceName.contains("/htmx.js") && !sourceName.contains("/htmx.js#")) {
80 patchedSourceCode = sourceCode.replace(
81 "result.push(...toArray(rootNode.querySelectorAll(standardSelector)))",
82 "result.push.apply(result, toArray(rootNode.querySelectorAll(standardSelector)))");
83
84 patchedSourceCode = patchedSourceCode.replace(
85 "result.push(...findAttributeTargets(eltToInheritFrom, attrName))",
86 "result.push.apply(result, findAttributeTargets(eltToInheritFrom, attrName))");
87
88 patchedSourceCode = patchedSourceCode.replace(
89 "for (const preservedElt of [...pantry.children]) {",
90 "for (const preservedElt of Array.from(pantry.children)) {");
91 }
92 else if (sourceName.contains("/htmx.min.js") && !sourceName.contains("/htmx.min.js#")) {
93
94 patchedSourceCode = sourceCode.replace(
95 "i.push(...M(c.querySelectorAll(e)))",
96 "i.push.apply(i,M(c.querySelectorAll(e)))");
97
98
99 patchedSourceCode = patchedSourceCode.replace(
100 "i.push(...F(c.querySelectorAll(e)))",
101 "i.push.apply(i,F(c.querySelectorAll(e)))");
102
103 patchedSourceCode = patchedSourceCode.replace(
104 "r.push(...we(i,n))",
105 "r.push.apply(r,we(i,n))");
106
107 patchedSourceCode = patchedSourceCode.replace(
108 "for(const t of[...e.children]){",
109 "for(const t of Array.from(e.children)){");
110 }
111
112 if (nextScriptPreProcessor_ != null) {
113 return nextScriptPreProcessor_.preProcess(htmlPage, patchedSourceCode, sourceName, lineNumber, htmlElement);
114 }
115
116 return patchedSourceCode;
117 }
118 }