@rhinostone/swig-django 2.8.3 → 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 +1 -1
- package/lib/index.js +1 -1
- package/lib/lexer.js +1 -1
- package/lib/parser.js +25 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@rhinostone/swig-django
|
|
2
2
|
=======================
|
|
3
3
|
|
|
4
|
-
[](https://www.npmjs.com/package/@rhinostone/swig-django) [](https://socket.dev/npm/package/@rhinostone/swig-django)
|
|
4
|
+
[](https://www.npmjs.com/package/@rhinostone/swig-django) [](https://socket.dev/npm/package/@rhinostone/swig-django) [](https://scorecard.dev/viewer/?uri=github.com/gina-io/swig)
|
|
5
5
|
|
|
6
6
|
Django Template Language 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
package/lib/lexer.js
CHANGED
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 Django'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 = 'django';
|
|
39
|
+
if (negate) {
|
|
40
|
+
node.negate = true;
|
|
41
|
+
}
|
|
42
|
+
return node;
|
|
43
|
+
}
|
|
44
|
+
|
|
24
45
|
/**
|
|
25
46
|
* Build a VarRef IR node flagged for Django-style runtime resolution. The
|
|
26
47
|
* `resolve` flag makes swig-core's emitVarRef emit `_utils.resolve(_ctx,
|
|
@@ -135,6 +156,9 @@ exports.parseExpr = function (tokens, filters, _posOut) {
|
|
|
135
156
|
if (m === '===' || m === '!==' || m === '==' || m === '!=') {
|
|
136
157
|
return { op: m, prec: 3 };
|
|
137
158
|
}
|
|
159
|
+
if (/^not\s+in$/.test(m)) {
|
|
160
|
+
return { op: 'not in', prec: 4 };
|
|
161
|
+
}
|
|
138
162
|
return { op: m, prec: 4 };
|
|
139
163
|
}
|
|
140
164
|
// Django `is` / `is not` are *identity* comparisons (not Jinja2 test
|
|
@@ -453,7 +477,7 @@ exports.parseExpr = function (tokens, filters, _posOut) {
|
|
|
453
477
|
continue;
|
|
454
478
|
}
|
|
455
479
|
var right = parseExpression(info.prec + 1);
|
|
456
|
-
left = ir.binaryOp(info.op, left, right);
|
|
480
|
+
left = (info.op === 'in' || info.op === 'not in') ? membership(left, right, info.op === 'not in') : ir.binaryOp(info.op, left, right);
|
|
457
481
|
}
|
|
458
482
|
return left;
|
|
459
483
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinostone/swig-django",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "Django-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.
|
|
25
|
+
"@rhinostone/swig-core": "2.9.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|