|
| 1 | +// Copyright (C) 2024 Richard Gibson. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | +/*--- |
| 4 | +esid: prod-ConditionalExpression |
| 5 | +description: > |
| 6 | + await binds more tightly than conditional operators |
| 7 | +info: | |
| 8 | + ConditionalExpression[In, Yield, Await] : |
| 9 | + ShortCircuitExpression[?In, ?Yield, ?Await] |
| 10 | + ShortCircuitExpression[?In, ?Yield, ?Await] `?` AssignmentExpression[+In, ?Yield, ?Await] `:` AssignmentExpression[?In, ?Yield, ?Await] |
| 11 | + |
| 12 | + ShortCircuitExpression[In, Yield, Await] : |
| 13 | + LogicalORExpression[?In, ?Yield, ?Await] |
| 14 | + CoalesceExpression[?In, ?Yield, ?Await] |
| 15 | + |
| 16 | + LogicalORExpression[In, Yield, Await] : |
| 17 | + LogicalANDExpression[?In, ?Yield, ?Await] |
| 18 | + LogicalORExpression[?In, ?Yield, ?Await] `||` LogicalANDExpression[?In, ?Yield, ?Await] |
| 19 | + |
| 20 | + LogicalANDExpression[In, Yield, Await] : |
| 21 | + BitwiseORExpression[?In, ?Yield, ?Await] |
| 22 | + LogicalANDExpression[?In, ?Yield, ?Await] `&&` BitwiseORExpression[?In, ?Yield, ?Await] |
| 23 | + |
| 24 | + BitwiseORExpression[In, Yield, Await] : |
| 25 | + BitwiseXORExpression[?In, ?Yield, ?Await] |
| 26 | + |
| 27 | + BitwiseXORExpression[In, Yield, Await] : |
| 28 | + BitwiseANDExpression[?In, ?Yield, ?Await] |
| 29 | + |
| 30 | + BitwiseANDExpression[In, Yield, Await] : |
| 31 | + EqualityExpression[?In, ?Yield, ?Await] |
| 32 | + |
| 33 | + EqualityExpression[In, Yield, Await] : |
| 34 | + RelationalExpression[?In, ?Yield, ?Await] |
| 35 | + |
| 36 | + RelationalExpression[In, Yield, Await] : |
| 37 | + ShiftExpression[?Yield, ?Await] |
| 38 | + |
| 39 | + ShiftExpression[Yield, Await] : |
| 40 | + AdditiveExpression[?Yield, ?Await] |
| 41 | + |
| 42 | + AdditiveExpression[Yield, Await] : |
| 43 | + MultiplicativeExpression[?Yield, ?Await] |
| 44 | + |
| 45 | + MultiplicativeExpression[Yield, Await] : |
| 46 | + ExponentiationExpression[?Yield, ?Await] |
| 47 | + |
| 48 | + ExponentiationExpression[Yield, Await] : |
| 49 | + UnaryExpression[?Yield, ?Await] |
| 50 | + |
| 51 | + UnaryExpression[Yield, Await] : |
| 52 | + UpdateExpression[?Yield, ?Await] |
| 53 | + [+Await] AwaitExpression[?Yield] |
| 54 | + |
| 55 | + AwaitExpression[Yield] : |
| 56 | + `await` UnaryExpression[?Yield, +Await] |
| 57 | +flags: [async] |
| 58 | +includes: [asyncHelpers.js] |
| 59 | +---*/ |
| 60 | + |
| 61 | +async function foo() { |
| 62 | + let x = 'initial value'; |
| 63 | + let shouldNotBeAwaited = { |
| 64 | + then: function(onFulfilled) { |
| 65 | + x = 'unexpected then() call'; |
| 66 | + Promise.resolve().then(onFulfilled); |
| 67 | + } |
| 68 | + }; |
| 69 | + // This must parse like `(await false) || shouldNotBeAwaited`. |
| 70 | + await false || shouldNotBeAwaited; |
| 71 | + assert.sameValue(x, 'initial value'); |
| 72 | +} |
| 73 | +asyncTest(foo); |
0 commit comments