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