@rhinostone/swig-core 2.5.1 → 2.5.3

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/engine.js +18 -8
  2. package/package.json +1 -1
package/lib/engine.js CHANGED
@@ -106,13 +106,15 @@ exports.importNonBlocks = function (blocks, tokens) {
106
106
  * which works for `{% extends "layout.html" %}` but for a bare
107
107
  * identifier (`{% extends parent_var %}`) yields a pre-lowered JS
108
108
  * source fragment such as `((typeof _ctx.parent_var !== "undefined")
109
- * ? _ctx.parent_var : …)`. Embedded here as a string literal it
110
- * becomes a garbage template lookup at runtime
111
- * (`Template not found: /((typeof _ctx.parent_var …`). Closing the
112
- * dynamic-extends gap requires the parser to stash an IRExpr on
113
- * `tokens.parent` and this helper to lower it through
114
- * `ir.extendsDeferred`'s `parentExpr` slot already designed as
115
- * `<IRExpr>` per the deferred IR contract.
109
+ * ? _ctx.parent_var : …)`. As a string literal that would become a
110
+ * garbage template lookup at runtime
111
+ * (`Template not found: /((typeof _ctx.parent_var …`). Closed: a
112
+ * dynamic path is lowered to an IRExpr by the extends tag's `lowerExpr`
113
+ * (lib/tags/extends.js) and stashed on the sibling `tokens.parentExpr`
114
+ * slot — NOT `tokens.parent`, which the sync `getParents` chain still
115
+ * reads as a string then passed through `ir.extendsDeferred`'s
116
+ * `path` slot below. A lone string-literal path keeps the
117
+ * `ir.literal('string', tokens.parent)` path unchanged.
116
118
  *
117
119
  * @param {object} tokens Parsed child template (must have `.parent`).
118
120
  * @param {object} options Per-call Swig options; `options.filename` is
@@ -149,7 +151,7 @@ function buildExtendsDeferred(tokens, options) {
149
151
  }
150
152
  });
151
153
  return ir.extendsDeferred(
152
- ir.literal('string', tokens.parent),
154
+ tokens.parentExpr || ir.literal('string', tokens.parent),
153
155
  childBlocks,
154
156
  childIRs,
155
157
  options.filename || ''
@@ -397,6 +399,14 @@ exports.install = function (self, frontend) {
397
399
  parents = [];
398
400
  tokens.tokens = [buildExtendsDeferred(tokens, options)];
399
401
  } else {
402
+ if (tokens.parentExpr) {
403
+ // A dynamic {% extends %} path lowered to tokens.parentExpr can
404
+ // only resolve at render time. The sync precompile path walks the
405
+ // parent chain at compile time, before any runtime value exists,
406
+ // so a dynamic parent is unresolvable here — fail with a pointer
407
+ // to the async render path rather than a cryptic not-found.
408
+ throw new Error('Dynamic {% extends %} requires the async render path — use renderFile(path, locals, cb) with a loader that sets loader.async === true.');
409
+ }
400
410
  parents = getParentsInternal(tokens, options);
401
411
  if (parents.length) {
402
412
  tokens.tokens = exports.remapBlocks(tokens.blocks, parents[0].tokens);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinostone/swig-core",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "Shared IR, backend, and runtime for the @rhinostone/swig family of template engines.",
5
5
  "keywords": [
6
6
  "template",