@rhinostone/swig-twig 2.4.2 → 2.5.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/filters.js +1 -1
- package/lib/index.js +1 -1
- package/lib/lexer.js +3 -3
- package/lib/parser.js +1 -1
- package/lib/tags/apply.js +1 -1
- package/lib/tags/block.js +1 -1
- package/lib/tags/extends.js +1 -1
- package/lib/tags/for.js +1 -1
- package/lib/tags/from.js +3 -3
- package/lib/tags/if.js +3 -3
- package/lib/tags/import.js +3 -3
- package/lib/tags/include.js +1 -1
- package/lib/tags/index.js +3 -6
- package/lib/tags/macro.js +3 -3
- package/lib/tags/set.js +1 -2
- package/lib/tags/verbatim.js +1 -1
- package/lib/tags/with.js +1 -1
- package/lib/tokentypes.js +2 -2
- package/package.json +2 -2
package/lib/filters.js
CHANGED
|
@@ -800,7 +800,7 @@ exports.merge = function (input, other) {
|
|
|
800
800
|
*
|
|
801
801
|
* Twig's native `|date` accepts DateTime / DateInterval objects, a
|
|
802
802
|
* timezone string argument, and locale-aware month/day names. Those are
|
|
803
|
-
*
|
|
803
|
+
* deferred — today this filter supports the same surface as
|
|
804
804
|
* native swig's `date` filter: Date object or epoch-ms number input, a
|
|
805
805
|
* format string, an optional numeric `offset` in minutes from GMT, and
|
|
806
806
|
* an optional `abbr` timezone abbreviation (output-only).
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @rhinostone/swig-twig — Twig frontend for the @rhinostone/swig family.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* End-to-end render wiring (Path A). The package now
|
|
5
5
|
* exposes a Twig constructor + default instance via `engine.install(self,
|
|
6
6
|
* frontend)` from @rhinostone/swig-core, so callers can `render(source,
|
|
7
7
|
* locals)` / `renderFile(path, locals, cb)` directly against Twig syntax.
|
package/lib/lexer.js
CHANGED
|
@@ -11,7 +11,7 @@ var TYPES = require('./tokentypes');
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/*!
|
|
14
|
-
*
|
|
14
|
+
* Twig lexer rule table.
|
|
15
15
|
*
|
|
16
16
|
* Covers the swig-shared token subset plus all Twig-only operators
|
|
17
17
|
* including string interpolation (`~` concat, `..` range, `??`
|
|
@@ -168,7 +168,7 @@ var rules = [
|
|
|
168
168
|
// cleanly decomposes into VAR `start` + RANGE `..` + VAR `end`. Native
|
|
169
169
|
// swig-core's VAR rule still uses `\w*` because it has no RANGE token;
|
|
170
170
|
// do not copy this tightening back without also auditing native's path
|
|
171
|
-
// semantics.
|
|
171
|
+
// semantics.
|
|
172
172
|
type: TYPES.VAR,
|
|
173
173
|
regex: [
|
|
174
174
|
/^[a-zA-Z_$]\w*((\.\$?\w+)+)?/,
|
|
@@ -256,7 +256,7 @@ exports.types = TYPES;
|
|
|
256
256
|
* Match the next token at the start of `str`.
|
|
257
257
|
*
|
|
258
258
|
* Throws via utils.throwError when no rule matches — including every
|
|
259
|
-
* Twig-only operator until
|
|
259
|
+
* Twig-only operator until its rules land. The throw is
|
|
260
260
|
* opaque (no line / file info); the Twig frontend's onCompileError
|
|
261
261
|
* callback attaches filename + line per the swig-core / frontend seam
|
|
262
262
|
* rule.
|
package/lib/parser.js
CHANGED
|
@@ -517,7 +517,7 @@ exports.parse = function (swig, source, opts, tags, filters) {
|
|
|
517
517
|
);
|
|
518
518
|
// Twig/Jinja2 whitespace-control. `{{- … -}}` / `{%- … -%}` strip
|
|
519
519
|
// surrounding whitespace; the `-?` lives only adjacent to the open /
|
|
520
|
-
// close marker (
|
|
520
|
+
// close marker (drop the inner `-?` after `\s*` so
|
|
521
521
|
// `{{ -5 }}` doesn't have its expression-`-` eaten as a strip marker).
|
|
522
522
|
var tagStrip = new RegExp('^' + escapeRegExp(tagOpen) + '-?\\s*|\\s*-?' + escapeRegExp(tagClose) + '$', 'g');
|
|
523
523
|
var varStrip = new RegExp('^' + escapeRegExp(varOpen) + '-?\\s*|\\s*-?' + escapeRegExp(varClose) + '$', 'g');
|
package/lib/tags/apply.js
CHANGED
package/lib/tags/block.js
CHANGED
package/lib/tags/extends.js
CHANGED
package/lib/tags/for.js
CHANGED
package/lib/tags/from.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Twig `{% from "file" import a, b as c %}` tag.
|
|
3
3
|
*
|
|
4
4
|
* Selective macro import syntax — binds a named subset of an imported
|
|
5
5
|
* template's macros into the current context, optionally renaming each
|
|
@@ -142,7 +142,7 @@ exports.parse = function (str, line, parser, types, stack, opts, swig, token) {
|
|
|
142
142
|
var path = pathTok.match.replace(/^['"]|['"]$/g, '');
|
|
143
143
|
|
|
144
144
|
if (opts && opts.codegenMode === 'async') {
|
|
145
|
-
//
|
|
145
|
+
// Async mode skips parse-time parseFile + macro
|
|
146
146
|
// pre-render. compile() emits IRFromImportDeferred; runtime resolves
|
|
147
147
|
// the template via _swig.getTemplate and binds each entry on _ctx.
|
|
148
148
|
token.args = [{ path: path, entries: entries }];
|
|
@@ -239,7 +239,7 @@ exports.parse = function (str, line, parser, types, stack, opts, swig, token) {
|
|
|
239
239
|
* `IRLegacyJS`.
|
|
240
240
|
*/
|
|
241
241
|
exports.compile = function (compiler, args, content, parents, options) {
|
|
242
|
-
//
|
|
242
|
+
// Async-codegen branch. Parse stashed a single bundle
|
|
243
243
|
// `[{path, entries: [{origName, aliasName}, ...]}]` in async mode (no
|
|
244
244
|
// macro pre-render); emit IRFromImportDeferred so the backend's
|
|
245
245
|
// `_swig.getTemplate` + per-entry `_ctx.<bind>` assignment happens at
|
package/lib/tags/if.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Twig `{% if %}` tag.
|
|
3
3
|
*
|
|
4
4
|
* Twig conditional: `{% if <expr> %}…{% endif %}`. The test expression
|
|
5
5
|
* is parsed via `parser.parseExpr` and attached to `token.irExpr`; the
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* mechanism (parser.js sets `ends: true` so subsequent tokens append to
|
|
8
8
|
* `token.content` until the matching `{% endif %}` arrives).
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Ships a single-branch shape — `{% else %}` / `{% elseif %}` are
|
|
11
|
+
* deferred. The compile path emits one
|
|
12
12
|
* IRIfBranch carrying the test IRExpr and the recursively-compiled
|
|
13
13
|
* body wrapped in IRLegacyJS.
|
|
14
14
|
*/
|
package/lib/tags/import.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Twig `{% import %}` tag.
|
|
3
3
|
*
|
|
4
4
|
* Twig import syntax:
|
|
5
5
|
*
|
|
@@ -116,7 +116,7 @@ exports.parse = function (str, line, parser, types, stack, opts, swig, token) {
|
|
|
116
116
|
var path = pathTok.match.replace(/^['"]|['"]$/g, '');
|
|
117
117
|
|
|
118
118
|
if (opts && opts.codegenMode === 'async') {
|
|
119
|
-
//
|
|
119
|
+
// Async mode skips the parse-time parseFile + macro
|
|
120
120
|
// pre-render. compile() emits IRImportDeferred; runtime resolves the
|
|
121
121
|
// template via _swig.getTemplate and binds .exports under the alias.
|
|
122
122
|
token.args = [path, aliasTok.match];
|
|
@@ -194,7 +194,7 @@ exports.parse = function (str, line, parser, types, stack, opts, swig, token) {
|
|
|
194
194
|
* imported macro into it.
|
|
195
195
|
*/
|
|
196
196
|
exports.compile = function (compiler, args, content, parents, options) {
|
|
197
|
-
//
|
|
197
|
+
// Async-codegen branch. Parse stashed `[path, alias]`
|
|
198
198
|
// in async mode (no macro pre-render); emit IRImportDeferred so the
|
|
199
199
|
// backend's `_swig.getTemplate` + `.exports` bind happens at runtime.
|
|
200
200
|
if (options && options.codegenMode === 'async') {
|
package/lib/tags/include.js
CHANGED
package/lib/tags/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Twig per-flavor tag registry.
|
|
3
3
|
*
|
|
4
4
|
* Each tag exports `{ parse, compile, ends, block }` with a Twig-tailored
|
|
5
5
|
* shape:
|
|
@@ -12,11 +12,8 @@
|
|
|
12
12
|
* native-swig `parser.on(types.X, fn)` callback indirection — Twig tags own
|
|
13
13
|
* their own arg-parsing path.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* per-flavor shape. Future sessions add `for`, `block`, `extends`,
|
|
18
|
-
* `include`, `import`, `macro`, `apply`, `verbatim`, `with`,
|
|
19
|
-
* `from … import`.
|
|
15
|
+
* The registry covers `set`, `if`, `for`, `block`, `extends`, `include`,
|
|
16
|
+
* `import`, `macro`, `apply`, `verbatim`, `with`, and `from … import`.
|
|
20
17
|
*/
|
|
21
18
|
|
|
22
19
|
module.exports = {
|
package/lib/tags/macro.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Twig `{% macro %}` tag.
|
|
3
3
|
*
|
|
4
4
|
* Twig macro syntax:
|
|
5
5
|
*
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* binding slots reject any `.` in the match before the
|
|
18
18
|
* `_dangerousProps` check.
|
|
19
19
|
*
|
|
20
|
-
* Twig kwargs (`{% macro foo(a=1, b="x") %}`) are deferred
|
|
21
|
-
*
|
|
20
|
+
* Twig kwargs (`{% macro foo(a=1, b="x") %}`) are deferred with the
|
|
21
|
+
* rest of the Twig-specific surface.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
var ir = require('@rhinostone/swig-core/lib/ir');
|
package/lib/tags/set.js
CHANGED
package/lib/tags/verbatim.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Twig `{% verbatim %}…{% endverbatim %}` tag.
|
|
3
3
|
*
|
|
4
4
|
* Preserves arbitrary template-like content as literal output. Inside
|
|
5
5
|
* a verbatim block, `{{ … }}`, `{% … %}` (other than `{% endverbatim %}`),
|
package/lib/tags/with.js
CHANGED
package/lib/tokentypes.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* but the cognitive overhead of re-mapping IDs across flavors is not
|
|
12
12
|
* worth the freedom.
|
|
13
13
|
*
|
|
14
|
-
* Twig-only IDs (30–37) are reserved here so
|
|
14
|
+
* Twig-only IDs (30–37) are reserved here so later commits can add lexer
|
|
15
15
|
* rules without renumbering. Keeping the layout stable up front avoids
|
|
16
16
|
* silent ID collisions across in-flight flavor work.
|
|
17
17
|
*
|
|
@@ -70,7 +70,7 @@ module.exports = {
|
|
|
70
70
|
/** Method call open — internal */
|
|
71
71
|
METHODOPEN: 25,
|
|
72
72
|
|
|
73
|
-
/* ---- Twig-only token IDs (reserved; rules land
|
|
73
|
+
/* ---- Twig-only token IDs (reserved; rules land later) ---- */
|
|
74
74
|
|
|
75
75
|
/** Twig string-concatenation operator — `~` */
|
|
76
76
|
TILDE: 30,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinostone/swig-twig",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.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.
|
|
25
|
+
"@rhinostone/swig-core": "2.5.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|