gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchrecords-hm55b2ae3b80dc|||PR records: HM55b briefTrackerrecords-hm55b2/plugins/web/compile.hl

60.7 KB

  1. // plugins/web/compile.hl — THE FRAMEWORK COMPILES EACH COMPONENT.
  2. //
  3. // Mission 313 (the creator, 15 Sep 14:30: "clientside interpreter + table against
  4. // component code per component, no tables needed"). The old hl:web ships ONE generic client
  5. // that walks a tree the seed carries: it pairs elements with nodes, asks a table which
  6. // members each element shows, asks `view.value` what each bound spot holds, and does it
  7. // again on every paint. hl:web ships the ANSWERS instead — this file writes each
  8. // component's own code, once, where the old hl:web would have walked.
  9. //
  10. // WHAT IS EMITTED, per component, beside the class `hlJs` compiled:
  11. //
  12. // v(c,m,o,host,i,rows,rk,fill,cr,opt) the component's View, unrolled: one
  13. // statement per element, per handler, per
  14. // bound spot. `cr` false CLAIMS the server's
  15. // DOM (take host.children[i], step on), `cr`
  16. // true CREATES it — the two walks the old hl:web
  17. // spells out separately, which differ only in
  18. // where an element comes from.
  19. // b["<for site>"] one `for` body — the row factory the keyed
  20. // region builds a row with.
  21. // t/e["<if site>"] an `if`'s two branches.
  22. // f["<reference site>"] the fragment this component writes into a
  23. // child's `slot` — built in THIS frame, which
  24. // is why it is this component's code.
  25. // p["<element site>"] the paint statements: `p` writes what one
  26. // member feeds (the old hl:web's paint(&m,s,name)),
  27. // `r` rewrites a row's element where the DOM
  28. // does not already hold it (rowPaint).
  29. //
  30. // The generated code calls a FIXED runtime (client.hl) for everything that is not this
  31. // component: the mount records, the keyed region diff, the binding edges, the
  32. // derivations, the socket, navigation. It never looks anything up in a table — the
  33. // names, the sites and the write sets are written into the statements.
  34. //
  35. // It is TEXT the framework produces, served from memory beside the module (WebFramework
  36. // `module`), never a JavaScript file under plugins/.
  37. import { newline, tab } from './view.hl'
  38. import HlwView from './view.hl'
  39. import HlwViewServer from './viewserver.hl'
  40. // The framework supplies its one graph-key → browser-key mapping. Reflection and
  41. // SSR keep the original key; only emitted component identities use this function.
  42. browserKeyOf = null
  43. // ---- the emitted half --------------------------------------------------------------
  44. module(gen, key, nodes, fnTable, fills) {
  45. literalFns = []
  46. fns = [] // the sub-walks: row bodies, if branches, fills
  47. done = {}
  48. rowVars = []
  49. tbl = tableOf(gen, key) // what the language says about this file, read once
  50. regions = regionIndex(tbl) // a `for`'s list reads, an `if`'s condition reads
  51. publicKey = browserKeyOf(key)
  52. root = walkTop(publicKey, nodes)
  53. // THE NAMED-REGION FILLS this View's root writes (`side { … }`): each is a sub-walk of THIS
  54. // component (its members, its handlers), run by the browser into the region a level above holds
  55. let fillNames = '{'
  56. let fillConds = '{'
  57. if (fills != null) {
  58. for (fl of fills) {
  59. sub(publicKey, fl.children, 'R', fl.site)
  60. fillNames = fillNames + (fillNames == '{' ? '' : ',') + str(fl.name) + ':' + str(fl.site)
  61. // a conditional fill (`if (x) { side { … } }`): the condition, read off the filling instance
  62. if (fl.cond != null) { fillConds = fillConds + (fillConds == '{' ? '' : ',') + str(fl.name) + ':function(inst,r){return ' + rawRead(fl.cond) + ';}' }
  63. }
  64. }
  65. fillNames = fillNames + '}'
  66. fillConds = fillConds + '}'
  67. let src = ';(function(){var g=(typeof globalThis!=="undefined"?globalThis:window);'
  68. src = src + 'var C=(g.__hlC=g.__hlC||{});'
  69. // the element a claim takes or a create makes — the one shape both walks share; a create
  70. // inside an svg (or an svg itself) is made in the SVG namespace, as the parser makes it
  71. // THE PRELUDE, one per module: the element a claim takes or a create makes, and the
  72. // two reads. A read written out in full — `(r["title"]!=null?r["title"]:inst["title"])`
  73. // — is 45 bytes and a component's View holds dozens of them; named, it is 16. The
  74. // rule is the same rule (a `for` row variable in scope wins over a member of the
  75. // same name, and a field path walks into it), spelled once.
  76. // A claim also moves the host's CURSOR — the last node the walk took there — which is
  77. // where a text leaf and a region's mark are looked for next (client.hl `leafNode`,
  78. // `markAt`).
  79. // MISSION 505: the five helpers (A, S, X, RV, RF) are bound off the runtime text (`paintHelpers` below) instead of written
  80. // into every module
  81. src = src + 'var A=g.__hlP.A,S=g.__hlP.S,X=g.__hlP.X,RV=g.__hlP.RV,RF=g.__hlP.RF,N=g.__hlP.N,TX=g.__hlP.TX;'
  82. src = src + 'var B={},T={},E={},F={},P={},D={},R={};'
  83. src = src + 'var L=[' + literalFns.join(',') + '];'
  84. // ONE FUNCTION PER LIST, however many sites reach it: a nested walk is written once
  85. // and named — emitting it per site made the reference app's home page 215 KB of the
  86. // same code over and over.
  87. let wi = 0
  88. for (f of fns) {
  89. wi = wi + 1
  90. let name = 'w' + wi
  91. src = src + 'var ' + name + '=' + f.src + ';'
  92. for (site of f.sites) { src = src + f.slot + '[' + str(site) + ']=' + name + ';' }
  93. }
  94. let paints = []
  95. collectPaints(&paints, nodes)
  96. for (e of paints) { src = src + 'P[' + str(e.site) + ']={p:' + e.paint + ',r:' + e.row + ',reads:' + e.reads + '};' }
  97. src = src + 'C[' + str(publicKey) + ']={v:' + root + ',b:B,t:T,e:E,f:F,p:P,d:D,r:R,rn:' + fillNames + ',rc:' + fillConds
  98. // THE ANSWERS A LOOKUP STILL NEEDS, and only those. A local event's write set stands
  99. // at its own listener and a region's names at its own region — written into the
  100. // call. These three are asked for by NAME at run time and cannot be: an inbound
  101. // frame names its event, a routine handed down names the member that holds it, and
  102. // a write set names the derivations that follow it. `on` is the one thing run FROM the
  103. // module's own scope: the language's instance-scoped handler (`on page.ev`, the instance's
  104. // own bus: runtime `hlInstanceBus`) with the event named at run time, which client.hl
  105. // `wireUp` registers for a page (#193). The bus class is read off the instance's own class
  106. // (`static __events__`): a module imports no `hlScopedBus` unless it writes an `on x.y`, and
  107. // a minified module renames `EventBus`.
  108. src = src + ',ev:' + eventMap() + ',mw:' + memberMap() + ',dv:' + derivList() + ',fn:' + fnMap(fnTable) + ',on:g.__hlP.O};'
  109. return src + '})();' + newline
  110. }
  111. // MISSION 505: THE SHARED PRELUDE, once per page. The five helpers every module's paint text calls — the element a claim
  112. // takes or a create makes (A), the text of a value (S), a region's sub-walk (X), the two reads (RV, RF) — were written
  113. // into every module: 699 bytes, 25 times on the reference app's start page. They are appended to the runtime text the
  114. // framework serves (WebFramework `runtime`), as `globalThis.__hlP`, and a module binds them by name (`module` above):
  115. // every module imports the runtime first, so they are there when its paint text runs. The two texts must agree on the
  116. // names; this is the only place the helpers are written.
  117. paintHelpers() {
  118. let s = ';(function(){var g=(typeof globalThis!=="undefined"?globalThis:window);var P=(g.__hlP=g.__hlP||{});'
  119. s = s + 'P.A=function(cr,host,i,tag){if(cr){if(tag==="svg"||(host.namespaceURI==="http://www.w3.org/2000/svg"&&host.localName.toLowerCase()!=="foreignobject")){return document.createElementNS("http://www.w3.org/2000/svg",tag);}return document.createElement(tag);}var e=host.children[i];if(e!=null){host.__hlCur=e;}return e;};'
  120. s = s + 'P.S=function(v){return v==null?"":""+v;};'
  121. s = s + 'P.X=async function(t,r,q){return await g.__hlX(t,q,r);};'
  122. s = s + 'P.RV=function(r,q,n){return r[n]!=null?r[n]:q[n];};'
  123. s = s + 'P.RF=function(r,q,n,p){var v=P.RV(r,q,n);for(var k=0;k<p.length;k++){if(v==null)return null;v=v[p[k]];}return v;};'
  124. // W200: the element idiom's fixed part (claim or create, the failed-claim report, the row/site/key stamp and the literal), a
  125. // build walk's text node, and the instance-scoped handler every module's `on:` names (client.hl `wireUp`)
  126. s = s + 'P.N=function(c,cr,host,i,tag,rows,site,key,lit){var el=P.A(cr,host,i,tag);if(el==null){c.acqFail(tag,host);return null;}el.__hlRows=rows;el.__hlSite=site;el.__hlKey=key;el.__hlLit=lit;return el;};'
  127. s = s + 'P.TX=function(h,t){h.appendChild(document.createTextNode(t));};'
  128. s = s + 'P.O=function(i,e,f){if(!Object.prototype.hasOwnProperty.call(i,"__instanceEvents__")){Object.defineProperty(i,"__instanceEvents__",{value:new (i.constructor.__events__.constructor)()});}i.__instanceEvents__.on(e,f);};'
  129. s = s + 'P.L=function(u){return import(u);};'
  130. return s + '})();'
  131. }
  132. tbl = null
  133. regions = {}
  134. // WHAT A FUNCTION VALUE WRITES, by the site it was made at (tickets #98, #99): the
  135. // module announces a function's return with its site, and the browser repaints this
  136. // set — the members it writes, closed over the methods it calls and the events it
  137. // emits, the same closure a handler's set gets. A function that writes nothing has
  138. // no entry.
  139. fnMap(fns) {
  140. let bySite = {}
  141. if (fns != null) {
  142. for (f of fns) {
  143. let names = closeWrites(&tbl, f.writes, f.reads)
  144. if (names.length > 0) { bySite[f.site] = names }
  145. }
  146. }
  147. return mapOf(bySite)
  148. }
  149. // what a DECLARED handler writes, by event: one entry per event name, unioned
  150. eventMap() {
  151. let byEvent = {}
  152. for (h of tbl.handlers) {
  153. if (!h.nested) {
  154. let have = byEvent[h.event] == null ? [] : byEvent[h.event]
  155. for (w of closeWrites(&tbl, h.writes, h.reads)) { if (!have.includes(w)) { have.push(w) } }
  156. byEvent[h.event] = have
  157. }
  158. }
  159. return mapOf(byEvent)
  160. }
  161. // A MEMBER HOLDING A ROUTINE: what calling it writes is what its initializer writes
  162. memberMap() {
  163. let byName = {}
  164. for (m of tbl.members) {
  165. if (m.nodes != null) { byName[m.name] = memberNames(m.nodes.writes) }
  166. }
  167. return mapOf(byName)
  168. }
  169. // EVERY INITIALIZER, IN DECLARATION ORDER, with the members it reads — the whole of
  170. // what a derivation needs; the class carries the computation itself as `__derive__`.
  171. // `srv` (written only when true, same rule as `isStatic` on a read — every byte here
  172. // ships to the browser) marks a SERVER REFERENCE SITE (COMPONENTS.md §9.1/§9.3): an
  173. // initializer that calls an imported class (`import Store from './store.hl'`, then
  174. // `Store.chatsOf(…)` — `hlDenotes`'s own `kind: 'class'`, not a second resolution).
  175. // It is evaluated per request, on the SERVER, and its value ships into the page as
  176. // state; `client.hl`'s `moved()` must never call it locally — routger's `conversations
  177. // = … ? store.chatsOf(session.user.id) : []` reached `hl:time`, which ships no client
  178. // half, the moment a session sync (0b17f65b) made `session` move in the browser and
  179. // `moved()` re-ran every derivation that reads it. A fresh value for a server
  180. // reference site ships in `sync` instead (WebFramework.hl `serverSyncNames`).
  181. derivList() {
  182. let src = '['
  183. let first = true
  184. let own = []
  185. for (m of tbl.members) { if (!m.isStatic) { own.push(m.name) } }
  186. for (d of tbl.derivations) {
  187. if (!first) { src = src + ',' }
  188. first = false
  189. src = src + '{name:' + str(d.name) + ',site:' + str(d.site) + ',reads:' + list(derivedReads(d, own))
  190. if (d.serverSite) { src = src + ',srv:true' }
  191. src = src + '}'
  192. }
  193. return src + ']'
  194. }
  195. // A derivation re-runs when any member it needs moves: the initializer's own reads plus
  196. // the compiler's transitive `inputs` (members read through methods and helpers it calls,
  197. // SPEC "Reflection builtins for frameworks"), kept to this class's instance members.
  198. derivedReads(d, own) {
  199. let out = memberNames(d.reads)
  200. if (d.inputs != null) {
  201. for (i of d.inputs) { if (own.includes(i) && !out.includes(i)) { out.push(i) } }
  202. }
  203. return out
  204. }
  205. mapOf(byName) {
  206. let src = '{'
  207. let first = true
  208. for (k of byName.keys()) {
  209. if (!first) { src = src + ',' }
  210. first = false
  211. src = src + str(k) + ':' + list(byName[k])
  212. }
  213. return src + '}'
  214. }
  215. // the write set and the read set of the handler at this site, closed over the methods
  216. // it calls and the handlers it emits to — computed here, written into the listener
  217. handlerSets(site) {
  218. for (h of tbl.handlers) {
  219. if (h.nested && h.site == site) {
  220. return list(closeWrites(&tbl, h.writes, h.reads)) + ',' + list(closeReads(&tbl, h.reads))
  221. }
  222. }
  223. return '[],[]'
  224. }
  225. // the named regions an `if`'s branch fills (`if (x) { side { … } }`), as a JS list, `null` for none: the
  226. // browser places those regions again when the condition changes
  227. fillNamesIn(nodes) {
  228. let out = ''
  229. for (c of nodes) {
  230. if (c.k == 'if' && c.regionfill != null) { out = out + (out == '' ? '' : ',') + str(c.regionfill) }
  231. }
  232. return out == '' ? 'null' : '[' + out + ']'
  233. }
  234. regionNamesAt(site) {
  235. let names = regions[site]
  236. return list(names == null ? [] : names)
  237. }
  238. fns = []
  239. literalFns = []
  240. // ---- the walk, unrolled ------------------------------------------------------------
  241. // `top` marks the View's own root list: an element there is a COMPOSITION ROOT — a
  242. // reference above may have overwritten some of its events and put classes on it, which
  243. // is what `opt` carries (the old hl:web's rootOverwrites and withRootClasses).
  244. walk(key, nodes) {
  245. return plain(key, nodes)
  246. }
  247. // a list's walk
  248. plain(key, nodes) {
  249. let body = ''
  250. for (n of nodes) { body = body + node(key, n, false, false) }
  251. return 'async function(c,m,o,host,i,rows,rk,fill,cr,opt){let inst=m.instance;let r=rows;' + body + 'return i;}'
  252. }
  253. // the View's own root list, whose elements are composition roots
  254. walkTop(key, nodes) {
  255. let body = ''
  256. for (n of nodes) {
  257. if (n.k == 'el' && n.tag == 'body') { body = body + elNode(key, n, true, true) }
  258. else { body = body + node(key, n, true, false) }
  259. }
  260. return 'async function(c,m,o,host,i,rows,rk,fill,cr,opt){let inst=m.instance;let r=rows;' + body + 'return i;}'
  261. }
  262. // W200: a text leaf made on the build walk, or taken on the claim walk (the server's text node), the fixed part in `TX`
  263. textLeaf(t) { return 'if(cr){TX(host,' + t + ');}else{await c.leafAt(host,false,i,null,' + t + ');}' }
  264. // a sub-walk, registered under its own site so the runtime can reach it by name
  265. // A SUB-WALK IS WRITTEN ONCE, however often the compile reaches its list.
  266. sub(key, nodes, slot, site) {
  267. if (done[slot + ' ' + site] != null) { return null }
  268. done[slot + ' ' + site] = true
  269. fns.push({ slot = slot; sites = [site]; src = walk(key, nodes); })
  270. return null
  271. }
  272. done = {}
  273. node(key, n, top, filterOns) {
  274. if (n.k == 'el') { return elNode(key, n, top) }
  275. if (n.k == 'text') { return textLeaf(str(n.text)) }
  276. if (n.k == 'on') {
  277. // A REFERENCE ABOVE MAY HAVE OVERWRITTEN THIS EVENT on the composition root:
  278. // the root's own handler for it is dropped and the reference's stands instead
  279. // (the old hl:web's withoutOns, which applies to the root element's direct children).
  280. let guard = filterOns ? 'if(!(opt&&opt.over&&opt.over.indexOf(' + str(n.event) + ')>=0)){' : '{'
  281. return guard + 'await c.onAt(m,host,' + str(n.event) + ',' + str(n.site) + ',rows,' + handlerSets(n.site) + ');}'
  282. }
  283. if (n.k == 'member' && n.name == 'slot') {
  284. // the SHELL's slot is where the route component hangs; a child's slot is the
  285. // fragment its host wrote, and the host's frame builds it
  286. return 'if(m.isShell){i=await c.slotShell(m,host,i,cr);}else if(fill!=null){i=await c.slotFill(m,o,host,i,fill,cr);}'
  287. }
  288. // A TEXT LEAF STANDING IN A LIST — an `if` branch, a `for` body — beside elements or
  289. // alone: its own text node, and a site of the member it reads (or of the row it
  290. // stands in), painted by rewriting that node.
  291. if (n.k == 'member' || n.k == 'field' || n.k == 'expr') {
  292. let names = readNames(n)
  293. return 'await c.textAt(m,host,cr,async function(inst,r){return ' + textRead(n) + ';},' + list(names) + ',rows,rk,' + pathReads(n) + ');'
  294. }
  295. if (n.k == 'for') {
  296. // THE ROW VARIABLE IS IN SCOPE INSIDE THE BODY, and a read of it is the ROW's,
  297. // not a member of the instance — the language resolves it that way and the site
  298. // sets must say the same, or a member of the same name would paint the row.
  299. rowVars.push(n.row)
  300. sub(key, n.body, 'B', n.site)
  301. rowVars.pop()
  302. return 'i=await c.forAt(m,o,host,i,' + str(n.site) + ',' + str(n.row) + ',function(inst,r){return ' + rawRead(n.list) + ';},rows,rk,fill,cr,' + regionNamesAt(n.site) + ',' + pathReads(n.list) + ');'
  303. }
  304. if (n.k == 'if' && n.regionfill != null) { return '' }
  305. if (n.k == 'if' && n.region != null) {
  306. // A NAMED REGION: the default is this component's own sub-walk; what stands between the
  307. // region's marks is the default, or the fill a lower level wrote (client.hl `regionAt`)
  308. sub(key, n.then, 'D', n.site)
  309. return 'i=await c.namedRegionAt(m,o,host,i,' + str(n.site) + ',' + str(n.region) + ',rows,rk,fill,cr);'
  310. }
  311. if (n.k == 'if') {
  312. sub(key, n.then, 'T', n.site)
  313. sub(key, n.other, 'E', n.site)
  314. return 'i=await c.ifAt(m,o,host,i,' + str(n.site) + ',function(inst,r){return ' + rawRead(n.cond) + ';},rows,rk,fill,cr,' + regionNamesAt(n.site) + ',' + fillNamesIn(n.then) + ',' + pathReads(n.cond) + ');'
  315. }
  316. if (n.k == 'component') {
  317. if (n.fill != null && n.fill.length > 0) { sub(key, n.fill, 'F', n.site) }
  318. return 'i=await c.kidAt(m,host,i,' + kidSpec(n) + ',rows,rk,fill,cr,opt);'
  319. }
  320. return ''
  321. }
  322. // ---- an element --------------------------------------------------------------------
  323. elNode(key, n, top, Boolean documentRoot = false) {
  324. // W200: the element, its claim-or-create, the failed-claim report and the row/site/key/literal stamp are the shared `N`
  325. // A literal reads only its arguments. Create it once at module scope instead of
  326. // allocating a function on every claim/create walk (#107 detached-node regression).
  327. literalIndex = literalFns.length
  328. literalFns.push('function(inst,r){return ' + litNamed(n) + ';}')
  329. let src = ''
  330. if (documentRoot) {
  331. attrNames = []
  332. for (a of n.attrs) { attrNames.push(a.name) }
  333. src = '{let el=host;await c.bodyHost(m,host,' + str(n.site) + ',' + list(attrNames) + ');'
  334. } else {
  335. src = '{let el=N(c,cr,host,i,' + str(n.tag) + ',rows,' + str(n.site) + ',' + str(key) + ',L[' + literalIndex + ']);if(!cr){i=i+1;}'
  336. }
  337. src = src + 'if(el!=null){'
  338. src = src + 'if(cr){' + createAttrs(n)
  339. if (!documentRoot) { src = src + (top ? 'await c.rootClasses(el,opt);' : '') + 'host.appendChild(el);' }
  340. src = src + '}'
  341. let names = siteNames(n)
  342. let valueMember = 'null'
  343. for (a of n.attrs) { if (a.member != null && a.name == 'value') { valueMember = str(a.member) } }
  344. let sited = ''
  345. if (names.length > 0 || valueMember != 'null') {
  346. sited = 'await c.siteAt(m,el,' + list(names) + ',' + str(n.site) + ',' + valueMember + ',' + (n.tag == 'select' ? 'true' : 'false') + ',rows);'
  347. }
  348. let kids = ''
  349. // AN ELEMENT THAT HOLDS ONLY TEXT is painted whole (`textContent`, see the paints):
  350. // built, it gets that text as one node; claimed, the server's is taken as it stands
  351. let whole = textOf(n)
  352. if (whole != null) {
  353. kids = 'if(cr){TX(host,' + whole + ');}'
  354. for (c of n.children) { if (c.k == 'on') { kids = kids + node(key, c, false, top) } }
  355. }
  356. else if (mixed(n)) { kids = mixedKids(key, n, top) }
  357. else { for (c of n.children) { kids = kids + node(key, c, false, top) } }
  358. let inner = '{let host=el;let i=0;' + kids + '}'
  359. // A SELECT IS SITED AFTER ITS OPTIONS: the member decides which option stands, and
  360. // the read-back that `siteAt` does reports nothing before they exist.
  361. if (n.tag == 'select') { src = src + inner + (selectValue(n) == 'null' ? '' : 'if(cr){await c.applySelectAt(m,el,' + selectValue(n) + ');}') + sited }
  362. else { src = src + sited + inner }
  363. return src + '}}'
  364. }
  365. // A TEXT LEAF BESIDE AN ELEMENT OR A REGION (ticket #86 follow-up): `td { d.n if (…) {…} }`
  366. // cannot be painted through `textContent`, which would wipe the branch. Each RUN of
  367. // adjacent leaves is one text node, held on the element (`__hlLeaves`, by the run's
  368. // index) where the walk builds or claims it, and the paints rewrite that node alone.
  369. mixed(n) {
  370. if (textOf(n) != null) { return false }
  371. for (c of n.children) { if (isReadNode(c)) { return true } }
  372. return false
  373. }
  374. isLeaf(c) { return c.k == 'text' || isReadNode(c) }
  375. // a node that shows a value read at render time: a member, a field path, or an expression
  376. isReadNode(c) { return (c.k == 'member' || c.k == 'field' || c.k == 'expr') && c.name != 'slot' }
  377. // the members whose move repaints a read (`Style` and a `for` row variable are not members
  378. // of the instance), and the guard a paint writes for them
  379. readNames(c) {
  380. let out = []
  381. for (nm of (c.k == 'expr' ? c.names : [c.name])) {
  382. if (nm != 'Style' && !rowVars.includes(nm) && !out.includes(nm)) { out.push(nm) }
  383. }
  384. return out
  385. }
  386. guardOf(c) {
  387. let g = ''
  388. for (nm of readNames(c)) { g = g + (g == '' ? '' : '||') + 'n===' + str(nm) }
  389. return g
  390. }
  391. // the runs of adjacent leaves, in order; an `on` renders nothing and splits none
  392. runsOf(n) {
  393. let out = []
  394. let run = []
  395. for (c of n.children) {
  396. if (isLeaf(c)) { run.push(c) }
  397. else if (c.k != 'on') {
  398. if (run.length > 0) { out.push(run) }
  399. run = []
  400. }
  401. }
  402. if (run.length > 0) { out.push(run) }
  403. return out
  404. }
  405. runText(run) {
  406. let src = '""'
  407. for (c of run) { src = src + '+(' + (c.k == 'text' ? str(c.text) : textRead(c)) + ')' }
  408. return src
  409. }
  410. runFeeds(run) {
  411. for (c of run) { if (c.k != 'text') { return true } }
  412. return false
  413. }
  414. mixedKids(key, n, top) {
  415. let kids = ''
  416. let run = []
  417. let k = 0
  418. for (c of n.children) {
  419. if (isLeaf(c)) { run.push(c) }
  420. else {
  421. if (c.k != 'on' && run.length > 0) { kids = kids + leafRun(run, k) k = k + 1 run = [] }
  422. kids = kids + node(key, c, false, top)
  423. }
  424. }
  425. if (run.length > 0) { kids = kids + leafRun(run, k) }
  426. return kids
  427. }
  428. // EVERY CALL INTO THE CLIENT IS AWAITED: its methods are async in the browser, and one
  429. // not awaited runs its DOM work after the walk has gone on — a built leaf then lands
  430. // after the elements that follow it (ticket #104).
  431. leafRun(run, k) {
  432. if (!runFeeds(run)) { return textLeaf(runText(run)) }
  433. return 'await c.leafAt(host,cr,i,' + k + ',' + runText(run) + ');'
  434. }
  435. // the attributes an element is BUILT with — a bound one written in, a literal one as it
  436. // stands. `value` is a property once the page is live and an attribute as the control's
  437. // default; a textarea has no value attribute at all and a select's value is an option.
  438. createAttrs(n) {
  439. let src = ''
  440. for (a of n.attrs) {
  441. if (isBool(a)) {
  442. src = src + '{' + boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) + '}'
  443. } else if (nullable(a)) {
  444. src = src + '{let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v!=null){el.setAttribute(' + str(a.name) + ',""+v);}}'
  445. } else {
  446. let rd = a.member != null ? readOf({ k = 'member'; name = a.member; }) : (a.ref != null ? readOf(a.ref) : str(a.text))
  447. src = src + '{let v=' + rd + ';'
  448. if (a.extra != null) { src = src + 'v=v+" "+' + str(a.extra) + ';' }
  449. if (n.tag == 'select' && a.name == 'value') { src = src + '}' }
  450. else if (a.name == 'value') {
  451. src = src + 'if(el.value!=null){el.value=v;' + (n.tag == 'textarea' ? '' : 'el.setAttribute("value",v);') + '}else{el.setAttribute("value",v);}}'
  452. } else { src = src + 'el.setAttribute(' + str(a.name) + ',v);}' }
  453. }
  454. }
  455. if (boundValue(n)) { src = src + 'el.setAttribute("autocomplete","off");' }
  456. return src
  457. }
  458. // a bound attribute whose null read is NO attribute (#177): not `value` (a control's
  459. // value has its own rules), and not one carrying extra classes
  460. nullable(a) {
  461. return (a.member != null || a.ref != null) && a.name != 'value' && a.extra == null && !v.isBoolAttr(a.name)
  462. }
  463. // a BOUND boolean attribute — a literal one was decided at build (WebFramework `element`)
  464. isBool(a) {
  465. return (a.member != null || a.ref != null) && v.isBoolAttr(a.name)
  466. }
  467. // A BOUND BOOLEAN ATTRIBUTE, WRITTEN (ticket #33): set when the value is on, REMOVED when
  468. // it is off — the markup's rule (viewserver.boolAttrs) — and the DOM property with it, because
  469. // once the page is live `checked` is the property and the attribute only its default.
  470. boolWrite(a, raw) {
  471. props = { allowfullscreen = 'allowFullscreen'; formnovalidate = 'formNoValidate'; ismap = 'isMap'; itemscope = 'itemScope'; nomodule = 'noModule'; novalidate = 'noValidate'; playsinline = 'playsInline'; readonly = 'readOnly'; }
  472. prop = props[a.name] != null ? props[a.name] : a.name
  473. return 'let on=!!' + raw + ';if(on){el.setAttribute(' + str(a.name) + ',"");}else if(el.removeAttribute){el.removeAttribute(' + str(a.name) + ');}if(' + str(prop) + ' in el&&el[' + str(prop) + ']!==on){el[' + str(prop) + ']=on;}'
  474. }
  475. // view.hl's `boundValue`, to the letter: a FORM CONTROL whose `value` reads a member or
  476. // a field, and not one the author gave an `autocomplete` of its own
  477. boundValue(n) {
  478. if (n.tag != 'input' && n.tag != 'textarea' && n.tag != 'select') { return false }
  479. let bound = false
  480. for (a of n.attrs) {
  481. if (a.name == 'autocomplete') { return false }
  482. if (a.name == 'value' && (a.member != null || a.ref != null)) { bound = true }
  483. }
  484. return bound
  485. }
  486. selectValue(n) {
  487. for (a of n.attrs) {
  488. if (a.name == 'value') {
  489. if (a.member != null) { return readOf({ k = 'member'; name = a.member; }) }
  490. if (a.ref != null) { return readOf(a.ref) }
  491. return str(a.text)
  492. }
  493. }
  494. return 'null'
  495. }
  496. // the element's own entries as the literal sees them — its attributes by name, then the
  497. // `for` row variables in scope (the row rides on the value)
  498. litNamed(n) {
  499. let src = '{'
  500. let first = true
  501. for (a of n.attrs) {
  502. if (!first) { src = src + ',' }
  503. first = false
  504. let v = a.member != null ? rawRead({ k = 'member'; name = a.member; }) : (a.ref != null ? rawRead(a.ref) : str(a.text))
  505. src = src + str(a.name) + ':' + v
  506. }
  507. return src + '}'
  508. }
  509. // the reference's own description, written at its use site: what it binds, what it
  510. // overwrites, the classes the host's `#Child` rule puts on it
  511. kidSpec(n) {
  512. let src = '{key:' + str(browserKeyOf(n.key)) + ',kid:' + str(kidKeyOf(n)) + ',site:' + str(n.site) + ',fill:' + ((n.fill != null && n.fill.length > 0) ? 'true' : 'false')
  513. src = src + ',bindings:['
  514. let first = true
  515. for (b of n.bindings) {
  516. if (!first) { src = src + ',' }
  517. first = false
  518. src = src + '{name:' + str(b.name) + ',member:' + (b.member == null ? 'null' : str(b.member))
  519. src = src + ',ref:' + (b.ref == null ? 'null' : 'function(inst,r){return ' + rawRead(b.ref) + ';}')
  520. src = src + ',refName:' + (b.ref == null ? 'null' : str(b.ref.name))
  521. src = src + ',text:' + (b.text == null ? 'null' : 'true') + ',value:' + (b.text == null ? 'null' : refLiteral(b)) + '}'
  522. }
  523. src = src + '],ons:['
  524. first = true
  525. for (o of n.ons) {
  526. if (!first) { src = src + ',' }
  527. first = false
  528. src = src + '{event:' + str(o.event) + ',site:' + str(o.site) + ',sets:[' + handlerSets(o.site) + ']}'
  529. }
  530. src = src + '],classes:' + list(n.classes == null ? [] : n.classes) + '}'
  531. return src
  532. }
  533. // view.hl's kidKey: the reference's path, joined — the key the server mounted it under
  534. kidKeyOf(n) {
  535. let out = ''
  536. for (p of n.path) { out = out + '/' + p }
  537. return out
  538. }
  539. // the value a literal binding carries — view.refValue, folded at compile time
  540. refLiteral(b) {
  541. if (b.kind == 'folded') { return jsValue(b.value) }
  542. if (b.kind == 'number') { return '' + b.text }
  543. if (b.kind == 'boolean') { return b.text == 'true' ? 'true' : 'false' }
  544. if (b.kind == 'null_literal') { return 'null' }
  545. return str(b.text)
  546. }
  547. jsValue(v) {
  548. if (v == null) { return 'null' }
  549. if (hlTypeName(v) == 'String') { return str(v) }
  550. if (hlTypeName(v) == 'Boolean') { return v ? 'true' : 'false' }
  551. if (hlTypeName(v) == 'Number') { return '' + v }
  552. return JSON.stringify(v)
  553. }
  554. // ---- the site set: what this element SHOWS ------------------------------------------
  555. // The old hl:web asked the module's table which members the element at this site reads. The
  556. // answer is a fact about the View, so it is written in: the members its bound
  557. // attributes and its text leaves name. `Style` is folded into a class name at build and
  558. // the shell's `slot` is swapped by navigation — neither is ever painted, and neither is
  559. // a member read that reaches here (a `for` row variable resolves to its row).
  560. siteNames(n) {
  561. let out = []
  562. for (a of n.attrs) {
  563. if (a.member != null && a.member != 'Style' && !rowVars.includes(a.member) && !out.includes(a.member)) { out.push(a.member) }
  564. // A FIELD OF A MEMBER (`value = f.title`, ticket #93) is a read of the member:
  565. // a write to `f.title`, or a new `f`, moves `f`, and this element repaints
  566. if (a.ref != null && a.ref.name != 'Style' && !rowVars.includes(a.ref.name) && !out.includes(a.ref.name)) { out.push(a.ref.name) }
  567. }
  568. for (c of n.children) {
  569. if (isReadNode(c)) {
  570. for (nm of readNames(c)) { if (!out.includes(nm)) { out.push(nm) } }
  571. }
  572. }
  573. return out
  574. }
  575. rowVars = []
  576. // ---- the paints ---------------------------------------------------------------------
  577. collectPaints(&out, nodes) {
  578. for (n of nodes) {
  579. if (n.k == 'el') {
  580. let paint = paintFn(n)
  581. let row = rowFn(n)
  582. if (paint != null || row != 'null') {
  583. out.push({ site = n.site; paint = paint == null ? 'null' : paint; row = row; reads = rowReadList(n); })
  584. }
  585. collectPaints(&out, n.children)
  586. } else if (n.k == 'for') { collectPaints(&out, n.body) }
  587. else if (n.k == 'if') { collectPaints(&out, n.then) collectPaints(&out, n.other) }
  588. else if (n.k == 'component') { if (n.fill != null) { collectPaints(&out, n.fill) } }
  589. }
  590. return null
  591. }
  592. // Preserve exact field paths for row delta selection; expression operands contribute
  593. // their own paths. A whole-record read has an empty path and overlaps every delta.
  594. pathReads(Hybrid n) {
  595. out = []
  596. readPaths(&n, &out)
  597. return JSON.stringify(out)
  598. }
  599. readPaths(&n, &out) {
  600. if (n == null) { return null }
  601. if (n.k == 'member' || n.k == 'field') {
  602. out.push({ name = n.name; path = n.path == null ? [] : n.path; })
  603. } else if (n.k == 'expr') { readPaths(&n.x, &out) }
  604. else if (n.k == 'bin') { readPaths(&n.l, &out) readPaths(&n.r, &out) }
  605. else if (n.k == 'un') { readPaths(&n.x, &out) }
  606. else if (n.k == 'cond') { readPaths(&n.c, &out) readPaths(&n.a, &out) readPaths(&n.b, &out) }
  607. return null
  608. }
  609. rowReadList(Hybrid n) {
  610. out = []
  611. for (a of n.attrs) {
  612. if (a.member != null) { out.push({ name = a.member; path = []; }) }
  613. if (a.ref != null) { readPaths(&a.ref, &out) }
  614. }
  615. for (c of n.children) { if (isReadNode(c)) { readPaths(&c, &out) } }
  616. return JSON.stringify(out)
  617. }
  618. // `paint(&m, s, name)`, compiled: the bound attributes under the member each reads, and
  619. // the text where the member that moved stands among the leaves.
  620. paintFn(n) {
  621. let body = ''
  622. for (a of n.attrs) {
  623. if (a.member != null) {
  624. body = body + 'if(n===' + str(a.member) + '){' + attrWrite(n, a, readOf({ k = 'member'; name = a.member; })) + '}'
  625. } else if (a.ref != null) {
  626. // a field of a member paints when the MEMBER moves (ticket #93)
  627. body = body + 'if(n===' + str(a.ref.name) + '){' + attrWrite(n, a, readOf(a.ref)) + '}'
  628. }
  629. }
  630. let text = textOf(n)
  631. if (text != null) {
  632. let guard = ''
  633. for (c of n.children) {
  634. if (isReadNode(c)) {
  635. let g = guardOf(c)
  636. if (g != '') {
  637. if (guard != '') { guard = guard + '||' }
  638. guard = guard + g
  639. }
  640. }
  641. }
  642. if (guard != '') { body = body + 'if(' + guard + '){el.textContent=' + text + ';}' }
  643. } else if (mixed(n)) {
  644. let k = 0
  645. for (run of runsOf(n)) {
  646. let guard = ''
  647. for (c of run) {
  648. if (c.k != 'text') {
  649. let g = guardOf(c)
  650. if (g != '') {
  651. if (guard != '') { guard = guard + '||' }
  652. guard = guard + g
  653. }
  654. }
  655. }
  656. if (guard != '') { body = body + 'if((' + guard + ')&&el.__hlLeaves&&el.__hlLeaves[' + k + ']){el.__hlLeaves[' + k + '].data=' + runText(run) + ';}' }
  657. k = k + 1
  658. }
  659. }
  660. if (body == '') { return null }
  661. return 'async function(el,inst,r,n,keepInput){' + body + '}'
  662. }
  663. // `rowPaint(&m, el)`, compiled: every bound spot, written only where the DOM does not
  664. // already hold it — which is why a push into 2000 rows costs the 1999 nothing.
  665. rowFn(n) {
  666. let body = ''
  667. for (a of n.attrs) {
  668. if (isBool(a)) {
  669. body = body + '{' + boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) + '}'
  670. } else if (nullable(a)) {
  671. body = body + '{let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v==null){if(el.hasAttribute(' + str(a.name) + ')){el.removeAttribute(' + str(a.name) + ');}}else{v=""+v;if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}}}'
  672. } else if (a.member != null || a.ref != null) {
  673. let one = 'let v=' + readOf(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';'
  674. if (a.extra != null) { one = one + 'v=v+" "+' + str(a.extra) + ';' }
  675. if (n.tag == 'select' && a.name == 'value') { one = one + 'if(el.value!==v){el.value=v;}' }
  676. else {
  677. one = one + 'if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}'
  678. if (a.name == 'value') { one = one + 'if(el.value!=null&&el.value!==v){el.value=v;}' }
  679. }
  680. if (a.name == 'value') { one = 'if(el!==keepInput||el!==document.activeElement){' + one + '}' }
  681. body = body + '{' + one + '}'
  682. }
  683. }
  684. let text = textOf(n)
  685. let feeds = false
  686. for (c of n.children) { if (isReadNode(c)) { feeds = true } }
  687. if (text != null && feeds) { body = body + '{let t=' + text + ';if(el.textContent!==t){el.textContent=t;}}' }
  688. if (text == null && feeds) {
  689. let k = 0
  690. for (run of runsOf(n)) {
  691. if (runFeeds(run)) { body = body + '{let x=el.__hlLeaves&&el.__hlLeaves[' + k + '];let t=' + runText(run) + ';if(x&&x.data!==t){x.data=t;}}' }
  692. k = k + 1
  693. }
  694. }
  695. if (body == '') { return 'null' }
  696. return 'async function(el,inst,r,keepInput){' + body + '}'
  697. }
  698. attrWrite(n, a, v) {
  699. if (isBool(a)) { return boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) }
  700. if (nullable(a)) { return 'let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v==null){if(el.hasAttribute(' + str(a.name) + ')){el.removeAttribute(' + str(a.name) + ');}}else{v=""+v;if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}}' }
  701. let src = 'let v=' + v + ';'
  702. if (a.extra != null) { src = src + 'v=v+" "+' + str(a.extra) + ';' }
  703. if (n.tag == 'select' && a.name == 'value') { return src + 'if(el!==keepInput||el!==document.activeElement){el.value=v;}' }
  704. // Setting an unchanged src can reload media; compare plain attributes before writing.
  705. if (a.name == 'value') { src = src + 'if(el!==keepInput||el!==document.activeElement){el.setAttribute(' + str(a.name) + ',v);if(el.value!=null&&el.value!==v){el.value=v;}}' }
  706. else { src = src + 'if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}' }
  707. return src
  708. }
  709. textOf(n) {
  710. let parts = []
  711. let content = 0
  712. let feeds = false
  713. for (c of n.children) {
  714. if (c.k != 'on') {
  715. content = content + 1
  716. if (c.k == 'text') { parts.push(str(c.text)) }
  717. else if (isReadNode(c)) { parts.push(textRead(c)) feeds = true }
  718. }
  719. }
  720. if (!feeds) { return null }
  721. if (parts.length != content) { return null }
  722. let src = '""'
  723. for (p of parts) { src = src + '+(' + p + ')' }
  724. return src
  725. }
  726. // ---- a read, written in ---------------------------------------------------------------
  727. // `view.value`'s own rule as an expression: a `for` row variable in scope wins over a
  728. // member of the same name, and a field path walks into it. `readOf` answers the STRING
  729. // the DOM takes; `rawRead` the value itself (a binding, a list, a condition).
  730. // A null bound value is empty, matching the server attribute writer.
  731. readOf(node) { return 'S(' + rawRead(node) + ')' }
  732. // A READ SHOWN AS TEXT: null is no text, as the server writes it (view.hl `escape`)
  733. textRead(node) { return 'S(' + rawRead(node) + ')' }
  734. rawRead(node) {
  735. if (node == null) { return 'null' }
  736. if (node.k == 'text') { return node.kind == 'folded' && hlTypeName(node.value) == 'Hybrid' ? JSON.stringify(node.value) : str(node.text) }
  737. if (node.k == 'expr') { return '(await X(' + JSON.stringify(node.x) + ',r,inst))' }
  738. if (node.k != 'field') { return 'RV(r,inst,' + str(node.name) + ')' }
  739. return 'RF(r,inst,' + str(node.name) + ',' + list(node.path) + ')'
  740. }
  741. list(names) {
  742. let src = '['
  743. let first = true
  744. for (n of names) {
  745. if (!first) { src = src + ',' }
  746. first = false
  747. src = src + str(n)
  748. }
  749. return src + ']'
  750. }
  751. // a JavaScript string literal — JSON's escaping is a subset of JavaScript's, so a
  752. // source text's quotes, newlines and backslashes survive into the statement unchanged
  753. str(s) {
  754. if (s == null) { return '""' }
  755. return JSON.stringify('' + s)
  756. }
  757. // ---- WHAT THE LANGUAGE SAYS ABOUT THIS FILE, read HERE and written into the code ----
  758. // The old hl:web shipped the language's answers to the browser as data: `hlJs` writes each file's
  759. // members, handlers and methods — every node of every initializer, with the names it
  760. // reads — into the module, and the client reduces that table on every boot. The answers
  761. // are facts about the source, so this file asks for them once, at compile time, and
  762. // writes the RESULT into the statements: a handler's write set stands at the listener
  763. // that needs it, a region's names at the region, the derivations as a list of what to
  764. // re-run. The module carries no table at all (WebFramework `module` drops the one the
  765. // emitter writes).
  766. //
  767. // The reflection is the framework's own analysis generation — the same `gen` the View
  768. // trees come from. Nothing starts a second one: a handle is only valid inside the
  769. // generation that made it.
  770. tableOf(gen, key) {
  771. let members = []
  772. let derivations = []
  773. let handlers = []
  774. let methods = []
  775. for (m of hlMembers(gen, key)) {
  776. let entry = { name = m.name; nodes = null; isStatic = m.isStatic == true; }
  777. if (m.hasValue) {
  778. let n = syntaxTree(gen, key, m.node)
  779. entry.nodes = n
  780. derivations.push({ name = m.name; site = n.site; reads = n.reads; serverSite = m.serverSite == true; pure = m.pure == true; writtenElsewhere = m.writtenElsewhere == true; inputs = m.inputs; })
  781. nestedHandlers(&handlers, n)
  782. }
  783. members.push(entry)
  784. }
  785. for (h of hlEvents(gen, key).handles) {
  786. let n = syntaxTree(gen, key, h.node)
  787. handlers.push({ event = h.event; site = n.site; reads = n.reads; writes = n.writes; nested = false; })
  788. }
  789. for (mm of hlMethods(gen, key)) {
  790. if (!mm.inlineHandler) {
  791. let n = syntaxTree(gen, key, mm.node)
  792. methods.push({ name = mm.name; reads = n.reads; writes = n.writes; })
  793. }
  794. }
  795. return { members = members; derivations = derivations; handlers = handlers; methods = methods; }
  796. }
  797. // A NESTED `on` IS A DOM HANDLER, filed under its own site — the id the View node
  798. // carries. Its body is not the literal's syntax, so the node answers for it and the
  799. // walk stops there.
  800. nestedHandlers(&into, n) {
  801. if (n == null) { return null }
  802. if (n.tag == 'on_statement') {
  803. into.push({ event = n.event; site = n.site; reads = n.reads; writes = n.writes; nested = true; })
  804. return null
  805. }
  806. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  807. if (c != null) { nestedHandlers(&into, c) }
  808. }
  809. for (l of [n.entries, n.args, n.elements]) {
  810. if (l != null) { for (c of l) { nestedHandlers(&into, c) } }
  811. }
  812. return null
  813. }
  814. // the site with its file's base name: everything after the last '/'. The path part
  815. // is not "up to the first ':'" — a package key has a colon of its own
  816. // ('hl:markdown/Markdown.hl:24:3'), and that reading left a package component's
  817. // sites unshortened, so its regions found no reads and never repainted (#111)
  818. shortSite(site) {
  819. if (site == null) { return null }
  820. let cut = site.lastIndexOf('/')
  821. if (cut < 0) { return site }
  822. return site.slice(cut + 1)
  823. }
  824. // the syntax of one node, recursively — hl:core/AST's `tree`, read off the framework's
  825. // own generation instead of starting one of its own
  826. syntaxTree(gen, key, node) {
  827. let n = hlSyntax(gen, key, node)
  828. if (n == null) { return null }
  829. // A SITE IS NAMED BY THE FILE'S BASE NAME. The reflection answers with the project
  830. // key ('components/sort_list.hl:77:26'); the View tree, the emitter's own
  831. // `__derive__` branches and every site this framework writes use the base name
  832. // ('sort_list.hl:77:26'). One spelling, or a lookup by site finds nothing.
  833. let out = { tag = n.tag; site = shortSite(n.site); reads = n.reads; writes = n.writes; }
  834. if (n.tag == 'object_expression') {
  835. let kids = []
  836. for (h of n.entries) { kids.push(syntaxTree(gen, key, h)) }
  837. out.entries = kids
  838. } else if (n.tag == 'object_property') {
  839. out.key = n.key
  840. out.value = syntaxTree(gen, key, n.value)
  841. } else if (n.tag == 'view_for') {
  842. out.list = syntaxTree(gen, key, n.list)
  843. out.body = syntaxTree(gen, key, n.body)
  844. } else if (n.tag == 'view_if') {
  845. out.condition = syntaxTree(gen, key, n.condition)
  846. out.consequent = syntaxTree(gen, key, n.consequent)
  847. out.alternate = syntaxTree(gen, key, n.alternate)
  848. } else if (n.tag == 'on_statement') {
  849. out.event = n.event
  850. } else if (n.tag == 'member_expression') {
  851. out.object = syntaxTree(gen, key, n.object)
  852. out.property = syntaxTree(gen, key, n.property)
  853. out.computed = n.computed
  854. } else if (n.tag == 'identifier') {
  855. out.name = n.name
  856. } else if (n.tag == 'call_expression') {
  857. out.callee = syntaxTree(gen, key, n.callee)
  858. let args = []
  859. for (h of n.args) { args.push(syntaxTree(gen, key, h)) }
  860. out.args = args
  861. } else if (n.tag == 'binary_expression') {
  862. out.left = syntaxTree(gen, key, n.left)
  863. out.right = syntaxTree(gen, key, n.right)
  864. } else if (n.tag == 'unary_expression') {
  865. out.operand = syntaxTree(gen, key, n.operand)
  866. } else if (n.tag == 'conditional_expression') {
  867. out.condition = syntaxTree(gen, key, n.condition)
  868. out.consequent = syntaxTree(gen, key, n.consequent)
  869. out.alternate = syntaxTree(gen, key, n.alternate)
  870. } else if (n.tag == 'array_expression') {
  871. let els = []
  872. for (h of n.elements) { els.push(syntaxTree(gen, key, h)) }
  873. out.elements = els
  874. }
  875. return out
  876. }
  877. // ---- the reductions the browser used to make on every boot --------------------------
  878. // A `for`'s names are what its list reads, an `if`'s what its condition reads — filed
  879. // under the region's own site.
  880. regionIndex(t) {
  881. let idx = {}
  882. for (m of t.members) { if (m.nodes != null) { indexRegions(&idx, m.nodes) } }
  883. return idx
  884. }
  885. indexRegions(&idx, n) {
  886. if (n == null) { return null }
  887. if (n.tag == 'view_for') {
  888. idx[n.site] = memberNames(nodeReads(n.list))
  889. indexRegions(&idx, n.body)
  890. return null
  891. }
  892. if (n.tag == 'view_if') {
  893. idx[n.site] = memberNames(nodeReads(n.condition))
  894. indexRegions(&idx, n.consequent)
  895. indexRegions(&idx, n.alternate)
  896. return null
  897. }
  898. if (n.tag == 'on_statement') { return null }
  899. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  900. if (c != null) { indexRegions(&idx, c) }
  901. }
  902. for (l of [n.entries, n.args, n.elements]) {
  903. if (l != null) { for (c of l) { indexRegions(&idx, c) } }
  904. }
  905. return null
  906. }
  907. // the member reads of a read list — the language resolved every name, so this is a
  908. // filter and not a second resolution
  909. memberNames(reads) {
  910. let out = []
  911. if (reads == null) { return out }
  912. for (r of reads) {
  913. if (r.kind == 'member' && r.isStatic != true && !out.includes(r.name)) { out.push(r.name) }
  914. }
  915. return out
  916. }
  917. nodeReads(n) {
  918. if (n == null) { return [] }
  919. if (n.reads != null) { return n.reads }
  920. let out = []
  921. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  922. if (c != null) { for (r of nodeReads(c)) { out.push(r) } }
  923. }
  924. for (l of [n.entries, n.args, n.elements]) {
  925. if (l != null) { for (c of l) { for (r of nodeReads(c)) { out.push(r) } } }
  926. }
  927. return out
  928. }
  929. // A ROUTINE'S WRITES, PLUS THE WRITES OF EVERYTHING IT REACHES — the method it calls
  930. // and the handler it emits to, transitively. Both are READS the language resolved, so
  931. // this is a walk of its answer and never a guess.
  932. closeWrites(&t, writes, reads) {
  933. let out = memberNames(writes)
  934. let queue = []
  935. reached(&queue, reads)
  936. let seen = {}
  937. while (queue.length > 0) {
  938. let at = queue.shift()
  939. if (seen[at] == null) {
  940. seen[at] = true
  941. let sp = at.indexOf(' ')
  942. let kind = at.slice(0, sp)
  943. let name = at.slice(sp + 1)
  944. for (mm of t.methods) {
  945. if (kind == 'method' && mm.name == name) {
  946. for (w of memberNames(mm.writes)) { if (!out.includes(w)) { out.push(w) } }
  947. reached(&queue, mm.reads)
  948. }
  949. }
  950. for (h of t.handlers) {
  951. if (kind == 'handler' && !h.nested && h.event == name) {
  952. for (w of memberNames(h.writes)) { if (!out.includes(w)) { out.push(w) } }
  953. reached(&queue, h.reads)
  954. }
  955. }
  956. for (mb of t.members) {
  957. if (kind == 'member' && mb.name == name && mb.nodes != null) {
  958. for (w of memberNames(mb.nodes.writes)) { if (!out.includes(w)) { out.push(w) } }
  959. reached(&queue, nodeReads(mb.nodes))
  960. }
  961. }
  962. }
  963. }
  964. return out
  965. }
  966. // the mirror: a handler's reads plus the reads of everything it reaches — the
  967. // candidates for a routine a host handed down, whose writes only the host's table names
  968. closeReads(&t, reads) {
  969. let out = memberNames(reads)
  970. let queue = []
  971. reached(&queue, reads)
  972. let seen = {}
  973. while (queue.length > 0) {
  974. let at = queue.shift()
  975. if (seen[at] == null) {
  976. seen[at] = true
  977. let sp = at.indexOf(' ')
  978. let kind = at.slice(0, sp)
  979. let name = at.slice(sp + 1)
  980. for (mm of t.methods) {
  981. if (kind == 'method' && mm.name == name) {
  982. for (r of memberNames(mm.reads)) { if (!out.includes(r)) { out.push(r) } }
  983. reached(&queue, mm.reads)
  984. }
  985. }
  986. for (h of t.handlers) {
  987. if (kind == 'handler' && !h.nested && h.event == name) {
  988. for (r of memberNames(h.reads)) { if (!out.includes(r)) { out.push(r) } }
  989. reached(&queue, h.reads)
  990. }
  991. }
  992. for (mb of t.members) {
  993. if (kind == 'member' && mb.name == name && mb.nodes != null) {
  994. for (r of memberNames(nodeReads(mb.nodes))) { if (!out.includes(r)) { out.push(r) } }
  995. reached(&queue, nodeReads(mb.nodes))
  996. }
  997. }
  998. }
  999. }
  1000. return out
  1001. }
  1002. reached(&queue, reads) {
  1003. if (reads == null) { return null }
  1004. for (r of reads) {
  1005. if (r.kind == 'method' || r.kind == 'handler' || (r.kind == 'member' && r.isStatic != true)) { queue.push(r.kind + ' ' + r.name) }
  1006. }
  1007. return null
  1008. }
  1009. // ---- THE SERVER RENDER, COMPILED --------------------------------------------------
  1010. // The old hl:web rendered a page by WALKING the View tree per request: for every node it asks
  1011. // what kind it is, for every element it builds the attribute string, and it decides the
  1012. // indentation of every line again, on every request, for every one of the 121 mounts a
  1013. // page may hold. Every one of those decisions is a fact about the View.
  1014. //
  1015. // So a component's render is compiled ONCE into a list of STEPS — constant text, and a
  1016. // read with its own closure — and a request is a concatenation. The structure (tags,
  1017. // static attributes, the readable form's line breaks, which element is a block) is
  1018. // decided at compile time; only the values are asked for per request.
  1019. //
  1020. // KEYED BY THE INDENT IT IS RENDERED AT, because that is the only thing about a
  1021. // component's HTML that its caller decides: the shell renders at one tab, the page at
  1022. // the depth the slot stands, a fill compactly (null). An app has a handful of those.
  1023. // the framework's `(key) => View tree`, for a kid whose steps are not built yet (set after the trees are)
  1024. treeOf = null
  1025. // the steps of a kid mount: the memo when it holds them, else built from the key's tree (read once, when they are built)
  1026. kidSteps(key, indent, classes, slotted) {
  1027. let ck = key + '|' + (indent == null ? '~' : indent) + '|' + joinList(classes) + '|' + (slotted ? '1' : '0')
  1028. if (steps[ck] == null) { return serverSteps(key, treeOf(key), indent, classes, slotted) }
  1029. return steps[ck]
  1030. }
  1031. bodySteps = {}
  1032. documentBody(String key, &nodes, &inst, &mounts) {
  1033. if (nodes.length != 1 || nodes[0].k != 'el' || nodes[0].tag != 'body') { return '<body>' }
  1034. if (bodySteps[key] == null) {
  1035. let root = nodes[0]
  1036. root.children = []
  1037. bodySteps[key] = blockSteps([root], null, false)
  1038. }
  1039. rows = {}
  1040. ctx = { slot = null }
  1041. html = runSteps(&bodySteps[key], &inst, &rows, &ctx, &mounts)
  1042. return html.slice(0, html.indexOf('>') + 1)
  1043. }
  1044. serverSteps(key, &nodes, indent, classes, slotted) {
  1045. let ck = key + '|' + (indent == null ? '~' : indent) + '|' + joinList(classes) + '|' + (slotted ? '1' : '0')
  1046. if (steps[ck] == null) {
  1047. steps[ck] = blockSteps(classes == null || classes.length == 0 ? nodes : v.withRootClasses(&nodes, &classes), indent, slotted)
  1048. }
  1049. return steps[ck]
  1050. }
  1051. // A `slot` THE HOST FILLED COUNTS AS CONTENT, and an empty one does not — the one
  1052. // thing about a component's shape its caller decides, so it is part of the key.
  1053. staticVoid = [ 'area' 'base' 'br' 'col' 'embed' 'hr' 'img' 'input' 'link' 'meta' 'source' 'track' 'wbr' ]
  1054. staticVerbatim = [ 'textarea' 'pre' 'script' 'style' ]
  1055. blocky(n, slotted) {
  1056. if (staticVerbatim.includes(n.tag)) { return false }
  1057. if (n.children.length == 0) { return false }
  1058. for (c of n.children) {
  1059. if (c.k == 'text' || c.k == 'field' || c.k == 'expr') { return false }
  1060. if (c.k == 'member' && !(c.name == 'slot' && slotted)) { return false }
  1061. }
  1062. return true
  1063. }
  1064. steps = {}
  1065. v = new HlwViewServer
  1066. viewRead = new HlwView
  1067. joinList(l) {
  1068. if (l == null) { return '' }
  1069. let out = ''
  1070. for (c of l) { out = out + ',' + c }
  1071. return out
  1072. }
  1073. // `render(nodes, …, indent)`: the readable form puts each element on its own line at
  1074. // `indent`, the compact one writes them end to end.
  1075. blockSteps(nodes, indent, slotted) {
  1076. let out = []
  1077. for (n of nodes) {
  1078. if (indent != null) {
  1079. if (n.k == 'el') { push(&out, { k = 's'; v = newline + indent; }) nodeSteps(&out, n, indent, slotted) }
  1080. else if (n.k == 'component') { nodeSteps(&out, n, indent, slotted) }
  1081. else if (n.k == 'for') { forSteps(&out, n, indent, slotted) }
  1082. else if (n.k == 'if') { ifSteps(&out, n, indent, slotted) }
  1083. else if (n.k == 'member' && n.name == 'slot') { push(&out, { k = 'slotline'; v = newline + indent; }) }
  1084. else if (n.k != 'on') { nodeSteps(&out, n, indent, slotted) }
  1085. } else {
  1086. nodeSteps(&out, n, null, slotted)
  1087. }
  1088. }
  1089. return out
  1090. }
  1091. forSteps(&out, n, indent, slotted) {
  1092. out.push({ k = 'for'; row = n.row; read = readFn(n.list); body = blockSteps(n.body, indent, slotted); })
  1093. return null
  1094. }
  1095. ifSteps(&out, n, indent, slotted) {
  1096. if (n.regionfill != null) { return null }
  1097. if (n.region != null) {
  1098. out.push({ k = 'region'; name = n.region; ind = indent; late = n.deferred == true; body = n.deferred == true ? [] : blockSteps(n.then, indent, slotted); })
  1099. return null
  1100. }
  1101. out.push({ k = 'if'; read = readFn(n.cond); then = blockSteps(n.then, indent, slotted); other = blockSteps(n.other, indent, slotted); })
  1102. return null
  1103. }
  1104. // a script's children: text and values written as they are (`view.rawText`)
  1105. rawSteps(nodes, slotted) {
  1106. let out = []
  1107. for (n of nodes) {
  1108. if (n.k == 'text') { push(&out, { k = 's'; v = v.rawText(n.text); }) }
  1109. else if (n.k == 'member' || n.k == 'field' || n.k == 'expr') { out.push({ k = 'raw'; read = readFn(n); }) }
  1110. else { nodeSteps(&out, n, null, slotted) }
  1111. }
  1112. return out
  1113. }
  1114. // one node's steps — `html(node, …)`, decided once
  1115. nodeSteps(&out, n, indent, slotted) {
  1116. if (n.k == 'text') { push(&out, { k = 's'; v = v.escape(n.text); }) return null }
  1117. if (n.k == 'on') { return null }
  1118. if (n.k == 'member' && n.name == 'slot') { out.push({ k = 'slot'; }) return null }
  1119. if (n.k == 'member' || n.k == 'field' || n.k == 'expr') { out.push({ k = 'r'; read = readFn(n); }) return null }
  1120. if (n.k == 'for') { forSteps(&out, n, indent, slotted) return null }
  1121. if (n.k == 'if') { ifSteps(&out, n, indent, slotted) return null }
  1122. if (n.k == 'component') {
  1123. out.push({ k = 'kid'; path = n.path; cls = n.cls; key = n.key; classes = n.classes; indent = indent;
  1124. fill = (n.fill == null || n.fill.length == 0) ? null : blockSteps(n.fill, null, slotted); })
  1125. return null
  1126. }
  1127. if (n.k == 'el') { elSteps(&out, n, indent, slotted) return null }
  1128. push(&out, { k = 's'; v = '<!-- ' + n.tag + ' not rendered yet -->'; })
  1129. return null
  1130. }
  1131. elSteps(&out, n, indent, slotted) {
  1132. let attrs = []
  1133. let valueRead = null // a textarea's value is its content
  1134. let selRead = null // a select's value selects an option
  1135. for (a of n.attrs) {
  1136. if (n.tag == 'textarea' && a.name == 'value') { valueRead = attrRead(a) }
  1137. else if (n.tag == 'select' && a.name == 'value') { selRead = attrRead(a) }
  1138. // a bound BOOLEAN attribute is its presence (ticket #33): ` checked=""` or nothing
  1139. else if ((a.member != null || a.ref != null) && v.isBoolAttr(a.name)) { attrs.push({ k = 'b'; name = a.name; read = attrRead(a); }) }
  1140. // a null read is no attribute (#177)
  1141. else if (nullable(a)) { attrs.push({ k = 'a'; name = a.name; read = attrRead(a); }) }
  1142. else if (a.member != null || a.ref != null) {
  1143. push(&attrs, { k = 's'; v = ' ' + a.name + '="'; })
  1144. attrs.push({ k = 'r'; read = attrRead(a); })
  1145. push(&attrs, { k = 's'; v = v.extraOf(a) + '"'; })
  1146. } else {
  1147. push(&attrs, { k = 's'; v = ' ' + a.name + '="' + v.escape(a.text) + '"'; })
  1148. }
  1149. }
  1150. if (v.boundValue(&n)) { push(&attrs, { k = 's'; v = ' autocomplete="off"'; }) }
  1151. // Only handled forms opt into the document's preboot submit capture (#349).
  1152. if (n.tag == 'form') {
  1153. for (c of n.children) {
  1154. if (c.k == 'on' && c.event == 'submit') {
  1155. push(&attrs, { k = 's'; v = ' data-hl-submit'; })
  1156. break
  1157. }
  1158. }
  1159. }
  1160. // the children, in the form this element takes: a block puts them one per line
  1161. let kids = []
  1162. // a script's and a style's content is raw text (#140, view.rawKids says why)
  1163. if (n.tag == 'script' || n.tag == 'style') { kids = rawSteps(n.children, slotted) }
  1164. else if (indent != null && blocky(n, slotted)) {
  1165. kids = blockSteps(n.children, indent + tab, slotted)
  1166. push(&kids, { k = 's'; v = newline + indent; })
  1167. } else {
  1168. kids = blockSteps(n.children, null, slotted)
  1169. }
  1170. if (valueRead != null) { kids = [{ k = 'r'; read = valueRead; }] }
  1171. // AN OPTION IS THE ONE ELEMENT WHOSE OWN TAG DEPENDS ON THE VALUE ABOVE IT: it
  1172. // carries `selected` when its value is the select's. Everything else is settled.
  1173. if (n.tag == 'option') {
  1174. out.push({ k = 'opt'; attrs = attrs; body = kids; ov = optionRead(n); })
  1175. return null
  1176. }
  1177. push(&out, { k = 's'; v = '<' + n.tag; })
  1178. for (a of attrs) { push(&out, a) }
  1179. if (staticVoid.includes(n.tag)) { push(&out, { k = 's'; v = '>'; }) return null }
  1180. push(&out, { k = 's'; v = '>'; })
  1181. // A SELECT HANDS ITS VALUE TO ITS OPTIONS, however deep they stand: its children
  1182. // run under it, and it is the only element that changes anything for them.
  1183. if (n.tag == 'select') { out.push({ k = 'sel'; read = selRead; body = kids; }) }
  1184. else { for (kk of kids) { push(&out, kk) } }
  1185. push(&out, { k = 's'; v = '</' + n.tag + '>'; })
  1186. return null
  1187. }
  1188. // CONSTANT TEXT MERGES. Two literal steps in a row are one string decided at compile
  1189. // time — which is what makes a request a concatenation of a handful of pieces instead
  1190. // of one per node.
  1191. push(&out, step) {
  1192. if (step.k == 's' && out.length > 0 && out[out.length - 1].k == 's') {
  1193. let last = out[out.length - 1]
  1194. last.v = last.v + step.v
  1195. out[out.length - 1] = last
  1196. return null
  1197. }
  1198. out.push(step)
  1199. return null
  1200. }
  1201. // ---- the reads, each with its own closure ------------------------------------------
  1202. // `view.value`'s rule, split once: a `for` row variable in scope wins over a member of
  1203. // the same name, and a field path walks into it. The closure holds the name — there is
  1204. // no node to look at per request.
  1205. readFn(node) {
  1206. if (node == null) { return (inst, rows) => { return null } }
  1207. if (node.k == 'text') { let t = viewRead.refValue(node) return (inst, rows) => { return t } }
  1208. if (node.k == 'expr') { let x = node.x return (inst, rows) => { return viewRead.evalExpr(&x, &inst, &rows) } }
  1209. let name = node.name
  1210. if (node.k != 'field') {
  1211. return (inst, rows) => { return rows[name] != null ? rows[name] : inst[name] }
  1212. }
  1213. let path = node.path
  1214. return (inst, rows) => {
  1215. let val = rows[name] != null ? rows[name] : inst[name]
  1216. for (f of path) {
  1217. if (val == null) { return null }
  1218. val = val[f]
  1219. }
  1220. return val
  1221. }
  1222. }
  1223. attrRead(a) {
  1224. if (a.member != null) { return readFn({ k = 'member'; name = a.member; }) }
  1225. if (a.ref != null) { return readFn(a.ref) }
  1226. let t = a.text
  1227. return (inst, rows) => { return t }
  1228. }
  1229. // an option's own value: its `value` attribute, or null when it has none (the browser
  1230. // then reports its text, and the run compares against what it rendered)
  1231. optionRead(n) {
  1232. for (a of n.attrs) {
  1233. if (a.name == 'value') { return attrRead(a) }
  1234. }
  1235. return null
  1236. }
  1237. // ---- the run: a concatenation ------------------------------------------------------
  1238. // EVERY REGION IS WRITTEN BETWEEN TWO MARKS (tickets #103, #104): an `if` around the
  1239. // branch that stands, a `for` around its rows and each row around its own nodes. The
  1240. // client claims them as they are and builds the same ones, and a region's nodes are
  1241. // exactly what stands between its two marks — nothing it holds has to be remembered
  1242. // node by node, and text beside a region can never run into the region's text.
  1243. regionOpen = '<!--hl:rg:'
  1244. regionClose = '<!--hl:/rg:'
  1245. markOpen = '<!--[-->'
  1246. markClose = '<!--]-->'
  1247. // THE PIECES ARE JOINED ONCE, AT THE END (ticket #127). `out = out + piece` copied
  1248. // the whole page so far for every piece: a 3.5 MB page of 2000 rows allocated 2.3 GB
  1249. // in growing copies, 7 GB per render all told — 12 s a load once the collector ran
  1250. // by bytes (#126), where the joined pieces take 2.5 s.
  1251. runSteps(&list, &inst, &rows, &ctx, &mounts) {
  1252. let out = []
  1253. runInto(&out, &list, &inst, &rows, &ctx, &mounts)
  1254. return out.join('')
  1255. }
  1256. // the same run, its pieces pushed onto the ONE list the caller joins: a nested region used to be
  1257. // joined into a string and then concatenated into its parent's list, so every piece was copied once
  1258. // per level it sat in (a README's blocks sit several levels deep)
  1259. runInto(&out, &list, &inst, &rows, &ctx, &mounts) {
  1260. for (s of list) {
  1261. if (s.k == 's') { out.push(s.v) }
  1262. else if (s.k == 'r') { let f = s.read out.push(v.escape(f(&inst, &rows))) }
  1263. else if (s.k == 'raw') { let f = s.read out.push(v.rawText(f(&inst, &rows))) }
  1264. else if (s.k == 'a') { let f = s.read let av = f(&inst, &rows) if (av != null) { out.push(' ' + s.name + '="' + v.escape(av) + '"') } }
  1265. else if (s.k == 'b') { let f = s.read if (v.boolOn(f(&inst, &rows))) { out.push(' ' + s.name + '=""') } }
  1266. else if (s.k == 'slot') { if (ctx.slot != null) { out.push(ctx.slot) } }
  1267. else if (s.k == 'slotline') { if (ctx.slot != null) { out.push(s.v + ctx.slot) } }
  1268. else if (s.k == 'for') {
  1269. let f = s.read
  1270. let list2 = f(&inst, &rows)
  1271. out.push(markOpen)
  1272. if (list2 != null) {
  1273. // THE ROW IS SET IN PLACE, and the name it shadows put back after the loop:
  1274. // `rows + {}` copied every enclosing row per iteration, and an outer row holds the
  1275. // whole list its inner `for` walks (a list block holding its N items): N rows of N items
  1276. let held = rows[s.row]
  1277. let ri = 0
  1278. let keys = viewRead.listKeys(&list2)
  1279. for (entry of list2) {
  1280. rows[s.row] = entry
  1281. let rc = v.rowCtx(&ctx, keys[ri])
  1282. out.push(markOpen)
  1283. runInto(&out, &s.body, &inst, &rows, &rc, &mounts)
  1284. out.push(markClose)
  1285. ri = ri + 1
  1286. }
  1287. rows[s.row] = held
  1288. }
  1289. out.push(markClose)
  1290. }
  1291. else if (s.k == 'region') {
  1292. // the region's default, between PLACEHOLDERS the document replaces once the page is known
  1293. // (a level above is rendered before the page below it is constructed): WebFramework `regions`
  1294. out.push(regionOpen + s.name + ':' + (s.ind == null ? '-' : '' + s.ind.length) + (s.late == true ? '!' : '') + '-->')
  1295. runInto(&out, &s.body, &inst, &rows, &ctx, &mounts)
  1296. out.push(regionClose + s.name + '-->')
  1297. }
  1298. else if (s.k == 'if') {
  1299. let f = s.read
  1300. out.push(markOpen)
  1301. if (f(&inst, &rows)) { runInto(&out, &s.then, &inst, &rows, &ctx, &mounts) }
  1302. else { runInto(&out, &s.other, &inst, &rows, &ctx, &mounts) }
  1303. out.push(markClose)
  1304. }
  1305. else if (s.k == 'opt') {
  1306. let head = runSteps(&s.attrs, &inst, &rows, &ctx, &mounts)
  1307. let body = runSteps(&s.body, &inst, &rows, &ctx, &mounts)
  1308. let mark = ''
  1309. if (ctx.sel != null) {
  1310. let ov = body
  1311. if (s.ov != null) { let f = s.ov ov = '' + f(&inst, &rows) }
  1312. if (ov == ctx.sel) { mark = ' selected' }
  1313. }
  1314. out.push('<option' + head + mark + '>' + body + '</option>')
  1315. }
  1316. else if (s.k == 'sel') {
  1317. let f = s.read
  1318. let inner = ctx + {}
  1319. inner.sel = f == null ? null : '' + f(&inst, &rows)
  1320. runInto(&out, &s.body, &inst, &rows, &inner, &mounts)
  1321. }
  1322. else if (s.k == 'kid') {
  1323. // THE KID IS READ IN PLACE: `let kid = ctx.kids[…]` copied the whole mount (its tree, its
  1324. // params, its state, its own kids) once per mount rendered. And the mounts a level holds
  1325. // travel as their own reference (`mounts`), not inside `ctx`: every `for` row copies the
  1326. // ctx, and a ctx holding the kids copied ALL of them per row (N rows of N mounts).
  1327. let kk = v.kidKeyIn(&s.path, &ctx)
  1328. if (mounts[kk] == null) { out.push('<!-- ' + s.cls + ' not mounted -->') }
  1329. else {
  1330. let fillText = s.fill == null ? null : runSteps(&s.fill, &inst, &rows, &ctx, &mounts)
  1331. let kidCtx = { slot = fillText; }
  1332. let empty = {}
  1333. let ksteps = kidSteps(s.key, s.indent, s.classes, fillText != null)
  1334. runInto(&out, &ksteps, &mounts[kk].page, &empty, &kidCtx, &mounts[kk].kids)
  1335. }
  1336. }
  1337. }
  1338. }

Branches

Latest commits

  • ae3b80dc|||PR records: HM55b briefTracker
  • 7ef3cb3bMerge branch 'records-st55' into mainTracker
  • fec2e080|||PR records: STATUS HM55Tracker
  • 8e174918Merge branch 'records-hm55b' into mainTracker
  • b1ecee57|||PR records: HM55 stateTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
  • b9c7c3c8Merge branch 'records-dp74' into mainTracker
  • 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
  • b1496147Merge branch 'ap61' into mainTracker
  • 2047955bMerge branch 'u12-gateports' into mainTracker
  • c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker