@idlizer/arktscgen 2.1.10-arktscgen-2 → 2.1.10-arktscgen-3

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 (231) hide show
  1. package/build/libarkts-copy/generator/options.json5 +89 -6
  2. package/build/libarkts-copy/native/meson.build +1 -0
  3. package/build/libarkts-copy/native/src/bridges.cc +10 -4
  4. package/build/libarkts-copy/native/src/common.cc +0 -12
  5. package/build/libarkts-copy/native/src/generated/bridges.cc +407 -723
  6. package/build/libarkts-copy/native/src/memoryTracker.cc +178 -0
  7. package/build/libarkts-copy/native/src/memoryTracker.h +52 -0
  8. package/build/libarkts-copy/package.json +1 -1
  9. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +14 -2
  10. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +2 -2
  11. package/build/libarkts-copy/src/arkts-api/index.ts +2 -1
  12. package/build/libarkts-copy/src/arkts-api/node-cache.ts +7 -11
  13. package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +1 -1
  14. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +4 -1
  15. package/{templates/node-map.ts → build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts} +8 -19
  16. package/build/libarkts-copy/src/arkts-api/utilities/extensions.ts +26 -9
  17. package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +309 -0
  18. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +7 -21
  19. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +41 -7
  20. package/build/libarkts-copy/src/arkts-api/visitor.ts +21 -14
  21. package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +1 -0
  22. package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +85 -172
  23. package/build/libarkts-copy/src/generated/factory.ts +2 -3
  24. package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +0 -1
  25. package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +0 -1
  26. package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +0 -1
  27. package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +11 -13
  28. package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +1 -2
  29. package/build/libarkts-copy/src/generated/peers/ArkTsConfig.ts +0 -1
  30. package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +0 -5
  31. package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +12 -14
  32. package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +0 -1
  33. package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +0 -1
  34. package/build/libarkts-copy/src/generated/peers/AstDumper.ts +0 -1
  35. package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +0 -1
  36. package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +0 -1
  37. package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +0 -1
  38. package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +0 -1
  39. package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +0 -1
  40. package/build/libarkts-copy/src/generated/peers/BindingProps.ts +0 -1
  41. package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +0 -1
  42. package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +0 -1
  43. package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +0 -1
  44. package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +1 -2
  45. package/build/libarkts-copy/src/generated/peers/CallExpression.ts +6 -2
  46. package/build/libarkts-copy/src/generated/peers/CatchClause.ts +0 -1
  47. package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +0 -1
  48. package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +0 -1
  49. package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +1 -24
  50. package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +26 -20
  51. package/build/libarkts-copy/src/generated/peers/ClassElement.ts +2 -30
  52. package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +1 -2
  53. package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +10 -12
  54. package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +1 -2
  55. package/build/libarkts-copy/src/generated/peers/CodeGen.ts +0 -1
  56. package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +0 -1
  57. package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +1 -2
  58. package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +0 -1
  59. package/build/libarkts-copy/src/generated/peers/Declaration.ts +0 -1
  60. package/build/libarkts-copy/src/generated/peers/Decorator.ts +0 -1
  61. package/build/libarkts-copy/src/generated/peers/DiagnosticInfo.ts +0 -1
  62. package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +0 -1
  63. package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +0 -1
  64. package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +0 -1
  65. package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +0 -1
  66. package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +9 -3
  67. package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +0 -1
  68. package/build/libarkts-copy/src/generated/peers/ETSIntrinsicNode.ts +0 -1
  69. package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +0 -1
  70. package/build/libarkts-copy/src/generated/peers/ETSModule.ts +12 -14
  71. package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +0 -1
  72. package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +0 -1
  73. package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +0 -1
  74. package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +0 -1
  75. package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +0 -1
  76. package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +13 -15
  77. package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +0 -1
  78. package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +1 -2
  79. package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +0 -1
  80. package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +0 -1
  81. package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +0 -1
  82. package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +2 -3
  83. package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +3 -4
  84. package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +0 -1
  85. package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +0 -1
  86. package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +1 -2
  87. package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +0 -1
  88. package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +0 -1
  89. package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +2 -3
  90. package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +0 -1
  91. package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +2 -3
  92. package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +2 -3
  93. package/build/libarkts-copy/src/generated/peers/Expression.ts +0 -1
  94. package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +0 -1
  95. package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +0 -1
  96. package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +0 -1
  97. package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +0 -1
  98. package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +10 -16
  99. package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +2 -3
  100. package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +2 -2
  101. package/build/libarkts-copy/src/generated/peers/IRNode.ts +0 -1
  102. package/build/libarkts-copy/src/generated/peers/Identifier.ts +0 -10
  103. package/build/libarkts-copy/src/generated/peers/IfStatement.ts +0 -1
  104. package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +1 -2
  105. package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +1 -2
  106. package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +0 -1
  107. package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +1 -2
  108. package/build/libarkts-copy/src/generated/peers/ImportSource.ts +0 -1
  109. package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +2 -3
  110. package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +0 -1
  111. package/build/libarkts-copy/src/generated/peers/LabelPair.ts +0 -1
  112. package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +1 -2
  113. package/build/libarkts-copy/src/generated/peers/Literal.ts +0 -1
  114. package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +0 -1
  115. package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +0 -1
  116. package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +0 -1
  117. package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +0 -1
  118. package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +5 -6
  119. package/build/libarkts-copy/src/generated/peers/NamedType.ts +2 -3
  120. package/build/libarkts-copy/src/generated/peers/NewExpression.ts +0 -1
  121. package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +0 -1
  122. package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +0 -1
  123. package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +0 -1
  124. package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +0 -5
  125. package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +0 -1
  126. package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +0 -1
  127. package/build/libarkts-copy/src/generated/peers/OverloadDeclaration.ts +0 -1
  128. package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +0 -1
  129. package/build/libarkts-copy/src/generated/peers/Program.ts +9 -2
  130. package/build/libarkts-copy/src/generated/peers/Property.ts +0 -1
  131. package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +0 -1
  132. package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +0 -1
  133. package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +0 -1
  134. package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +22 -19
  135. package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +0 -1
  136. package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +0 -1
  137. package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +0 -1
  138. package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +2 -1
  139. package/build/libarkts-copy/src/generated/peers/SourceRange.ts +0 -1
  140. package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +0 -5
  141. package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +0 -1
  142. package/build/libarkts-copy/src/generated/peers/Statement.ts +0 -1
  143. package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +0 -1
  144. package/build/libarkts-copy/src/generated/peers/SuggestionInfo.ts +0 -1
  145. package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +0 -1
  146. package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +0 -1
  147. package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +1 -2
  148. package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +0 -1
  149. package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +0 -1
  150. package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +0 -1
  151. package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +0 -1
  152. package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +0 -1
  153. package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +1 -2
  154. package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +0 -1
  155. package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +1 -2
  156. package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +2 -25
  157. package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +0 -1
  158. package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +0 -1
  159. package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +1 -2
  160. package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +1 -2
  161. package/build/libarkts-copy/src/generated/peers/TSImportType.ts +1 -2
  162. package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +0 -1
  163. package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +0 -1
  164. package/build/libarkts-copy/src/generated/peers/TSInferType.ts +1 -2
  165. package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +0 -1
  166. package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +14 -38
  167. package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +0 -1
  168. package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +0 -1
  169. package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +0 -1
  170. package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +1 -2
  171. package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +1 -2
  172. package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +0 -1
  173. package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +0 -1
  174. package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +0 -1
  175. package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +0 -1
  176. package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +0 -1
  177. package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +0 -1
  178. package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +0 -1
  179. package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +0 -1
  180. package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +0 -1
  181. package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +0 -1
  182. package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +0 -1
  183. package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +2 -3
  184. package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +1 -2
  185. package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +0 -1
  186. package/build/libarkts-copy/src/generated/peers/TSThisType.ts +0 -1
  187. package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +0 -1
  188. package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +26 -40
  189. package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +0 -1
  190. package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +0 -1
  191. package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +0 -1
  192. package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +11 -13
  193. package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +1 -2
  194. package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +0 -1
  195. package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +0 -1
  196. package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +0 -1
  197. package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +2 -3
  198. package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +0 -1
  199. package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +0 -1
  200. package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +0 -1
  201. package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +0 -1
  202. package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +2 -3
  203. package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +0 -1
  204. package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +1 -2
  205. package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +0 -1
  206. package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +0 -1
  207. package/build/libarkts-copy/src/generated/peers/TryStatement.ts +1 -2
  208. package/build/libarkts-copy/src/generated/peers/TypeNode.ts +10 -12
  209. package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +0 -1
  210. package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +0 -1
  211. package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +0 -1
  212. package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +0 -1
  213. package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +0 -1
  214. package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +0 -1
  215. package/build/libarkts-copy/src/generated/peers/VReg.ts +0 -1
  216. package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +0 -1
  217. package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +11 -20
  218. package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +0 -1
  219. package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +0 -1
  220. package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +0 -1
  221. package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +0 -1
  222. package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +0 -1
  223. package/build/libarkts-copy/src/index.ts +2 -1
  224. package/build/libarkts-copy/src/plugin-utils.ts +0 -10
  225. package/build/libarkts-copy/src/reexport-for-generated.ts +1 -20
  226. package/build/libarkts-copy/src/utils.ts +3 -0
  227. package/lib/index.js +34 -22
  228. package/package.json +4 -3
  229. package/templates/factory.ts +0 -1
  230. package/templates/peer.ts +0 -1
  231. package/build/libarkts-copy/src/arkts-api/ChainExpressionFilter.ts +0 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/arktscgen",
