optional-chain-prod-expression.js (1147B)
1 // Copyright 2020 Salesforce.com, Inc. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: prod-OptionalExpression 5 description: > 6 Productions for ?. [Expression] 7 info: | 8 OptionalChain: 9 ?.[ Expression ] 10 features: [optional-chaining] 11 ---*/ 12 13 const $ = 'x'; 14 const arr = [39, 42]; 15 16 arr.true = 'prop'; 17 arr[1.1] = 'other prop'; 18 19 const obj = { 20 a: 'hello', 21 undefined: 40, 22 $: 0, 23 NaN: 41, 24 null: 42, 25 x: 43, 26 true: 44 27 }; 28 29 assert.sameValue(arr?.[0], 39, '[0]'); 30 assert.sameValue(arr?.[0, 1], 42, '[0, 1]'); 31 assert.sameValue(arr?.[1], 42, '[1]'); 32 assert.sameValue(arr?.[1, 0], 39, '[1, 0]'); 33 assert.sameValue(arr?.[{}, NaN, undefined, 2, 0, 10 / 10], 42, '[{}, NaN, undefined, 2, 0, 10 / 10]'); 34 assert.sameValue(arr?.[true], 'prop', '[true]'); 35 assert.sameValue(arr?.[1.1], 'other prop', '[1.1]'); 36 37 assert.sameValue(obj?.[undefined], 40, '[undefined]'); 38 assert.sameValue(obj?.[NaN], 41, '[NaN]'); 39 assert.sameValue(obj?.[null], 42, '[null]'); 40 assert.sameValue(obj?.['$'], 0, '["$"]'); 41 assert.sameValue(obj?.[$], 43, '[$]'); 42 assert.sameValue(obj?.[true], 44, '[true]'); 43 44 reportCompare(0, 0);