@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.
- package/lib/ir.js +20 -14
- 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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
10
|
-
*
|
|
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 /
|
|
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.
|
|
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
|
|
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
|
-
*
|
|
523
|
-
*
|
|
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
|
/*!
|