3
- "version": "2.1.10-arktscgen-2",
3
+ "version": "2.1.10-arktscgen-3",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "bin": "lib/index.js",
@@ -19,7 +19,7 @@
19
19
  "license": "Apache-2.0",
20
20
  "keywords": [],
21
21
  "dependencies": {
22
- "@idlizer/core": "2.1.10-arktscgen-2",
22
+ "@idlizer/core": "2.1.10-arktscgen-3",
23
23
  "@types/node": "^18.0.0",
24
24
  "commander": "^10.0.0",
25
25
  "typescript": "^4.9.5"
@@ -38,7 +38,8 @@
38
38
  },
39
39
  "scripts": {
40
40
  "compile:core": "npm run --prefix ../core compile",
41
- "compile": "npm run compile:core && rollup -c",
41
+ "compile:self": "rollup -c",
42
+ "compile": "npm run compile:core && npm run compile:self",
42
43
  "external:test": "npm run --prefix ../external/ui2abc/libarkts run",
43
44
  "external:clean": "rimraf ../external/ui2abc/libarkts/src/generated/peers",
44
45
  "external:generate": "npm run compile && node . --panda-sdk-path ../external/incremental/tools/panda/node_modules/@panda/sdk/ --output-dir ../external/ui2abc/ --options-file ../external/ui2abc/libarkts/generator/options.json5 --debug --no-initialize",
@@ -24,7 +24,6 @@ import {
24
24
  unpackNonNullableNode,
25
25
  unpackNode,
26
26
  unpackNodeArray,
27
- assertValidPeer,
28
27
  AstNode,
29
28
  KNativePointer,
30
29
  nodeByType,
package/templates/peer.ts CHANGED
@@ -24,7 +24,6 @@ import {
24
24
  unpackNonNullableNode,
25
25
  unpackNode,
26
26
  unpackNodeArray,
27
- assertValidPeer,
28
27
  AstNode,
29
28
  KNativePointer,
30
29
  nodeByType,
@@ -1,79 +0,0 @@
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 { BlockStatement, ChainExpression, Expression, isChainExpression, isMemberExpression, MemberExpression } from "src/generated";
17
- import { AbstractVisitor } from "./AbstractVisitor";
18
- import { AstNode } from "./peers/AstNode"
19
- import { factory } from "./factory/nodeFactory";
20
- import { Es2pandaTokenType, Es2pandaVariableDeclarationKind, Es2pandaVariableDeclaratorFlag } from "src/generated/Es2pandaEnums";
21
-
22
-
23
- export class ChainExpressionFilter extends AbstractVisitor {
24
- static counter = 0
25
- transformChainExpression(node: ChainExpression): Expression {
26
- const expression = node.expression
27
- if (expression == undefined) return node
28
- if (!isMemberExpression(expression)) return node
29
- return this.transformMemberExpression(expression)
30
- }
31
- transformMemberExpression(expression: MemberExpression): Expression {
32
- const temporaryVarName = `chaintmp%%_${ChainExpressionFilter.counter++}`
33
- return factory.createBlockExpression(
34
- [
35
- factory.createVariableDeclaration(
36
- Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET,
37
- [
38
- factory.createVariableDeclarator(
39
- Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_LET,
40
- factory.createIdentifier(temporaryVarName),
41
- expression.object
42
- )
43
- ],
44
- undefined
45
- ),
46
- factory.createExpressionStatement(
47
- factory.createConditionalExpression(
48
- factory.createBinaryExpression(
49
- factory.createIdentifier(temporaryVarName, undefined),
50
- factory.createUndefinedLiteral(),
51
- Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_STRICT_EQUAL
52
- ),
53
- factory.createUndefinedLiteral(),
54
- factory.createMemberExpression(
55
- factory.createIdentifier(temporaryVarName, undefined),
56
- expression.property,
57
- expression.kind,
58
- expression.isComputed,
59
- false
60
- )
61
- )
62
- )
63
- ]
64
- )
65
- }
66
-
67
-
68
- visitor(beforeChildren: BlockStatement): BlockStatement
69
- visitor(beforeChildren: AstNode): AstNode {
70
- const node = this.visitEachChild(beforeChildren)
71
- if (isChainExpression(node)) {
72
- return this.transformChainExpression(node)
73
- }
74
- if (isMemberExpression(node) && node.isOptional) {
75
- return this.transformMemberExpression(node)
76
- }
77
- return node
78
- }
79
- }