Skip to content

Instantly share code, notes, and snippets.

@peterjanes
Last active January 5, 2026 01:45
Show Gist options
  • Select an option

  • Save peterjanes/68e1eee7c71d1233b4c34e4fdbe5aa59 to your computer and use it in GitHub Desktop.

Select an option

Save peterjanes/68e1eee7c71d1233b4c34e4fdbe5aa59 to your computer and use it in GitHub Desktop.
confusing webc behaviour
<a>
 months: <t>Map</t>
 yearNum: <t>2014</t>
 <b>
  months: <t>Map</t>
  yearNum: <t>2014</t>
  month: <t>Map</t>
  monthNum: <t>1</t>
  <c>
   months: <t>Map</t>
   yearNum: <t>2014</t>
   month: <t>Map</t>
   monthNum: <t>1</t>
   day: <t>Number</t>
   <d>
    event: <e>{text: 'a'}</e>
   </d>
  </c>

etc.

Basically I want to iterate through Maps of Maps, and the current behaviour of 0.12 beta doesn't let me do that. (It kind of works in 0.11, except for the problem of being able to access the outer loop variables.) Instead of (key, data) of myMap.entries() returning the keys and data in myMap, key contains a [key,data] array and data contains the index of the entry in the map.

If this isn't (or isn't meant to be) possible in WebC, I can use key[0]/key[1], it's just a bit counterintuitive. Something like a webc:set might be handy in that case, although I'm not sure how it would look.

{
"name": "webc-strangeness",
"version": "1.0.0",
"type": "module",
"devDependencies": {
"@11ty/webc": "^0.12.0-beta.2"
}
}
import { WebC } from '@11ty/webc'
const page = new WebC()
page.setBundlerMode(true)
page.setInputPath('test.webc')
const { html, css, js, components } = await page.compile()
console.log(html)
<a webc:for="(months, yearNum) of new Map([ [2014, new Map([ [1, new Map([ [1, {text: 'a'}], [2, {text: 'b'}] ])], [2, new Map([ [3, {text: 'c'}], [4, {text: 'd'}] ])] ])], [2015, new Map([ [3, new Map([ [5, {text: 'e'}], [6, {text: 'f'}] ])], [4, new Map([ [7, {text: 'g'}], [8, {text: 'h'}] ])] ])] ]).entries()">
months: <t @raw="months.constructor.name"></t>
yearNum: <t @raw="yearNum"></t>
<b webc:for="(month, monthNum) of months.entries()">
months: <t @raw="months?.constructor?.name"></t>
yearNum: <t @raw="yearNum"></t>
month: <t @raw="month?.constructor?.name"></t>
monthNum: <t @raw="monthNum"></t>
<c webc:for="day of [1,2,3,4,5,6,7,8,9,10]">
months: <t @raw="months?.constructor?.name"></t>
yearNum: <t @raw="yearNum"></t>
month: <t @raw="month?.constructor?.name"></t>
monthNum: <t @raw="monthNum"></t>
day: <t @raw="day?.constructor?.name"></t>
<!--- webc:ignore on next line because month is undefined --->
<d webc:for="evt of (month.get(day) || [])" webc:ignore>
event: <e @raw="evt"></e>
</d>
</c>
</b>
</a>
<a>
months: <t>Array</t>
yearNum: <t></t>
<b>
months: <t></t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
</b>
<b>
months: <t></t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
</b>
</a>
<a>
months: <t>Array</t>
yearNum: <t>1</t>
<b>
months: <t></t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
</b>
<b>
months: <t></t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t></t>
yearNum: <t></t>
month: <t></t>
monthNum: <t></t>
day: <t>Number</t>
</c>
</b>
</a>
<a>
months: <t>Array</t>
yearNum: <t></t>
<b>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
</b>
<b>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t></t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
</b>
</a>
<a>
months: <t>Array</t>
yearNum: <t>1</t>
<b>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t></t>
day: <t>Number</t>
</c>
</b>
<b>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
<c>
months: <t>Array</t>
yearNum: <t>1</t>
month: <t>Array</t>
monthNum: <t>1</t>
day: <t>Number</t>
</c>
</b>
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment