@barefootjs/jsx 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/parsed-expr-emitter.d.ts +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/combine-client-js.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +1 -1
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.js +330 -70
- package/dist/ir-to-client-js/collect-elements.d.ts +26 -14
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts +8 -3
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +30 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/provider-and-child-inits.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +3 -3
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +36 -4
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +19 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +203 -203
- package/src/__tests__/child-components-in-map.test.ts +333 -0
- package/src/__tests__/combine-client-js.test.ts +47 -0
- package/src/__tests__/dangerously-set-inner-html.test.ts +82 -0
- package/src/__tests__/expression-parser.test.ts +167 -13
- package/src/__tests__/ir-to-client-js/reactivity.test.ts +1 -0
- package/src/__tests__/staged-ir/06-multi-stage-soak.test.ts +18 -3
- package/src/__tests__/static-loop-csr-materialize.test.ts +6 -4
- package/src/__tests__/text-slot-escaping.test.ts +56 -0
- package/src/adapters/parsed-expr-emitter.ts +7 -0
- package/src/combine-client-js.ts +66 -22
- package/src/expression-parser.ts +200 -17
- package/src/ir-to-client-js/collect-elements.ts +170 -32
- package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +1 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/event-delegation.ts +8 -3
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -3
- package/src/ir-to-client-js/emit-reactive.ts +9 -0
- package/src/ir-to-client-js/emit-registration.ts +1 -1
- package/src/ir-to-client-js/generate-init.ts +16 -1
- package/src/ir-to-client-js/html-template.ts +238 -12
- package/src/ir-to-client-js/imports.ts +1 -1
- package/src/ir-to-client-js/index.ts +1 -0
- package/src/ir-to-client-js/phases/provider-and-child-inits.ts +12 -1
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +4 -8
- package/src/ir-to-client-js/plan/static-array-child-init.ts +3 -3
- package/src/ir-to-client-js/types.ts +37 -4
- package/src/ir-to-client-js/utils.ts +41 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import ts from 'typescript'
|
|
7
7
|
import type { AttrValue, IRTemplatePart, LoopParamBinding, FreeReference, IRNode } from '../types'
|
|
8
|
-
import type { TopLevelLoop, BranchLoop } from './types'
|
|
8
|
+
import type { TopLevelLoop, BranchLoop, LoopOffset } from './types'
|
|
9
9
|
import { buildLoopChainExpr } from '../loop-chain'
|
|
10
10
|
import {
|
|
11
11
|
iterateJsTokens,
|
|
@@ -145,6 +145,46 @@ export function buildChainedArrayExpr(elem: TopLevelLoop | BranchLoop): string {
|
|
|
145
145
|
})
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
* The single source of truth for what contributes to a loop's child-index
|
|
150
|
+
* offset: the static sibling count (a folded integer) followed by one
|
|
151
|
+
* `(arr).length` term per preceding sibling loop. The additive and
|
|
152
|
+
* subtractive forms below are thin projections over this list, so they can
|
|
153
|
+
* never drift in which terms they include, and a new offset contributor is
|
|
154
|
+
* added here once rather than in every consumer (#1693).
|
|
155
|
+
*/
|
|
156
|
+
function loopOffsetTerms(offset: LoopOffset | undefined): string[] {
|
|
157
|
+
if (!offset) return []
|
|
158
|
+
const terms: string[] = []
|
|
159
|
+
if (offset.staticCount) terms.push(String(offset.staticCount))
|
|
160
|
+
terms.push(...offset.dynamicTerms)
|
|
161
|
+
return terms
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Build the additive `children[idx]` access expression for a loop's items —
|
|
166
|
+
* `indexParam` plus every offset term.
|
|
167
|
+
*
|
|
168
|
+
* Examples:
|
|
169
|
+
* - no offset → `__idx`
|
|
170
|
+
* - one static sibling → `__idx + 1`
|
|
171
|
+
* - one preceding `.map()` → `__idx + (arr).length`
|
|
172
|
+
* - static sibling + 2 `.map()`→ `__idx + 1 + (a).length + (b).length`
|
|
173
|
+
*/
|
|
174
|
+
export function buildLoopChildIndexExpr(indexParam: string, offset: LoopOffset | undefined): string {
|
|
175
|
+
return [indexParam, ...loopOffsetTerms(offset)].join(' + ')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Build the subtractive counterpart of `buildLoopChildIndexExpr` — used by
|
|
180
|
+
* event delegation to recover a loop item's array index from its DOM child
|
|
181
|
+
* index. Returns the trailing `` - <static> - (arr).length …`` suffix (empty
|
|
182
|
+
* when there is no offset) appended after `…indexOf(__el)`.
|
|
183
|
+
*/
|
|
184
|
+
export function buildLoopChildIndexSubtraction(offset: LoopOffset | undefined): string {
|
|
185
|
+
return loopOffsetTerms(offset).map(term => ` - ${term}`).join('')
|
|
186
|
+
}
|
|
187
|
+
|
|
148
188
|
/**
|
|
149
189
|
* Map of JSX event names to DOM event property names.
|
|
150
190
|
* JSX uses React-style naming (e.g., onDoubleClick) which gets converted to
|