Skip to content

Commit

Permalink
var name change
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Nov 14, 2023
1 parent 8b4c91e commit 1438d97
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
6 changes: 3 additions & 3 deletions esm/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const arrayComment = () => array;
*/
const resolve = (template, values, xml) => {
const content = createContent(parser(template, prefix, xml), xml);
let comment = false, entries = empty;
let asArray = false, entries = empty;
const { length } = template;
if (length > 1) {
const tw = document.createTreeWalker(content, 1 | 128);
Expand All @@ -55,7 +55,7 @@ const resolve = (template, values, xml) => {
if (node.data === search) {
let update = isArray(values[i - 1]) ? arrayComment : boundComment;
if (update === boundComment) replace.push(node);
else comment = true;
else asArray = true;
entries.push(entry(COMMENT_NODE, createPath(node), update));
search = `${prefix}${i++}`;
}
Expand All @@ -82,7 +82,7 @@ const resolve = (template, values, xml) => {
replace[i].replaceWith(document.createTextNode(''));
}
const l = content.childNodes.length;
return set(cache, template, cel(content, entries, l === 1 && comment ? 0 : l));
return set(cache, template, cel(content, entries, l === 1 && asArray ? 0 : l));
};

/** @type {WeakMap<TemplateStringsArray, Resolved>} */
Expand Down
6 changes: 2 additions & 4 deletions test/blank-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module">
// https://github.com/WebReflection/lighterhtml/issues/92
// ucdn --debug
import {render, html} from '../esm/index.js';
import {render, html, htmlFor} from '../keyed.js';

let state = 0;

Expand Down Expand Up @@ -38,7 +36,7 @@
const one = (name = 'one') => html`${box(() => html`one`)}`;


const two = (name = 'two', value = 'opt') => html`${box(() => html`
const two = (name = 'two', value = 'opt') => html`${box(() => htmlFor(two)`
<label class="block px-3 mb-3">
<input type="radio" class="form-radio" name=${name} value=${value}>
<span>two</span>
Expand Down
9 changes: 2 additions & 7 deletions test/dbmonster.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="dbmonster.css">
<script src="https://unpkg.com/perf-monitor@0.3.0/dist/umd/perf-monitor.js"></script>
<script src="../index.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {"use strict";

const {render, html} = uhtml;
<script type="module">
import { render, html } from '../index.js';

const target = document.querySelector('#app');

Expand Down Expand Up @@ -71,8 +68,6 @@
}

update();

}, {once: true});
</script>
</head>
<body>
Expand Down
17 changes: 17 additions & 0 deletions test/empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>uhtml</title>
<script type="module">
import { render, html } from '../index.js';
const update = value => {
render(document.body, html`${value}`);
}
update('test');
setTimeout(update, 1000, 'OK');
</script>
</head>
<body></body>
</html>
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>udom</title>
<title>uhtml</title>
<script type="module">
const testUHTML = () => import('./uhtml.js').then(({ render, html }) => {
console.time('parse uhtml');
Expand Down

0 comments on commit 1438d97

Please sign in to comment.