@nxtedition/lib 23.15.3 → 23.15.5
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.test.js +12 -0
- package/util/template/javascript.js +32 -23
- package/yield.js +3 -2
package/package.json
CHANGED
|
@@ -22,3 +22,15 @@ test('nexpression', async () => {
|
|
|
22
22
|
|
|
23
23
|
assert.strictEqual(await compiler.resolveTemplate('{{ foo }}', { foo: 'bar' }), 'bar')
|
|
24
24
|
})
|
|
25
|
+
|
|
26
|
+
test('pipe short-circuit', async () => {
|
|
27
|
+
const compiler = makeTemplateCompiler({
|
|
28
|
+
ds: {},
|
|
29
|
+
logger: console,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
assert.strictEqual(
|
|
33
|
+
await compiler.resolveTemplate('{{#js _($.id, x => x + "ASD") }}', { foo: 'bar' }),
|
|
34
|
+
undefined,
|
|
35
|
+
)
|
|
36
|
+
})
|
|
@@ -7,6 +7,7 @@ import fp from 'lodash/fp.js'
|
|
|
7
7
|
import moment from 'moment-timezone'
|
|
8
8
|
import Timecode from 'smpte-timecode'
|
|
9
9
|
import transform from './transform.js'
|
|
10
|
+
import { doYield } from '../../yield.js'
|
|
10
11
|
|
|
11
12
|
const SEP = String.fromCharCode(30) // ASCII 1E
|
|
12
13
|
|
|
@@ -223,7 +224,7 @@ function makeWrapper(expression) {
|
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
export default function ({ ds, proxify, compiler, logger, platform }) {
|
|
226
|
-
const schedule = platform?.schedule ??
|
|
227
|
+
const schedule = platform?.schedule ?? doYield
|
|
227
228
|
|
|
228
229
|
class Expression {
|
|
229
230
|
constructor(script, expression, args, observer) {
|
|
@@ -244,6 +245,15 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
|
|
|
244
245
|
this._wrap = null
|
|
245
246
|
this._suspended = false
|
|
246
247
|
this._errored = false
|
|
248
|
+
this._globalThis = {
|
|
249
|
+
fp: null,
|
|
250
|
+
moment: null,
|
|
251
|
+
Timecode: null,
|
|
252
|
+
datefns: null,
|
|
253
|
+
JSON5: null,
|
|
254
|
+
$: null,
|
|
255
|
+
nxt: null,
|
|
256
|
+
}
|
|
247
257
|
|
|
248
258
|
if (rxjs.isObservable(args)) {
|
|
249
259
|
this._subscription = args.subscribe({
|
|
@@ -257,7 +267,7 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
|
|
|
257
267
|
})
|
|
258
268
|
} else {
|
|
259
269
|
this._args = proxify ? this.wrap(args) : args
|
|
260
|
-
this.
|
|
270
|
+
this._refresh()
|
|
261
271
|
}
|
|
262
272
|
}
|
|
263
273
|
|
|
@@ -361,15 +371,13 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
|
|
|
361
371
|
throw new Error('expression is already suspended')
|
|
362
372
|
}
|
|
363
373
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
nxt: globalThis.nxt,
|
|
372
|
-
}
|
|
374
|
+
this._globalThis.fp = globalThis.fp
|
|
375
|
+
this._globalThis.moment = globalThis.moment
|
|
376
|
+
this._globalThis.Timecode = globalThis.Timecode
|
|
377
|
+
this._globalThis.datefns = globalThis.datefns
|
|
378
|
+
this._globalThis.JSON5 = globalThis.JSON5
|
|
379
|
+
this._globalThis.$ = globalThis.$
|
|
380
|
+
this._globalThis.nxt = globalThis.nxt
|
|
373
381
|
|
|
374
382
|
let value
|
|
375
383
|
try {
|
|
@@ -387,14 +395,13 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
|
|
|
387
395
|
// - Use https://github.com/tc39/proposal-shadowrealm?
|
|
388
396
|
value = this._script()
|
|
389
397
|
} finally {
|
|
390
|
-
globalThis.fp =
|
|
391
|
-
globalThis.
|
|
392
|
-
globalThis.
|
|
393
|
-
globalThis.
|
|
394
|
-
globalThis.
|
|
395
|
-
globalThis
|
|
396
|
-
globalThis
|
|
397
|
-
globalThis.nxt = savedThis.nxt
|
|
398
|
+
globalThis.fp = this._globalThis.fp
|
|
399
|
+
globalThis.moment = this._globalThis.moment
|
|
400
|
+
globalThis.Timecode = this._globalThis.Timecode
|
|
401
|
+
globalThis.datefns = this._globalThis.datefns
|
|
402
|
+
globalThis.JSON5 = this._globalThis.JSON5
|
|
403
|
+
globalThis.$ = this._globalThis.$
|
|
404
|
+
globalThis.nxt = this._globalThis.nxt
|
|
398
405
|
}
|
|
399
406
|
|
|
400
407
|
this._errored = false
|
|
@@ -624,10 +631,12 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
|
|
|
624
631
|
script = new Function(
|
|
625
632
|
transform(`
|
|
626
633
|
const _ = (value, ...fns) => {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
634
|
+
if (value != null) {
|
|
635
|
+
for (const fn of fns) {
|
|
636
|
+
value = fn(value)
|
|
637
|
+
if (value == null) {
|
|
638
|
+
return value
|
|
639
|
+
}
|
|
631
640
|
}
|
|
632
641
|
}
|
|
633
642
|
return value
|
package/yield.js
CHANGED
|
@@ -2,6 +2,7 @@ import { FixedQueue } from './fixed-queue.js'
|
|
|
2
2
|
|
|
3
3
|
const yieldTimeout = 50
|
|
4
4
|
const yieldQueue = new FixedQueue()
|
|
5
|
+
const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
|
|
5
6
|
let yieldScheduled = false
|
|
6
7
|
let yieldTime = performance.now()
|
|
7
8
|
let yieldActive = false
|
|
@@ -17,7 +18,7 @@ export function maybeYield(opts, callback) {
|
|
|
17
18
|
export function doYield(opts, callback) {
|
|
18
19
|
if (!yieldScheduled) {
|
|
19
20
|
yieldScheduled = true
|
|
20
|
-
|
|
21
|
+
yieldSchedule(dispatchYield)
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
if (callback) {
|
|
@@ -44,7 +45,7 @@ function dispatchYield() {
|
|
|
44
45
|
resolve(null)
|
|
45
46
|
|
|
46
47
|
if (performance.now() - yieldTime > yieldTimeout) {
|
|
47
|
-
|
|
48
|
+
yieldSchedule(dispatchYield)
|
|
48
49
|
return
|
|
49
50
|
}
|
|
50
51
|
}
|