@rhinostone/swig-core 2.2.0 → 2.3.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.
Files changed (2) hide show
  1. package/lib/ir.js +20 -14
  2. package/package.json +1 -1
package/lib/ir.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * Swig IR — intermediate representation for the shared backend.
3
3
  *
4
- * Phase 1: typedef stubs only. No runtime code here Phase 1 keeps the
5
- * native frontend emitting JS source directly. Phase 2 ports the native
6
- * frontend to emit IR, at which point `@rhinostone/swig-core/lib/backend.js`
7
- * walks an IRTemplate and produces the compiled `new Function(...)` body.
4
+ * Two halves: the `@typedef` schema for every IR node shape, and the
5
+ * runtime factories (further down) that build them. Every frontend
6
+ * (native Swig, Twig, and future flavors) lowers its parse tree into
7
+ * these shapes; `@rhinostone/swig-core/lib/backend.js` then walks an
8
+ * IRTemplate and produces the compiled `new Function(...)` body.
8
9
  *
9
- * Every frontend (native Swig, Twig, Jinja2, Django) must lower its
10
- * parse tree into these shapes. Constructs that cannot lower cleanly
11
- * must throw at parse time — no silent partial behavior.
10
+ * Constructs that cannot lower cleanly must throw at parse time — no
11
+ * silent partial behavior.
12
12
  */
13
13
 
14
14
  /**
@@ -103,11 +103,17 @@
103
103
  /**
104
104
  * For-loop. `emptyBody` supports Twig/Django `{% for … %}{% else %}`.
105
105
  *
106
+ * `iterable` is typed `IRExpr | string` for Phase 2 — the native
107
+ * frontend still hands in a raw JS-source string (its `for` tag has
108
+ * not migrated to expression-level IR), while the Twig frontend lowers
109
+ * to a real {@link IRExpr}. Backends MUST tolerate both shapes — same
110
+ * transitional widening as {@link IRSet}'s `target`.
111
+ *
106
112
  * @typedef {Object} IRFor
107
113
  * @property {'For'} type
108
114
  * @property {string} [key] Loop key var (second binding).
109
115
  * @property {string} value Loop value var (first binding).
110
- * @property {IRExpr} iterable
116
+ * @property {IRExpr|string} iterable Transitional — see note above.
111
117
  * @property {IRStatement[]} body
112
118
  * @property {IRStatement[]} [emptyBody]
113
119
  * @property {IRLoc} [loc]
@@ -279,12 +285,13 @@
279
285
  * In sync codegen mode the parser pre-resolves `extends` / `include` /
280
286
  * `import` / Twig `from` paths via `swig.parseFile(...)` and inlines
281
287
  * the resolved tokens at parse-finalization time. That model can't run
282
- * against an async-only loader (S3 / Redis / fetch-backed), and it
288
+ * against an async-only loader (S3 / Redis / network-backed), and it
283
289
  * can't handle dynamic paths (`{% extends parent_var %}`) since the
284
290
  * value isn't known until render.
285
291
  *
286
292
  * The deferred shapes carry the unresolved path expression to render
287
- * time. The async backend (`compileAsync`) emits cb-shaped or
293
+ * time. In async codegen mode (`backend.compile` with
294
+ * `options.codegenMode === 'async'`) the backend emits cb-shaped or
288
295
  * AsyncFunction-shaped JS that hits a runtime `_swig.getTemplate(...)`
289
296
  * call to resolve and apply the parent / included / imported template.
290
297
  *
@@ -511,7 +518,7 @@
511
518
  */
512
519
 
513
520
  /* ------------------------------------------------------------------ *
514
- * Runtime node factories — Phase 2 scaffold (Session 7, 2026-04-14).
521
+ * Runtime node factories.
515
522
  *
516
523
  * Each factory returns a plain JSON-serialisable object matching one
517
524
  * of the typedefs above. `loc` is always optional; when omitted it is
@@ -519,9 +526,8 @@
519
526
  * `'loc' in node`). All other parameters are required unless documented
520
527
  * otherwise on the corresponding typedef.
521
528
  *
522
- * No consumers yet this commit introduces the schema surface only.
523
- * Subsequent sessions will migrate the native frontend's token-tree
524
- * production over to these shapes.
529
+ * Consumed by every frontend's tag handlers and `tokenparser.js` (which
530
+ * build the IR) and by `backend.js` (which walks it).
525
531
  * ------------------------------------------------------------------ */
526
532
 
527
533
  /*!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinostone/swig-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Shared IR, backend, and runtime for the @rhinostone/swig family of template engines.",
5
5
  "keywords": [
6
6
  "template",