@nxtedition/lib 14.0.13 → 14.0.15
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/package.json +1 -1
- package/util/template/index.js +24 -16
- package/util/template/javascript.js +11 -4
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -10,6 +10,10 @@ const weakCache = require('../../weakCache')
|
|
|
10
10
|
module.exports = ({ ds, proxify }) => {
|
|
11
11
|
const compiler = {
|
|
12
12
|
current: null,
|
|
13
|
+
resolveTemplate,
|
|
14
|
+
onResolveTemplate,
|
|
15
|
+
compileTemplate,
|
|
16
|
+
isTemplate,
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
const compilers = {
|
|
@@ -154,19 +158,28 @@ module.exports = ({ ds, proxify }) => {
|
|
|
154
158
|
|
|
155
159
|
const { pre, type, body, post } = match
|
|
156
160
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
throw new Error('unknown expression type: ' + type)
|
|
160
|
-
}
|
|
161
|
+
if (type === 'js') {
|
|
162
|
+
const expr = compilers.js(body)
|
|
161
163
|
|
|
162
|
-
|
|
164
|
+
if (!pre && !post) {
|
|
165
|
+
return (str, args$) => expr(args$)
|
|
166
|
+
}
|
|
163
167
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
return (str, args$) => expr(args$).pipe(rx.map((body) => `${pre}${stringify(body)}${post}`))
|
|
169
|
+
} else if (type === 'nxt') {
|
|
170
|
+
const expr = compilers.nxt(body)
|
|
167
171
|
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
if (!pre && !post) {
|
|
173
|
+
return (str, args$) => expr(args$)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return (str, args$) =>
|
|
177
|
+
expr(args$).pipe(
|
|
178
|
+
rx.switchMap((body) => onResolveTemplate(`${pre}${stringify(body, true)}${post}`, args$))
|
|
179
|
+
)
|
|
180
|
+
} else {
|
|
181
|
+
throw new Error('unknown expression type: ' + type)
|
|
182
|
+
}
|
|
170
183
|
}
|
|
171
184
|
|
|
172
185
|
function stringify(value, escape) {
|
|
@@ -216,10 +229,5 @@ module.exports = ({ ds, proxify }) => {
|
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
231
|
|
|
219
|
-
return
|
|
220
|
-
resolveTemplate,
|
|
221
|
-
onResolveTemplate,
|
|
222
|
-
compileTemplate,
|
|
223
|
-
isTemplate,
|
|
224
|
-
})
|
|
232
|
+
return compiler
|
|
225
233
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const assert = require('node:assert')
|
|
1
2
|
const weakCache = require('../../weakCache')
|
|
2
3
|
const rxjs = require('rxjs')
|
|
3
4
|
const vm = require('node:vm')
|
|
@@ -174,10 +175,13 @@ const globals = {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
function proxify(value, expression, handler) {
|
|
178
|
+
assert(expression)
|
|
179
|
+
assert(handler)
|
|
180
|
+
|
|
177
181
|
if (!value) {
|
|
178
182
|
return value
|
|
179
183
|
} else if (rxjs.isObservable(value)) {
|
|
180
|
-
return proxify(expression.observe(value), expression)
|
|
184
|
+
return proxify(expression.observe(value), expression, handler)
|
|
181
185
|
} else if (typeof value?.then === 'function') {
|
|
182
186
|
return proxify(expression.wait(value), expression, handler)
|
|
183
187
|
} else if (typeof value === 'object') {
|
|
@@ -191,7 +195,7 @@ const MAP_POOL = []
|
|
|
191
195
|
|
|
192
196
|
function makeWrapper(expression) {
|
|
193
197
|
const handler = {
|
|
194
|
-
get: (target, prop) => proxify(target[prop],
|
|
198
|
+
get: (target, prop) => proxify(target[prop], expression, handler),
|
|
195
199
|
}
|
|
196
200
|
return (value) => proxify(value, expression, handler)
|
|
197
201
|
}
|
|
@@ -319,8 +323,11 @@ module.exports = ({ ds, proxify, compiler }) => {
|
|
|
319
323
|
// TODO (fix): freeze?
|
|
320
324
|
self._context.$ = self._args
|
|
321
325
|
self._context.nxt = self
|
|
326
|
+
|
|
327
|
+
const previous = compiler.current
|
|
328
|
+
compiler.current = self
|
|
329
|
+
|
|
322
330
|
try {
|
|
323
|
-
compiler.current = this
|
|
324
331
|
const value = self._script.runInContext(self._context)
|
|
325
332
|
if (value !== self._value) {
|
|
326
333
|
self._value = value
|
|
@@ -338,7 +345,7 @@ module.exports = ({ ds, proxify, compiler }) => {
|
|
|
338
345
|
})
|
|
339
346
|
)
|
|
340
347
|
} finally {
|
|
341
|
-
compiler.current =
|
|
348
|
+
compiler.current = previous
|
|
342
349
|
|
|
343
350
|
self._context.$ = null
|
|
344
351
|
self._context.nxt = null
|