chocola 1.6.0 → 2.0.0-next.10
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/README.md +34 -36
- package/compiler/chalk.js +34 -0
- package/compiler/component-processor.js +526 -398
- package/compiler/config.js +3 -56
- package/compiler/dom-processor.js +12 -75
- package/compiler/fs.js +0 -11
- package/compiler/index.js +126 -254
- package/compiler/module-graph.js +210 -0
- package/compiler/pipeline.js +54 -196
- package/compiler/render.js +181 -0
- package/compiler/runtime-generator.js +20 -15
- package/compiler/utils.js +79 -126
- package/dev/index.js +28 -11
- package/index.js +0 -31
- package/package.json +11 -13
- package/parser/component.js +268 -0
- package/parser/context.js +59 -0
- package/parser/css.js +96 -0
- package/parser/index.js +5 -0
- package/parser/template.js +120 -0
- package/parser/utils.js +32 -0
- package/runtime/index.js +312 -0
- package/server/index.js +402 -0
- package/utils.js +41 -6
package/utils.js
CHANGED
|
@@ -2,16 +2,51 @@ import { promises as fs } from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { throwError } from "./compiler/utils.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Returns `chocola.config.json` as an object.
|
|
7
|
-
* @param {import("fs").PathLike} __rootdir
|
|
8
|
-
* @returns {Object}
|
|
9
|
-
*/
|
|
10
|
-
export async function getChocolaConfig(__rootdir) {
|
|
5
|
+
export async function getConfig(__rootdir) {
|
|
11
6
|
try {
|
|
12
7
|
const config = await fs.readFile(path.join(__rootdir, "chocola.config.json"), "utf-8");
|
|
13
8
|
return JSON.parse(config);
|
|
14
9
|
} catch(err) {
|
|
15
10
|
throwError("An error occurred while fetching the Chocola config file:\n" + err);
|
|
16
11
|
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const LBRACE_PH = "_%%CHOCOLA-LBRACE%%_";
|
|
15
|
+
const RBRACE_PH = "_%%CHOCOLA-RBRACE%%_";
|
|
16
|
+
const PROTECTED_REGEX = /_%%CHOCOLA-(?:AMP|LT|GT)\d+%%_/g;
|
|
17
|
+
|
|
18
|
+
let protectSeq = 0;
|
|
19
|
+
|
|
20
|
+
export function protectCurlyBraces(html) {
|
|
21
|
+
return html
|
|
22
|
+
.replace(/&(?:lbrace|#123|#x7B);/gi, LBRACE_PH)
|
|
23
|
+
.replace(/&(?:rcub|#125|#x7D);/gi, RBRACE_PH)
|
|
24
|
+
.split(/(<script\b[^>]*>[\s\S]*?<\/script>|<style\b[^>]*>[\s\S]*?<\/style>)/gi)
|
|
25
|
+
.map((part, i) => i % 2 === 0
|
|
26
|
+
? part.replace(/\{([^{}]*)\}/g, (m, inner) =>
|
|
27
|
+
`{${inner
|
|
28
|
+
.replace(/&/g, () => `_%%CHOCOLA-AMP${protectSeq++}%%_`)
|
|
29
|
+
.replace(/</g, () => `_%%CHOCOLA-LT${protectSeq++}%%_`)
|
|
30
|
+
.replace(/>/g, () => `_%%CHOCOLA-GT${protectSeq++}%%_`)}}`)
|
|
31
|
+
: part)
|
|
32
|
+
.join("");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function restoreCurlyBraces(html) {
|
|
36
|
+
return html
|
|
37
|
+
.replace(/_%%CHOCOLA-LBRACE%%_/g, "{")
|
|
38
|
+
.replace(/_%%CHOCOLA-RBRACE%%_/g, "}")
|
|
39
|
+
.replace(PROTECTED_REGEX, char => {
|
|
40
|
+
if (char.includes("AMP")) return "&";
|
|
41
|
+
if (char.includes("LT")) return "<";
|
|
42
|
+
return ">";
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function restoreTemplateChars(str) {
|
|
47
|
+
return str.replace(PROTECTED_REGEX, char => {
|
|
48
|
+
if (char.includes("AMP")) return "&";
|
|
49
|
+
if (char.includes("LT")) return "<";
|
|
50
|
+
return ">";
|
|
51
|
+
});
|
|
17
52
|
}
|