@itrocks/template 0.0.26 → 0.0.27
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/cjs/template.d.ts +4 -3
- package/cjs/template.js +9 -7
- package/esm/template.d.ts +4 -3
- package/esm/template.js +9 -7
- package/package.json +1 -1
package/cjs/template.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { SortedArray } from '@itrocks/sorted-array';
|
2
|
-
type
|
2
|
+
type BlockStackEntry = {
|
3
3
|
blockStart: number;
|
4
4
|
collection: any[];
|
5
|
+
condition?: boolean;
|
5
6
|
data: any;
|
6
7
|
iteration: number;
|
7
8
|
iterations: number;
|
8
|
-
}
|
9
|
+
};
|
9
10
|
export type VariableParser = [parser: string, (variable: string, data: any) => any];
|
10
11
|
export declare const frontScripts: SortedArray<string>;
|
11
12
|
export { Template };
|
@@ -13,7 +14,7 @@ export default class Template {
|
|
13
14
|
data?: any;
|
14
15
|
containerData?: any;
|
15
16
|
blockBack: number;
|
16
|
-
blockStack:
|
17
|
+
blockStack: BlockStackEntry[];
|
17
18
|
doExpression: boolean;
|
18
19
|
index: number;
|
19
20
|
length: number;
|
package/cjs/template.js
CHANGED
@@ -16,7 +16,7 @@ class Template {
|
|
16
16
|
containerData;
|
17
17
|
// block stack
|
18
18
|
blockBack = 0;
|
19
|
-
blockStack;
|
19
|
+
blockStack = [];
|
20
20
|
// parser
|
21
21
|
doExpression = true;
|
22
22
|
index = 0;
|
@@ -65,7 +65,6 @@ class Template {
|
|
65
65
|
this.addLinks.distinct = true;
|
66
66
|
this.doneLinks.distinct = true;
|
67
67
|
this.headLinks.distinct = true;
|
68
|
-
this.blockStack = [];
|
69
68
|
if (containerData) {
|
70
69
|
this.blockStack.push({ blockStart: 0, collection: [], data: containerData, iteration: 0, iterations: 1 });
|
71
70
|
}
|
@@ -391,8 +390,12 @@ class Template {
|
|
391
390
|
return variable.substring(1, variable.length - 1);
|
392
391
|
}
|
393
392
|
if (firstChar === '-') {
|
394
|
-
|
395
|
-
|
393
|
+
let dataBack;
|
394
|
+
do {
|
395
|
+
this.blockBack++;
|
396
|
+
dataBack = this.blockStack[this.blockStack.length - this.blockBack];
|
397
|
+
} while (dataBack.condition);
|
398
|
+
return dataBack.data;
|
396
399
|
}
|
397
400
|
for (const [prefix, callback] of this.parsers) {
|
398
401
|
if (firstChar === prefix) {
|
@@ -455,8 +458,7 @@ class Template {
|
|
455
458
|
continue;
|
456
459
|
}
|
457
460
|
// end condition / loop block
|
458
|
-
if ('
|
459
|
-
&& ['end-->', 'END-->'].includes(this.source.substring(this.index, this.index + 6))) {
|
461
|
+
if ((firstChar === 'e') && (this.source.substring(this.index, this.index + 6) === 'end-->')) {
|
460
462
|
this.target += this.trimEndLine(this.source.substring(this.start, tagIndex));
|
461
463
|
iteration++;
|
462
464
|
if (iteration < iterations) {
|
@@ -487,7 +489,7 @@ class Template {
|
|
487
489
|
this.target = '';
|
488
490
|
this.inLiteral = false;
|
489
491
|
const condition = await this.parseExpression(data, '}', '-->');
|
490
|
-
this.blockStack.push({ blockStart, collection, data, iteration, iterations });
|
492
|
+
this.blockStack.push({ blockStart, collection, condition, data, iteration, iterations });
|
491
493
|
let blockData = condition ? (this.target ? data : undefined) : this.target;
|
492
494
|
blockStart = this.index;
|
493
495
|
iteration = 0;
|
package/esm/template.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { SortedArray } from '@itrocks/sorted-array';
|
2
|
-
type
|
2
|
+
type BlockStackEntry = {
|
3
3
|
blockStart: number;
|
4
4
|
collection: any[];
|
5
|
+
condition?: boolean;
|
5
6
|
data: any;
|
6
7
|
iteration: number;
|
7
8
|
iterations: number;
|
8
|
-
}
|
9
|
+
};
|
9
10
|
export type VariableParser = [parser: string, (variable: string, data: any) => any];
|
10
11
|
export declare const frontScripts: SortedArray<string>;
|
11
12
|
export { Template };
|
@@ -13,7 +14,7 @@ export default class Template {
|
|
13
14
|
data?: any;
|
14
15
|
containerData?: any;
|
15
16
|
blockBack: number;
|
16
|
-
blockStack:
|
17
|
+
blockStack: BlockStackEntry[];
|
17
18
|
doExpression: boolean;
|
18
19
|
index: number;
|
19
20
|
length: number;
|
package/esm/template.js
CHANGED
@@ -11,7 +11,7 @@ export default class Template {
|
|
11
11
|
containerData;
|
12
12
|
// block stack
|
13
13
|
blockBack = 0;
|
14
|
-
blockStack;
|
14
|
+
blockStack = [];
|
15
15
|
// parser
|
16
16
|
doExpression = true;
|
17
17
|
index = 0;
|
@@ -60,7 +60,6 @@ export default class Template {
|
|
60
60
|
this.addLinks.distinct = true;
|
61
61
|
this.doneLinks.distinct = true;
|
62
62
|
this.headLinks.distinct = true;
|
63
|
-
this.blockStack = [];
|
64
63
|
if (containerData) {
|
65
64
|
this.blockStack.push({ blockStart: 0, collection: [], data: containerData, iteration: 0, iterations: 1 });
|
66
65
|
}
|
@@ -386,8 +385,12 @@ export default class Template {
|
|
386
385
|
return variable.substring(1, variable.length - 1);
|
387
386
|
}
|
388
387
|
if (firstChar === '-') {
|
389
|
-
|
390
|
-
|
388
|
+
let dataBack;
|
389
|
+
do {
|
390
|
+
this.blockBack++;
|
391
|
+
dataBack = this.blockStack[this.blockStack.length - this.blockBack];
|
392
|
+
} while (dataBack.condition);
|
393
|
+
return dataBack.data;
|
391
394
|
}
|
392
395
|
for (const [prefix, callback] of this.parsers) {
|
393
396
|
if (firstChar === prefix) {
|
@@ -450,8 +453,7 @@ export default class Template {
|
|
450
453
|
continue;
|
451
454
|
}
|
452
455
|
// end condition / loop block
|
453
|
-
if ('
|
454
|
-
&& ['end-->', 'END-->'].includes(this.source.substring(this.index, this.index + 6))) {
|
456
|
+
if ((firstChar === 'e') && (this.source.substring(this.index, this.index + 6) === 'end-->')) {
|
455
457
|
this.target += this.trimEndLine(this.source.substring(this.start, tagIndex));
|
456
458
|
iteration++;
|
457
459
|
if (iteration < iterations) {
|
@@ -482,7 +484,7 @@ export default class Template {
|
|
482
484
|
this.target = '';
|
483
485
|
this.inLiteral = false;
|
484
486
|
const condition = await this.parseExpression(data, '}', '-->');
|
485
|
-
this.blockStack.push({ blockStart, collection, data, iteration, iterations });
|
487
|
+
this.blockStack.push({ blockStart, collection, condition, data, iteration, iterations });
|
486
488
|
let blockData = condition ? (this.target ? data : undefined) : this.target;
|
487
489
|
blockStart = this.index;
|
488
490
|
iteration = 0;
|
package/package.json
CHANGED