forked from WebReflection/uhtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.cjs
More file actions
33 lines (30 loc) · 1.26 KB
/
init.cjs
File metadata and controls
33 lines (30 loc) · 1.26 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
const { readFileSync, writeFileSync } = require('fs');
const { join } = require('path');
const init = join(__dirname, '..', 'esm', 'init.js');
const uhtml = readFileSync(init).toString();
writeFileSync(init, `
// ⚠️ WARNING - THIS FILE IS AN ARTIFACT - DO NOT EDIT
/**
* @param {Document} document
* @returns {import("./keyed.js")}
*/
export default document => ${
// tested via integration
uhtml
.replace(`svg || ('ownerSVGElement' in element)`, `/* c8 ignore start */ svg || ('ownerSVGElement' in element) /* c8 ignore stop */`)
.replace(/diffFragment = \(([\S\s]+?)return /, 'diffFragment = /* c8 ignore start */($1/* c8 ignore stop */return ')
.replace(/udomdiff = \(([\S\s]+?)return /, 'udomdiff = /* c8 ignore start */($1/* c8 ignore stop */return ')
.replace(/^(\s+)replaceWith\(([^}]+?)\}/m, '$1/* c8 ignore start */\n$1replaceWith($2}\n$1/* c8 ignore stop */')
.replace(/^(\s+)(["'])use strict\2;/m, '$1$2use strict$2;\n\n$1const { constructor: DocumentFragment } = document.createDocumentFragment();')
.replace(/^[^(]+/, '')
.replace(/\n exports\.Hole = Hole;[\S\s]*return exports;/m, `
return {
Hole : Hole,
attr : attr,
html : html,
htmlFor : htmlFor,
render : keyed$1,
svg : svg,
svgFor : svgFor,
};`)
}`);