@idlizer/arktscgen 2.1.2

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.
Files changed (229) hide show
  1. package/build/libarkts-copy/generator/options.json5 +155 -0
  2. package/build/libarkts-copy/native/meson.build +62 -0
  3. package/build/libarkts-copy/native/meson_options.txt +24 -0
  4. package/build/libarkts-copy/native/src/bridges.cc +265 -0
  5. package/build/libarkts-copy/native/src/common.cc +231 -0
  6. package/build/libarkts-copy/native/src/common.h +39 -0
  7. package/build/libarkts-copy/native/src/generated/bridges.cc +11979 -0
  8. package/build/libarkts-copy/package.json +51 -0
  9. package/build/libarkts-copy/src/Es2pandaEnums.ts +183 -0
  10. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +123 -0
  11. package/build/libarkts-copy/src/InteropNativeModule.ts +50 -0
  12. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +31 -0
  13. package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +147 -0
  14. package/build/libarkts-copy/src/arkts-api/index.ts +28 -0
  15. package/build/libarkts-copy/src/arkts-api/node-utilities/createCallExpression.ts +40 -0
  16. package/build/libarkts-copy/src/arkts-api/node-utilities/createNumberLiteral.ts +28 -0
  17. package/build/libarkts-copy/src/arkts-api/node-utilities/createScriptFunction.ts +55 -0
  18. package/build/libarkts-copy/src/arkts-api/peers/ArktsObject.ts +45 -0
  19. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +121 -0
  20. package/build/libarkts-copy/src/arkts-api/peers/Config.ts +52 -0
  21. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +46 -0
  22. package/build/libarkts-copy/src/arkts-api/peers/Program.ts +55 -0
  23. package/build/libarkts-copy/src/arkts-api/static/global.ts +67 -0
  24. package/build/libarkts-copy/src/arkts-api/utilities/nativePtrDecoder.ts +69 -0
  25. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +156 -0
  26. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +135 -0
  27. package/build/libarkts-copy/src/arkts-api/visitor.ts +297 -0
  28. package/build/libarkts-copy/src/es2panda.ts +277 -0
  29. package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +1266 -0
  30. package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +3745 -0
  31. package/build/libarkts-copy/src/generated/factory.ts +1299 -0
  32. package/build/libarkts-copy/src/generated/index.ts +191 -0
  33. package/build/libarkts-copy/src/generated/node-map.ts +182 -0
  34. package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +39 -0
  35. package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +49 -0
  36. package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +40 -0
  37. package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +110 -0
  38. package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +74 -0
  39. package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +98 -0
  40. package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +70 -0
  41. package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +57 -0
  42. package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +95 -0
  43. package/build/libarkts-copy/src/generated/peers/AstDumper.ts +42 -0
  44. package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +53 -0
  45. package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +53 -0
  46. package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +95 -0
  47. package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +64 -0
  48. package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +63 -0
  49. package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +53 -0
  50. package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +65 -0
  51. package/build/libarkts-copy/src/generated/peers/CallExpression.ts +97 -0
  52. package/build/libarkts-copy/src/generated/peers/CatchClause.ts +64 -0
  53. package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +53 -0
  54. package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +50 -0
  55. package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +58 -0
  56. package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +233 -0
  57. package/build/libarkts-copy/src/generated/peers/ClassElement.ts +80 -0
  58. package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +54 -0
  59. package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +70 -0
  60. package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +58 -0
  61. package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +74 -0
  62. package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +65 -0
  63. package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +50 -0
  64. package/build/libarkts-copy/src/generated/peers/Decorator.ts +54 -0
  65. package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +52 -0
  66. package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +58 -0
  67. package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +54 -0
  68. package/build/libarkts-copy/src/generated/peers/ETSDynamicFunctionType.ts +40 -0
  69. package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +84 -0
  70. package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +68 -0
  71. package/build/libarkts-copy/src/generated/peers/ETSLaunchExpression.ts +57 -0
  72. package/build/libarkts-copy/src/generated/peers/ETSModule.ts +71 -0
  73. package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +62 -0
  74. package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +69 -0
  75. package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +60 -0
  76. package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +50 -0
  77. package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +51 -0
  78. package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +126 -0
  79. package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +54 -0
  80. package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +51 -0
  81. package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +51 -0
  82. package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +73 -0
  83. package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +58 -0
  84. package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +68 -0
  85. package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +50 -0
  86. package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +53 -0
  87. package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +55 -0
  88. package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +50 -0
  89. package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +58 -0
  90. package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +56 -0
  91. package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +73 -0
  92. package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +57 -0
  93. package/build/libarkts-copy/src/generated/peers/Expression.ts +75 -0
  94. package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +59 -0
  95. package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +61 -0
  96. package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +64 -0
  97. package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +61 -0
  98. package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +40 -0
  99. package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +69 -0
  100. package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +64 -0
  101. package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +62 -0
  102. package/build/libarkts-copy/src/generated/peers/Identifier.ts +154 -0
  103. package/build/libarkts-copy/src/generated/peers/IfStatement.ts +65 -0
  104. package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +61 -0
  105. package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +54 -0
  106. package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +53 -0
  107. package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +54 -0
  108. package/build/libarkts-copy/src/generated/peers/ImportSource.ts +49 -0
  109. package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +57 -0
  110. package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +40 -0
  111. package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +60 -0
  112. package/build/libarkts-copy/src/generated/peers/Literal.ts +40 -0
  113. package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +40 -0
  114. package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +48 -0
  115. package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +95 -0
  116. package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +54 -0
  117. package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +105 -0
  118. package/build/libarkts-copy/src/generated/peers/NamedType.ts +76 -0
  119. package/build/libarkts-copy/src/generated/peers/NewExpression.ts +56 -0
  120. package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +50 -0
  121. package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +47 -0
  122. package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +90 -0
  123. package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +50 -0
  124. package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +50 -0
  125. package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +57 -0
  126. package/build/libarkts-copy/src/generated/peers/Property.ts +82 -0
  127. package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +57 -0
  128. package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +62 -0
  129. package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +201 -0
  130. package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +53 -0
  131. package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +79 -0
  132. package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +82 -0
  133. package/build/libarkts-copy/src/generated/peers/Statement.ts +39 -0
  134. package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +56 -0
  135. package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +50 -0
  136. package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +62 -0
  137. package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +63 -0
  138. package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +50 -0
  139. package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +53 -0
  140. package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +76 -0
  141. package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +50 -0
  142. package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +50 -0
  143. package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +60 -0
  144. package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +63 -0
  145. package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +65 -0
  146. package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +81 -0
  147. package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +66 -0
  148. package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +53 -0
  149. package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +67 -0
  150. package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +61 -0
  151. package/build/libarkts-copy/src/generated/peers/TSImportType.ts +64 -0
  152. package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +65 -0
  153. package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +56 -0
  154. package/build/libarkts-copy/src/generated/peers/TSInferType.ts +54 -0
  155. package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +53 -0
  156. package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +102 -0
  157. package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +54 -0
  158. package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +54 -0
  159. package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +54 -0
  160. package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +64 -0
  161. package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +71 -0
  162. package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +53 -0
  163. package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +63 -0
  164. package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +60 -0
  165. package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +50 -0
  166. package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +58 -0
  167. package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +50 -0
  168. package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +50 -0
  169. package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +50 -0
  170. package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +66 -0
  171. package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +54 -0
  172. package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +72 -0
  173. package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +63 -0
  174. package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +67 -0
  175. package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +50 -0
  176. package/build/libarkts-copy/src/generated/peers/TSThisType.ts +50 -0
  177. package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +53 -0
  178. package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +88 -0
  179. package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +63 -0
  180. package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +53 -0
  181. package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +63 -0
  182. package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +84 -0
  183. package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +62 -0
  184. package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +54 -0
  185. package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +60 -0
  186. package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +54 -0
  187. package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +62 -0
  188. package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +50 -0
  189. package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +53 -0
  190. package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +50 -0
  191. package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +50 -0
  192. package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +61 -0
  193. package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +59 -0
  194. package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +60 -0
  195. package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +50 -0
  196. package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +54 -0
  197. package/build/libarkts-copy/src/generated/peers/TryStatement.ts +75 -0
  198. package/build/libarkts-copy/src/generated/peers/TypeNode.ts +49 -0
  199. package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +39 -0
  200. package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +40 -0
  201. package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +53 -0
  202. package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +57 -0
  203. package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +50 -0
  204. package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +60 -0
  205. package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +42 -0
  206. package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +71 -0
  207. package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +69 -0
  208. package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +58 -0
  209. package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +56 -0
  210. package/build/libarkts-copy/src/reexport-for-generated.ts +33 -0
  211. package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +1375 -0
  212. package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +110 -0
  213. package/build/libarkts-copy/src/ts-api/index.ts +35 -0
  214. package/build/libarkts-copy/src/ts-api/static/enums.ts +18 -0
  215. package/build/libarkts-copy/src/ts-api/types.ts +920 -0
  216. package/build/libarkts-copy/src/ts-api/utilities/private.ts +289 -0
  217. package/build/libarkts-copy/src/ts-api/utilities/public.ts +55 -0
  218. package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +155 -0
  219. package/build/libarkts-copy/src/utils.ts +89 -0
  220. package/build/libarkts-copy/tsconfig.json +15 -0
  221. package/lib/index.js +11858 -0
  222. package/package.json +54 -0
  223. package/templates/Es2pandaEnums.ts +16 -0
  224. package/templates/Es2pandaNativeModule.ts +32 -0
  225. package/templates/bridges.cc +18 -0
  226. package/templates/factory.ts +34 -0
  227. package/templates/index.ts +16 -0
  228. package/templates/node-map.ts +31 -0
  229. package/templates/peer.ts +32 -0
