@rhinostone/swig-twig 2.8.4 → 2.9.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  @rhinostone/swig-twig
2
2
  =====================
3
3
 
4
- [![NPM version](https://img.shields.io/npm/v/@rhinostone/swig-twig.svg?style=flat)](https://www.npmjs.com/package/@rhinostone/swig-twig) [![Socket Badge](https://socket.dev/api/badge/npm/package/@rhinostone/swig-twig)](https://socket.dev/npm/package/@rhinostone/swig-twig)
4
+ [![NPM version](https://img.shields.io/npm/v/@rhinostone/swig-twig.svg?style=flat)](https://www.npmjs.com/package/@rhinostone/swig-twig) [![Socket Badge](https://socket.dev/api/badge/npm/package/@rhinostone/swig-twig)](https://socket.dev/npm/package/@rhinostone/swig-twig) [![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/gina-io/swig?label=openssf%20scorecard&style=flat)](https://scorecard.dev/viewer/?uri=github.com/gina-io/swig)
5
5
 
6
6
  Twig-syntax frontend for the [@rhinostone/swig-core](https://www.npmjs.com/package/@rhinostone/swig-core) template engine. Part of the multi-flavor architecture introduced in `2.0.0` — see [ROADMAP.md](https://github.com/gina-io/swig/blob/develop/ROADMAP.md) for the release narrative.
7
7
 
package/lib/index.js CHANGED
@@ -27,7 +27,7 @@ exports.name = 'twig';
27
27
  *
28
28
  * @type {String}
29
29
  */
30
- exports.version = "2.8.4";
30
+ exports.version = "2.9.0";
31
31
 
32
32
  /**
33
33
  * Expression-level parser — Pratt-style recursive descent that consumes
package/lib/lexer.js CHANGED
@@ -122,7 +122,7 @@ var rules = [
122
122
  {
123
123
  type: TYPES.COMPARATOR,
124
124
  regex: [
125
- /^(===|==|\!==|\!=|<=|<|>=|>|in\s)\s*/
125
+ /^(===|==|\!==|\!=|<=|<|>=|>|not\s+in\s|in\s)\s*/
126
126
  ],
127
127
  idx: 1
128
128
  },
package/lib/parser.js CHANGED
@@ -21,6 +21,27 @@ function escapeRegExp(str) {
21
21
  */
22
22
  var _reserved = ['break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with'];
23
23
 
24
+ /**
25
+ * Build the IR of `left in right`, or of `left not in right` when `negate`
26
+ * is set: a BinaryOp `in` flagged with this flavor's name, so swig-core
27
+ * emits Twig's membership test (`_utils.isIn`) instead of the JavaScript
28
+ * `in` operator, which tests keys.
29
+ *
30
+ * @param {object} left The needle.
31
+ * @param {object} right The container.
32
+ * @param {boolean} [negate] The `not in` form.
33
+ * @return {object} IRBinaryOp.
34
+ * @private
35
+ */
36
+ function membership(left, right, negate) {
37
+ var node = ir.binaryOp('in', left, right);
38
+ node.membership = 'twig';
39
+ if (negate) {
40
+ node.negate = true;
41
+ }
42
+ return node;
43
+ }
44
+
24
45
  /**
25
46
  * Twig expression parser — Pratt-style recursive descent.
26
47
  *
@@ -108,6 +129,9 @@ exports.parseExpr = function (tokens, filters, _posOut) {
108
129
  if (m === '===' || m === '!==' || m === '==' || m === '!=') {
109
130
  return { op: m, prec: 3 };
110
131
  }
132
+ if (/^not\s+in$/.test(m)) {
133
+ return { op: 'not in', prec: 4 };
134
+ }
111
135
  return { op: m, prec: 4 };
112
136
  }
113
137
  if (tok.type === _t.IS) {
@@ -398,6 +422,8 @@ exports.parseExpr = function (tokens, filters, _posOut) {
398
422
  var right = parseExpression(info.prec + 1);
399
423
  if (info.op === '..') {
400
424
  left = ir.fnCall(ir.varRef(['_utils', 'range']), [left, right]);
425
+ } else if (info.op === 'in' || info.op === 'not in') {
426
+ left = membership(left, right, info.op === 'not in');
401
427
  } else {
402
428
  left = ir.binaryOp(info.op, left, right);
403
429
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinostone/swig-twig",
3
- "version": "2.8.4",
3
+ "version": "2.9.0",
4
4
  "description": "Twig-syntax frontend for the @rhinostone/swig-core template engine. Part of the @rhinostone/swig multi-flavor family.",
5
5
  "keywords": [
6
6
  "template",
@@ -22,7 +22,7 @@
22
22
  "node": ">=12"
23
23
  },
24
24
  "peerDependencies": {
25
- "@rhinostone/swig-core": "2.8.4"
25
+ "@rhinostone/swig-core": "2.9.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"