tangled
alpha
login
or
join now
tombl.dev
/
dhtml
1
fork
atom
a post-component library for building user-interfaces on the web.
1
fork
atom
overview
issues
pulls
pipelines
random tidy (#28)
authored by
tombl.dev
and committed by
GitHub
1 year ago
ceae60b4
7480b24e
+9
-7
2 changed files
expand all
collapse all
unified
split
src
html.js
tsconfig.json
+8
-7
src/html.js
reviewed
···
17
17
const isElement = node => node.nodeType === /** @satisfies {typeof Node.ELEMENT_NODE} */ (1)
18
18
19
19
/** @return {node is Text} */
20
20
-
const isTextNode = node => node.nodeType === /** @satisfies {typeof Node.TEXT_NODE} */ (3)
20
20
+
const isText = node => node.nodeType === /** @satisfies {typeof Node.TEXT_NODE} */ (3)
21
21
22
22
/** @return {node is DocumentFragment} */
23
23
const isDocumentFragment = node => node.nodeType === /** @satisfies {typeof Node.DOCUMENT_FRAGMENT_NODE} */ (11)
···
81
81
if (DEV) {
82
82
Span.prototype.toString = function () {
83
83
let result = ''
84
84
-
for (const node of this) result += /** @type {HTMLElement} */ (node).outerHTML ?? String(node)
84
84
+
for (const node of this)
85
85
+
result += isElement(node)
86
86
+
? node.outerHTML
87
87
+
: `${node.constructor.name}(${'data' in node ? JSON.stringify(node.data) : node})`
85
88
return result
86
89
}
87
90
}
···
227
230
const walker = document.createTreeWalker(templateElement.content, NODE_FILTER_TEXT | NODE_FILTER_ELEMENT)
228
231
while (nextPart < compiled._parts.length && walker.nextNode()) {
229
232
const node = /** @type {Text | Element} */ (walker.currentNode)
230
230
-
if (isTextNode(node)) {
233
233
+
if (isText(node)) {
231
234
const nodes = [...node.data.matchAll(DYNAMIC_GLOBAL)].reverse().map(match => {
232
235
node.splitText(match.index + match[0].length)
233
236
const dyn = new Comment()
···
255
258
256
259
let match = DYNAMIC_WHOLE.exec(name)
257
260
if (match !== null) {
261
261
+
// custom part:
258
262
toRemove.push(name)
259
263
const idx = parseInt(match[1])
260
264
···
267
271
DEV: assert(!DYNAMIC_GLOBAL.test(value), `expected a whole dynamic value for ${name}, got a partial one`)
268
272
patch(node, idx, () => new CustomPartStandalone(value))
269
273
}
270
270
-
continue
271
271
-
}
272
272
-
273
273
-
if (name[0] === '@') {
274
274
+
} else if (name[0] === '@') {
274
275
// event:
275
276
toRemove.push(name)
276
277
match = DYNAMIC_WHOLE.exec(value)
+1
tsconfig.json
reviewed
···
8
8
"module": "es2020",
9
9
"target": "es2020",
10
10
"verbatimModuleSyntax": true,
11
11
+
"allowUnusedLabels": true, // esbuild drops DEV labeled code in the prod build
11
12
"moduleResolution": "bundler"
12
13
},
13
14
"include": ["src", "examples"]