content-entry-transform 1.5.18 → 1.6.0
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/package.json +1 -1
- package/src/expression-transformer.mjs +11 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IteratorContentEntry } from "content-entry";
|
|
2
2
|
import { iterableStringInterceptor } from "iterable-string-interceptor";
|
|
3
3
|
|
|
4
|
-
export function createPropertiesInterceptor(
|
|
4
|
+
export function createPropertiesInterceptor(evaluate) {
|
|
5
5
|
return async function* transformer(
|
|
6
6
|
expression,
|
|
7
7
|
remainder,
|
|
@@ -10,13 +10,13 @@ export function createPropertiesInterceptor(properties) {
|
|
|
10
10
|
leadIn,
|
|
11
11
|
leadOut
|
|
12
12
|
) {
|
|
13
|
-
function ev(e,
|
|
14
|
-
if (
|
|
13
|
+
function ev(e, depth) {
|
|
14
|
+
if (depth > 9) {
|
|
15
15
|
throw new Error(`Circular reference evaluating: ${expression}`, {
|
|
16
16
|
cause: expression
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
let value =
|
|
19
|
+
let value = evaluate(e);
|
|
20
20
|
if (value !== undefined) {
|
|
21
21
|
if (typeof value === "string") {
|
|
22
22
|
while (true) {
|
|
@@ -25,7 +25,7 @@ export function createPropertiesInterceptor(properties) {
|
|
|
25
25
|
const lo = value.indexOf(leadOut, li + leadIn.length);
|
|
26
26
|
value =
|
|
27
27
|
value.substring(0, li) +
|
|
28
|
-
ev(value.substring(li + leadIn.length, lo),
|
|
28
|
+
ev(value.substring(li + leadIn.length, lo), depth + 1) +
|
|
29
29
|
value.substring(lo + leadOut.length);
|
|
30
30
|
} else {
|
|
31
31
|
break;
|
|
@@ -46,7 +46,7 @@ export function createPropertiesInterceptor(properties) {
|
|
|
46
46
|
/**
|
|
47
47
|
* Transformer expanding '{{}}' expressions
|
|
48
48
|
* @param {string} match
|
|
49
|
-
* @param {Object} properties
|
|
49
|
+
* @param {Object|Function} properties
|
|
50
50
|
* @param {string} name
|
|
51
51
|
* @returns
|
|
52
52
|
*/
|
|
@@ -63,6 +63,10 @@ export function createExpressionTransformer(
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
const interceptor = createPropertiesInterceptor(
|
|
67
|
+
typeof properties === "function" ? properties : name => properties[name]
|
|
68
|
+
);
|
|
69
|
+
|
|
66
70
|
return {
|
|
67
71
|
name,
|
|
68
72
|
match,
|
|
@@ -75,11 +79,7 @@ export function createExpressionTransformer(
|
|
|
75
79
|
const ne = new IteratorContentEntry(
|
|
76
80
|
entry.name,
|
|
77
81
|
{ destination: entry.destination },
|
|
78
|
-
() =>
|
|
79
|
-
iterableStringInterceptor(
|
|
80
|
-
streamToText(stream),
|
|
81
|
-
createPropertiesInterceptor(properties)
|
|
82
|
-
)
|
|
82
|
+
() => iterableStringInterceptor(streamToText(stream), interceptor)
|
|
83
83
|
);
|
|
84
84
|
return ne;
|
|
85
85
|
}
|