@rhinostone/swig 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.
@@ -1,3 +1,5 @@
1
+ var _t = require('@rhinostone/swig-core/lib/tokentypes');
2
+
1
3
  /**
2
4
  * Makes the current template extend a parent template. This tag must be the first item in your template.
3
5
  *
@@ -8,7 +10,13 @@
8
10
  * @example
9
11
  * {% extends "./layout.html" %}
10
12
  *
11
- * @param {string} parentFile Relative path to the file that this template extends.
13
+ * @example
14
+ * // A dynamic parent path resolves on the async render path
15
+ * // (renderFile(path, locals, cb) with loader.async === true); the
16
+ * // synchronous render path requires a string literal.
17
+ * {% extends layout_var %}
18
+ *
19
+ * @param {string|var} parentFile Relative path to the file that this template extends. A dynamic (variable) path is resolved on the async render path only.
12
20
  */
13
21
  // extends is a parse-time declaration, not an emit-time construct. The
14
22
  // engine's getParents / remapBlocks resolves the parent chain before the
@@ -24,4 +32,27 @@ exports.parse = function () {
24
32
  return true;
25
33
  };
26
34
 
35
+ /*!
36
+ * Lower a dynamic parent-path to IR so `{% extends layout_var %}`
37
+ * resolves at render time on the async codegen path. A lone
38
+ * string-literal path (`{% extends "x.html" %}`) returns undefined, so
39
+ * the engine keeps its existing tokens.parent string + ir.literal path
40
+ * unchanged; only a dynamic path is lowered. Mirrors include.js. The
41
+ * resulting IRExpr is read back as token.irExpr.file by the parser
42
+ * splitter and stashed on the sibling tokens.parentExpr slot.
43
+ */
44
+ exports.lowerExpr = function (parser, tokens) {
45
+ var i, tk, pathTokens = [];
46
+ for (i = 0; i < tokens.length; i += 1) {
47
+ tk = tokens[i];
48
+ if (tk.type === _t.WHITESPACE) { continue; }
49
+ pathTokens.push(tk);
50
+ }
51
+ if (!pathTokens.length) { return undefined; }
52
+ if (pathTokens.length === 1 && pathTokens[0].type === _t.STRING) {
53
+ return undefined;
54
+ }
55
+ return { file: parser.parseExpr(tokens) };
56
+ };
57
+
27
58
  exports.ends = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinostone/swig",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "A simple, powerful, and extendable templating engine for node.js and browsers, similar to Django, Jinja2, and Twig.",
5
5
  "keywords": [
6
6
  "template",
@@ -21,7 +21,7 @@
21
21
  "Rhinostone <contact@gina.io>"
22
22
  ],
23
23
  "dependencies": {
24
- "@rhinostone/swig-core": "2.5.1"
24
+ "@rhinostone/swig-core": "2.5.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "esbuild": "^0.28.0",