@player-ui/async-node-plugin 0.11.3--canary.649.23399 → 0.11.3--canary.649.23416

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.
@@ -3641,8 +3641,19 @@ var AsyncNodePlugin = function() {
3641
3641
  return _context.model.delete(binding);
3642
3642
  };
3643
3643
  var conditional = function(ctx, condition, ifTrue, ifFalse) {
3644
- var resolution = ctx.evaluate(condition);
3645
- if (resolution) {
3644
+ var testResult = ctx.evaluate(condition);
3645
+ if (_instanceof(testResult, Promise)) {
3646
+ return testResult.then(function(resolvedTest) {
3647
+ if (resolvedTest) {
3648
+ return ctx.evaluate(ifTrue);
3649
+ }
3650
+ if (ifFalse) {
3651
+ return ctx.evaluate(ifFalse);
3652
+ }
3653
+ return null;
3654
+ });
3655
+ }
3656
+ if (testResult) {
3646
3657
  return ctx.evaluate(ifTrue);
3647
3658
  }
3648
3659
  if (ifFalse) {
@@ -3856,9 +3867,6 @@ var AsyncNodePlugin = function() {
3856
3867
  }
3857
3868
  });
3858
3869
  this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
3859
- if (options.async) {
3860
- return _this._resolveNodeAsync(result, node, options);
3861
- }
3862
3870
  return _this._resolveNode(result, node, options);
3863
3871
  });
3864
3872
  this.evaluate = this.evaluate.bind(this);
@@ -4004,9 +4012,31 @@ var AsyncNodePlugin = function() {
4004
4012
  if (operator.resolveParams === false) {
4005
4013
  return operator(expressionContext, node.left, node.right);
4006
4014
  }
4007
- return operator(expressionContext, resolveNode(node.left), resolveNode(node.right));
4015
+ var left2 = resolveNode(node.left);
4016
+ var right2 = resolveNode(node.right);
4017
+ if (isPromiselike(left2) || isPromiselike(right2)) {
4018
+ return Promise.all([
4019
+ left2,
4020
+ right2
4021
+ ]).then(function(param) {
4022
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4023
+ return operator(expressionContext, leftVal, rightVal);
4024
+ });
4025
+ }
4026
+ return operator(expressionContext, left2, right2);
4027
+ }
4028
+ var left = resolveNode(node.left);
4029
+ var right = resolveNode(node.right);
4030
+ if (isPromiselike(left) || isPromiselike(right)) {
4031
+ return Promise.all([
4032
+ left,
4033
+ right
4034
+ ]).then(function(param) {
4035
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4036
+ return operator(leftVal, rightVal);
4037
+ });
4008
4038
  }
4009
- return operator(resolveNode(node.left), resolveNode(node.right));
4039
+ return operator(left, right);
4010
4040
  }
4011
4041
  return;
4012
4042
  }
@@ -4014,9 +4044,24 @@ var AsyncNodePlugin = function() {
4014
4044
  var operator1 = this.operators.unary.get(node.operator);
4015
4045
  if (operator1) {
4016
4046
  if ("resolveParams" in operator1) {
4017
- return operator1(expressionContext, operator1.resolveParams === false ? node.argument : resolveNode(node.argument));
4047
+ if (operator1.resolveParams === false) {
4048
+ return operator1(expressionContext, node.argument);
4049
+ }
4050
+ var arg2 = resolveNode(node.argument);
4051
+ if (isPromiselike(arg2)) {
4052
+ return arg2.then(function(argVal) {
4053
+ return operator1(expressionContext, argVal);
4054
+ });
4055
+ }
4056
+ return operator1(expressionContext, arg2);
4018
4057
  }
4019
- return operator1(resolveNode(node.argument));
4058
+ var arg = resolveNode(node.argument);
4059
+ if (isPromiselike(arg)) {
4060
+ return arg.then(function(argVal) {
4061
+ return operator1(argVal);
4062
+ });
4063
+ }
4064
+ return operator1(arg);
4020
4065
  }
4021
4066
  return;
4022
4067
  }