@@ -0,0 +1,289 @@
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 {
23
+ SyntaxKind,
24
+ TokenSyntaxKind,
25
+ NodeFlags,
26
+ } from "../static/enums"
27
+ import {
28
+ Es2pandaAstNodeType,
29
+ Es2pandaModifierFlags,
30
+ Es2pandaScriptFunctionFlags,
31
+ Es2pandaTokenType,
32
+ Es2pandaVariableDeclarationKind,
33
+ } from "../../arkts-api"
34
+
35
+ export function todo(): any {
36
+ throwError("Not yet implemented")
37
+ }
38
+
39
+ type kindTypes =
40
+ | { new (node: arkts.AstNode): ts.Node }
41
+ | { new (node: arkts.Identifier): ts.Identifier }
42
+ | { new (node: arkts.EtsScript): ts.SourceFile }
43
+ | { new (node: arkts.StringLiteral): ts.StringLiteral }
44
+ | { new (node: arkts.NumberLiteral): ts.NumericLiteral }
45
+ | { new (node: arkts.ExpressionStatement): ts.ExpressionStatement }
46
+ | { new (node: arkts.FunctionDeclaration): ts.FunctionDeclaration }
47
+ | { new (node: arkts.ReturnStatement): ts.ReturnStatement }
48
+ | { new (node: arkts.ETSParameterExpression): ts.ParameterDeclaration }
49
+ | { new (node: arkts.CallExpression): ts.CallExpression }
50
+ | { new (node: arkts.BlockStatement): ts.Block }
51
+ | { new (node: arkts.TSTypeParameter): ts.TypeParameterDeclaration}
52
+ | { new (node: arkts.MemberExpression): ts.PropertyAccessExpression}
53
+ | { new (node: arkts.IfStatement): ts.IfStatement}
54
+ | { new (node: arkts.ETSTypeReference): ts.TypeReferenceNode }
55
+ | { new (node: arkts.ETSPrimitiveType | arkts.ETSTypeReference): ts.KeywordTypeNode }
56
+ | { new (node: arkts.BinaryExpression): ts.BinaryExpression }
57
+ | { new (node: arkts.ETSUnionType): ts.UnionTypeNode }
58
+ | { new (node: arkts.ArrowFunctionExpression): ts.ArrowFunction }
59
+ | { new (node: arkts.ClassDeclaration): ts.ClassDeclaration }
60
+ | { new (node: arkts.MethodDefinition): ts.MethodDeclaration }
61
+ | { new (node: arkts.VariableDeclarator): ts.VariableDeclaration }
62
+ | { new (node: arkts.VariableDeclaration): ts.VariableStatement }
63
+
64
+ export function classByEtsNode(node: arkts.AstNode) {
65
+ const types =
66
+ new Map<Es2pandaAstNodeType, kindTypes>([
67
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE, ts.SourceFile],
68
+ [Es2pandaAstNodeType.AST_NODE_TYPE_IDENTIFIER, ts.Identifier],
69
+ [Es2pandaAstNodeType.AST_NODE_TYPE_STRING_LITERAL, ts.StringLiteral],
70
+ [Es2pandaAstNodeType.AST_NODE_TYPE_NUMBER_LITERAL, ts.NumericLiteral],
71
+ [Es2pandaAstNodeType.AST_NODE_TYPE_EXPRESSION_STATEMENT, ts.ExpressionStatement],
72
+ [Es2pandaAstNodeType.AST_NODE_TYPE_FUNCTION_DECLARATION, ts.FunctionDeclaration],
73
+ [Es2pandaAstNodeType.AST_NODE_TYPE_RETURN_STATEMENT, ts.ReturnStatement],
74
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION, ts.ParameterDeclaration],
75
+ [Es2pandaAstNodeType.AST_NODE_TYPE_CALL_EXPRESSION, ts.CallExpression],
76
+ [Es2pandaAstNodeType.AST_NODE_TYPE_BLOCK_STATEMENT, ts.Block],
77
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ETS_TYPE_REFERENCE, ts.TypeReferenceNode],
78
+ [Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER, ts.TypeParameterDeclaration],
79
+ [Es2pandaAstNodeType.AST_NODE_TYPE_MEMBER_EXPRESSION, ts.PropertyAccessExpression],
80
+ [Es2pandaAstNodeType.AST_NODE_TYPE_IF_STATEMENT, ts.IfStatement],
81
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ETS_PRIMITIVE_TYPE, ts.KeywordTypeNode],
82
+ [Es2pandaAstNodeType.AST_NODE_TYPE_BINARY_EXPRESSION, ts.BinaryExpression],
83
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ETS_UNION_TYPE, ts.UnionTypeNode],
84
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION, ts.ArrowFunction],
85
+ [Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DECLARATION, ts.ClassDeclaration],
86
+ [Es2pandaAstNodeType.AST_NODE_TYPE_METHOD_DEFINITION, ts.MethodDeclaration],
87
+ [Es2pandaAstNodeType.AST_NODE_TYPE_VARIABLE_DECLARATION, ts.VariableStatement],
88
+ [Es2pandaAstNodeType.AST_NODE_TYPE_VARIABLE_DECLARATOR, ts.VariableDeclaration],
89
+ [Es2pandaAstNodeType.AST_NODE_TYPE_SUPER_EXPRESSION, ts.SuperExpression],
90
+
91
+ [Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_STATIC_BLOCK, ts.UnsupportedNode],
92
+ [Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_PROPERTY, ts.UnsupportedNode],
93
+ [Es2pandaAstNodeType.AST_NODE_TYPE_ETS_IMPORT_DECLARATION, ts.UnsupportedNode],
94
+ ])
95
+
96
+ return types.get(node.type) ?? throwError(`UNSUPPORTED NODE (ts): ${Es2pandaAstNodeType[node.type]}`)
97
+ }
98
+
99
+ // TODO: add checks for casts in functions below
100
+
101
+ export function unpackNode<U extends arkts.AstNode, T extends ts.Node<U> >(node: U): T
102
+ export function unpackNode<U extends arkts.AstNode | undefined, T extends ts.Node<U> >(node: U): T | undefined
103
+ export function unpackNode<U extends arkts.AstNode | undefined, T extends ts.Node<U> >(node: U): T | undefined {
104
+ if (node === undefined) {
105
+ return undefined
106
+ }
107
+ return (new (classByEtsNode(node))(node as any)) as T
108
+ }
109
+
110
+ export function passNode<T extends arkts.AstNode>(node: ts.Node<T>): T
111
+ export function passNode<T extends arkts.AstNode>(node: ts.Node<T> | undefined): T | undefined
112
+ export function passNode<T extends arkts.AstNode>(node: ts.Node<T> | undefined): T | undefined {
113
+ if (node === undefined) {
114
+ return undefined
115
+ }
116
+ return (node.node as T) ?? throwError('trying to pass non-compatible node')
117
+ }
118
+
119
+ export function unpackNodeArray<U extends arkts.AstNode | undefined, T extends ts.Node<arkts.AstNode> >(nodes: readonly U[]): ts.NodeArray<T>
120
+ export function unpackNodeArray<U extends arkts.AstNode | undefined, T extends ts.Node<arkts.AstNode> >(nodes: readonly U[] | undefined): ts.NodeArray<T> | undefined
121
+ export function unpackNodeArray<U extends arkts.AstNode | undefined, T extends ts.Node<arkts.AstNode> >(nodes: readonly U[] | undefined): ts.NodeArray<T> | undefined {
122
+ return nodes?.map((node: U) => unpackNode(node)) as ReadonlyArray<ts.Node<arkts.AstNode> > as ts.NodeArray<T>
123
+ }
124
+
125
+ export function passNodeArray<T extends arkts.AstNode>(nodes: readonly ts.Node<T>[]): T[]
126
+ export function passNodeArray<T extends arkts.AstNode>(nodes: readonly ts.Node<T>[] | undefined): T[] | undefined
127
+ export function passNodeArray<T extends arkts.AstNode>(nodes: readonly ts.Node<T>[] | undefined): T[] | undefined {
128
+ return nodes?.map((node: ts.Node<T>) => passNode<T>(node))
129
+ }
130
+
131
+ export function passIdentifier(node: ts.Identifier | string, typeAnnotation?: ts.TypeNode): arkts.Identifier
132
+ export function passIdentifier(node: ts.Identifier | string | undefined, typeAnnotation?: ts.TypeNode): arkts.Identifier | undefined
133
+ export function passIdentifier(node: ts.Identifier | string | undefined, typeAnnotation?: ts.TypeNode): arkts.Identifier | undefined {
134
+ if (node === undefined) {
135
+ return undefined
136
+ }
137
+ if (node instanceof ts.Identifier) {
138
+ if (typeAnnotation === undefined) {
139
+ return node.node
140
+ }
141
+ return arkts.Identifier.create(
142
+ node.node.name,
143
+ passNode(typeAnnotation)
144
+ )
145
+ }
146
+ return arkts.Identifier.create(
147
+ node,
148
+ passNode(typeAnnotation)
149
+ )
150
+ }
151
+
152
+ // TODO: support optional params
153
+ export function passTypeParams(params: readonly ts.TypeParameterDeclaration[] | undefined): arkts.TSTypeParameterDeclaration | undefined {
154
+ if (params === undefined) {
155
+ return undefined
156
+ }
157
+ return arkts.factory.createTypeParameterDeclaration(
158
+ passNodeArray(params)
159
+ )
160
+ }
161
+
162
+ export function unpackModifiers(modifiers: KInt | undefined): ts.NodeArray<ts.Modifier> {
163
+ const translation = new Map<Es2pandaModifierFlags, ts.ModifierSyntaxKind>([
164
+ // [Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, SyntaxKind.UnknownKeyword],
165
+ // [Es2pandaModifierFlags.MODIFIER_FLAGS_CONSTRUCTOR, SyntaxKind.ConstructorKeyword],
166
+
167
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT, SyntaxKind.AbstractKeyword],
168
+ // TODO: unsupported
169
+ // [Es2pandaModifierFlags. , SyntaxKind.AccessorKeyword],
170
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_ASYNC, SyntaxKind.AsyncKeyword],
171
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_CONST, SyntaxKind.ConstKeyword],
172
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE, SyntaxKind.DeclareKeyword],
173
+ // TODO: choose one
174
+ // [Es2pandaModifierFlags.MODIFIER_FLAGS_DEFAULT_EXPORT, SyntaxKind.DefaultClause],
175
+ // [Es2pandaModifierFlags.MODIFIER_FLAGS_DEFAULT_EXPORT, SyntaxKind.DefaultKeyword],
176
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT, SyntaxKind.ExportKeyword],
177
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_IN, SyntaxKind.InKeyword],
178
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, SyntaxKind.PrivateKeyword],
179
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_PROTECTED, SyntaxKind.ProtectedKeyword],
180
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, SyntaxKind.PublicKeyword],
181
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_OUT, SyntaxKind.OutKeyword],
182
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_OVERRIDE, SyntaxKind.OverrideKeyword],
183
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_READONLY, SyntaxKind.ReadonlyKeyword],
184
+ [Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC, SyntaxKind.StaticKeyword],
185
+ ])
186
+
187
+ const bits = function*(flags: KInt) {
188
+ let bit: KInt = 1
189
+ while (flags >= bit) {
190
+ if ((flags & bit) > 0) {
191
+ yield bit
192
+ }
193
+ bit <<= 1
194
+ }
195
+ }
196
+ if (modifiers === undefined) {
197
+ return [] as ReadonlyArray<ts.Modifier> as ts.NodeArray<ts.Modifier>
198
+ }
199
+ let mods: ts.Modifier[] = []
200
+ for (const bit of bits(modifiers)) {
201
+ mods.push(new ts.Modifier(translation.get(bit) ?? throwError(`Unsupported modifier: ${bit}`)))
202
+ }
203
+ return mods as ReadonlyArray<ts.Modifier> as ts.NodeArray<ts.Modifier>
204
+ }
205
+
206
+ export function passModifiers(modifiers: ReadonlyArray<ts.Modifier | undefined | Es2pandaModifierFlags> | undefined): KInt {
207
+ const translation = new Map<ts.ModifierSyntaxKind, Es2pandaModifierFlags>([
208
+ // [SyntaxKind.UnknownKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_NONE],
209
+ // [SyntaxKind.ConstructorKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_CONSTRUCTOR],
210
+
211
+ [SyntaxKind.AbstractKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT],
212
+ // TODO: unsupported
213
+ // [SyntaxKind.AccessorKeyword, Es2pandaModifierFlags.],
214
+ [SyntaxKind.AsyncKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_ASYNC],
215
+ [SyntaxKind.ConstKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_CONST],
216
+ [SyntaxKind.DeclareKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE],
217
+ [SyntaxKind.DefaultKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_DEFAULT_EXPORT],
218
+ [SyntaxKind.ExportKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT],
219
+ [SyntaxKind.InKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_IN],
220
+ [SyntaxKind.PrivateKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE],
221
+ [SyntaxKind.ProtectedKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_PROTECTED],
222
+ [SyntaxKind.PublicKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC],
223
+ [SyntaxKind.OutKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_OUT],
224
+ [SyntaxKind.OverrideKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_OVERRIDE],
225
+ [SyntaxKind.ReadonlyKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_READONLY],
226
+ [SyntaxKind.StaticKeyword, Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC],
227
+ ])
228
+
229
+ if (modifiers === undefined) {
230
+ return Es2pandaModifierFlags.MODIFIER_FLAGS_NONE
231
+ }
232
+ return modifiers
233
+ .map((mod: ts.Modifier | undefined | Es2pandaModifierFlags) => {
234
+ if (mod === undefined) {
235
+ return Es2pandaModifierFlags.MODIFIER_FLAGS_NONE
236
+ }
237
+ if (typeof mod === 'object') {
238
+ return translation.get(mod.kind) ?? throwError(`Unsupported modifier: ${mod.kind}`)
239
+ }
240
+ return mod
241
+ })
242
+ .reduce(
243
+ (prev, curr) => (prev | curr),
244
+ Es2pandaModifierFlags.MODIFIER_FLAGS_NONE
245
+ )
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 modifiers?.reduce(
266
+ (prev, curr) => prev | (translation.get(curr.kind) ?? throwError(`Unsupported ScriptFunction flag: ${curr.kind}`)),
267
+ Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE
268
+ ) ?? Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE
269
+ }
270
+
271
+ export function passVariableDeclarationKind(flags: NodeFlags): Es2pandaVariableDeclarationKind {
272
+ const translation = new Map<NodeFlags, Es2pandaVariableDeclarationKind>([
273
+ [NodeFlags.Const, Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST],
274
+ [NodeFlags.Let, Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET],
275
+ [NodeFlags.None, Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_VAR],
276
+ ])
277
+
278
+ return translation.get(flags) ?? throwError('unsupported VariableDeclarationKind')
279
+ }
280
+
281
+ export function unpackVariableDeclarationKind(kind: Es2pandaVariableDeclarationKind): NodeFlags {
282
+ const translation = new Map<Es2pandaVariableDeclarationKind, NodeFlags>([
283
+ [Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, NodeFlags.Const],
284
+ [Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET, NodeFlags.Let],
285
+ [Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_VAR, NodeFlags.None],
286
+ ])
287
+
288
+ return translation.get(kind) ?? throwError('unsupported VariableDeclarationKind')
289
+ }
@@ -0,0 +1,55 @@
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
+ // TODO: 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
+ // TODO: like in arkts utils
46
+ export function getOriginalNode(node: ts.Node): ts.Node {
47
+ if (node.node === undefined) {
48
+ // TODO: 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
+ }
@@ -0,0 +1,155 @@
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
+ // TODO: 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
+ // TODO: rethink (remove as)
33
+ function nodesVisitor<T extends ts.Node, TIn extends ts.NodeArray<T> | undefined>(nodes: TIn, visitor: Visitor): T[] | TIn {
34
+ if (nodes === undefined) {
35
+ return nodes
36
+ }
37
+ return nodes.map(node => visitor(node) as T)
38
+ }
39
+
40
+ type VisitEachChildFunction<T extends ts.Node> = (node: T, visitor: Visitor) => T
41
+
42
+ // TODO: add more nodes
43
+ type HasChildren =
44
+ | ts.SourceFile
45
+ | ts.FunctionDeclaration
46
+ | ts.ExpressionStatement
47
+ | ts.CallExpression
48
+ | ts.PropertyAccessExpression
49
+ | ts.ClassDeclaration
50
+ | ts.MethodDeclaration
51
+ | ts.Block
52
+ | ts.VariableStatement
53
+ | ts.VariableDeclarationList
54
+
55
+ type VisitEachChildTable = { [TNode in HasChildren as TNode["kind"]]: VisitEachChildFunction<TNode> }
56
+
57
+ // TODO: add more nodes
58
+ const visitEachChildTable: VisitEachChildTable = {
59
+ [SyntaxKind.SourceFile]: function (node: ts.SourceFile, visitor: Visitor) {
60
+ return factory.updateSourceFile(
61
+ node,
62
+ nodesVisitor(node.statements, visitor)
63
+ )
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(
79
+ node,
80
+ nodeVisitor(node.expression, visitor)
81
+ )
82
+ },
83
+ [SyntaxKind.CallExpression]: function (node: ts.CallExpression, visitor: Visitor) {
84
+ return factory.updateCallExpression(
85
+ node,
86
+ nodeVisitor(node.expression, visitor),
87
+ undefined,
88
+ nodesVisitor(node.arguments, visitor)
89
+ )
90
+ },
91
+ [SyntaxKind.PropertyAccessExpression]: function (node: ts.PropertyAccessExpression, visitor: Visitor) {
92
+ return factory.updatePropertyAccessExpression(
93
+ node,
94
+ nodeVisitor(node.expression, visitor),
95
+ nodeVisitor(node.name, visitor)
96
+ )
97
+ },
98
+ [SyntaxKind.ClassDeclaration]: function (node: ts.ClassDeclaration, visitor: Visitor) {
99
+ return factory.updateClassDeclaration(
100
+ node,
101
+ undefined,
102
+ nodeVisitor(node.name, visitor),
103
+ undefined,
104
+ undefined,
105
+ nodesVisitor(node.members, visitor)
106
+ )
107
+ },
108
+ [SyntaxKind.MethodDeclaration]: function (node: ts.MethodDeclaration, visitor: Visitor) {
109
+ return factory.updateMethodDeclaration(
110
+ node,
111
+ undefined,
112
+ undefined,
113
+ nodeVisitor(node.name, visitor),
114
+ undefined,
115
+ undefined,
116
+ nodesVisitor(node.parameters, visitor),
117
+ undefined,
118
+ nodeVisitor(node.body, visitor),
119
+ )
120
+ },
121
+ [SyntaxKind.Block]: function (node: ts.Block, visitor: Visitor) {
122
+ return factory.updateBlock(
123
+ node,
124
+ nodesVisitor(node.statements, visitor),
125
+ )
126
+ },
127
+ [SyntaxKind.VariableStatement]: function (node: ts.VariableStatement, visitor: Visitor) {
128
+ return factory.updateVariableStatement(
129
+ node,
130
+ undefined,
131
+ nodeVisitor(node.declarationList, visitor),
132
+ )
133
+ },
134
+ [SyntaxKind.VariableDeclarationList]: function (node: ts.VariableDeclarationList, visitor: Visitor) {
135
+ return factory.updateVariableDeclarationList(
136
+ node,
137
+ nodesVisitor(node.declarations, visitor),
138
+ )
139
+ },
140
+ }
141
+
142
+ function nodeHasChildren(node: ts.Node): node is HasChildren {
143
+ return node.kind in visitEachChildTable
144
+ }
145
+
146
+ export function visitEachChild<T extends ts.Node>(
147
+ node: T,
148
+ visitor: Visitor
149
+ ): T {
150
+ const visitFunc = (visitEachChildTable as Record<SyntaxKind, VisitEachChildFunction<any> | undefined>)[node.kind];
151
+ if (nodeHasChildren(node) && visitFunc === undefined) {
152
+ throwError('Unsupported node kind: ' + node.kind)
153
+ }
154
+ return (visitFunc === undefined) ? node : visitFunc(node, visitor);
155
+ }
@@ -0,0 +1,89 @@
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
+ export function throwError(error: string): never {
17
+ throw new Error(error)
18
+ }
19
+
20
+ export function withWarning<T>(value: T, message: string): T {
21
+ // console.warn(message)
22
+ return value
23
+ }
24
+
25
+ export function isNumber(value: any): value is number {
26
+ return typeof value === `number`
27
+ }
28
+
29
+ function replacePercentOutsideStrings(code: string): string {
30
+ const stringPattern = /("[^"]*"|'[^']*'|`[^`]*`)/g;
31
+ const percentPattern = /(?<!["'`])(%)(?![\d\s])/g;
32
+ const strings = code.match(stringPattern) || [];
33
+
34
+ let placeholderCounter = 0;
35
+ const placeholderMap = new Map<string, string>();
36
+ strings.forEach((string) => {
37
+ const placeholder = `__STRING_PLACEHOLDER_${placeholderCounter++}__`;
38
+ placeholderMap.set(placeholder, string);
39
+ code = code.replace(string, placeholder);
40
+ });
41
+
42
+ code = code.replace(percentPattern, '_');
43
+
44
+ placeholderMap.forEach((originalString, placeholder) => {
45
+ code = code.replace(new RegExp(placeholder, 'g'), originalString);
46
+ });
47
+
48
+ return code;
49
+ }
50
+
51
+ function replaceIllegalHashes(code: string): string {
52
+ const stringPattern = /("[^"]*"|'[^']*'|`[^`]*`)/g;
53
+ const strings = code.match(stringPattern) || [];
54
+
55
+ let placeholderCounter = 0;
56
+ const placeholderMap = new Map<string, string>();
57
+ strings.forEach((string) => {
58
+ const placeholder = `__STRING_PLACEHOLDER_${placeholderCounter++}__`;
59
+ placeholderMap.set(placeholder, string);
60
+ code = code.replace(string, placeholder);
61
+ });
62
+
63
+ code = code.replace(/#/g, '_');
64
+
65
+ placeholderMap.forEach((originalString, placeholder) => {
66
+ code = code.replace(new RegExp(placeholder, 'g'), originalString);
67
+ });
68
+
69
+ return code;
70
+ }
71
+
72
+ function replaceGensymWrappers(code: string): string {
73
+ const gensymWrapper = /\({let ([_a-zA-Z0-9]+?) = ([\s\S]*?);\n([\s\S]*?)}\)/g
74
+ return code.replaceAll(gensymWrapper, (match, name, val, expr) => {
75
+ return `((() => { let ${name} = ${val}; return ${expr} })())`
76
+ })
77
+ }
78
+
79
+ /*
80
+ TODO:
81
+ The lowerings insert %% and other special symbols into names of temporary variables.
82
+ Until we keep feeding ast dumps back to the parser this function is needed.
83
+ */
84
+ export function filterSource(text: string): string {
85
+ const filtered = replaceGensymWrappers(replaceIllegalHashes(replacePercentOutsideStrings(text)))
86
+ .replaceAll("<cctor>", "_cctor_")
87
+
88
+ return filtered
89
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "@koalaui/build-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build",
5
+ "baseUrl": ".",
6
+ "rootDir": ".",
7
+ "module": "CommonJS"
8
+ },
9
+ "include": [
10
+ "./src/**/*.ts",
11
+ ],
12
+ "exclude": [
13
+ "./src/ts-api/**/*.ts",
14
+ ]
15
+ }