1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16let an_array = [1,2,3] 17let element = an_array[0] 18let element1 = an_array[-2] 19an_array[-5] 20an_array[+5] 21an_array[~5] 22an_array[!5] 23class A { 24 a: number = -11; 25 A(){} 26 aa():number{ 27 let ss: number[] = [-1,-5] 28 ss[-2] 29 return ss[0]; 30 } 31} 32function test() { 33 return -1; 34} 35 36let arr: string[] = ['1', '2'] 37arr[-2] 38arr[-0.13536] 39arr[test()] 40arr[test()*6] 41const b: number = -9; 42arr[b] 43let a: A = new A() 44arr[a.a] 45arr[a.aa()] 46 47arr[a.a+5] 48arr[a.aa()*5] 49 50arr[-1*6] 51const m:number = Infinity; 52arr[-Infinity] 53arr[m] 54arr[-m] 55let n:number = Number.MIN_SAFE_INTEGER; 56arr [-Number.MIN_SAFE_INTEGER] 57arr[Number.MIN_SAFE_INTEGER] 58arr[n] 59arr[-n] 60arr[-Number.NaN] 61arr[Number.NaN] 62const p:number = Number.MAX_SAFE_INTEGER; 63arr [-Number.MAX_SAFE_INTEGER] 64arr[Number.MAX_SAFE_INTEGER-5] 65arr[-p] 66arr[-p+7] 67let q:number = Number.POSITIVE_INFINITY 68arr[-Number.POSITIVE_INFINITY] 69arr[q] 70arr[-q] 71const c = Number.NEGATIVE_INFINITY 72arr[-Number.NEGATIVE_INFINITY] 73arr[c] 74const y1 = 6+n 75const y2 = -6-n 76const y3 = -6*m 77const y4 = -6/2 78const y5 = -6/b 79const y6 = -6%5 80arr[y1] 81arr[y2] 82arr[y3] 83arr[y4] 84arr[y5] 85arr[y6] 86const y7 = -(-6/b) 87arr[y7] 88arr[-1 as string] 89arr[-1 as number] 90arr[-1 as Number] 91arr[NaN]; 92arr[-NaN]; 93enum E34 { 94 BLUE = -1, 95} 96let a34 = arr[E34.BLUE]; 97let a35 = arr[-E34.BLUE]; 98const num = -2; 99arr[(num + 1) as number]; 100arr[num as number];