abdk-mustache-js 1.0.2 → 1.0.4
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/CHANGELOG.md +41 -0
- package/README.md +103 -19
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +102 -66
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +111 -78
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.0.4] — 2026-04-11
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Standalone tag whitespace stripping** — section, inverted-section, comment,
|
|
15
|
+
set-delimiter, partial, block, and parent tags that appear alone on a line
|
|
16
|
+
(with only optional leading whitespace) now consume the entire line, including
|
|
17
|
+
leading whitespace and trailing newline (`\n` or `\r\n`), per the Mustache
|
|
18
|
+
spec. Variable tags are never treated as standalone.
|
|
19
|
+
- **Permissive whitespace inside tags** — spaces are now permitted before and
|
|
20
|
+
after any tag sigil and around the tag name: `{{ # section }}`,
|
|
21
|
+
`{{> partial }}`, `{{ = [ ] = }}`, etc. Applies uniformly to all tag types.
|
|
22
|
+
- **Function-based partial loader** — all four public functions
|
|
23
|
+
(`render`, `renderCompiled`, `renderAsync`, `renderCompiledAsync`) now accept
|
|
24
|
+
either a plain partial object *or* a single loader function
|
|
25
|
+
`(name) => template | null` (async for the async variants) in place of the
|
|
26
|
+
`partials` argument. The loader is called at most once per partial name per
|
|
27
|
+
render call.
|
|
28
|
+
- **Stricter parent-body validation** — inside a `{{< parent}}` body, sections,
|
|
29
|
+
variables, partials, and nested parents now raise a compile-time error instead
|
|
30
|
+
of being silently ignored. Plain text and comments are still silently
|
|
31
|
+
discarded; block overrides (`{{$ block}}`) and set-delimiter tags are
|
|
32
|
+
processed normally.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## [1.0.3] — 2026-04-11
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- `renderCompiledAsync` / `renderAsync`: `wrapView` was calling async view
|
|
41
|
+
functions **eagerly** at wrap time and returning `null` directly to
|
|
42
|
+
Mustache.js instead of returning a callable wrapper function. As a result,
|
|
43
|
+
every async function in the view was always rendered as an empty string,
|
|
44
|
+
regardless of its resolved value, and every async function — including unused
|
|
45
|
+
ones — was invoked unconditionally. `wrapView` now returns a proper wrapper
|
|
46
|
+
function registered in `wrappedValues`; the underlying async function is only
|
|
47
|
+
called when Mustache.js actually invokes it during rendering.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
10
51
|
## [1.0.2] — 2026-04-11
|
|
11
52
|
|
|
12
53
|
### Fixed
|
package/README.md
CHANGED
|
@@ -16,8 +16,13 @@ functions** for high-throughput rendering.
|
|
|
16
16
|
function; subsequent renders are pure function calls with no parsing overhead
|
|
17
17
|
- **Full Mustache syntax** — variables, sections, inverted sections, comments,
|
|
18
18
|
partials, dynamic partials, and set-delimiter tags
|
|
19
|
+
- **Standalone tag whitespace stripping** — section, comment, partial,
|
|
20
|
+
set-delimiter, and inheritance tags on their own line consume that whole line
|
|
21
|
+
(leading whitespace + trailing newline), per spec
|
|
19
22
|
- **Template inheritance** — `{{< parent}}` / `{{$ block}}` for layout
|
|
20
23
|
composition (extends the base Mustache spec)
|
|
24
|
+
- **Permissive tag whitespace** — spaces are allowed before and after any tag
|
|
25
|
+
sigil: `{{ # name }}`, `{{> partial }}`, `{{ = [ ] = }}`, etc.
|
|
21
26
|
- **Async rendering** — `renderAsync` / `renderCompiledAsync` resolve async
|
|
22
27
|
and Promise-returning view values automatically, with lazy async partial
|
|
23
28
|
loading
|
|
@@ -115,6 +120,76 @@ const page = compile(`
|
|
|
115
120
|
renderCompiled(page, { name: "Alice" }, { layout });
|
|
116
121
|
```
|
|
117
122
|
|
|
123
|
+
#### What is allowed inside a parent body (`{{< parent}} … {{/parent}}`)
|
|
124
|
+
|
|
125
|
+
The spec says everything except block overrides should be silently ignored
|
|
126
|
+
inside a parent. This implementation is deliberately stricter on errors but
|
|
127
|
+
also more useful:
|
|
128
|
+
|
|
129
|
+
| Content | Behaviour |
|
|
130
|
+
|---------|-----------|
|
|
131
|
+
| Plain text | Silently ignored |
|
|
132
|
+
| Comments `{{! … }}` | Silently ignored |
|
|
133
|
+
| Block overrides `{{$ block }} … {{/block}}` | Processed normally — overrides the named block in the parent template |
|
|
134
|
+
| Set-delimiter tags `{{= … =}}` | **Processed** — delimiter change takes effect for the rest of the parent body, allowing different delimiters for different block overrides |
|
|
135
|
+
| Sections `{{#}}` / `{{^}}` | **Compile-time error** — hiding structural tags would conceal bugs |
|
|
136
|
+
| Variables `{{name}}` / `{{{name}}}` / `{{& name}}` | **Compile-time error** |
|
|
137
|
+
| Partials `{{> …}}` / `{{> *…}}` | **Compile-time error** |
|
|
138
|
+
| Nested parents `{{< …}}` | **Compile-time error** |
|
|
139
|
+
|
|
140
|
+
Example — changing delimiters mid-parent to override two blocks with
|
|
141
|
+
different delimiter styles:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const parent = compile("{{$a}}A{{/a}} {{$b}}B{{/b}}");
|
|
145
|
+
const child = compile("{{< parent}}{{=[ ]=}}[$a]X[/a][={{ }}=]{{$b}}Y{{/b}}{{/parent}}");
|
|
146
|
+
renderCompiled(child, {}, { parent }); // "X Y"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Standalone tags
|
|
150
|
+
|
|
151
|
+
Tags that appear alone on a line (with only optional leading whitespace) are
|
|
152
|
+
treated as **standalone**: the entire line, including the leading whitespace
|
|
153
|
+
and the trailing newline (`\n` or `\r\n`), is removed from the output. This
|
|
154
|
+
applies to section, inverted-section, comment, set-delimiter, partial, block,
|
|
155
|
+
and parent tags. Variable tags are never standalone.
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
Template:
|
|
159
|
+
| before
|
|
160
|
+
{{#show}}
|
|
161
|
+
| inside
|
|
162
|
+
{{/show}}
|
|
163
|
+
| after
|
|
164
|
+
|
|
165
|
+
Output (show = true):
|
|
166
|
+
| before
|
|
167
|
+
| inside
|
|
168
|
+
| after
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
> **Note:** The spec also requires standalone partial tags to prepend their
|
|
172
|
+
> leading whitespace as indentation to every line of the included partial.
|
|
173
|
+
> This implementation does **not** support partial indentation — the partial
|
|
174
|
+
> content is inserted as-is.
|
|
175
|
+
|
|
176
|
+
### Whitespace inside tags
|
|
177
|
+
|
|
178
|
+
Spaces are permitted before and after any tag sigil, and around any tag name.
|
|
179
|
+
All three positions are equivalent:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
{{ name }} — spaces around name
|
|
183
|
+
{{# section }} — space after sigil
|
|
184
|
+
{{ # section }} — space before and after sigil
|
|
185
|
+
{{> * dynamic }} — spaces around * in dynamic partial
|
|
186
|
+
{{ = [ ] = }} — spaces around = in set-delimiter
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This applies uniformly to all tag types: variables, sections, inverted
|
|
190
|
+
sections, comments, partials, dynamic partials, blocks, parents, and
|
|
191
|
+
set-delimiter tags.
|
|
192
|
+
|
|
118
193
|
### Unescaped output
|
|
119
194
|
|
|
120
195
|
Use triple mustaches `{{{…}}}` or `{{& …}}` to skip HTML escaping:
|
|
@@ -146,7 +221,7 @@ const html = await renderAsync(
|
|
|
146
221
|
);
|
|
147
222
|
```
|
|
148
223
|
|
|
149
|
-
Async partials (loaded on demand):
|
|
224
|
+
Async partials (loaded on demand via a loader function):
|
|
150
225
|
|
|
151
226
|
```ts
|
|
152
227
|
import { renderAsync } from "abdk-mustache-js";
|
|
@@ -154,12 +229,18 @@ import { renderAsync } from "abdk-mustache-js";
|
|
|
154
229
|
const html = await renderAsync(
|
|
155
230
|
"{{> header}}{{body}}",
|
|
156
231
|
{ body: "Content" },
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
232
|
+
// loader function — called once per partial name, result cached
|
|
233
|
+
async (name) => fetchTemplate(name)
|
|
234
|
+
);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Or pass a plain object of pre-compiled string partials:
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
const html = await renderAsync(
|
|
241
|
+
"{{> header}}{{body}}",
|
|
242
|
+
{ body: "Content" },
|
|
243
|
+
{ header: "<h1>ABDK</h1>" }
|
|
163
244
|
);
|
|
164
245
|
```
|
|
165
246
|
|
|
@@ -181,7 +262,7 @@ Renders a pre-compiled template synchronously.
|
|
|
181
262
|
|-----------|------|---------|
|
|
182
263
|
| `template` | `CompiledTemplate` | — |
|
|
183
264
|
| `view` | `any` | — |
|
|
184
|
-
| `partials` | `{ [name: string]: CompiledTemplate }` | `{}` |
|
|
265
|
+
| `partials` | `{ [name: string]: CompiledTemplate }` \| `(name: string) => CompiledTemplate \| null` | `{}` |
|
|
185
266
|
| `escape` | `(s: string) => string` | built-in HTML escape |
|
|
186
267
|
|
|
187
268
|
### `render(template, view, partials?, escape?): string`
|
|
@@ -193,32 +274,33 @@ first use per `render` call).
|
|
|
193
274
|
|-----------|------|---------|
|
|
194
275
|
| `template` | `string` | — |
|
|
195
276
|
| `view` | `any` | — |
|
|
196
|
-
| `partials` | `{ [name: string]: string }` | `{}` |
|
|
277
|
+
| `partials` | `{ [name: string]: string }` \| `(name: string) => string \| null` | `{}` |
|
|
197
278
|
| `escape` | `(s: string) => string` | built-in HTML escape |
|
|
198
279
|
|
|
199
280
|
### `renderCompiledAsync(template, view, partials?, escape?): Promise<string>`
|
|
200
281
|
|
|
201
282
|
Renders a pre-compiled template; asynchronous view property functions are
|
|
202
|
-
resolved automatically (re-rendering until all promises settle).
|
|
203
|
-
|
|
283
|
+
resolved automatically (re-rendering until all promises settle). When a loader
|
|
284
|
+
function is supplied, it is called at most once per partial name per
|
|
285
|
+
`renderCompiledAsync` call.
|
|
204
286
|
|
|
205
287
|
| Parameter | Type | Default |
|
|
206
|
-
|
|
288
|
+
|-----------|------|---------||
|
|
207
289
|
| `template` | `CompiledTemplate` | — |
|
|
208
290
|
| `view` | `any` | — |
|
|
209
|
-
| `partials` | `{ [name: string]: () => Promise<CompiledTemplate
|
|
291
|
+
| `partials` | `{ [name: string]: CompiledTemplate }` \| `(name: string) => Promise<CompiledTemplate \| null>` | `{}` |
|
|
210
292
|
| `escape` | `(s: string) => string` | built-in HTML escape |
|
|
211
293
|
|
|
212
294
|
### `renderAsync(template, view, partials?, escape?): Promise<string>`
|
|
213
295
|
|
|
214
296
|
Convenience wrapper around `renderCompiledAsync` that accepts a template
|
|
215
|
-
string and string
|
|
297
|
+
string and string partials or an async loader function.
|
|
216
298
|
|
|
217
299
|
| Parameter | Type | Default |
|
|
218
|
-
|
|
300
|
+
|-----------|------|---------||
|
|
219
301
|
| `template` | `string` | — |
|
|
220
302
|
| `view` | `any` | — |
|
|
221
|
-
| `partials` | `{ [name: string]: string \| (
|
|
303
|
+
| `partials` | `{ [name: string]: string }` \| `(name: string) => Promise<string \| null>` | `{}` |
|
|
222
304
|
| `escape` | `(s: string) => string` | built-in HTML escape |
|
|
223
305
|
|
|
224
306
|
### `CompiledTemplate` (type)
|
|
@@ -226,7 +308,8 @@ string and string / async-function partials.
|
|
|
226
308
|
```ts
|
|
227
309
|
type CompiledTemplate = (
|
|
228
310
|
view: any[],
|
|
229
|
-
partials: { [name: string]: CompiledTemplate }
|
|
311
|
+
partials: { [name: string]: CompiledTemplate }
|
|
312
|
+
| ((name: string) => CompiledTemplate | null),
|
|
230
313
|
blocks: { [name: string]: () => string },
|
|
231
314
|
escape: (string: string) => string
|
|
232
315
|
) => string;
|
|
@@ -247,9 +330,10 @@ type CompiledTemplate = (
|
|
|
247
330
|
| Dynamic partials `{{> *name}}` | ✓ |
|
|
248
331
|
| Set delimiters `{{= <% %> =}}` | ✓ |
|
|
249
332
|
| Template inheritance `{{< parent}}` / `{{$ block}}` | ✓ (extension) |
|
|
333
|
+
| Standalone tag whitespace stripping | ✓ |
|
|
334
|
+
| Whitespace before/after any tag sigil | ✓ (extension) |
|
|
250
335
|
| Lambda sections (raw text + render callback) | ✗ (optional spec feature) |
|
|
251
|
-
|
|
|
252
|
-
| Partial indentation | ✗ |
|
|
336
|
+
| Partial indentation (standalone partial prepends indent) | ✗ (intentionally omitted) |
|
|
253
337
|
|
|
254
338
|
---
|
|
255
339
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export type CompiledTemplate = (view: any[], partials: {
|
|
2
2
|
[name: string]: CompiledTemplate;
|
|
3
|
-
}, blocks: {
|
|
3
|
+
} | ((name: string) => CompiledTemplate | null), blocks: {
|
|
4
4
|
[name: string]: () => string;
|
|
5
5
|
}, escape: (string: string) => string) => string;
|
|
6
6
|
export declare function compile(template: string): CompiledTemplate;
|
|
7
7
|
export declare function renderCompiled(template: CompiledTemplate, view: any, partials?: {
|
|
8
8
|
[name: string]: CompiledTemplate;
|
|
9
|
-
}, escape?: (string: string) => string): string;
|
|
9
|
+
} | ((name: string) => CompiledTemplate | null), escape?: (string: string) => string): string;
|
|
10
10
|
export declare function render(template: string, view: any, partials?: {
|
|
11
11
|
[name: string]: string;
|
|
12
|
-
}, escape?: (string: string) => string): string;
|
|
12
|
+
} | ((name: string) => string | null), escape?: (string: string) => string): string;
|
|
13
13
|
export declare function renderCompiledAsync(template: CompiledTemplate, view: any, partials?: {
|
|
14
|
-
[name: string]:
|
|
15
|
-
}, escape?: (string: string) => string): Promise<string>;
|
|
14
|
+
[name: string]: CompiledTemplate;
|
|
15
|
+
} | ((name: string) => Promise<CompiledTemplate | null>), escape?: (string: string) => string): Promise<string>;
|
|
16
16
|
export declare function renderAsync(template: string, view: any, partials?: {
|
|
17
|
-
[name: string]: string
|
|
18
|
-
}, escape?: (string: string) => string): Promise<string>;
|
|
17
|
+
[name: string]: string;
|
|
18
|
+
} | ((name: string) => Promise<string | null>), escape?: (string: string) => string): Promise<string>;
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,GAAG,EAAE,EACX,QAAQ,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,GAAG,EAAE,EACX,QAAQ,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,GAC1C,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAAC,EAC/C,MAAM,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,MAAM,CAAA;CAAE,EACxC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,KAAK,MAAM,CAAC;AAEhD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAuK1D;AAeD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,GAAG,EACT,QAAQ,GAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,GAC1C,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAAM,EACpD,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAmB,GAC9C,MAAM,CAER;AAED,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG,EACT,QAAQ,GAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAChC,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAM,EAC1C,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAmB,GAC9C,MAAM,CAWR;AAED,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,GAAG,EACT,QAAQ,GAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,GAC1C,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAM,EAC7D,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAmB,GAC9C,OAAO,CAAC,MAAM,CAAC,CA6EjB;AAED,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG,EACT,QAAQ,GAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAChC,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAM,EACnD,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAmB,GAC9C,OAAO,CAAC,MAAM,CAAC,CAUjB"}
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ function escapeRegExp(string) {
|
|
|
29
29
|
function compileTagRegExp(leftDelimiter, rightDelimiter) {
|
|
30
30
|
const escapedLeftDelimiter = escapeRegExp(leftDelimiter);
|
|
31
31
|
const escapedRightDelimiter = escapeRegExp(rightDelimiter);
|
|
32
|
-
return new RegExp(`${escapedLeftDelimiter}\\s*(\\{[^}]*\\}\\s*|[^{\\s].*?)${escapedRightDelimiter}`, "
|
|
32
|
+
return new RegExp(`${escapedLeftDelimiter}\\s*(\\{[^}]*\\}\\s*|[^{\\s].*?)${escapedRightDelimiter}`, "gs");
|
|
33
33
|
}
|
|
34
34
|
function compile(template) {
|
|
35
35
|
let code = ``;
|
|
@@ -53,6 +53,7 @@ function compile(template) {
|
|
|
53
53
|
code += `const s=(x)=>x==null?"":String(x);`;
|
|
54
54
|
code += `const S=(x)=>x==null?"":e(x);`;
|
|
55
55
|
code += `const o=(n)=>v.find(x=>x!=null&&typeof x==="object"&&n in x);`;
|
|
56
|
+
code += `const P=(n)=>typeof p==="function"?p(n):p[n];`;
|
|
56
57
|
code += `let x;`;
|
|
57
58
|
code += `let r="";`;
|
|
58
59
|
let tagRegExp = compileTagRegExp('{{', '}}');
|
|
@@ -64,13 +65,52 @@ function compile(template) {
|
|
|
64
65
|
const match = tagRegExp.exec(template);
|
|
65
66
|
if (!match)
|
|
66
67
|
break;
|
|
67
|
-
if (!inParent && match.index > index)
|
|
68
|
-
code += `r+=${quoteString(template.slice(index, match.index))};`;
|
|
69
|
-
index = tagRegExp.lastIndex;
|
|
70
68
|
const tag = match[1].trim();
|
|
71
|
-
const tagMatch = tag.match(/^(?:=\s*([^=\s]+)\s+([^=\s]+)\s*=|#\s*(\S+)|\^\s*(\S+)|\/\s*(\S+)|\{\s*(\S+)\s*\}|&\s*(\S+)
|
|
69
|
+
const tagMatch = tag.match(/^(?:=\s*([^=\s]+)\s+([^=\s]+)\s*=|#\s*(\S+)|\^\s*(\S+)|\/\s*(\S+)|\{\s*(\S+)\s*\}|&\s*(\S+)|![\s\S]*|>\s*\*\s*(\S+)|>\s*(\S+)|\$\s*(\S+)|<\s*\*\s*(\S+)|<\s*(\S+)|\s*(\S+))$/);
|
|
72
70
|
if (!tagMatch)
|
|
73
71
|
throw new Error(`Invalid tag: ${tag}`);
|
|
72
|
+
let left = match.index;
|
|
73
|
+
let right = tagRegExp.lastIndex;
|
|
74
|
+
if (!tagMatch[6] && !tagMatch[7] && !tagMatch[13]) { // Standalone tags
|
|
75
|
+
let isStandalone = true;
|
|
76
|
+
while (left > 0) {
|
|
77
|
+
const ch = template[left - 1];
|
|
78
|
+
if (ch.match(/\S/)) {
|
|
79
|
+
isStandalone = false;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
else if (ch.match(/[\n\r]/))
|
|
83
|
+
break;
|
|
84
|
+
else
|
|
85
|
+
left--;
|
|
86
|
+
}
|
|
87
|
+
if (isStandalone) {
|
|
88
|
+
while (right < template.length) {
|
|
89
|
+
const ch = template[right];
|
|
90
|
+
if (ch.match(/\S/)) {
|
|
91
|
+
isStandalone = false;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
else if (ch.match(/[\n\r]/)) {
|
|
95
|
+
right++;
|
|
96
|
+
if (right < template.length
|
|
97
|
+
&& template[right].match(/[\n\r]/)
|
|
98
|
+
&& template[right] !== ch)
|
|
99
|
+
right++;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
right++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!isStandalone) {
|
|
107
|
+
left = match.index;
|
|
108
|
+
right = tagRegExp.lastIndex;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!inParent && match.index > index)
|
|
112
|
+
code += `r+=${quoteString(template.slice(index, left))};`;
|
|
113
|
+
index = right;
|
|
74
114
|
if (tagMatch[1] && tagMatch[2]) { // Set delimiters
|
|
75
115
|
tagRegExp = compileTagRegExp(tagMatch[1], tagMatch[2]);
|
|
76
116
|
}
|
|
@@ -112,16 +152,13 @@ function compile(template) {
|
|
|
112
152
|
if (inParent)
|
|
113
153
|
throw new Error("Partials cannot be nested inside parents");
|
|
114
154
|
resolve(tagMatch[8]);
|
|
115
|
-
code += `x=
|
|
155
|
+
code += `x=P(x);`;
|
|
116
156
|
code += `r+=x?x(v,p,{},e):"";`;
|
|
117
157
|
}
|
|
118
158
|
else if (tagMatch[9]) { // Partial
|
|
119
159
|
if (inParent)
|
|
120
160
|
throw new Error("Partials cannot be nested inside parents");
|
|
121
|
-
|
|
122
|
-
code += `x=p.${tagMatch[9]};`;
|
|
123
|
-
else
|
|
124
|
-
code += `x=p[${quoteString(tagMatch[9])}];`;
|
|
161
|
+
code += `x=P(${quoteString(tagMatch[9])});`;
|
|
125
162
|
code += `r+=x?x(v,p,{},e):"";`;
|
|
126
163
|
}
|
|
127
164
|
else if (tagMatch[10]) { // Block
|
|
@@ -150,17 +187,14 @@ function compile(template) {
|
|
|
150
187
|
if (inParent)
|
|
151
188
|
throw new Error("Parents cannot be nested inside parents");
|
|
152
189
|
resolve(tagMatch[11]);
|
|
153
|
-
code += `x=
|
|
190
|
+
code += `x=P(x);`;
|
|
154
191
|
code += `if(x)r+=x(v,p,{`;
|
|
155
192
|
stack.push([tagMatch[11], () => code += `},e);`]);
|
|
156
193
|
}
|
|
157
194
|
else if (tagMatch[12]) { // Parent
|
|
158
195
|
if (inParent)
|
|
159
196
|
throw new Error("Parents cannot be nested inside parents");
|
|
160
|
-
|
|
161
|
-
code += `x=p.${tagMatch[12]};`;
|
|
162
|
-
else
|
|
163
|
-
code += `x=p[${quoteString(tagMatch[12])}];`;
|
|
197
|
+
code += `x=P(${quoteString(tagMatch[12])});`;
|
|
164
198
|
code += `if(x)r+=x(v,p,{`;
|
|
165
199
|
inParent = true;
|
|
166
200
|
stack.push([tagMatch[12], () => {
|
|
@@ -211,12 +245,13 @@ function renderCompiled(template, view, partials = {}, escape = escapeHTML) {
|
|
|
211
245
|
}
|
|
212
246
|
function render(template, view, partials = {}, escape = escapeHTML) {
|
|
213
247
|
const compiledPartials = {};
|
|
214
|
-
return renderCompiled(compile(template), view,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
248
|
+
return renderCompiled(compile(template), view, name => {
|
|
249
|
+
var _a;
|
|
250
|
+
const template = typeof partials === "function"
|
|
251
|
+
? partials(name)
|
|
252
|
+
: (_a = partials[name]) !== null && _a !== void 0 ? _a : null;
|
|
253
|
+
return template === null ? null : compile(template);
|
|
254
|
+
}, escape);
|
|
220
255
|
}
|
|
221
256
|
function renderCompiledAsync(template_1, view_1) {
|
|
222
257
|
return __awaiter(this, arguments, void 0, function* (template, view, partials = {}, escape = escapeHTML) {
|
|
@@ -241,73 +276,74 @@ function renderCompiledAsync(template_1, view_1) {
|
|
|
241
276
|
return wrappedObject;
|
|
242
277
|
}
|
|
243
278
|
else if (typeof view === "function") {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
279
|
+
const wrappedFunction = () => {
|
|
280
|
+
if (values.has(view))
|
|
281
|
+
return wrapView(values.get(view));
|
|
282
|
+
else if (pendingValues.has(view))
|
|
283
|
+
return null;
|
|
284
|
+
else {
|
|
285
|
+
const promise = Promise.resolve(view());
|
|
286
|
+
pendingValues.set(view, promise);
|
|
287
|
+
promise.then(value => {
|
|
288
|
+
values.set(view, value);
|
|
289
|
+
pendingValues.delete(view);
|
|
290
|
+
}).catch(() => {
|
|
291
|
+
// Rejection is handled by Promise.all in the render loop;
|
|
292
|
+
// suppress the unhandled rejection on this detached chain.
|
|
293
|
+
});
|
|
294
|
+
return values.has(view) ? wrapView(values.get(view)) : null;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
wrappedValues.set(view, wrappedFunction);
|
|
298
|
+
return wrappedFunction;
|
|
260
299
|
}
|
|
261
300
|
else
|
|
262
301
|
return view;
|
|
263
302
|
};
|
|
264
|
-
const wrappedPartials =
|
|
265
|
-
const pendingPartials =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (name
|
|
270
|
-
return
|
|
271
|
-
else if (name
|
|
303
|
+
const wrappedPartials = new Map();
|
|
304
|
+
const pendingPartials = new Map();
|
|
305
|
+
while (true) {
|
|
306
|
+
const result = template([wrapView(view)], (name) => {
|
|
307
|
+
var _a;
|
|
308
|
+
if (wrappedPartials.has(name))
|
|
309
|
+
return wrappedPartials.get(name);
|
|
310
|
+
else if (pendingPartials.has(name))
|
|
272
311
|
return null;
|
|
273
312
|
else {
|
|
274
|
-
const promise = Promise.resolve(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
313
|
+
const promise = Promise.resolve(typeof partials === "function"
|
|
314
|
+
? partials(name)
|
|
315
|
+
: (_a = partials[name]) !== null && _a !== void 0 ? _a : null);
|
|
316
|
+
pendingPartials.set(name, promise);
|
|
317
|
+
promise.then(partial => {
|
|
318
|
+
wrappedPartials.set(name, partial);
|
|
319
|
+
pendingPartials.delete(name);
|
|
279
320
|
}).catch(() => {
|
|
280
321
|
// Rejection is handled by Promise.all in the render loop;
|
|
281
322
|
// suppress the unhandled rejection on this detached chain.
|
|
282
323
|
});
|
|
283
|
-
return name
|
|
284
|
-
?
|
|
324
|
+
return wrappedPartials.has(name)
|
|
325
|
+
? wrappedPartials.get(name)
|
|
285
326
|
: null;
|
|
286
327
|
}
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
};
|
|
290
|
-
while (true) {
|
|
291
|
-
const result = template([wrapView(view)], wrapPartials(partials), {}, escape);
|
|
292
|
-
if (pendingValues.size === 0 && Object.keys(pendingPartials).length === 0)
|
|
328
|
+
}, {}, escape);
|
|
329
|
+
if (pendingValues.size === 0 && pendingPartials.size === 0)
|
|
293
330
|
return result;
|
|
294
331
|
yield Promise.all([
|
|
295
332
|
...pendingValues.values(),
|
|
296
|
-
...
|
|
333
|
+
...pendingPartials.values()
|
|
297
334
|
]);
|
|
298
|
-
pendingValues.clear();
|
|
299
335
|
wrappedValues.clear();
|
|
300
336
|
}
|
|
301
337
|
});
|
|
302
338
|
}
|
|
303
339
|
function renderAsync(template_1, view_1) {
|
|
304
340
|
return __awaiter(this, arguments, void 0, function* (template, view, partials = {}, escape = escapeHTML) {
|
|
305
|
-
return renderCompiledAsync(compile(template), view,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
341
|
+
return renderCompiledAsync(compile(template), view, (name) => __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
const template = typeof partials === "function"
|
|
343
|
+
? yield partials(name)
|
|
344
|
+
: partials[name];
|
|
345
|
+
return template === null ? null : compile(template);
|
|
346
|
+
}), escape);
|
|
311
347
|
});
|
|
312
348
|
}
|
|
313
349
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AA6BA,0BA0IC;AAeD,wCAOC;AAED,wBAiBC;AAED,kDAkFC;AAED,kCAeC;AArTD,SAAS,UAAU,CAAC,KAAY;IAC9B,MAAM,KAAK,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO,4BAA4B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,gBAAgB,CAAC,aAAqB,EAAE,cAAsB;IACrE,MAAM,oBAAoB,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IACzD,MAAM,qBAAqB,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;IAC3D,OAAO,IAAI,MAAM,CAAC,GAAG,oBAAoB,mCAAmC,qBAAqB,EAAE,EACjG,GAAG,CAAC,CAAC;AACT,CAAC;AAQD,SAAgB,OAAO,CAAC,QAAgB;IACtC,IAAI,IAAI,GAAG,EAAE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Aa,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CAAA;AAED,SAAsB,WAAW;yDAC/B,QAAgB,EAChB,IAAS,EACT,WACiD,EAAE,EACnD,SAAqC,UAAU;QAE/C,OAAO,mBAAmB,CACxB,OAAO,CAAC,QAAQ,CAAC,EACjB,IAAI,EACJ,CAAO,IAAI,EAAE,EAAE;YACb,MAAM,QAAQ,GAAG,OAAO,QAAQ,KAAK,UAAU;gBAC7C,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC;gBACtB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnB,OAAO,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAA,EAAE,MAAM,CAAC,CAAC;IACf,CAAC;CAAA"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -18,12 +18,13 @@ function compileTagRegExp(leftDelimiter: string, rightDelimiter: string): RegExp
|
|
|
18
18
|
const escapedLeftDelimiter = escapeRegExp(leftDelimiter);
|
|
19
19
|
const escapedRightDelimiter = escapeRegExp(rightDelimiter);
|
|
20
20
|
return new RegExp(`${escapedLeftDelimiter}\\s*(\\{[^}]*\\}\\s*|[^{\\s].*?)${escapedRightDelimiter}`,
|
|
21
|
-
"
|
|
21
|
+
"gs");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export type CompiledTemplate = (
|
|
25
25
|
view: any[],
|
|
26
|
-
partials: { [name: string]: CompiledTemplate }
|
|
26
|
+
partials: { [name: string]: CompiledTemplate }
|
|
27
|
+
| ((name: string) => CompiledTemplate | null),
|
|
27
28
|
blocks: { [name: string]: () => string },
|
|
28
29
|
escape: (string: string) => string) => string;
|
|
29
30
|
|
|
@@ -49,6 +50,7 @@ export function compile(template: string): CompiledTemplate {
|
|
|
49
50
|
code += `const s=(x)=>x==null?"":String(x);`;
|
|
50
51
|
code += `const S=(x)=>x==null?"":e(x);`;
|
|
51
52
|
code += `const o=(n)=>v.find(x=>x!=null&&typeof x==="object"&&n in x);`;
|
|
53
|
+
code += `const P=(n)=>typeof p==="function"?p(n):p[n];`
|
|
52
54
|
code += `let x;`;
|
|
53
55
|
code += `let r="";`;
|
|
54
56
|
|
|
@@ -60,12 +62,44 @@ export function compile(template: string): CompiledTemplate {
|
|
|
60
62
|
tagRegExp.lastIndex = index;
|
|
61
63
|
const match = tagRegExp.exec(template);
|
|
62
64
|
if (!match) break;
|
|
63
|
-
if (!inParent && match.index > index)
|
|
64
|
-
code += `r+=${quoteString(template.slice(index, match.index))};`;
|
|
65
|
-
index = tagRegExp.lastIndex;
|
|
66
65
|
const tag = match[1].trim();
|
|
67
|
-
const tagMatch = tag.match(/^(?:=\s*([^=\s]+)\s+([^=\s]+)\s*=|#\s*(\S+)|\^\s*(\S+)|\/\s*(\S+)|\{\s*(\S+)\s*\}|&\s*(\S+)
|
|
66
|
+
const tagMatch = tag.match(/^(?:=\s*([^=\s]+)\s+([^=\s]+)\s*=|#\s*(\S+)|\^\s*(\S+)|\/\s*(\S+)|\{\s*(\S+)\s*\}|&\s*(\S+)|![\s\S]*|>\s*\*\s*(\S+)|>\s*(\S+)|\$\s*(\S+)|<\s*\*\s*(\S+)|<\s*(\S+)|\s*(\S+))$/);
|
|
68
67
|
if (!tagMatch) throw new Error(`Invalid tag: ${tag}`);
|
|
68
|
+
let left = match.index;
|
|
69
|
+
let right = tagRegExp.lastIndex;
|
|
70
|
+
if (!tagMatch[6] && !tagMatch[7] && !tagMatch[13]) { // Standalone tags
|
|
71
|
+
let isStandalone = true;
|
|
72
|
+
while (left > 0) {
|
|
73
|
+
const ch = template[left - 1];
|
|
74
|
+
if (ch.match(/\S/)) {
|
|
75
|
+
isStandalone = false;
|
|
76
|
+
break;
|
|
77
|
+
} else if (ch.match(/[\n\r]/)) break;
|
|
78
|
+
else left--;
|
|
79
|
+
}
|
|
80
|
+
if (isStandalone) {
|
|
81
|
+
while (right < template.length) {
|
|
82
|
+
const ch = template[right];
|
|
83
|
+
if (ch.match(/\S/)) {
|
|
84
|
+
isStandalone = false;
|
|
85
|
+
break;
|
|
86
|
+
} else if (ch.match(/[\n\r]/)) {
|
|
87
|
+
right++;
|
|
88
|
+
if (right < template.length
|
|
89
|
+
&& template[right].match(/[\n\r]/)
|
|
90
|
+
&& template[right] !== ch) right++;
|
|
91
|
+
break;
|
|
92
|
+
} else right++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!isStandalone) {
|
|
96
|
+
left = match.index;
|
|
97
|
+
right = tagRegExp.lastIndex;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!inParent && match.index > index)
|
|
101
|
+
code += `r+=${quoteString(template.slice(index, left))};`;
|
|
102
|
+
index = right;
|
|
69
103
|
if (tagMatch[1] && tagMatch[2]) { // Set delimiters
|
|
70
104
|
tagRegExp = compileTagRegExp(tagMatch[1], tagMatch[2]);
|
|
71
105
|
} else if (tagMatch[3]) { // Section
|
|
@@ -99,13 +133,11 @@ export function compile(template: string): CompiledTemplate {
|
|
|
99
133
|
if (inParent)
|
|
100
134
|
throw new Error("Partials cannot be nested inside parents");
|
|
101
135
|
resolve(tagMatch[8]);
|
|
102
|
-
code += `x=
|
|
136
|
+
code += `x=P(x);`;
|
|
103
137
|
code += `r+=x?x(v,p,{},e):"";`;
|
|
104
138
|
} else if (tagMatch[9]) { // Partial
|
|
105
139
|
if (inParent) throw new Error("Partials cannot be nested inside parents");
|
|
106
|
-
|
|
107
|
-
code += `x=p.${tagMatch[9]};`;
|
|
108
|
-
else code += `x=p[${quoteString(tagMatch[9])}];`;
|
|
140
|
+
code += `x=P(${quoteString(tagMatch[9])});`;
|
|
109
141
|
code += `r+=x?x(v,p,{},e):"";`;
|
|
110
142
|
} else if (tagMatch[10]) { // Block
|
|
111
143
|
if (inParent) {
|
|
@@ -128,14 +160,12 @@ export function compile(template: string): CompiledTemplate {
|
|
|
128
160
|
} else if (tagMatch[11]) { // Dynamic Parent
|
|
129
161
|
if (inParent) throw new Error("Parents cannot be nested inside parents");
|
|
130
162
|
resolve(tagMatch[11]);
|
|
131
|
-
code += `x=
|
|
163
|
+
code += `x=P(x);`;
|
|
132
164
|
code += `if(x)r+=x(v,p,{`;
|
|
133
165
|
stack.push([tagMatch[11], () => code += `},e);`]);
|
|
134
166
|
} else if (tagMatch[12]) { // Parent
|
|
135
167
|
if (inParent) throw new Error("Parents cannot be nested inside parents");
|
|
136
|
-
|
|
137
|
-
code += `x=p.${tagMatch[12]};`;
|
|
138
|
-
else code += `x=p[${quoteString(tagMatch[12])}];`;
|
|
168
|
+
code += `x=P(${quoteString(tagMatch[12])});`;
|
|
139
169
|
code += `if(x)r+=x(v,p,{`;
|
|
140
170
|
inParent = true;
|
|
141
171
|
stack.push([tagMatch[12], () => {
|
|
@@ -183,7 +213,8 @@ function escapeHTML(string: string): string {
|
|
|
183
213
|
export function renderCompiled(
|
|
184
214
|
template: CompiledTemplate,
|
|
185
215
|
view: any,
|
|
186
|
-
partials: { [name: string]: CompiledTemplate }
|
|
216
|
+
partials: { [name: string]: CompiledTemplate }
|
|
217
|
+
| ((name: string) => CompiledTemplate | null) = {},
|
|
187
218
|
escape: (string: string) => string = escapeHTML
|
|
188
219
|
): string {
|
|
189
220
|
return template([view], partials, {}, escape);
|
|
@@ -192,26 +223,27 @@ export function renderCompiled(
|
|
|
192
223
|
export function render(
|
|
193
224
|
template: string,
|
|
194
225
|
view: any,
|
|
195
|
-
partials: { [name: string]: string }
|
|
226
|
+
partials: { [name: string]: string }
|
|
227
|
+
| ((name: string) => string | null) = {},
|
|
196
228
|
escape: (string: string) => string = escapeHTML
|
|
197
229
|
): string {
|
|
198
230
|
const compiledPartials: { [name: string]: CompiledTemplate } = {};
|
|
199
231
|
return renderCompiled(
|
|
200
232
|
compile(template),
|
|
201
233
|
view,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}])), escape);
|
|
234
|
+
name => {
|
|
235
|
+
const template = typeof partials === "function"
|
|
236
|
+
? partials(name)
|
|
237
|
+
: partials[name] ?? null;
|
|
238
|
+
return template === null ? null : compile(template);
|
|
239
|
+
}, escape);
|
|
209
240
|
}
|
|
210
241
|
|
|
211
242
|
export async function renderCompiledAsync(
|
|
212
243
|
template: CompiledTemplate,
|
|
213
244
|
view: any,
|
|
214
|
-
partials: { [name: string]:
|
|
245
|
+
partials: { [name: string]: CompiledTemplate }
|
|
246
|
+
| ((name: string) => Promise<CompiledTemplate | null>) = {},
|
|
215
247
|
escape: (string: string) => string = escapeHTML
|
|
216
248
|
): Promise<string> {
|
|
217
249
|
const wrappedValues = new Map<any, any>();
|
|
@@ -233,61 +265,61 @@ export async function renderCompiledAsync(
|
|
|
233
265
|
wrappedObject[key] = wrapView(view[key]);
|
|
234
266
|
return wrappedObject;
|
|
235
267
|
} else if (typeof view === "function") {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
268
|
+
const wrappedFunction = () => {
|
|
269
|
+
if (values.has(view)) return wrapView(values.get(view));
|
|
270
|
+
else if (pendingValues.has(view)) return null;
|
|
271
|
+
else {
|
|
272
|
+
const promise = Promise.resolve(view());
|
|
273
|
+
pendingValues.set(view, promise);
|
|
274
|
+
promise.then(value => {
|
|
275
|
+
values.set(view, value);
|
|
276
|
+
pendingValues.delete(view);
|
|
277
|
+
}).catch(() => {
|
|
278
|
+
// Rejection is handled by Promise.all in the render loop;
|
|
279
|
+
// suppress the unhandled rejection on this detached chain.
|
|
280
|
+
});
|
|
281
|
+
return values.has(view) ? wrapView(values.get(view)) : null;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
wrappedValues.set(view, wrappedFunction);
|
|
285
|
+
return wrappedFunction;
|
|
250
286
|
} else return view;
|
|
251
287
|
};
|
|
252
288
|
|
|
253
|
-
const wrappedPartials
|
|
254
|
-
const pendingPartials
|
|
255
|
-
|
|
256
|
-
const wrapPartials = (partials: {
|
|
257
|
-
[name: string]: () => Promise<CompiledTemplate>
|
|
258
|
-
}) => {
|
|
259
|
-
return Object.fromEntries(
|
|
260
|
-
Object.entries(partials)
|
|
261
|
-
.map(([name, partial]) => {
|
|
262
|
-
if (name in wrappedPartials) return [name, wrappedPartials[name]];
|
|
263
|
-
else if (name in pendingPartials) return null;
|
|
264
|
-
else {
|
|
265
|
-
const promise = Promise.resolve(partial());
|
|
266
|
-
pendingPartials[name] = promise;
|
|
267
|
-
promise.then(compiled => {
|
|
268
|
-
wrappedPartials[name] = compiled;
|
|
269
|
-
delete pendingPartials[name];
|
|
270
|
-
}).catch(() => {
|
|
271
|
-
// Rejection is handled by Promise.all in the render loop;
|
|
272
|
-
// suppress the unhandled rejection on this detached chain.
|
|
273
|
-
});
|
|
274
|
-
return name in wrappedPartials
|
|
275
|
-
? [name, wrappedPartials[name]]
|
|
276
|
-
: null;
|
|
277
|
-
}
|
|
278
|
-
})
|
|
279
|
-
.filter((entry): entry is [string, CompiledTemplate] => entry !== null)
|
|
280
|
-
);
|
|
281
|
-
};
|
|
289
|
+
const wrappedPartials = new Map<string, CompiledTemplate | null>();
|
|
290
|
+
const pendingPartials = new Map<string, Promise<CompiledTemplate | null>>();
|
|
282
291
|
|
|
283
292
|
while (true) {
|
|
284
|
-
const result = template(
|
|
285
|
-
|
|
293
|
+
const result = template(
|
|
294
|
+
[wrapView(view)],
|
|
295
|
+
(name) => {
|
|
296
|
+
if (wrappedPartials.has(name)) return wrappedPartials.get(name)!;
|
|
297
|
+
else if (pendingPartials.has(name)) return null;
|
|
298
|
+
else {
|
|
299
|
+
const promise = Promise.resolve(
|
|
300
|
+
typeof partials === "function"
|
|
301
|
+
? partials(name)
|
|
302
|
+
: partials[name] ?? null
|
|
303
|
+
);
|
|
304
|
+
pendingPartials.set(name, promise);
|
|
305
|
+
promise.then(partial => {
|
|
306
|
+
wrappedPartials.set(name, partial);
|
|
307
|
+
pendingPartials.delete(name);
|
|
308
|
+
}).catch(() => {
|
|
309
|
+
// Rejection is handled by Promise.all in the render loop;
|
|
310
|
+
// suppress the unhandled rejection on this detached chain.
|
|
311
|
+
});
|
|
312
|
+
return wrappedPartials.has(name)
|
|
313
|
+
? wrappedPartials.get(name)!
|
|
314
|
+
: null;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
{}, escape);
|
|
318
|
+
if (pendingValues.size === 0 && pendingPartials.size === 0) return result;
|
|
286
319
|
await Promise.all([
|
|
287
320
|
...pendingValues.values(),
|
|
288
|
-
...
|
|
321
|
+
...pendingPartials.values()
|
|
289
322
|
]);
|
|
290
|
-
pendingValues.clear();
|
|
291
323
|
wrappedValues.clear();
|
|
292
324
|
}
|
|
293
325
|
}
|
|
@@ -295,16 +327,17 @@ export async function renderCompiledAsync(
|
|
|
295
327
|
export async function renderAsync(
|
|
296
328
|
template: string,
|
|
297
329
|
view: any,
|
|
298
|
-
partials: { [name: string]: string
|
|
330
|
+
partials: { [name: string]: string }
|
|
331
|
+
| ((name: string) => Promise<string | null>) = {},
|
|
299
332
|
escape: (string: string) => string = escapeHTML
|
|
300
333
|
): Promise<string> {
|
|
301
334
|
return renderCompiledAsync(
|
|
302
335
|
compile(template),
|
|
303
336
|
view,
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
337
|
+
async (name) => {
|
|
338
|
+
const template = typeof partials === "function"
|
|
339
|
+
? await partials(name)
|
|
340
|
+
: partials[name];
|
|
341
|
+
return template === null ? null : compile(template);
|
|
342
|
+
}, escape);
|
|
310
343
|
}
|