@@ -4037,6 +4082,14 @@ var AsyncNodePlugin = function() {
4037
4082
  var args = node.args.map(function(n) {
4038
4083
  return resolveNode(n);
4039
4084
  });
4085
+ var hasPromises = args.some(isPromiselike);
4086
+ if (hasPromises) {
4087
+ return Promise.all(args).then(function(resolvedArgs) {
4088
+ return operator2.apply(void 0, [
4089
+ expressionContext
4090
+ ].concat(_to_consumable_array(resolvedArgs)));
4091
+ });
4092
+ }
4040
4093
  return operator2.apply(void 0, [
4041
4094
  expressionContext
4042
4095
  ].concat(_to_consumable_array(args)));
@@ -4051,11 +4104,31 @@ var AsyncNodePlugin = function() {
4051
4104
  if (node.type === "MemberExpression") {
4052
4105
  var obj = resolveNode(node.object);
4053
4106
  var prop = resolveNode(node.property);
4107
+ if (isPromiselike(obj) || isPromiselike(prop)) {
4108
+ return Promise.all([
4109
+ obj,
4110
+ prop
4111
+ ]).then(function(param) {
4112
+ var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
4113
+ return objVal[propVal];
4114
+ });
4115
+ }
4054
4116
  return obj[prop];
4055
4117
  }
4056
4118
  if (node.type === "Assignment") {
4057
4119
  if (node.left.type === "ModelRef") {
4058
4120
  var value = resolveNode(node.right);
4121
+ if (isPromiselike(value)) {
4122
+ return value.then(function(resolvedValue) {
4123
+ model.set([
4124
+ [
4125
+ node.left.ref,
4126
+ resolvedValue
4127
+ ]
4128
+ ]);
4129
+ return resolvedValue;
4130
+ });
4131
+ }
4059
4132
  model.set([
4060
4133
  [
4061
4134
  node.left.ref,
@@ -4066,6 +4139,12 @@ var AsyncNodePlugin = function() {
4066
4139
  }
4067
4140
  if (node.left.type === "Identifier") {
4068
4141
  var value1 = resolveNode(node.right);
4142
+ if (isPromiselike(value1)) {
4143
+ return value1.then(function(resolvedValue) {
4144
+ _this.vars[node.left.name] = resolvedValue;
4145
+ return resolvedValue;
4146
+ });
4147
+ }
4069
4148
  this.vars[node.left.name] = value1;
4070
4149
  return value1;
4071
4150
  }
@@ -4093,12 +4172,47 @@ var AsyncNodePlugin = function() {
4093
4172
  if (operation.resolveParams === false) {
4094
4173
  newValue = operation(expressionContext, node.left, node.right);
4095
4174
  } else {
4096
- newValue = operation(expressionContext, resolveNode(node.left), resolveNode(node.right));
4175
+ var left1 = resolveNode(node.left);
4176
+ var right1 = resolveNode(node.right);
4177
+ if (isPromiselike(left1) || isPromiselike(right1)) {
4178
+ newValue = Promise.all([
4179
+ left1,
4180
+ right1
4181
+ ]).then(function(param) {
4182
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4183
+ return operation(expressionContext, leftVal, rightVal);
4184
+ });
4185
+ } else {
4186
+ newValue = operation(expressionContext, left1, right1);
4187
+ }
4097
4188
  }
4098
4189
  } else {
4099
- newValue = operation(resolveNode(node.left), resolveNode(node.right));
4190
+ var left3 = resolveNode(node.left);
4191
+ var right3 = resolveNode(node.right);
4192
+ if (isPromiselike(left3) || isPromiselike(right3)) {
4193
+ newValue = Promise.all([
4194
+ left3,
4195
+ right3
4196
+ ]).then(function(param) {
4197
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4198
+ return operation(leftVal, rightVal);
4199
+ });
4200
+ } else {
4201
+ newValue = operation(left3, right3);
4202
+ }
4100
4203
  }
4101
4204
  if (node.left.type === "ModelRef") {
4205
+ if (isPromiselike(newValue)) {
4206
+ return newValue.then(function(resolvedValue) {
4207
+ model.set([
4208
+ [
4209
+ node.left.ref,
4210
+ resolvedValue
4211
+ ]
4212
+ ]);
4213
+ return resolvedValue;
4214
+ });
4215
+ }
4102
4216
  model.set([
4103
4217
  [
4104
4218
  node.left.ref,
@@ -4106,6 +4220,12 @@ var AsyncNodePlugin = function() {
4106
4220
  ]
4107
4221
  ]);
4108
4222
  } else if (node.left.type === "Identifier") {
4223
+ if (isPromiselike(newValue)) {
4224
+ return newValue.then(function(resolvedValue) {
4225
+ _this.vars[node.left.name] = resolvedValue;
4226
+ return resolvedValue;
4227
+ });
4228
+ }
4109
4229
  this.vars[node.left.name] = newValue;
4110
4230
  }
4111
4231
  return newValue;
@@ -4113,459 +4233,6 @@ var AsyncNodePlugin = function() {
4113
4233
  return resolveNode(node.left);
4114
4234
  }
4115
4235
  }
4116
- },
4117
- {
4118
- key: "_resolveNodeAsync",
4119
- value: function _resolveNodeAsync(_currentValue, node, options) {
4120
- var _this = this;
4121
- return _async_to_generator(function() {
4122
- var resolveNode, model, expressionContext, operator, _tmp, _tmp1, operator1, _tmp2, _tmp3, attributes, resolvedAttributes, expressionName, operator2, args, obj, prop, value, value1, testResult, result, branchResult, operation, newValue, _tmp4, _tmp5;
4123
- return _ts_generator(this, function(_state) {
4124
- switch(_state.label){
4125
- case 0:
4126
- resolveNode = options.resolveNode, model = options.model;
4127
- expressionContext = _object_spread_props(_object_spread({}, options), {
4128
- evaluate: function(expr) {
4129
- return _this.evaluate(expr, options);
4130
- }
4131
- });
4132
- if (!(node.type === "BinaryExpression" || node.type === "LogicalExpression")) return [
4133
- 3,
4134
- 7
4135
- ];
4136
- operator = _this.operators.binary.get(node.operator);
4137
- if (!operator) return [
4138
- 3,
4139
- 6
4140
- ];
4141
- if (!("resolveParams" in operator)) return [
4142
- 3,
4143
- 3
4144
- ];
4145
- if (operator.resolveParams === false) {
4146
- return [
4147
- 2,
4148
- operator(expressionContext, node.left, node.right)
4149
- ];
4150
- }
4151
- _tmp = [
4152
- expressionContext
4153
- ];
4154
- return [
4155
- 4,
4156
- resolveNode(node.left)
4157
- ];
4158
- case 1:
4159
- _tmp = _tmp.concat([
4160
- _state.sent()
4161
- ]);
4162
- return [
4163
- 4,
4164
- resolveNode(node.right)
4165
- ];
4166
- case 2:
4167
- return [
4168
- 2,
4169
- operator.apply(void 0, _tmp.concat([
4170
- _state.sent()
4171
- ]))
4172
- ];
4173
- case 3:
4174
- return [
4175
- 4,
4176
- resolveNode(node.left)
4177
- ];
4178
- case 4:
4179
- _tmp1 = [
4180
- _state.sent()
4181
- ];
4182
- return [
4183
- 4,
4184
- resolveNode(node.right)
4185
- ];
4186
- case 5:
4187
- return [
4188
- 2,
4189
- operator.apply(void 0, _tmp1.concat([
4190
- _state.sent()
4191
- ]))
4192
- ];
4193
- case 6:
4194
- return [
4195
- 2
4196
- ];
4197
- case 7:
4198
- if (!(node.type === "UnaryExpression")) return [
4199
- 3,
4200
- 14
4201
- ];
4202
- operator1 = _this.operators.unary.get(node.operator);
4203
- if (!operator1) return [
4204
- 3,
4205
- 13
4206
- ];
4207
- if (!("resolveParams" in operator1)) return [
4208
- 3,
4209
- 11
4210
- ];
4211
- _tmp2 = [
4212
- expressionContext
4213
- ];
4214
- if (!(operator1.resolveParams === false)) return [
4215
- 3,
4216
- 8
4217
- ];
4218
- _tmp3 = node.argument;
4219
- return [
4220
- 3,
4221
- 10
4222
- ];
4223
- case 8:
4224
- return [
4225
- 4,
4226
- resolveNode(node.argument)
4227
- ];
4228
- case 9:
4229
- _tmp3 = _state.sent();
4230
- _state.label = 10;
4231
- case 10:
4232
- return [
4233
- 2,
4234
- operator1.apply(void 0, _tmp2.concat([
4235
- _tmp3
4236
- ]))
4237
- ];
4238
- case 11:
4239
- return [
4240
- 4,
4241
- resolveNode(node.argument)
4242
- ];
4243
- case 12:
4244
- return [
4245
- 2,
4246
- operator1.apply(void 0, [
4247
- _state.sent()
4248
- ])
4249
- ];
4250
- case 13:
4251
- return [
4252
- 2
4253
- ];
4254
- case 14:
4255
- if (!(node.type === "Object")) return [
4256
- 3,
4257
- 16
4258
- ];
4259
- attributes = node.attributes;
4260
- resolvedAttributes = {};
4261
- return [
4262
- 4,
4263
- Promise.all(attributes.map(function() {
4264
- var _ref = _async_to_generator(function(attr) {
4265
- var key, value;
4266
- return _ts_generator(this, function(_state) {
4267
- switch(_state.label){
4268
- case 0:
4269
- return [
4270
- 4,
4271
- resolveNode(attr.key)
4272
- ];
4273
- case 1:
4274
- key = _state.sent();
4275
- return [
4276
- 4,
4277
- resolveNode(attr.value)
4278
- ];
4279
- case 2:
4280
- value = _state.sent();
4281
- resolvedAttributes[key] = value;
4282
- return [
4283
- 2
4284
- ];
4285
- }
4286
- });
4287
- });
4288
- return function(attr) {
4289
- return _ref.apply(this, arguments);
4290
- };
4291
- }()))
4292
- ];
4293
- case 15:
4294
- _state.sent();
4295
- return [
4296
- 2,
4297
- resolvedAttributes
4298
- ];
4299
- case 16:
4300
- if (!(node.type === "CallExpression")) return [
4301
- 3,
4302
- 18
4303
- ];
4304
- expressionName = node.callTarget.name;
4305
- operator2 = _this.operators.expressions.get(expressionName);
4306
- if (!operator2) {
4307
- throw new Error("Unknown expression function: ".concat(expressionName));
4308
- }
4309
- if ("resolveParams" in operator2 && operator2.resolveParams === false) {
4310
- return [
4311
- 2,
4312
- operator2.apply(void 0, [
4313
- expressionContext
4314
- ].concat(_to_consumable_array(node.args)))
4315
- ];
4316
- }
4317
- return [
4318
- 4,
4319
- Promise.all(node.args.map(function() {
4320
- var _ref = _async_to_generator(function(n) {
4321
- return _ts_generator(this, function(_state) {
4322
- switch(_state.label){
4323
- case 0:
4324
- return [
4325
- 4,
4326
- resolveNode(n)
4327
- ];
4328
- case 1:
4329
- return [
4330
- 2,
4331
- _state.sent()
4332
- ];
4333
- }
4334
- });
4335
- });
4336
- return function(n) {
4337
- return _ref.apply(this, arguments);
4338
- };
4339
- }()))
4340
- ];
4341
- case 17:
4342
- args = _state.sent();
4343
- return [
4344
- 2,
4345
- operator2.apply(void 0, [
4346
- expressionContext
4347
- ].concat(_to_consumable_array(args)))
4348
- ];
4349
- case 18:
4350
- if (node.type === "ModelRef") {
4351
- return [
4352
- 2,
4353
- model.get(node.ref, {
4354
- context: {
4355
- model: options.model
4356
- }
4357
- })
4358
- ];
4359
- }
4360
- if (!(node.type === "MemberExpression")) return [
4361
- 3,
4362
- 21
4363
- ];
4364
- return [
4365
- 4,
4366
- resolveNode(node.object)
4367
- ];
4368
- case 19:
4369
- obj = _state.sent();
4370
- return [
4371
- 4,
4372
- resolveNode(node.property)
4373
- ];
4374
- case 20:
4375
- prop = _state.sent();
4376
- return [
4377
- 2,
4378
- obj[prop]
4379
- ];
4380
- case 21:
4381
- if (!(node.type === "Assignment")) return [
4382
- 3,
4383
- 26
4384
- ];
4385
- if (!(node.left.type === "ModelRef")) return [
4386
- 3,
4387
- 23
4388
- ];
4389
- return [
4390
- 4,
4391
- resolveNode(node.right)
4392
- ];
4393
- case 22:
4394
- value = _state.sent();
4395
- model.set([
4396
- [
4397
- node.left.ref,
4398
- value
4399
- ]
4400
- ]);
4401
- return [
4402
- 2,
4403
- value
4404
- ];
4405
- case 23:
4406
- if (!(node.left.type === "Identifier")) return [
4407
- 3,
4408
- 25
4409
- ];
4410
- return [
4411
- 4,
4412
- resolveNode(node.right)
4413
- ];
4414
- case 24:
4415
- value1 = _state.sent();
4416
- _this.vars[node.left.name] = value1;
4417
- return [
4418
- 2,
4419
- value1
4420
- ];
4421
- case 25:
4422
- return [
4423
- 2
4424
- ];
4425
- case 26:
4426
- if (!(node.type === "ConditionalExpression")) return [
4427
- 3,
4428
- 29
4429
- ];
4430
- return [
4431
- 4,
4432
- resolveNode(node.test)
4433
- ];
4434
- case 27:
4435
- testResult = _state.sent();
4436
- result = testResult ? node.consequent : node.alternate;
4437
- return [
4438
- 4,
4439
- resolveNode(result)
4440
- ];
4441
- case 28:
4442
- branchResult = _state.sent();
4443
- return [
4444
- 2,
4445
- branchResult
4446
- ];
4447
- case 29:
4448
- if (node.type === "ArrayExpression") {
4449
- return [
4450
- 2,
4451
- Promise.all(node.elements.map(function() {
4452
- var _ref = _async_to_generator(function(ele) {
4453
- return _ts_generator(this, function(_state) {
4454
- switch(_state.label){
4455
- case 0:
4456
- return [
4457
- 4,
4458
- resolveNode(ele)
4459
- ];
4460
- case 1:
4461
- return [
4462
- 2,
4463
- _state.sent()
4464
- ];
4465
- }
4466
- });
4467
- });
4468
- return function(ele) {
4469
- return _ref.apply(this, arguments);
4470
- };
4471
- }()))
4472
- ];
4473
- }
4474
- if (!(node.type === "Modification")) return [
4475
- 3,
4476
- 39
4477
- ];
4478
- operation = _this.operators.binary.get(node.operator);
4479
- if (!operation) return [
4480
- 3,
4481
- 38
4482
- ];
4483
- if (!("resolveParams" in operation)) return [
4484
- 3,
4485
- 34
4486
- ];
4487
- if (!(operation.resolveParams === false)) return [
4488
- 3,
4489
- 30
4490
- ];
4491
- newValue = operation(expressionContext, node.left, node.right);
4492
- return [
4493
- 3,
4494
- 33
4495
- ];
4496
- case 30:
4497
- _tmp4 = [
4498
- expressionContext
4499
- ];
4500
- return [
4501
- 4,
4502
- resolveNode(node.left)
4503
- ];
4504
- case 31:
4505
- _tmp4 = _tmp4.concat([
4506
- _state.sent()
4507
- ]);
4508
- return [
4509
- 4,
4510
- resolveNode(node.right)
4511
- ];
4512
- case 32:
4513
- newValue = operation.apply(void 0, _tmp4.concat([
4514
- _state.sent()
4515
- ]));
4516
- _state.label = 33;
4517
- case 33:
4518
- return [
4519
- 3,
4520
- 37
4521
- ];
4522
- case 34:
4523
- return [
4524
- 4,
4525
- resolveNode(node.left)
4526
- ];
4527
- case 35:
4528
- _tmp5 = [
4529
- _state.sent()
4530
- ];
4531
- return [
4532
- 4,
4533
- resolveNode(node.right)
4534
- ];
4535
- case 36:
4536
- newValue = operation.apply(void 0, _tmp5.concat([
4537
- _state.sent()
4538
- ]));
4539
- _state.label = 37;
4540
- case 37:
4541
- if (node.left.type === "ModelRef") {
4542
- model.set([
4543
- [
4544
- node.left.ref,
4545
- newValue
4546
- ]
4547
- ]);
4548
- } else if (node.left.type === "Identifier") {
4549
- _this.vars[node.left.name] = newValue;
4550
- }
4551
- return [
4552
- 2,
4553
- newValue
4554
- ];
4555
- case 38:
4556
- return [
4557
- 2,
4558
- resolveNode(node.left)
4559
- ];
4560
- case 39:
4561
- return [
4562
- 2,
4563
- _this._resolveNode(_currentValue, node, options)
4564
- ];
4565
- }
4566
- });
4567
- })();
4568
- }
4569
4236
  }
4570
4237
  ]);
4571
4238
  return ExpressionEvaluator;