-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathcreator.js
More file actions
37 lines (36 loc) · 1.23 KB
/
Copy pathcreator.js
File metadata and controls
37 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { PersistentFragment } from './persistent-fragment.js';
import { bc, detail } from './literals.js';
import { array, hole } from './handler.js';
import { empty, find } from './utils.js';
import { cache } from './literals.js';
/** @param {(template: TemplateStringsArray, values: any[]) => import("./parser.js").Resolved} parse */
export default parse => (
/**
* @param {TemplateStringsArray} template
* @param {any[]} values
* @returns {import("./literals.js").Cache}
*/
(template, values) => {
const { a: fragment, b: entries, c: direct } = parse(template, values);
const root = document.importNode(fragment, true);
/** @type {import("./literals.js").Detail[]} */
let details = empty;
if (entries !== empty) {
details = [];
for (let current, prev, i = 0; i < entries.length; i++) {
const { a: path, b: update, c: name } = entries[i];
const node = path === prev ? current : (current = find(root, (prev = path)));
details[i] = detail(
update,
node,
name,
update === array ? [] : (update === hole ? cache() : null)
);
}
}
return bc(
direct ? root.firstChild : new PersistentFragment(root),
details,
);
}
);