@idlizer/arktscgen 2.1.10-arktscgen-5 → 2.1.10-arktscgen-7
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 +24 -47
- package/build/libarkts-copy/native/meson.build +29 -13
- package/build/libarkts-copy/native/meson_options.txt +9 -3
- package/build/libarkts-copy/native/mingw.cross +2 -0
- package/build/libarkts-copy/native/src/{bridges.cc → bridges.cpp} +31 -92
- package/build/libarkts-copy/native/src/{common.cc → common.cpp} +240 -107
- package/build/libarkts-copy/native/src/common.h +22 -22
- package/build/libarkts-copy/native/src/{memoryTracker.cc → memoryTracker.cpp} +45 -32
- package/build/libarkts-copy/package.json +13 -11
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +10 -63
- package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +9 -3
- package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +10 -7
- package/build/libarkts-copy/src/arkts-api/ProgramProvider.ts +14 -5
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +19 -1
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -0
- package/build/libarkts-copy/src/arkts-api/index.ts +0 -2
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +12 -3
- package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/OverloadDeclaration.ts +29 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +0 -16
- package/build/libarkts-copy/src/arkts-api/peers/Config.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +9 -9
- package/build/libarkts-copy/src/arkts-api/plugins.ts +113 -15
- package/build/libarkts-copy/src/arkts-api/static/global.ts +1 -4
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +5 -5
- package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +2 -1
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +11 -43
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +41 -9
- package/build/libarkts-copy/src/arkts-api/visitor.ts +4 -25
- package/build/libarkts-copy/src/checkSdk.ts +1 -1
- package/build/libarkts-copy/src/index.ts +1 -2
- package/build/libarkts-copy/src/memo-node-cache.ts +143 -0
- package/build/libarkts-copy/src/plugin-utils.ts +72 -40
- package/build/libarkts-copy/src/reexport-for-generated.ts +3 -1
- package/build/libarkts-copy/src/tracer.ts +2 -2
- package/build/libarkts-copy/src/utils.ts +10 -14
- package/build/libarkts-copy/tsconfig.json +0 -3
- package/lib/index.js +5517 -10446
- package/package.json +9 -7
- package/templates/{bridges.cc → bridges.cpp} +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +0 -45
- package/build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts +0 -23
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +0 -1250
- package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +0 -125
- package/build/libarkts-copy/src/ts-api/index.ts +0 -27
- package/build/libarkts-copy/src/ts-api/static/enums.ts +0 -18
- package/build/libarkts-copy/src/ts-api/types.ts +0 -1075
- package/build/libarkts-copy/src/ts-api/utilities/private.ts +0 -292
- package/build/libarkts-copy/src/ts-api/utilities/public.ts +0 -55
- package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +0 -139
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022-2023 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 { throwError } from '../../utils';
|
|
17
|
-
|
|
18
|
-
import * as ts from '../';
|
|
19
|
-
import * as arkts from '../../arkts-api';
|
|
20
|
-
|
|
21
|
-
import { KInt } from '@koalaui/interop';
|
|
22
|
-
import { SyntaxKind, TokenSyntaxKind, NodeFlags } from '../static/enums';
|
|
23
|
-
import {
|
|
24
|
-
Es2pandaAstNodeType,
|
|
25
|
-
Es2pandaModifierFlags,
|
|
26
|
-
Es2pandaScriptFunctionFlags,
|
|
27
|
-
Es2pandaTokenType,
|
|
28
|
-
Es2pandaVariableDeclarationKind,
|
|
29
|
-
} from '../../arkts-api';
|
|
30
|
-
|
|
31
|
-
export function emptyImplementation(): any {
|
|
32
|
-
throwError('Not yet implemented');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type kindTypes =
|
|
36
|
-
| { new (node: arkts.AstNode): ts.Node }
|
|
37
|
-
| { new (node: arkts.Identifier): ts.Identifier }
|
|
38
|
-
| { new (node: arkts.EtsScript): ts.SourceFile }
|
|
39
|
-
| { new (node: arkts.StringLiteral): ts.StringLiteral }
|
|
40
|
-
| { new (node: arkts.NumberLiteral): ts.NumericLiteral }
|
|
41
|
-
| { new (node: arkts.ExpressionStatement): ts.ExpressionStatement }
|
|
42
|
-
| { new (node: arkts.FunctionDeclaration): ts.FunctionDeclaration }
|
|
43
|
-
| { new (node: arkts.ReturnStatement): ts.ReturnStatement }
|
|
44
|
-
| { new (node: arkts.ETSParameterExpression): ts.ParameterDeclaration }
|
|
45
|
-
| { new (node: arkts.CallExpression): ts.CallExpression }
|
|
46
|
-
| { new (node: arkts.BlockStatement): ts.Block }
|
|
47
|
-
| { new (node: arkts.TSTypeParameter): ts.TypeParameterDeclaration }
|
|
48
|
-
| { new (node: arkts.MemberExpression): ts.PropertyAccessExpression }
|
|
49
|
-
| { new (node: arkts.IfStatement): ts.IfStatement }
|
|
50
|
-
| { new (node: arkts.ETSTypeReference): ts.TypeReferenceNode }
|
|
51
|
-
| { new (node: arkts.ETSPrimitiveType | arkts.ETSTypeReference): ts.KeywordTypeNode }
|
|
52
|
-
| { new (node: arkts.BinaryExpression): ts.BinaryExpression }
|
|
53
|
-
| { new (node: arkts.ETSUnionType): ts.UnionTypeNode }
|
|
54
|
-
| { new (node: arkts.ArrowFunctionExpression): ts.ArrowFunction }
|
|
55
|
-
| { new (node: arkts.ClassDeclaration): ts.ClassDeclaration }
|
|
56
|
-
| { new (node: arkts.MethodDefinition): ts.MethodDeclaration }
|
|
57
|
-
| { new (node: arkts.VariableDeclarator): ts.VariableDeclaration }
|
|
58
|
-
| { new (node: arkts.VariableDeclaration): ts.VariableStatement };
|
|
59
|
-
|
|
60
|
-
export function classByEtsNode(node: arkts.AstNode) {
|
|
61
|
-
const types = new Map<Es2pandaAstNodeType, kindTypes>([
|
|
62
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE, ts.SourceFile],
|
|
63
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_IDENTIFIER, ts.Identifier],
|
|
64
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_STRING_LITERAL, ts.StringLiteral],
|
|
65
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_NUMBER_LITERAL, ts.NumericLiteral],
|
|
66
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_EXPRESSION_STATEMENT, ts.ExpressionStatement],
|
|
67
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_FUNCTION_DECLARATION, ts.FunctionDeclaration],
|
|
68
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_RETURN_STATEMENT, ts.ReturnStatement],
|
|
69
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION, ts.ParameterDeclaration],
|
|
70
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_CALL_EXPRESSION, ts.CallExpression],
|
|
71
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_BLOCK_STATEMENT, ts.Block],
|
|
72
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ETS_TYPE_REFERENCE, ts.TypeReferenceNode],
|
|
73
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER, ts.TypeParameterDeclaration],
|
|
74
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_MEMBER_EXPRESSION, ts.PropertyAccessExpression],
|
|
75
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_IF_STATEMENT, ts.IfStatement],
|
|
76
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ETS_PRIMITIVE_TYPE, ts.KeywordTypeNode],
|
|
77
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_BINARY_EXPRESSION, ts.BinaryExpression],
|
|
78
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ETS_UNION_TYPE, ts.UnionTypeNode],
|
|
79
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION, ts.ArrowFunction],
|
|
80
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DECLARATION, ts.ClassDeclaration],
|
|
81
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_METHOD_DEFINITION, ts.MethodDeclaration],
|
|
82
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_VARIABLE_DECLARATION, ts.VariableStatement],
|
|
83
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_VARIABLE_DECLARATOR, ts.VariableDeclaration],
|
|
84
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_SUPER_EXPRESSION, ts.SuperExpression],
|
|
85
|
-
|
|
86
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_STATIC_BLOCK, ts.UnsupportedNode],
|
|
87
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_PROPERTY, ts.UnsupportedNode],
|
|
88
|
-
[Es2pandaAstNodeType.AST_NODE_TYPE_ETS_IMPORT_DECLARATION, ts.UnsupportedNode],
|
|
89
|
-
]);
|
|
90
|
-
|
|
91
|
-
return types.get(node.type) ?? throwError(`UNSUPPORTED NODE (ts): ${Es2pandaAstNodeType[node.type]}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Improve: add checks for casts in functions below
|
|
95
|
-
|
|
96
|
-
export function unpackNode<U extends arkts.AstNode, T extends ts.Node<U>>(node: U): T;
|
|
97
|
-
export function unpackNode<U extends arkts.AstNode | undefined, T extends ts.Node<U>>(node: U): T | undefined;
|
|
98
|
-
export function unpackNode<U extends arkts.AstNode | undefined, T extends ts.Node<U>>(node: U): T | undefined {
|
|
99
|
-
if (node === undefined) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
return new (classByEtsNode(node))(node as any) as T;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function passNode<T extends arkts.AstNode>(node: ts.Node<T>): T;
|
|
106
|
-
export function passNode<T extends arkts.AstNode>(node: ts.Node<T> | undefined): T | undefined;
|
|
107
|
-
export function passNode<T extends arkts.AstNode>(node: ts.Node<T> | undefined): T | undefined {
|
|
108
|
-
if (node === undefined) {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
return (node.node as T) ?? throwError('trying to pass non-compatible node');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function unpackNodeArray<U extends arkts.AstNode | undefined, T extends ts.Node<arkts.AstNode>>(
|
|
115
|
-
nodes: readonly U[]
|
|
116
|
-
): ts.NodeArray<T>;
|
|
117
|
-
export function unpackNodeArray<U extends arkts.AstNode | undefined, T extends ts.Node<arkts.AstNode>>(
|
|
118
|
-
nodes: readonly U[] | undefined
|
|
119
|
-
): ts.NodeArray<T> | undefined;
|
|
120
|
-
export function unpackNodeArray<U extends arkts.AstNode | undefined, T extends ts.Node<arkts.AstNode>>(
|
|
121
|
-
nodes: readonly U[] | undefined
|
|
122
|
-
): ts.NodeArray<T> | undefined {
|
|
123
|
-
return nodes?.map((node: U) => unpackNode(node)) as ReadonlyArray<ts.Node<arkts.AstNode>> as ts.NodeArray<T>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function passNodeArray<T extends arkts.AstNode>(nodes: readonly ts.Node<T>[]): T[];
|
|
127
|
-
export function passNodeArray<T extends arkts.AstNode>(nodes: readonly ts.Node<T>[] | undefined): T[] | undefined;
|
|
128
|
-
export function passNodeArray<T extends arkts.AstNode>(nodes: readonly ts.Node<T>[] | undefined): T[] | undefined {
|
|
129
|
-
return nodes?.map((node: ts.Node<T>) => passNode<T>(node));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function passIdentifier(node: ts.Identifier | string, typeAnnotation?: ts.TypeNode): arkts.Identifier;
|
|
133
|
-
export function passIdentifier(
|
|
134
|
-
node: ts.Identifier | string | undefined,
|
|
135
|
-
typeAnnotation?: ts.TypeNode
|
|
136
|
-
): arkts.Identifier | undefined;
|
|
137
|
-
export function passIdentifier(
|
|
138
|
-
node: ts.Identifier | string | undefined,
|
|
139
|
-
typeAnnotation?: ts.TypeNode
|
|
140
|
-
): arkts.Identifier | undefined {
|
|
141
|
-
if (node === undefined) {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
if (node instanceof ts.Identifier) {
|
|
145
|
-
if (typeAnnotation === undefined) {
|
|
146
|
-
return node.node;
|
|
147
|
-
}
|
|
148
|
-
return arkts.Identifier.create(node.node.name, passNode(typeAnnotation));
|
|
149
|
-
}
|
|
150
|
-
return arkts.Identifier.create(node, passNode(typeAnnotation));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Improve: support optional params
|
|
154
|
-
export function passTypeParams(
|
|
155
|
-
params: readonly ts.TypeParameterDeclaration[] | undefined
|
|
156
|
-
): arkts.TSTypeParameterDeclaration | undefined {
|
|
157
|
-
if (params === undefined) {
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
return arkts.factory.createTypeParameterDeclaration(passNodeArray(params));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function unpackModifiers(modifiers: KInt | undefined): ts.NodeArray<ts.Modifier> {
|
|
164
|
-
const translation = new Map<Es2pandaModifierFlags, ts.ModifierSyntaxKind>([
|
|
165
|
-
// [Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, SyntaxKind.UnknownKeyword],
|
|
166
|
-
// [Es2pandaModifierFlags.MODIFIER_FLAGS_CONSTRUCTOR, SyntaxKind.ConstructorKeyword],
|
|
167
|
-
|
|
168
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT, SyntaxKind.AbstractKeyword],
|
|
169
|
-
// Improve: unsupported
|
|
170
|
-
// [Es2pandaModifierFlags. , SyntaxKind.AccessorKeyword],
|
|
171
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_ASYNC, SyntaxKind.AsyncKeyword],
|
|
172
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_CONST, SyntaxKind.ConstKeyword],
|
|
173
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE, SyntaxKind.DeclareKeyword],
|
|
174
|
-
// Improve: choose one
|
|
175
|
-
// [Es2pandaModifierFlags.MODIFIER_FLAGS_DEFAULT_EXPORT, SyntaxKind.DefaultClause],
|
|
176
|
-
// [Es2pandaModifierFlags.MODIFIER_FLAGS_DEFAULT_EXPORT, SyntaxKind.DefaultKeyword],
|
|
177
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT, SyntaxKind.ExportKeyword],
|
|
178
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_IN, SyntaxKind.InKeyword],
|
|
179
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, SyntaxKind.PrivateKeyword],
|
|
180
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_PROTECTED, SyntaxKind.ProtectedKeyword],
|
|
181
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, SyntaxKind.PublicKeyword],
|
|
182
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_OUT, SyntaxKind.OutKeyword],
|
|
183
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_OVERRIDE, SyntaxKind.OverrideKeyword],
|
|
184
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_READONLY, SyntaxKind.ReadonlyKeyword],
|
|
185
|
-
[Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC, SyntaxKind.StaticKeyword],
|
|
186
|
-
]);
|
|
187
|
-
|
|
188
|
-
const bits = function* (flags: KInt) {
|
|
189
|
-
let bit: KInt = 1;
|
|
190
|
-
while (flags >= bit) {
|
|
191
|
-
if ((flags & bit) > 0) {
|
|
192
|
-
yield bit;
|
|
193
|
-
}
|
|
194
|
-
bit <<= 1;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
if (modifiers === undefined) {
|
|
198
|
-
return [] as ReadonlyArray<ts.Modifier> as ts.NodeArray<ts.Modifier>;
|
|
199
|
-
}
|
|
200
|
-
let mods: ts.Modifier[] = [];
|
|
201
|
-
for (const bit of bits(modifiers)) {
|
|
202
|
-
mods.push(new ts.Modifier(translation.get(bit) ?? throwError(`Unsupported modifier: ${bit}`)));
|
|
203
|
-
}
|
|
204
|
-
return mods as ReadonlyArray<ts.Modifier> as ts.NodeArray<ts.Modifier>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function passModifiers(
|
|
208
|
-
modifiers: ReadonlyArray<ts.Modifier | undefined | Es2pandaModifierFlags> | undefined
|
|
209
|
-
): KInt {
|
|
210
|
-
const translation = new Map<ts.ModifierSyntaxKind, Es2pandaModifierFlags>([
|
|
211
|
-
// [SyntaxKind.UnknownKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_NONE],
|
|
212
|
-
// [SyntaxKind.ConstructorKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_CONSTRUCTOR],
|
|
213
|
-
|
|
214
|
-
[SyntaxKind.AbstractKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT],
|
|
215
|
-
// Improve: unsupported
|
|
216
|
-
// [SyntaxKind.AccessorKeyword, Es2pandaModifierFlags.],
|
|
217
|
-
[SyntaxKind.AsyncKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_ASYNC],
|
|
218
|
-
[SyntaxKind.ConstKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_CONST],
|
|
219
|
-
[SyntaxKind.DeclareKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE],
|
|
220
|
-
[SyntaxKind.DefaultKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_DEFAULT_EXPORT],
|
|
221
|
-
[SyntaxKind.ExportKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT],
|
|
222
|
-
[SyntaxKind.InKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_IN],
|
|
223
|
-
[SyntaxKind.PrivateKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE],
|
|
224
|
-
[SyntaxKind.ProtectedKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_PROTECTED],
|
|
225
|
-
[SyntaxKind.PublicKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC],
|
|
226
|
-
[SyntaxKind.OutKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_OUT],
|
|
227
|
-
[SyntaxKind.OverrideKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_OVERRIDE],
|
|
228
|
-
[SyntaxKind.ReadonlyKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_READONLY],
|
|
229
|
-
[SyntaxKind.StaticKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC],
|
|
230
|
-
]);
|
|
231
|
-
|
|
232
|
-
if (modifiers === undefined) {
|
|
233
|
-
return Es2pandaModifierFlags.MODIFIER_FLAGS_NONE;
|
|
234
|
-
}
|
|
235
|
-
return modifiers
|
|
236
|
-
.map((mod: ts.Modifier | undefined | Es2pandaModifierFlags) => {
|
|
237
|
-
if (mod === undefined) {
|
|
238
|
-
return Es2pandaModifierFlags.MODIFIER_FLAGS_NONE;
|
|
239
|
-
}
|
|
240
|
-
if (typeof mod === 'object') {
|
|
241
|
-
return translation.get(mod.kind) ?? throwError(`Unsupported modifier: ${mod.kind}`);
|
|
242
|
-
}
|
|
243
|
-
return mod;
|
|
244
|
-
})
|
|
245
|
-
.reduce((prev, curr) => prev | curr, Es2pandaModifierFlags.MODIFIER_FLAGS_NONE);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function passToken<TKind extends TokenSyntaxKind>(token: ts.Token<TKind>): KInt {
|
|
249
|
-
const translation = new Map<TokenSyntaxKind, Es2pandaTokenType>([
|
|
250
|
-
[SyntaxKind.PlusToken, Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_PLUS],
|
|
251
|
-
[SyntaxKind.MinusToken, Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_MINUS],
|
|
252
|
-
[SyntaxKind.AsteriskToken, Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_MULTIPLY],
|
|
253
|
-
]);
|
|
254
|
-
|
|
255
|
-
return translation.get(token.kind) ?? throwError('unsupported token');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function passModifiersToScriptFunction(modifiers: readonly ts.Modifier[] | undefined): KInt {
|
|
259
|
-
const translation = new Map<ts.ModifierSyntaxKind, Es2pandaScriptFunctionFlags>([
|
|
260
|
-
[SyntaxKind.StaticKeyword, Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_STATIC_BLOCK],
|
|
261
|
-
[SyntaxKind.AsyncKeyword, Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ASYNC],
|
|
262
|
-
[SyntaxKind.PublicKeyword, Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE],
|
|
263
|
-
]);
|
|
264
|
-
|
|
265
|
-
return (
|
|
266
|
-
modifiers?.reduce(
|
|
267
|
-
(prev, curr) =>
|
|
268
|
-
prev | (translation.get(curr.kind) ?? throwError(`Unsupported ScriptFunction flag: ${curr.kind}`)),
|
|
269
|
-
Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE
|
|
270
|
-
) ?? Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export function passVariableDeclarationKind(flags: NodeFlags): Es2pandaVariableDeclarationKind {
|
|
275
|
-
const translation = new Map<NodeFlags, Es2pandaVariableDeclarationKind>([
|
|
276
|
-
[NodeFlags.Const, Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST],
|
|
277
|
-
[NodeFlags.Let, Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET],
|
|
278
|
-
[NodeFlags.None, Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_VAR],
|
|
279
|
-
]);
|
|
280
|
-
|
|
281
|
-
return translation.get(flags) ?? throwError('unsupported VariableDeclarationKind');
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export function unpackVariableDeclarationKind(kind: Es2pandaVariableDeclarationKind): NodeFlags {
|
|
285
|
-
const translation = new Map<Es2pandaVariableDeclarationKind, NodeFlags>([
|
|
286
|
-
[Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, NodeFlags.Const],
|
|
287
|
-
[Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET, NodeFlags.Let],
|
|
288
|
-
[Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_VAR, NodeFlags.None],
|
|
289
|
-
]);
|
|
290
|
-
|
|
291
|
-
return translation.get(kind) ?? throwError('unsupported VariableDeclarationKind');
|
|
292
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022-2023 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 { global } from '../../arkts-api/static/global';
|
|
17
|
-
import { throwError } from '../../utils';
|
|
18
|
-
import * as ts from '../.';
|
|
19
|
-
import { KNativePointer, nullptr } from '@koalaui/interop';
|
|
20
|
-
import { unpackNonNullableNode } from '../../arkts-api';
|
|
21
|
-
|
|
22
|
-
export { proceedToState, startChecker } from '../../arkts-api';
|
|
23
|
-
|
|
24
|
-
// Improve: like in arkts utils
|
|
25
|
-
export function getDecl(node: ts.Node): ts.Node | undefined {
|
|
26
|
-
if (node.node === undefined) {
|
|
27
|
-
throwError('there is no arkts pair of ts node (unable to getDecl)');
|
|
28
|
-
}
|
|
29
|
-
let decl: KNativePointer = node.node.peer;
|
|
30
|
-
decl = global.es2panda._AstNodeVariableConst(global.context, decl);
|
|
31
|
-
if (decl === nullptr) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
decl = global.es2panda._VariableDeclaration(global.context, decl);
|
|
35
|
-
if (decl === nullptr) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
decl = global.es2panda._DeclNode(global.context, decl);
|
|
39
|
-
if (decl === nullptr) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return ts.unpackNode(unpackNonNullableNode(decl));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Improve: like in arkts utils
|
|
46
|
-
export function getOriginalNode(node: ts.Node): ts.Node {
|
|
47
|
-
if (node.node === undefined) {
|
|
48
|
-
// Improve: fix this
|
|
49
|
-
throwError('there is no arkts pair of ts node (unable to getOriginalNode)');
|
|
50
|
-
}
|
|
51
|
-
if (node.node.originalPeer === nullptr) {
|
|
52
|
-
return node;
|
|
53
|
-
}
|
|
54
|
-
return ts.unpackNode(unpackNonNullableNode(node.node.originalPeer));
|
|
55
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022-2023 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 { throwError } from '../../utils';
|
|
17
|
-
|
|
18
|
-
import * as ts from '../.';
|
|
19
|
-
import { factory } from '../factory/nodeFactory';
|
|
20
|
-
import { SyntaxKind } from '../static/enums';
|
|
21
|
-
|
|
22
|
-
type Visitor = (node: ts.Node) => ts.Node;
|
|
23
|
-
|
|
24
|
-
// Improve: rethink (remove as)
|
|
25
|
-
function nodeVisitor<T extends ts.Node | undefined>(node: T, visitor: Visitor): T {
|
|
26
|
-
if (node === undefined) {
|
|
27
|
-
return node;
|
|
28
|
-
}
|
|
29
|
-
return visitor(node) as T;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Improve: rethink (remove as)
|
|
33
|
-
function nodesVisitor<T extends ts.Node, TIn extends ts.NodeArray<T> | undefined>(
|
|
34
|
-
nodes: TIn,
|
|
35
|
-
visitor: Visitor
|
|
36
|
-
): T[] | TIn {
|
|
37
|
-
if (nodes === undefined) {
|
|
38
|
-
return nodes;
|
|
39
|
-
}
|
|
40
|
-
return nodes.map((node) => visitor(node) as T);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type VisitEachChildFunction<T extends ts.Node> = (node: T, visitor: Visitor) => T;
|
|
44
|
-
|
|
45
|
-
// Improve: add more nodes
|
|
46
|
-
type HasChildren =
|
|
47
|
-
| ts.SourceFile
|
|
48
|
-
| ts.FunctionDeclaration
|
|
49
|
-
| ts.ExpressionStatement
|
|
50
|
-
| ts.CallExpression
|
|
51
|
-
| ts.PropertyAccessExpression
|
|
52
|
-
| ts.ClassDeclaration
|
|
53
|
-
| ts.MethodDeclaration
|
|
54
|
-
| ts.Block
|
|
55
|
-
| ts.VariableStatement
|
|
56
|
-
| ts.VariableDeclarationList;
|
|
57
|
-
|
|
58
|
-
type VisitEachChildTable = { [TNode in HasChildren as TNode['kind']]: VisitEachChildFunction<TNode> };
|
|
59
|
-
|
|
60
|
-
// Improve: add more nodes
|
|
61
|
-
const visitEachChildTable: VisitEachChildTable = {
|
|
62
|
-
[SyntaxKind.SourceFile]: function (node: ts.SourceFile, visitor: Visitor) {
|
|
63
|
-
return factory.updateSourceFile(node, nodesVisitor(node.statements, visitor));
|
|
64
|
-
},
|
|
65
|
-
[SyntaxKind.FunctionDeclaration]: function (node: ts.FunctionDeclaration, visitor: Visitor) {
|
|
66
|
-
return factory.updateFunctionDeclaration(
|
|
67
|
-
node,
|
|
68
|
-
node.modifiers,
|
|
69
|
-
undefined,
|
|
70
|
-
nodeVisitor(node.name, visitor),
|
|
71
|
-
nodesVisitor(node.typeParameters, visitor),
|
|
72
|
-
nodesVisitor(node.parameters, visitor),
|
|
73
|
-
nodeVisitor(node.type, visitor),
|
|
74
|
-
nodeVisitor(node.body, visitor)
|
|
75
|
-
);
|
|
76
|
-
},
|
|
77
|
-
[SyntaxKind.ExpressionStatement]: function (node: ts.ExpressionStatement, visitor: Visitor) {
|
|
78
|
-
return factory.updateExpressionStatement(node, nodeVisitor(node.expression, visitor));
|
|
79
|
-
},
|
|
80
|
-
[SyntaxKind.CallExpression]: function (node: ts.CallExpression, visitor: Visitor) {
|
|
81
|
-
return factory.updateCallExpression(
|
|
82
|
-
node,
|
|
83
|
-
nodeVisitor(node.expression, visitor),
|
|
84
|
-
undefined,
|
|
85
|
-
nodesVisitor(node.arguments, visitor)
|
|
86
|
-
);
|
|
87
|
-
},
|
|
88
|
-
[SyntaxKind.PropertyAccessExpression]: function (node: ts.PropertyAccessExpression, visitor: Visitor) {
|
|
89
|
-
return factory.updatePropertyAccessExpression(
|
|
90
|
-
node,
|
|
91
|
-
nodeVisitor(node.expression, visitor),
|
|
92
|
-
nodeVisitor(node.name, visitor)
|
|
93
|
-
);
|
|
94
|
-
},
|
|
95
|
-
[SyntaxKind.ClassDeclaration]: function (node: ts.ClassDeclaration, visitor: Visitor) {
|
|
96
|
-
return factory.updateClassDeclaration(
|
|
97
|
-
node,
|
|
98
|
-
undefined,
|
|
99
|
-
nodeVisitor(node.name, visitor),
|
|
100
|
-
undefined,
|
|
101
|
-
undefined,
|
|
102
|
-
nodesVisitor(node.members, visitor)
|
|
103
|
-
);
|
|
104
|
-
},
|
|
105
|
-
[SyntaxKind.MethodDeclaration]: function (node: ts.MethodDeclaration, visitor: Visitor) {
|
|
106
|
-
return factory.updateMethodDeclaration(
|
|
107
|
-
node,
|
|
108
|
-
undefined,
|
|
109
|
-
undefined,
|
|
110
|
-
nodeVisitor(node.name, visitor),
|
|
111
|
-
undefined,
|
|
112
|
-
undefined,
|
|
113
|
-
nodesVisitor(node.parameters, visitor),
|
|
114
|
-
undefined,
|
|
115
|
-
nodeVisitor(node.body, visitor)
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
[SyntaxKind.Block]: function (node: ts.Block, visitor: Visitor) {
|
|
119
|
-
return factory.updateBlock(node, nodesVisitor(node.statements, visitor));
|
|
120
|
-
},
|
|
121
|
-
[SyntaxKind.VariableStatement]: function (node: ts.VariableStatement, visitor: Visitor) {
|
|
122
|
-
return factory.updateVariableStatement(node, undefined, nodeVisitor(node.declarationList, visitor));
|
|
123
|
-
},
|
|
124
|
-
[SyntaxKind.VariableDeclarationList]: function (node: ts.VariableDeclarationList, visitor: Visitor) {
|
|
125
|
-
return factory.updateVariableDeclarationList(node, nodesVisitor(node.declarations, visitor));
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
function nodeHasChildren(node: ts.Node): node is HasChildren {
|
|
130
|
-
return node.kind in visitEachChildTable;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function visitEachChild<T extends ts.Node>(node: T, visitor: Visitor): T {
|
|
134
|
-
const visitFunc = (visitEachChildTable as Record<SyntaxKind, VisitEachChildFunction<any> | undefined>)[node.kind];
|
|
135
|
-
if (nodeHasChildren(node) && visitFunc === undefined) {
|
|
136
|
-
throwError('Unsupported node kind: ' + node.kind);
|
|
137
|
-
}
|
|
138
|
-
return visitFunc === undefined ? node : visitFunc(node, visitor);
|
|
139
|
-
}
|