@idlizer/arktscgen 2.1.10-arktscgen-2 → 2.1.10-arktscgen-3a
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.
- package/build/libarkts-copy/generator/options.json5 +89 -6
- package/build/libarkts-copy/native/meson.build +1 -0
- package/build/libarkts-copy/native/src/bridges.cc +10 -4
- package/build/libarkts-copy/native/src/common.cc +0 -12
- package/build/libarkts-copy/native/src/generated/bridges.cc +416 -723
- package/build/libarkts-copy/native/src/memoryTracker.cc +178 -0
- package/build/libarkts-copy/native/src/memoryTracker.h +52 -0
- package/build/libarkts-copy/package.json +8 -8
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +14 -2
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +2 -2
- package/build/libarkts-copy/src/arkts-api/index.ts +2 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +4 -1
- package/{templates/node-map.ts → build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts} +8 -19
- package/build/libarkts-copy/src/arkts-api/utilities/extensions.ts +26 -9
- package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +309 -0
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +7 -21
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +61 -7
- package/build/libarkts-copy/src/arkts-api/visitor.ts +21 -14
- package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +1 -0
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +88 -172
- package/build/libarkts-copy/src/generated/factory.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +11 -13
- package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ArkTsConfig.ts +3 -1
- package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +0 -5
- package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +12 -14
- package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AstDumper.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BindingProps.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/CallExpression.ts +6 -2
- package/build/libarkts-copy/src/generated/peers/CatchClause.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +1 -24
- package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +26 -20
- package/build/libarkts-copy/src/generated/peers/ClassElement.ts +2 -30
- package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +10 -12
- package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/CodeGen.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/Declaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/Decorator.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/DiagnosticInfo.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSIntrinsicNode.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSModule.ts +12 -14
- package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +13 -15
- package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +3 -4
- package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/Expression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +10 -16
- package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +2 -2
- package/build/libarkts-copy/src/generated/peers/IRNode.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/Identifier.ts +0 -10
- package/build/libarkts-copy/src/generated/peers/IfStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ImportSource.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/LabelPair.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/Literal.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +5 -6
- package/build/libarkts-copy/src/generated/peers/NamedType.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/NewExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +0 -5
- package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/OverloadDeclaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/Program.ts +9 -2
- package/build/libarkts-copy/src/generated/peers/Property.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +22 -19
- package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +2 -1
- package/build/libarkts-copy/src/generated/peers/SourceRange.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +0 -5
- package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/Statement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SuggestionInfo.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +2 -25
- package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSImportType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSInferType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +14 -38
- package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSThisType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +26 -40
- package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +11 -13
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TryStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TypeNode.ts +10 -12
- package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/VReg.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +11 -20
- package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +0 -1
- package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +0 -1
- package/build/libarkts-copy/src/index.ts +2 -1
- package/build/libarkts-copy/src/plugin-utils.ts +0 -10
- package/build/libarkts-copy/src/reexport-for-generated.ts +1 -20
- package/lib/index.js +115 -38
- package/package.json +4 -3
- package/templates/factory.ts +0 -1
- package/templates/peer.ts +0 -1
- package/build/libarkts-copy/src/arkts-api/ChainExpressionFilter.ts +0 -79
|
@@ -0,0 +1,309 @@
|
|
|
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
|
+
|
|
16
|
+
import * as process from 'process';
|
|
17
|
+
import { global as localGlobal} from '../static/global';
|
|
18
|
+
|
|
19
|
+
const BYTES_PER_KIBIBYTE = 1024;
|
|
20
|
+
|
|
21
|
+
interface MemoryContext {
|
|
22
|
+
startTime: number;
|
|
23
|
+
startMemory: {
|
|
24
|
+
rss: number;
|
|
25
|
+
heapTotal: number;
|
|
26
|
+
heapUsed: number;
|
|
27
|
+
external: number;
|
|
28
|
+
arrayBuffers: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Event {
|
|
33
|
+
name: string,
|
|
34
|
+
startTime: number,
|
|
35
|
+
endTime?: number,
|
|
36
|
+
parentEvent?: string,
|
|
37
|
+
duration?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function formatTime(ms: number): string {
|
|
41
|
+
const milliseconds = Math.floor(ms % 1000);
|
|
42
|
+
const seconds = Math.floor((ms / 1000) % 60);
|
|
43
|
+
const minutes = Math.floor((ms / (1000 * 60)) % 60);
|
|
44
|
+
const hours = Math.floor(ms / (1000 * 60 * 60));
|
|
45
|
+
|
|
46
|
+
return `${pad(hours, 2)}:${pad(minutes, 2)}:${pad(seconds, 2)}:${pad(milliseconds, 3)}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function pad(value: number, length: number): string {
|
|
50
|
+
return value.toString().padStart(length, '0');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function round(value: number, index: number = 2): number {
|
|
54
|
+
const factor = Math.pow(10, index);
|
|
55
|
+
return Math.round(value * factor) / factor;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class Performance {
|
|
59
|
+
private static instance: Performance;
|
|
60
|
+
private events: Map<string, Event>;
|
|
61
|
+
private historyEvents = new Map<string | null, Event[]>();
|
|
62
|
+
private scopes: string[];
|
|
63
|
+
private shouldSkip: boolean;
|
|
64
|
+
private totalDuration: number;
|
|
65
|
+
private memoryContexts = new Map<string, MemoryContext>();
|
|
66
|
+
private memoryTrackerEnable: boolean;
|
|
67
|
+
private constructor() {
|
|
68
|
+
this.events = new Map();
|
|
69
|
+
this.historyEvents = new Map();
|
|
70
|
+
this.scopes = [];
|
|
71
|
+
this.shouldSkip = true;
|
|
72
|
+
this.memoryTrackerEnable = false;
|
|
73
|
+
this.totalDuration = 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public static getInstance(): Performance {
|
|
77
|
+
if (!this.instance) {
|
|
78
|
+
this.instance = new Performance();
|
|
79
|
+
}
|
|
80
|
+
return this.instance;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
skip(shouldSkip: boolean = true): void {
|
|
84
|
+
this.shouldSkip = shouldSkip;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
enableMemoryTracker(enableMemoryTracker: boolean = false): void {
|
|
88
|
+
this.memoryTrackerEnable = enableMemoryTracker;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
createEvent(name: string): Event {
|
|
92
|
+
if (this.shouldSkip) {
|
|
93
|
+
return { name: '', startTime: 0 };
|
|
94
|
+
}
|
|
95
|
+
const startTime: number = performance.now();
|
|
96
|
+
const newEvent: Event = { name, startTime };
|
|
97
|
+
this.events.set(name, newEvent);
|
|
98
|
+
this.scopes.push(name);
|
|
99
|
+
return newEvent;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
stopEvent(name: string, shouldLog: boolean = false): Event {
|
|
103
|
+
if (this.shouldSkip) {
|
|
104
|
+
return { name: '', startTime: 0 };
|
|
105
|
+
}
|
|
106
|
+
if (!this.events.has(name) || this.scopes.length === 0) {
|
|
107
|
+
throw new Error(`Event ${name} is not created.`);
|
|
108
|
+
}
|
|
109
|
+
if (this.scopes[this.scopes.length - 1] !== name) {
|
|
110
|
+
console.warn(`[PERFORMANCE WARNING] Event ${name} early exit.`);
|
|
111
|
+
}
|
|
112
|
+
this.scopes.pop();
|
|
113
|
+
|
|
114
|
+
const event: Event = this.events.get(name)!;
|
|
115
|
+
const endTime: number = performance.now();
|
|
116
|
+
const parentEvent: string = this.scopes[this.scopes.length - 1];
|
|
117
|
+
const duration: number = endTime - event.startTime;
|
|
118
|
+
if (!parentEvent) {
|
|
119
|
+
this.totalDuration += duration;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (shouldLog) {
|
|
123
|
+
console.log(
|
|
124
|
+
`[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(duration)}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const newEvent = { ...event, endTime, parentEvent, duration };
|
|
129
|
+
const history = this.historyEvents.get(parentEvent ?? null) || [];
|
|
130
|
+
this.historyEvents.set(parentEvent ?? null, [...history, newEvent]);
|
|
131
|
+
return newEvent;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
stopLastEvent(shouldLog: boolean = false): Event {
|
|
135
|
+
if (this.shouldSkip) {
|
|
136
|
+
return { name: '', startTime: 0 };
|
|
137
|
+
}
|
|
138
|
+
if (this.scopes.length === 0) {
|
|
139
|
+
throw new Error("No last event");
|
|
140
|
+
}
|
|
141
|
+
const name: string = this.scopes.pop()!;
|
|
142
|
+
if (!this.events.has(name)) {
|
|
143
|
+
throw new Error(`Event ${name} is not created.`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const event: Event = this.events.get(name)!;
|
|
147
|
+
const endTime: number = performance.now();
|
|
148
|
+
const parentEvent: string = this.scopes[this.scopes.length - 1];
|
|
149
|
+
const duration: number = endTime - event.startTime;
|
|
150
|
+
if (!parentEvent) {
|
|
151
|
+
this.totalDuration += duration;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (shouldLog) {
|
|
155
|
+
console.log(
|
|
156
|
+
`[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(duration)}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const newEvent = { ...event, endTime, parentEvent, duration };
|
|
161
|
+
const history = this.historyEvents.get(parentEvent ?? null) || [];
|
|
162
|
+
this.historyEvents.set(parentEvent ?? null, [...history, newEvent]);
|
|
163
|
+
return newEvent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
clearAllEvents(shouldLog: boolean = false): void {
|
|
167
|
+
if (this.shouldSkip) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
for (let i = 0; i < this.scopes.length; i ++) {
|
|
171
|
+
this.stopLastEvent(shouldLog);
|
|
172
|
+
}
|
|
173
|
+
this.events = new Map();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
clearTotalDuration(): void {
|
|
177
|
+
this.totalDuration = 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
clearHistory(): void {
|
|
181
|
+
this.historyEvents = new Map();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
visualizeEvents(shouldLog: boolean = false): void {
|
|
185
|
+
if (this.shouldSkip) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const that = this;
|
|
189
|
+
function buildVisualization(parentKey: string | null, indentLevel: number): [string, number] {
|
|
190
|
+
const children = that.historyEvents.get(parentKey) || [];
|
|
191
|
+
let result = '';
|
|
192
|
+
|
|
193
|
+
children.forEach(child => {
|
|
194
|
+
const indent = ' '.repeat(indentLevel);
|
|
195
|
+
const duration = child.duration ?? 0;
|
|
196
|
+
const [_result, count] = buildVisualization(child.name, indentLevel + 1);
|
|
197
|
+
result += `${indent}- ${child.name}: ${formatTime(duration)}(${round(duration)}), ${count}\n`;
|
|
198
|
+
result += _result;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return [result, children.length];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const [finalResult, _] = buildVisualization(null, 0);
|
|
205
|
+
if (shouldLog) {
|
|
206
|
+
console.log(`[PERFORMANCE] ===== FINAL RESULT ====`);
|
|
207
|
+
console.log(`TOTAL: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`);
|
|
208
|
+
console.log(finalResult.trimEnd());
|
|
209
|
+
console.log(`[PERFORMANCE] ===== FINAL RESULT ====`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
startMemRecord(label: string = `measurement-${Date.now()}`): void {
|
|
214
|
+
// 强制进行垃圾回收(需要 Node.js 启动时添加 --expose-gc 参数)
|
|
215
|
+
if (!this.memoryTrackerEnable) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (global.gc) {
|
|
219
|
+
(global as any).gc();
|
|
220
|
+
}
|
|
221
|
+
const startMemory = process.memoryUsage();
|
|
222
|
+
this.memoryContexts.set(label, {
|
|
223
|
+
startTime: Date.now(),
|
|
224
|
+
startMemory: {
|
|
225
|
+
rss: startMemory.rss / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE),
|
|
226
|
+
heapTotal: startMemory.heapTotal / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE),
|
|
227
|
+
heapUsed: startMemory.heapUsed / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE),
|
|
228
|
+
external: startMemory.external / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE),
|
|
229
|
+
arrayBuffers: (startMemory.arrayBuffers || 0) / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
stopMemRecord(label: string = `measurement-${Date.now()}`, runGc: boolean = false): void {
|
|
237
|
+
if (!this.memoryTrackerEnable) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const context = this.memoryContexts.get(label);
|
|
241
|
+
|
|
242
|
+
if (!context) {
|
|
243
|
+
console.error(`未找到标签为 "${label}" 的内存测量上下文`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 可选:在测量结束前执行垃圾回收
|
|
248
|
+
if (runGc && global.gc) {
|
|
249
|
+
(global as any).gc();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 记录结束时的内存使用情况
|
|
253
|
+
const endTime = Date.now();
|
|
254
|
+
const endMemory = process.memoryUsage();
|
|
255
|
+
|
|
256
|
+
// 计算内存使用增量
|
|
257
|
+
const memoryDiff = {
|
|
258
|
+
rss: endMemory.rss / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE) - context.startMemory.rss,
|
|
259
|
+
heapTotal: endMemory.heapTotal / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE) - context.startMemory.heapTotal,
|
|
260
|
+
heapUsed: endMemory.heapUsed / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE) - context.startMemory.heapUsed,
|
|
261
|
+
external: endMemory.external / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE) - context.startMemory.external,
|
|
262
|
+
arrayBuffers: ((endMemory.arrayBuffers || 0) / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)) - context.startMemory.arrayBuffers
|
|
263
|
+
};
|
|
264
|
+
const duration = endTime - context.startTime;
|
|
265
|
+
|
|
266
|
+
console.log('[PERFORMANCE]', `内存测量结果 [标签: ${label}]`);
|
|
267
|
+
console.log('[PERFORMANCE]', `执行时间: ${duration}ms`);
|
|
268
|
+
console.log('---------------------------------------------------------------');
|
|
269
|
+
console.log('[PERFORMANCE]', `内存类型 | 开始值(MB) | 结束值(MB) | 增量(MB)`);
|
|
270
|
+
console.log('---------------------------------------------------------------');
|
|
271
|
+
console.log('[PERFORMANCE]', `RSS | ${context.startMemory.rss.toFixed(2)} | ${(endMemory.rss / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.rss.toFixed(2)}`);
|
|
272
|
+
console.log('[PERFORMANCE]', `Heap Total | ${context.startMemory.heapTotal.toFixed(2)} | ${(endMemory.heapTotal / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.heapTotal.toFixed(2)}`);
|
|
273
|
+
console.log('[PERFORMANCE]', `Heap Used | ${context.startMemory.heapUsed.toFixed(2)} | ${(endMemory.heapUsed / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.heapUsed.toFixed(2)}`);
|
|
274
|
+
console.log('[PERFORMANCE]', `External | ${context.startMemory.external.toFixed(2)} | ${(endMemory.external / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.external.toFixed(2)}`);
|
|
275
|
+
if (endMemory.arrayBuffers !== undefined) {
|
|
276
|
+
console.log(`Array Buffers | ${context.startMemory.arrayBuffers.toFixed(2)} | ${((endMemory.arrayBuffers || 0) / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.arrayBuffers.toFixed(2)}`);
|
|
277
|
+
}
|
|
278
|
+
console.log('---------------------------------------------------------------');
|
|
279
|
+
this.memoryContexts.delete(label);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
memoryTrackerReset(): void {
|
|
284
|
+
if (!this.memoryTrackerEnable) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
localGlobal.es2panda._MemoryTrackerReset(localGlobal.context);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
memoryTrackerGetDelta(tag: string): void {
|
|
291
|
+
if (!this.memoryTrackerEnable) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
console.log('---------------------------------------------------------------');
|
|
295
|
+
console.log('[PERFORMANCE] Increamental memory:', tag);
|
|
296
|
+
localGlobal.es2panda._MemoryTrackerGetDelta(localGlobal.context);
|
|
297
|
+
console.log('---------------------------------------------------------------');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
memoryTrackerPrintCurrent(tag: string): void {
|
|
301
|
+
if (!this.memoryTrackerEnable) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
console.log('---------------------------------------------------------------');
|
|
305
|
+
console.log('[PERFORMANCE] Current total memory:', tag);
|
|
306
|
+
localGlobal.es2panda._MemoryTrackerPrintCurrent(localGlobal.context);
|
|
307
|
+
console.log('---------------------------------------------------------------');
|
|
308
|
+
}
|
|
309
|
+
}
|
|
@@ -68,31 +68,31 @@ export function acceptNativeObjectArrayResult<T extends ArktsObject>(arrayObject
|
|
|
68
68
|
return new NativePtrDecoder().decode(arrayObject).map(factory);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export function unpackNonNullableNode<T extends AstNode>(peer: KNativePointer): T {
|
|
71
|
+
export function unpackNonNullableNode<T extends AstNode>(peer: KNativePointer, typeHint?: Es2pandaAstNodeType): T {
|
|
72
72
|
if (peer === nullptr) {
|
|
73
73
|
throwError('peer is NULLPTR (maybe you should use unpackNode)')
|
|
74
74
|
}
|
|
75
|
-
return nodeFrom(peer)
|
|
75
|
+
return nodeFrom(peer, typeHint)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export function unpackNode<T extends AstNode>(peer: KNativePointer): T | undefined {
|
|
78
|
+
export function unpackNode<T extends AstNode>(peer: KNativePointer, typeHint?: Es2pandaAstNodeType): T | undefined {
|
|
79
79
|
if (peer === nullptr) {
|
|
80
80
|
return undefined
|
|
81
81
|
}
|
|
82
|
-
return nodeFrom<T>(peer)
|
|
82
|
+
return nodeFrom<T>(peer, typeHint)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export function passNode(node: ArktsObject | undefined): KNativePointer {
|
|
86
86
|
return node?.peer ?? nullptr
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export function unpackNodeArray<T extends AstNode>(nodesPtr: KNativePointer): T[] {
|
|
89
|
+
export function unpackNodeArray<T extends AstNode>(nodesPtr: KNativePointer, typeHint?: Es2pandaAstNodeType): T[] {
|
|
90
90
|
if (nodesPtr === nullptr) {
|
|
91
|
-
|
|
91
|
+
return []
|
|
92
92
|
}
|
|
93
93
|
return new NativePtrDecoder()
|
|
94
94
|
.decode(nodesPtr)
|
|
95
|
-
.map((peer: KNativePointer) => unpackNonNullableNode(peer))
|
|
95
|
+
.map((peer: KNativePointer) => unpackNonNullableNode(peer, typeHint))
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export function passNodeArray(nodes: readonly ArktsObject[] | undefined): BigUint64Array {
|
|
@@ -104,20 +104,6 @@ export function passNodeArray(nodes: readonly ArktsObject[] | undefined): BigUin
|
|
|
104
104
|
)
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export function unpackNonNullableObject<T extends ArktsObject>(type: { new (peer: KNativePointer): T }, peer: KNativePointer): T {
|
|
108
|
-
if (peer === nullptr) {
|
|
109
|
-
throwError('peer is NULLPTR (maybe you should use unpackObject)')
|
|
110
|
-
}
|
|
111
|
-
return new type(peer)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function unpackObject<T extends ArktsObject>(type: { new (peer: KNativePointer): T }, peer: KNativePointer): T | undefined {
|
|
115
|
-
if (peer === nullptr) {
|
|
116
|
-
return undefined
|
|
117
|
-
}
|
|
118
|
-
return new type(peer)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
107
|
export function unpackString(peer: KNativePointer): string {
|
|
122
108
|
return global.interop._RawUtf8ToString(peer)
|
|
123
109
|
}
|
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
|
|
16
16
|
import { global } from "../static/global"
|
|
17
17
|
import { isNumber, throwError, withWarning } from "../../utils"
|
|
18
|
-
import { KNativePointer, nullptr, KInt} from "@koalaui/interop"
|
|
19
|
-
import { passNode,
|
|
20
|
-
import { Es2pandaContextState, Es2pandaModifierFlags, Es2pandaMethodDefinitionKind,
|
|
18
|
+
import { KNativePointer, nullptr, KInt, KUInt} from "@koalaui/interop"
|
|
19
|
+
import { passNode, unpackNodeArray, unpackNonNullableNode, passString, unpackString, passStringArray, unpackNode } from "./private"
|
|
20
|
+
import { Es2pandaContextState, Es2pandaModifierFlags, Es2pandaMethodDefinitionKind, Es2pandaAstNodeType, Es2pandaPluginDiagnosticType } from "../../generated/Es2pandaEnums"
|
|
21
21
|
import type { AstNode } from "../peers/AstNode"
|
|
22
|
-
import { SourcePosition } from "../../generated"
|
|
23
|
-
import { isSameNativeObject } from "../peers/ArktsObject"
|
|
22
|
+
import { DiagnosticInfo, Identifier, isConditionalExpression, SourcePosition, SourceRange, SuggestionInfo, VariableDeclarator } from "../../generated"
|
|
24
23
|
import {
|
|
25
24
|
type AnnotationUsage,
|
|
26
25
|
ClassDefinition,
|
|
@@ -32,7 +31,6 @@ import {
|
|
|
32
31
|
isScriptFunction,
|
|
33
32
|
isIdentifier,
|
|
34
33
|
isETSModule,
|
|
35
|
-
ImportSpecifier,
|
|
36
34
|
Program,
|
|
37
35
|
isObjectExpression,
|
|
38
36
|
ETSImportDeclaration,
|
|
@@ -47,9 +45,9 @@ import {
|
|
|
47
45
|
import { Config } from "../peers/Config"
|
|
48
46
|
import { Context } from "../peers/Context"
|
|
49
47
|
import { NodeCache } from "../node-cache"
|
|
50
|
-
import { listPrograms } from "../plugins"
|
|
51
48
|
import { factory } from "../factory/nodeFactory"
|
|
52
49
|
import { traceGlobal } from "../../tracer"
|
|
50
|
+
import { DiagnosticKind } from "../peers/DiagnosticKind"
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Improve: Replace or remove with better naming
|
|
@@ -232,6 +230,26 @@ export function getPeerDecl(peer: KNativePointer): AstNode | undefined {
|
|
|
232
230
|
return unpackNonNullableNode(decl)
|
|
233
231
|
}
|
|
234
232
|
|
|
233
|
+
export function declarationFromIdentifier(node: Identifier): AstNode | undefined {
|
|
234
|
+
return unpackNode(global.generatedEs2panda._DeclarationFromIdentifier(global.context, node.peer))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function resolveGensymVariableDeclaratorForDefaultParam(node: VariableDeclarator): Identifier | undefined {
|
|
238
|
+
const init = node.init
|
|
239
|
+
if (isConditionalExpression(init) && isIdentifier(init.consequent) && init.consequent.name.startsWith("gensym%%_")) {
|
|
240
|
+
return init.consequent
|
|
241
|
+
}
|
|
242
|
+
return undefined
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function resolveGensymVariableDeclaratorForOptionalCall(node: VariableDeclarator): Identifier | undefined {
|
|
246
|
+
const init = node.init
|
|
247
|
+
if (isIdentifier(node.id) && node.id.name.startsWith("gensym%%_") && isIdentifier(init)) {
|
|
248
|
+
return init
|
|
249
|
+
}
|
|
250
|
+
return undefined
|
|
251
|
+
}
|
|
252
|
+
|
|
235
253
|
export function getPeerObjectDecl(peer: KNativePointer): AstNode | undefined {
|
|
236
254
|
const decl = global.es2panda._ClassVariableDeclaration(global.context, peer);
|
|
237
255
|
if (decl === nullptr) {
|
|
@@ -395,3 +413,39 @@ export function generateStaticDeclarationsFromContext(outputPath: string): KInt
|
|
|
395
413
|
passString(outputPath)
|
|
396
414
|
);
|
|
397
415
|
}
|
|
416
|
+
|
|
417
|
+
export function createTypeNodeFromTsType(node: AstNode): AstNode | undefined {
|
|
418
|
+
const typeAnnotation = global.es2panda._CreateTypeNodeFromTsType(global.context, node.peer);
|
|
419
|
+
if (typeAnnotation === nullptr) {
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
return unpackNonNullableNode(typeAnnotation);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export function createSourcePosition(index: KUInt, line: KUInt): SourcePosition {
|
|
426
|
+
return new SourcePosition(global.generatedEs2panda._CreateSourcePosition(global.context, index, line))
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export function createSourceRange(start: SourcePosition, end: SourcePosition): SourceRange {
|
|
430
|
+
return new SourceRange(global.generatedEs2panda._CreateSourceRange(global.context, start.peer, end.peer))
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export function createDiagnosticInfo(kind: DiagnosticKind, position: SourcePosition, ...args: string[]): DiagnosticInfo {
|
|
434
|
+
return new DiagnosticInfo(global.es2panda._CreateDiagnosticInfo(global.context, kind.peer, passStringArray(args), args.length, position.peer))
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export function createSuggestionInfo(kind: DiagnosticKind, substitutionCode: string, title: string, range: SourceRange, ...args: string[]): SuggestionInfo {
|
|
438
|
+
return new SuggestionInfo(global.es2panda._CreateSuggestionInfo(global.context, kind.peer, passStringArray(args), args.length, substitutionCode, title, range.peer))
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function createDiagnosticKind(message: string, type: Es2pandaPluginDiagnosticType): DiagnosticKind {
|
|
442
|
+
return new DiagnosticKind(global.es2panda._CreateDiagnosticKind(global.context, message, type));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export function logDiagnostic(kind: DiagnosticKind, pos: SourcePosition, ...args: string[]): void {
|
|
446
|
+
global.es2panda._LogDiagnostic(global.context, kind.peer, passStringArray(args), args.length, pos.peer);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export function logDiagnosticWithSuggestion(diagnosticInfo: DiagnosticInfo, suggestionInfo: SuggestionInfo): void {
|
|
450
|
+
global.generatedEs2panda._LogDiagnosticWithSuggestion(global.context, diagnosticInfo.peer, suggestionInfo.peer);
|
|
451
|
+
}
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
ClassDeclaration,
|
|
29
29
|
ClassDefinition,
|
|
30
30
|
ClassProperty,
|
|
31
|
+
ClassStaticBlock,
|
|
31
32
|
ConditionalExpression,
|
|
32
33
|
DoWhileStatement,
|
|
33
34
|
ETSFunctionType,
|
|
@@ -244,24 +245,12 @@ function visitETSModule(node: ETSModule, visitor: Visitor) {
|
|
|
244
245
|
function visitCallExpression(node: CallExpression, visitor: Visitor) {
|
|
245
246
|
global.updateTracker.push()
|
|
246
247
|
const newCallee = nodeVisitor(node.callee, visitor)
|
|
247
|
-
const
|
|
248
|
-
const newArguments: readonly Expression[] = nodesVisitor(oldArguments, visitor)
|
|
248
|
+
const newArguments: readonly Expression[] = nodesVisitor(node.arguments, visitor)
|
|
249
249
|
const newTypeParams = nodeVisitor(node.typeParams, visitor)
|
|
250
250
|
const newTrailingBlock = nodeVisitor(node.trailingBlock, visitor)
|
|
251
251
|
if (global.updateTracker.check()) {
|
|
252
|
-
if (!isSameNativeObject(newArguments, oldArguments)) {
|
|
253
|
-
const result = factory.createCallExpression(
|
|
254
|
-
newCallee,
|
|
255
|
-
newArguments,
|
|
256
|
-
newTypeParams,
|
|
257
|
-
node.isOptional,
|
|
258
|
-
node.hasTrailingComma,
|
|
259
|
-
newTrailingBlock,
|
|
260
|
-
)
|
|
261
|
-
result.onUpdate(node)
|
|
262
|
-
return result
|
|
263
|
-
}
|
|
264
252
|
node.setCallee(newCallee)
|
|
253
|
+
node.setArguments(newArguments)
|
|
265
254
|
node.setTypeParams(newTypeParams)
|
|
266
255
|
node.setTrailingBlock(newTrailingBlock)
|
|
267
256
|
}
|
|
@@ -1108,6 +1097,23 @@ function visitTSTypeParameterDeclaration(node: TSTypeParameterDeclaration, visit
|
|
|
1108
1097
|
return node
|
|
1109
1098
|
}
|
|
1110
1099
|
|
|
1100
|
+
function visitClassStaticBlock(node: ClassStaticBlock, visitor: Visitor) {
|
|
1101
|
+
global.updateTracker.push()
|
|
1102
|
+
const newId = nodeVisitor(node.id, visitor)
|
|
1103
|
+
const newFunction = nodeVisitor(node.function, visitor)
|
|
1104
|
+
if (global.updateTracker.check()) {
|
|
1105
|
+
const result = ClassStaticBlock.createClassStaticBlock(
|
|
1106
|
+
factory.createFunctionExpression(
|
|
1107
|
+
newId,
|
|
1108
|
+
newFunction,
|
|
1109
|
+
)
|
|
1110
|
+
)
|
|
1111
|
+
result.onUpdate(node)
|
|
1112
|
+
return result
|
|
1113
|
+
}
|
|
1114
|
+
return node
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1111
1117
|
const visitsTable: (((node: any, visitor: Visitor) => any) | undefined)[] = []
|
|
1112
1118
|
|
|
1113
1119
|
export function initVisitsTable() {
|
|
@@ -1166,6 +1172,7 @@ export function initVisitsTable() {
|
|
|
1166
1172
|
visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_UPDATE_EXPRESSION] = visitUpdateExpression
|
|
1167
1173
|
visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER_DECLARATION] = visitTSTypeParameterDeclaration
|
|
1168
1174
|
visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER_INSTANTIATION] = visitTSTypeParameterInstantiation
|
|
1175
|
+
visitsTable[Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_STATIC_BLOCK] = visitClassStaticBlock
|
|
1169
1176
|
}
|
|
1170
1177
|
|
|
1171
1178
|
export function visitEachChild(
|
|
@@ -658,6 +658,7 @@ export enum Es2pandaClassDefinitionModifiers {
|
|
|
658
658
|
CLASS_DEFINITION_MODIFIERS_FROM_STRUCT = 65536,
|
|
659
659
|
CLASS_DEFINITION_MODIFIERS_FUNCTIONAL_REFERENCE = 131072,
|
|
660
660
|
CLASS_DEFINITION_MODIFIERS_LAZY_IMPORT_OBJECT_CLASS = 262144,
|
|
661
|
+
CLASS_DEFINITION_MODIFIERS_INIT_IN_CCTOR = 524288,
|
|
661
662
|
CLASS_DEFINITION_MODIFIERS_DECLARATION_ID_REQUIRED = 3,
|
|
662
663
|
CLASS_DEFINITION_MODIFIERS_ETS_MODULE = 8196
|
|
663
664
|
}
|