1/* 2 * Copyright (c) 2022-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 16import { 17 Component, 18 State, 19} from '@kit.ArkUI'; 20 21import { ExportLitAsPropName } from './ignore_files/good'; 22 23enum LiteralAsPropertyNameEnum { 24 One = "one", 25 PrivateTwo = "_2", 26 Two = "Two" 27} 28 29class LiteralAsPropertyName { 30 public one: string = "1111111111"; 31 private __2: string; 32 Two: number; 33} 34 35const litAsPropName: LiteralAsPropertyName = { 36 one: "1", 37 __2: 'two', 38 Two: 2.0, 39}; 40 41console.log(litAsPropName.one); 42console.log(litAsPropName.__2); 43console.log(litAsPropName.Two); 44 45class LiteralAsPropertyName_fix { 46 public one: string = "1111111111"; 47 private _2: string; 48 Two: number; 49} 50 51const litAsPropName_fix: LiteralAsPropertyName_fix = { 52 one: "1111111111", 53 _2: 'two', 54 Two: 2.0, 55}; 56 57console.log("Fixed listAsPropName:"); 58console.log(litAsPropName_fix.one); 59console.log(litAsPropName_fix._2); 60console.log(litAsPropName_fix.Two); 61 62let x = {"name": 20.0, 2: 30.0} 63 64console.log(x["name"]); 65console.log(x[2]); 66 67class X_class { 68 public name: number; 69 public _2: number; 70} 71 72interface GeneratedObjectLiteralInterface_1 { 73 name: number; 74 _2: number; 75} 76let x_fix: GeneratedObjectLiteralInterface_1 = {name: 20.0, _2: 20.0}; 77 78console.log("Fixed x object literal:"); 79console.log(x_fix.name); 80console.log(x_fix._2); 81 82interface litAsPropNameIface { 83 one: string; 84 ___2: string; 85 __2: number; 86} 87const int: litAsPropNameIface = { 88 one: '12321', 89 ___2: 'weqwewq', 90 __2: 123.0 91}; 92 93const imp: ExportLitAsPropName = { 1: 234.0 }; 94 95LiteralAsPropertyNameEnum['One'] 96 97LiteralAsPropertyNameEnum.PrivateTwo; 98 99{ 100 const enum Direction { 101 __empty = 1.0, 102 } 103} 104 105const enum Direction16 { 106 ___x5c = 1.0, 107 __x5c = 1.0, 108} 109 110const enum Direction17 { 111 ___x5c = 1.0, 112 __x5c = 1.0, 113} 114let case17: number = Direction17.___x5c 115let case172: number = Direction17.__x5c 116 117const enum Direction11 { 118__x21x21 = 1.0, 119} 120const enum Direction23 { 121aaa = 1.0, 122} 123// ArkUI 124@Component 125struct Index { 126@State message: string = 'Hello World'; 127private case11 = Direction11.__x21x21 128build() { 129} 130} 131 132 133class A{ 134 public age:number = 1.0; 135} 136 137let a:A = { age: 30.0} 138 139 140class B { 141 public age: number = 1.0 // error in arkts2 142} 143 144let obj11: Record<string, number> = { 145 ['value']: 1.0, // Error in arkts 2.0 146 'value2': 1.0 // ok 147} 148 149class CompPropClass { 150 ['CompProp'] = 1.0; // Error in arkts 2.0 151 [2.0] = 'CompProp2'; // Error in arkts 2.0 152 [LiteralAsPropertyNameEnum.One] = 3.0; // Error in arkts 2.0 153} 154 155let compPropObj = { 156 ['CompProp']: 1.0, // Error in arkts 2.0 157 [2.0]: 'CompProp2', // Error in arkts 2.0 158 [LiteralAsPropertyNameEnum.One]: 3.0 // Error in arkts 2.0 159};