@idlizer/arktscgen 2.1.10-arktscgen-9 → 2.1.10-arktscgen-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,6 +61,7 @@ export interface ProjectConfig {
61
61
  frameworkMode?: string;
62
62
  isUi2abc?: boolean;
63
63
  memoPluginOptions?: Object;
64
+ uiPluginOptions?: Object;
64
65
  }
65
66
 
66
67
  export interface PluginContextBase {
@@ -56,22 +56,34 @@ function round(value: number, index: number = 2): number {
56
56
  return Math.round(value * factor) / factor;
57
57
  }
58
58
 
59
+ interface DetailedEventInfo {
60
+ duration: number;
61
+ count: number;
62
+ }
63
+
59
64
  export class Performance {
60
65
  private static instance: Performance;
61
66
  private events: Map<string, Event>;
67
+ private detailedEvents: Map<string, Event>;
62
68
  private historyEvents = new Map<string | null, Event[]>();
63
69
  private scopes: string[];
64
70
  private shouldSkip: boolean;
71
+ private shouldSkipDetail: boolean;
65
72
  private totalDuration: number;
66
73
  private memoryContexts = new Map<string, MemoryContext>();
67
74
  private memoryTrackerEnable: boolean;
75
+ private detailedEventInfos: Map<string, DetailedEventInfo>;
76
+
68
77
  private constructor() {
69
78
  this.events = new Map();
79
+ this.detailedEvents = new Map();
70
80
  this.historyEvents = new Map();
71
81
  this.scopes = [];
72
82
  this.shouldSkip = true;
83
+ this.shouldSkipDetail = true;
73
84
  this.memoryTrackerEnable = false;
74
85
  this.totalDuration = 0;
86
+ this.detailedEventInfos = new Map<string, DetailedEventInfo>();
75
87
  }
76
88
 
77
89
  public static getInstance(): Performance {
@@ -81,8 +93,14 @@ export class Performance {
81
93
  return this.instance;
82
94
  }
83
95
 
84
- skip(shouldSkip: boolean = true): void {
96
+ skip(shouldSkip: boolean = true): this {
85
97
  this.shouldSkip = shouldSkip;
98
+ return this;
99
+ }
100
+
101
+ skipDetail(shouldSkipDetail: boolean = true): this {
102
+ this.shouldSkipDetail = shouldSkipDetail;
103
+ return this;
86
104
  }
87
105
 
88
106
  enableMemoryTracker(enableMemoryTracker: boolean = false): void {
@@ -100,6 +118,57 @@ export class Performance {
100
118
  return newEvent;
101
119
  }
102
120
 
121
+ logDetailedEventInfos(shouldLog: boolean = false): void {
122
+ if (!shouldLog) {
123
+ return;
124
+ }
125
+ const sortedEvents = new Map([...this.detailedEventInfos.entries()].sort((a, b) => a[0].localeCompare(b[0])));
126
+ for (const [key, value] of sortedEvents) {
127
+ const dura = formatTime(value.duration);
128
+ const duraRound = round(value.duration);
129
+ const perDura = formatTime(value.duration / value.count);
130
+ const duraPerDura = round(value.duration / value.count);
131
+ console.log(
132
+ `[PERFORMANCE] name: ${key}, detailed-total-duration: ${dura}(${duraRound}), total-count: ${value.count}, time-per-conversion: ${perDura}(${duraPerDura})`
133
+ );
134
+ }
135
+ }
136
+
137
+ createDetailedEvent(name: string) {
138
+ if (this.shouldSkipDetail) {
139
+ return { name: '', startTime: 0 };
140
+ }
141
+ const startTime: number = performance.now();
142
+ const newEvent: Event = { name, startTime };
143
+ this.detailedEvents.set(name, newEvent);
144
+ }
145
+
146
+ stopDetailedEvent(name: string, shouldLog: boolean = false) {
147
+ if (this.shouldSkipDetail) {
148
+ return { name: '', startTime: 0 };
149
+ }
150
+ if (!this.detailedEvents.has(name)) {
151
+ throw new Error(`Event ${name} is not created.`);
152
+ }
153
+
154
+ const event: Event = this.detailedEvents.get(name)!;
155
+ const endTime: number = performance.now();
156
+ const duration: number = endTime - event.startTime;
157
+
158
+ let totalDetailedDuration = duration;
159
+ let totalDetailedCount = 1;
160
+ if (this.detailedEventInfos.has(name)) {
161
+ const lastInfo = this.detailedEventInfos.get(name)!;
162
+ totalDetailedDuration += lastInfo.duration;
163
+ totalDetailedCount += lastInfo.count;
164
+ }
165
+
166
+ this.detailedEventInfos.set(name, {
167
+ duration: totalDetailedDuration,
168
+ count: totalDetailedCount,
169
+ });
170
+ }
171
+
103
172
  stopEvent(name: string, shouldLog: boolean = false): Event {
104
173
  if (this.shouldSkip) {
105
174
  return { name: '', startTime: 0 };
@@ -122,7 +191,9 @@ export class Performance {
122
191
 
123
192
  if (shouldLog) {
124
193
  console.log(
125
- `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(duration)}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
194
+ `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(
195
+ duration
196
+ )}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
126
197
  );
127
198
  }
128
199
 
@@ -154,7 +225,9 @@ export class Performance {
154
225
 
155
226
  if (shouldLog) {
156
227
  console.log(
157
- `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(duration)}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
228
+ `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(
229
+ duration
230
+ )}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
158
231
  );
159
232
  }
160
233
 
@@ -176,6 +249,8 @@ export class Performance {
176
249
 
177
250
  clearTotalDuration(): void {
178
251
  this.totalDuration = 0;
252
+ this.detailedEventInfos.clear();
253
+ this.detailedEvents.clear();
179
254
  }
180
255
 
181
256
  clearHistory(): void {
@@ -273,23 +348,38 @@ export class Performance {
273
348
  console.log('---------------------------------------------------------------');
274
349
  console.log(
275
350
  '[PERFORMANCE]',
276
- `RSS | ${context.startMemory.rss.toFixed(2)} | ${(endMemory.rss / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.rss.toFixed(2)}`
351
+ `RSS | ${context.startMemory.rss.toFixed(2)} | ${(
352
+ endMemory.rss /
353
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
354
+ ).toFixed(2)} | ${memoryDiff.rss.toFixed(2)}`
277
355
  );
278
356
  console.log(
279
357
  '[PERFORMANCE]',
280
- `Heap Total | ${context.startMemory.heapTotal.toFixed(2)} | ${(endMemory.heapTotal / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.heapTotal.toFixed(2)}`
358
+ `Heap Total | ${context.startMemory.heapTotal.toFixed(2)} | ${(
359
+ endMemory.heapTotal /
360
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
361
+ ).toFixed(2)} | ${memoryDiff.heapTotal.toFixed(2)}`
281
362
  );
282
363
  console.log(
283
364
  '[PERFORMANCE]',
284
- `Heap Used | ${context.startMemory.heapUsed.toFixed(2)} | ${(endMemory.heapUsed / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.heapUsed.toFixed(2)}`
365
+ `Heap Used | ${context.startMemory.heapUsed.toFixed(2)} | ${(
366
+ endMemory.heapUsed /
367
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
368
+ ).toFixed(2)} | ${memoryDiff.heapUsed.toFixed(2)}`
285
369
  );
286
370
  console.log(
287
371
  '[PERFORMANCE]',
288
- `External | ${context.startMemory.external.toFixed(2)} | ${(endMemory.external / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.external.toFixed(2)}`
372
+ `External | ${context.startMemory.external.toFixed(2)} | ${(
373
+ endMemory.external /
374
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
375
+ ).toFixed(2)} | ${memoryDiff.external.toFixed(2)}`
289
376
  );
290
- if (!!endMemory.arrayBuffers) {
377
+ if (endMemory.arrayBuffers !== undefined) {
291
378
  console.log(
292
- `Array Buffers | ${context.startMemory.arrayBuffers.toFixed(2)} | ${((endMemory.arrayBuffers || 0) / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.arrayBuffers.toFixed(2)}`
379
+ `Array Buffers | ${context.startMemory.arrayBuffers.toFixed(2)} | ${(
380
+ (endMemory.arrayBuffers || 0) /
381
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
382
+ ).toFixed(2)} | ${memoryDiff.arrayBuffers.toFixed(2)}`
293
383
  );
294
384
  }
295
385
  console.log('---------------------------------------------------------------');
@@ -20,9 +20,7 @@ import {
20
20
  passNode,
21
21
  unpackNodeArray,
22
22
  unpackNonNullableNode,
23
- passString,
24
23
  unpackString,
25
- passStringArray,
26
24
  unpackNode,
27
25
  } from './private';
28
26
  import {
@@ -30,20 +28,18 @@ import {
30
28
  Es2pandaModifierFlags,
31
29
  Es2pandaMethodDefinitionKind,
32
30
  Es2pandaAstNodeType,
33
- Es2pandaPluginDiagnosticType,
34
31
  } from '../../../generated/Es2pandaEnums';
35
32
  import type { AstNode } from '../peers/AstNode';
36
33
  import {
37
- DiagnosticInfo,
34
+ AnnotationAllowed,
38
35
  Identifier,
39
36
  isConditionalExpression,
40
37
  SourcePosition,
41
- SourceRange,
42
- SuggestionInfo,
43
38
  VariableDeclarator,
44
39
  } from '../../../generated';
45
40
  import {
46
- type AnnotationUsage,
41
+ AnnotationUsage,
42
+ compiler,
47
43
  ClassDefinition,
48
44
  ClassProperty,
49
45
  ETSModule,
@@ -63,14 +59,12 @@ import {
63
59
  MemberExpression,
64
60
  isMethodDefinition,
65
61
  TypeNode,
66
- DiagnosticKind
67
62
  } from '../../../generated';
68
63
  import { Config } from '../peers/Config';
69
64
  import { Context } from '../peers/Context';
70
65
  import { NodeCache } from '../node-cache';
71
66
  import { factory } from '../factory/nodeFactory';
72
67
  import { traceGlobal } from '../../tracer';
73
- import { compiler } from '../../../generated';
74
68
 
75
69
  /**
76
70
  * Improve: Replace or remove with better naming
@@ -78,15 +72,8 @@ import { compiler } from '../../../generated';
78
72
  * @deprecated
79
73
  */
80
74
  export function createETSModuleFromContext(): ETSModule {
81
- let program = global.generatedEs2panda._ContextProgram(global.context);
82
- if (program === nullptr || program === null) {
83
- throw new Error(`Program is null for context ${global.context.toString(16)}`);
84
- }
85
- const ast = global.generatedEs2panda._ProgramAst(global.context, program);
86
- if (ast === nullptr || ast === null) {
87
- throw new Error(`AST is null for program ${program.toString(16)}`);
88
- }
89
- return new ETSModule(ast, Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE);
75
+ const program = compiler.contextProgram();
76
+ return program.getAstCasted();
90
77
  }
91
78
 
92
79
  /**
@@ -104,13 +91,8 @@ export function createETSModuleFromSource(
104
91
  }
105
92
  global.compilerContext = Context.createFromString(source);
106
93
  proceedToState(state);
107
- let program = global.generatedEs2panda._ContextProgram(global.compilerContext.peer);
108
- if (program === nullptr)
109
- throw new Error(`Program is null for ${source} 0x${global.compilerContext.peer.toString(16)}`);
110
- return new ETSModule(
111
- global.generatedEs2panda._ProgramAst(global.context, program),
112
- Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE
113
- );
94
+ const program = compiler.contextProgram();
95
+ return program.getAstCasted();
114
96
  }
115
97
 
116
98
  export function metaDatabase(fileName: string): string {
@@ -118,26 +100,31 @@ export function metaDatabase(fileName: string): string {
118
100
  return `${fileName}.meta.json`;
119
101
  }
120
102
 
121
- export function checkErrors() {
122
- if (global.es2panda._ContextState(global.context) === Es2pandaContextState.ES2PANDA_STATE_ERROR) {
103
+ export function checkErrors(proceedTo?: string) {
104
+ if (compiler.contextState() === Es2pandaContextState.ES2PANDA_STATE_ERROR) {
123
105
  traceGlobal(() => `Terminated due to compilation errors occured`);
124
- console.log(unpackString(global.generatedEs2panda._GetAllErrorMessages(global.context)));
125
- // global.es2panda._DestroyConfig(global.config)
126
- throw new Error(`Compilation error`)
127
- }
128
- }
129
-
130
- function format(value: number): string {
131
- return `${(value / 1024 / 1024 / 1024).toFixed(4)} GB`
132
- }
133
106
 
134
- // Improve: move to profiler
135
- function dumpMemoryProfilerInfo(str: string) {
136
- console.log(str, format(process.memoryUsage().rss));
107
+ const errorMessage = compiler.contextErrorMessage();
108
+ if (errorMessage === undefined) {
109
+ throwError(`Could not get ContextErrorMessage`);
110
+ }
111
+ const allErrorMessages = compiler.getAllErrorMessages();
112
+ if (allErrorMessages === undefined) {
113
+ throwError(`Could not get AllErrorMessages`);
114
+ }
115
+ const actionMsg = proceedTo ? " to " + proceedTo : ""
116
+ throwError([`Failed to proceed${actionMsg}`, errorMessage, allErrorMessages].join(`\n`));
117
+ }
137
118
  }
138
119
 
139
- export function proceedToState(state: Es2pandaContextState): void {
140
- if (state <= global.es2panda._ContextState(global.context)) {
120
+ export function proceedToState(state: Es2pandaContextState, _contextPtr?: KNativePointer, ignoreErrors = false): void {
121
+ if (compiler.contextState() === Es2pandaContextState.ES2PANDA_STATE_ERROR) {
122
+ NodeCache.clear();
123
+ if (!ignoreErrors) {
124
+ checkErrors(Es2pandaContextState[state]);
125
+ }
126
+ }
127
+ if (state <= compiler.contextState()) {
141
128
  return;
142
129
  }
143
130
  NodeCache.clear();
@@ -147,17 +134,16 @@ export function proceedToState(state: Es2pandaContextState): void {
147
134
  traceGlobal(() => `Proceeding to state ${Es2pandaContextState[state]}: done`);
148
135
  const after = Date.now();
149
136
  global.profiler.proceededToState(after - before);
150
- if (state == Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) {
151
- dumpMemoryProfilerInfo("Memory usage (rss) after proceed to bin:")
137
+ if (!ignoreErrors) {
138
+ checkErrors(Es2pandaContextState[state]);
152
139
  }
153
- checkErrors();
154
140
  }
155
141
 
156
142
  /** @deprecated Use {@link rebindContext} instead */
157
143
  export function rebindSubtree(node: AstNode): void {
158
144
  NodeCache.clear();
159
145
  traceGlobal(() => `Rebind: start`);
160
- global.es2panda._AstNodeRebind(global.context, node.peer);
146
+ compiler.astNodeRebind(node);
161
147
  traceGlobal(() => `Rebind: done`);
162
148
  checkErrors();
163
149
  }
@@ -166,18 +152,14 @@ export function rebindSubtree(node: AstNode): void {
166
152
  export function recheckSubtree(node: AstNode): void {
167
153
  NodeCache.clear();
168
154
  traceGlobal(() => `Recheck: start`);
169
- global.generatedEs2panda._AstNodeRecheck(global.context, node.peer);
155
+ compiler.astNodeRecheck(node);
170
156
  traceGlobal(() => `Recheck: done`);
171
- checkErrors();
172
157
  }
173
158
 
174
159
  export function rebindContext(context: KNativePointer = global.context): void {
175
160
  NodeCache.clear();
176
161
  traceGlobal(() => `Rebind: start`);
177
- global.es2panda._AstNodeRebind(
178
- context,
179
- global.generatedEs2panda._ProgramAst(context, global.generatedEs2panda._ContextProgram(context))
180
- );
162
+ compiler.astNodeRebind(compiler.contextProgram().getAstCasted());
181
163
  traceGlobal(() => `Rebind: done`);
182
164
  checkErrors();
183
165
  }
@@ -185,10 +167,7 @@ export function rebindContext(context: KNativePointer = global.context): void {
185
167
  export function recheckContext(context: KNativePointer = global.context): void {
186
168
  NodeCache.clear();
187
169
  traceGlobal(() => `Recheck: start`);
188
- global.generatedEs2panda._AstNodeRecheck(
189
- context,
190
- global.generatedEs2panda._ProgramAst(context, global.generatedEs2panda._ContextProgram(context))
191
- );
170
+ compiler.astNodeRecheck(compiler.contextProgram().getAstCasted());
192
171
  traceGlobal(() => `Recheck: done`);
193
172
  checkErrors();
194
173
  }
@@ -257,10 +236,6 @@ export function getPeerDecl(peer: KNativePointer): AstNode | undefined {
257
236
  return unpackNonNullableNode(decl);
258
237
  }
259
238
 
260
- export function declarationFromIdentifier(node: Identifier): AstNode | undefined {
261
- return unpackNode(global.generatedEs2panda._DeclarationFromIdentifier(global.context, node.peer));
262
- }
263
-
264
239
  export function resolveGensymVariableDeclaratorForDefaultParam(node: VariableDeclarator): Identifier | undefined {
265
240
  const init = node.init;
266
241
  if (
@@ -281,6 +256,14 @@ export function resolveGensymVariableDeclaratorForOptionalCall(node: VariableDec
281
256
  return undefined;
282
257
  }
283
258
 
259
+ export function getPeerIdentifierDecl(peer: KNativePointer): AstNode | undefined {
260
+ const decl = global.generatedEs2panda._DeclarationFromIdentifier(global.context, peer);
261
+ if (decl === nullptr) {
262
+ return undefined;
263
+ }
264
+ return unpackNonNullableNode(decl);
265
+ }
266
+
284
267
  export function getPeerObjectDecl(peer: KNativePointer): AstNode | undefined {
285
268
  const decl = global.es2panda._ClassVariableDeclaration(global.context, peer);
286
269
  if (decl === nullptr) {
@@ -289,11 +272,28 @@ export function getPeerObjectDecl(peer: KNativePointer): AstNode | undefined {
289
272
  return unpackNonNullableNode(decl);
290
273
  }
291
274
 
275
+ export function getPeerMemberDecl(peer: KNativePointer): AstNode | undefined {
276
+ const decl = global.es2panda._DeclarationFromMemberExpression(global.context, peer);
277
+ if (decl === nullptr) {
278
+ return undefined;
279
+ }
280
+ return unpackNonNullableNode(decl);
281
+ }
282
+
283
+ export function getPeerPropertyDecl(peer: KNativePointer): AstNode | undefined {
284
+ const decl = global.es2panda._DeclarationFromProperty(global.context, peer);
285
+ if (decl === nullptr) {
286
+ return undefined;
287
+ }
288
+ return unpackNonNullableNode(decl);
289
+ }
290
+
291
+
292
292
  export function getAnnotations(node: AstNode): readonly AnnotationUsage[] {
293
293
  if (!isFunctionDeclaration(node) && !isScriptFunction(node) && !isClassDefinition(node)) {
294
294
  throwError('for now annotations allowed only for: functionDeclaration, scriptFunction, classDefinition');
295
295
  }
296
- return unpackNodeArray(global.generatedEs2panda._AnnotationAllowedAnnotations(global.context, node.peer));
296
+ return new AnnotationAllowed(node.peer).annotations
297
297
  }
298
298
 
299
299
  export function getOriginalNode(node: AstNode): AstNode {
@@ -321,7 +321,7 @@ export function getJsDoc(node: AstNode): string | undefined {
321
321
  // Use this function if you need
322
322
  // the language level modifiers: public, declare, export, etc.
323
323
  export function classDefinitionFlags(node: ClassDefinition): Es2pandaModifierFlags {
324
- return global.generatedEs2panda._AstNodeModifiers(global.context, node.peer);
324
+ return node.modifierFlags
325
325
  }
326
326
 
327
327
  // Improve: ClassProperty's optional flag is set by AstNode's modifiers flags.
@@ -377,25 +377,6 @@ export function findStdlib(): string {
377
377
  return `${sdk}/ets/stdlib`;
378
378
  }
379
379
 
380
- export function generateTsDeclarationsFromContext(
381
- outputDeclEts: string,
382
- outputEts: string,
383
- exportAll: boolean,
384
- isolated: boolean,
385
- recordFile: string,
386
- genAnnotations: boolean
387
- ): KInt {
388
- return global.generatedEs2panda._GenerateTsDeclarationsFromContext(
389
- global.context,
390
- passString(outputDeclEts),
391
- passString(outputEts),
392
- exportAll,
393
- isolated,
394
- recordFile,
395
- genAnnotations
396
- );
397
- }
398
-
399
380
  export function setAllParents(ast: AstNode): void {
400
381
  global.es2panda._AstNodeUpdateAll(global.context, ast.peer);
401
382
  }
@@ -405,7 +386,7 @@ export function getProgramFromAstNode(node: AstNode): Program {
405
386
  }
406
387
 
407
388
  export function importDeclarationInsert(node: ETSImportDeclaration, program: Program): void {
408
- global.generatedEs2panda._InsertETSImportDeclarationAndParse(global.context, program.peer, node.peer);
389
+ compiler.insertETSImportDeclarationAndParse(program, node);
409
390
  }
410
391
 
411
392
  export function signatureReturnType(signature: KNativePointer): KNativePointer {
@@ -438,10 +419,6 @@ export function originalSourcePositionString(node: AstNode | undefined) {
438
419
  return `[${program.absoluteName}${sourcePosition.toString()}]`;
439
420
  }
440
421
 
441
- export function generateStaticDeclarationsFromContext(outputPath: string): KInt {
442
- return global.generatedEs2panda._GenerateStaticDeclarationsFromContext(global.context, passString(outputPath));
443
- }
444
-
445
422
  export function createTypeNodeFromTsType(node: AstNode): AstNode | undefined {
446
423
  const typeAnnotation = global.es2panda._CreateTypeNodeFromTsType(global.context, node.peer);
447
424
  if (typeAnnotation === nullptr) {
@@ -450,62 +427,6 @@ export function createTypeNodeFromTsType(node: AstNode): AstNode | undefined {
450
427
  return unpackNonNullableNode(typeAnnotation);
451
428
  }
452
429
 
453
- export function createSourcePosition(index: KUInt, line: KUInt): SourcePosition {
454
- return new SourcePosition(global.generatedEs2panda._CreateSourcePosition(global.context, index, line));
455
- }
456
-
457
- export function createSourceRange(start: SourcePosition, end: SourcePosition): SourceRange {
458
- return new SourceRange(global.generatedEs2panda._CreateSourceRange(global.context, start.peer, end.peer));
459
- }
460
-
461
- export function createDiagnosticInfo(
462
- kind: DiagnosticKind,
463
- position: SourcePosition,
464
- ...args: string[]
465
- ): DiagnosticInfo {
466
- return new DiagnosticInfo(
467
- global.generatedEs2panda._CreateDiagnosticInfo(
468
- global.context,
469
- kind.peer,
470
- passStringArray(args),
471
- args.length,
472
- position.peer
473
- )
474
- );
475
- }
476
-
477
- export function createSuggestionInfo(
478
- kind: DiagnosticKind,
479
- substitutionCode: string,
480
- title: string,
481
- range: SourceRange,
482
- ...args: string[]
483
- ): SuggestionInfo {
484
- return new SuggestionInfo(
485
- global.generatedEs2panda._CreateSuggestionInfo(
486
- global.context,
487
- kind.peer,
488
- passStringArray(args),
489
- args.length,
490
- substitutionCode,
491
- title,
492
- range.peer
493
- )
494
- );
495
- }
496
-
497
- export function createDiagnosticKind(message: string, type: Es2pandaPluginDiagnosticType): DiagnosticKind {
498
- return new DiagnosticKind(global.es2panda._CreateDiagnosticKind(global.context, message, type));
499
- }
500
-
501
- export function logDiagnostic(kind: DiagnosticKind, pos: SourcePosition, ...args: string[]): void {
502
- global.es2panda._LogDiagnostic(global.context, kind.peer, passStringArray(args), args.length, pos.peer);
503
- }
504
-
505
- export function logDiagnosticWithSuggestion(diagnosticInfo: DiagnosticInfo, suggestionInfo: SuggestionInfo): void {
506
- global.generatedEs2panda._LogDiagnosticWithSuggestion(global.context, diagnosticInfo.peer, suggestionInfo.peer);
507
- }
508
-
509
430
  export function filterNodes(node: AstNode, filter: string, deeperAfterMatch: boolean): AstNode[] {
510
431
  return unpackNodeArray(global.es2panda._FilterNodes(global.context, passNode(node), filter, deeperAfterMatch));
511
432
  }
@@ -522,12 +443,8 @@ export function filterNodesByTypes(node: AstNode, types: Es2pandaAstNodeType[]):
522
443
  return unpackNodeArray(global.es2panda._FilterNodes3(global.context, passNode(node), typesArray, types.length));
523
444
  }
524
445
 
525
- // This functions are used as capitalized in build-system, unlike the others
526
- // See https://gitcode.com/openharmony/arkcompiler_ets_frontend/issues/8196
527
- export function MemInitialize() {
528
- compiler.memInitialize()
529
- }
530
-
531
- export function MemFinalize() {
532
- compiler.memFinalize()
446
+ export function jumpFromETSTypeReferenceToTSTypeAliasDeclarationTypeAnnotation(node: AstNode): AstNode | undefined {
447
+ return unpackNode(
448
+ global.es2panda._JumpFromETSTypeReferenceToTSTypeAliasDeclarationTypeAnnotation(global.context, passNode(node))
449
+ );
533
450
  }
@@ -19,6 +19,7 @@ import {
19
19
  ArrayExpression,
20
20
  ArrowFunctionExpression,
21
21
  AssignmentExpression,
22
+ AwaitExpression,
22
23
  BinaryExpression,
23
24
  BlockExpression,
24
25
  BlockStatement,
@@ -764,6 +765,7 @@ function visitClassProperty(node: ClassProperty, visitor: Visitor): ClassPropert
764
765
  result.onUpdate(node);
765
766
  return result;
766
767
  }
768
+ node.setKey(newKey);
767
769
  node.setValue(newValue);
768
770
  node.setTypeAnnotation(newTypeAnnotation);
769
771
  node.setAnnotations(newAnnotations);
@@ -773,12 +775,12 @@ function visitClassProperty(node: ClassProperty, visitor: Visitor): ClassPropert
773
775
 
774
776
  function visitProperty(node: Property, visitor: Visitor): Property {
775
777
  global.updateTracker.push();
778
+ const oldKey = node.key;
776
779
  const newKey = nodeVisitor(node.key, visitor);
777
780
  const newValue = nodeVisitor(node.value, visitor);
778
781
  if (global.updateTracker.check()) {
779
- const result = factory.createProperty(node.kind, newKey, newValue, node.isMethod, node.isComputed);
780
- result.onUpdate(node);
781
- return result;
782
+ node.setKey(newKey);
783
+ node.setValue(newValue);
782
784
  }
783
785
  return node;
784
786
  }
@@ -957,6 +959,17 @@ function visitClassStaticBlock(node: ClassStaticBlock, visitor: Visitor): ClassS
957
959
  return node;
958
960
  }
959
961
 
962
+ function visitAwaitExpression(node: AwaitExpression, visitor: Visitor): AwaitExpression {
963
+ global.updateTracker.push();
964
+ const newArgument = nodeVisitor(node.argument, visitor);
965
+ if (global.updateTracker.check()) {
966
+ const result = factory.createAwaitExpression(newArgument);
967
+ result.onUpdate(node);
968
+ return result;
969
+ }
970
+ return node;
971
+ }
972
+
960
973
  const visitsTable: (((node: any, visitor: Visitor) => any) | undefined)[] = [];
961
974
 
962
975
  export function initVisitsTable(): void {
@@ -1017,6 +1030,7 @@ export function initVisitsTable(): void {
1017
1030
  visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER_DECLARATION] = visitTSTypeParameterDeclaration;
1018
1031
  visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER_INSTANTIATION] = visitTSTypeParameterInstantiation;
1019
1032
  visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_STATIC_BLOCK] = visitClassStaticBlock;
1033
+ visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_AWAIT_EXPRESSION] = visitAwaitExpression;
1020
1034
  }
1021
1035
 
1022
1036
  initVisitsTable();
@@ -245,3 +245,7 @@ export function filterSource(text: string): string {
245
245
  // console.error(dumperUnwrappers.reduceRight((code, f) => f(code), text).split('\n').map((it, index) => `${`${index + 1}`.padStart(4)} |${it}`).join('\n'))
246
246
  return dumperUnwrappers.reduceRight((code, f) => f(code), text);
247
247
  }
248
+
249
+ export function getEnumName(enumType: any, value: number): string | undefined {
250
+ return enumType[value];
251
+ }