@idlizer/arktscgen 2.1.9-arktscgen-8 → 2.1.10-arktscgen-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 (268) hide show
  1. package/build/libarkts-copy/generator/options.json5 +141 -3
  2. package/build/libarkts-copy/native/mingw.cross +13 -0
  3. package/build/libarkts-copy/native/src/bridges.cc +101 -232
  4. package/build/libarkts-copy/native/src/common.cc +55 -10
  5. package/build/libarkts-copy/native/src/common.h +1 -0
  6. package/build/libarkts-copy/native/src/generated/bridges.cc +1669 -44
  7. package/build/libarkts-copy/package.json +14 -17
  8. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +39 -50
  9. package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +1 -1
  10. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +6 -5
  11. package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +5 -2
  12. package/build/libarkts-copy/src/arkts-api/node-cache.ts +4 -0
  13. package/build/libarkts-copy/src/arkts-api/node-utilities/ArkTsConfig.ts +7 -6
  14. package/build/libarkts-copy/src/arkts-api/node-utilities/NumberLiteral.ts +3 -1
  15. package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +25 -6
  16. package/build/libarkts-copy/src/{wrapper-compat/arkts-api/peers/ImportPathManager.ts → arkts-api/node-utilities/OpaqueTypeNode.ts} +8 -17
  17. package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +11 -21
  18. package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +7 -0
  19. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +10 -8
  20. package/build/libarkts-copy/src/arkts-api/peers/Config.ts +6 -0
  21. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +3 -15
  22. package/build/libarkts-copy/src/arkts-api/peers/ExternalSource.ts +4 -0
  23. package/build/libarkts-copy/src/arkts-api/plugins.ts +3 -4
  24. package/build/libarkts-copy/src/arkts-api/static/global.ts +29 -1
  25. package/build/libarkts-copy/src/arkts-api/utilities/extensions.ts +68 -5
  26. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +3 -3
  27. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +74 -42
  28. package/build/libarkts-copy/src/arkts-api/visitor.ts +965 -364
  29. package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +98 -91
  30. package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +610 -13
  31. package/build/libarkts-copy/src/generated/factory.ts +2 -2
  32. package/build/libarkts-copy/src/generated/index.ts +3 -2
  33. package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +3 -2
  34. package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +3 -2
  35. package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +3 -2
  36. package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +6 -7
  37. package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +6 -7
  38. package/build/libarkts-copy/src/generated/peers/ArkTsConfig.ts +4 -0
  39. package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +6 -7
  40. package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +6 -7
  41. package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +5 -6
  42. package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +6 -7
  43. package/build/libarkts-copy/src/generated/peers/AstDumper.ts +3 -0
  44. package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +5 -6
  45. package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +5 -6
  46. package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +5 -6
  47. package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +5 -6
  48. package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +5 -6
  49. package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +5 -6
  50. package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +6 -7
  51. package/build/libarkts-copy/src/generated/peers/CallExpression.ts +5 -6
  52. package/build/libarkts-copy/src/generated/peers/CatchClause.ts +6 -7
  53. package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +5 -6
  54. package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +5 -6
  55. package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +7 -8
  56. package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +9 -8
  57. package/build/libarkts-copy/src/generated/peers/ClassElement.ts +3 -2
  58. package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +5 -6
  59. package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +15 -8
  60. package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +5 -6
  61. package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +5 -6
  62. package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +6 -7
  63. package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +5 -6
  64. package/build/libarkts-copy/src/generated/peers/Decorator.ts +5 -6
  65. package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +5 -6
  66. package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +5 -6
  67. package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +5 -6
  68. package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +5 -6
  69. package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +5 -6
  70. package/build/libarkts-copy/src/generated/peers/ETSIntrinsicNode.ts +7 -8
  71. package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +5 -6
  72. package/build/libarkts-copy/src/generated/peers/ETSModule.ts +5 -6
  73. package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +5 -6
  74. package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +6 -7
  75. package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +6 -7
  76. package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +5 -6
  77. package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +5 -6
  78. package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +7 -8
  79. package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +5 -6
  80. package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +3 -4
  81. package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +5 -6
  82. package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +5 -6
  83. package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +9 -10
  84. package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +5 -6
  85. package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +6 -7
  86. package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +5 -6
  87. package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +5 -6
  88. package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +5 -6
  89. package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +6 -7
  90. package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +5 -6
  91. package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +5 -6
  92. package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +9 -10
  93. package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +5 -6
  94. package/build/libarkts-copy/src/generated/peers/Expression.ts +7 -2
  95. package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +5 -6
  96. package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +5 -6
  97. package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +5 -6
  98. package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +4 -5
  99. package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +6 -7
  100. package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +6 -7
  101. package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +3 -0
  102. package/build/libarkts-copy/src/generated/peers/Identifier.ts +7 -8
  103. package/build/libarkts-copy/src/generated/peers/IfStatement.ts +5 -6
  104. package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +5 -6
  105. package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +5 -6
  106. package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +5 -6
  107. package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +5 -6
  108. package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +5 -6
  109. package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +5 -6
  110. package/build/libarkts-copy/src/generated/peers/Literal.ts +3 -2
  111. package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +3 -2
  112. package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +3 -2
  113. package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +5 -10
  114. package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +5 -6
  115. package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +5 -6
  116. package/build/libarkts-copy/src/generated/peers/NamedType.ts +5 -6
  117. package/build/libarkts-copy/src/generated/peers/NewExpression.ts +5 -6
  118. package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +5 -6
  119. package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +10 -9
  120. package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +5 -6
  121. package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +5 -6
  122. package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +5 -6
  123. package/build/libarkts-copy/src/generated/peers/OverloadDeclaration.ts +5 -6
  124. package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +5 -6
  125. package/build/libarkts-copy/src/generated/peers/Program.ts +2 -0
  126. package/build/libarkts-copy/src/generated/peers/Property.ts +6 -7
  127. package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +5 -6
  128. package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +6 -7
  129. package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +19 -6
  130. package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +5 -6
  131. package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +6 -0
  132. package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +5 -6
  133. package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +3 -0
  134. package/build/libarkts-copy/src/generated/peers/Statement.ts +3 -2
  135. package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +6 -7
  136. package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +5 -6
  137. package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +5 -6
  138. package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +5 -6
  139. package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +5 -6
  140. package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +5 -6
  141. package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +5 -6
  142. package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +5 -6
  143. package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +5 -6
  144. package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +6 -7
  145. package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +5 -6
  146. package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +5 -6
  147. package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +6 -7
  148. package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +6 -7
  149. package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +5 -6
  150. package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +5 -6
  151. package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +5 -6
  152. package/build/libarkts-copy/src/generated/peers/TSImportType.ts +5 -6
  153. package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +5 -6
  154. package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +5 -6
  155. package/build/libarkts-copy/src/generated/peers/TSInferType.ts +5 -6
  156. package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +5 -6
  157. package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +5 -6
  158. package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +5 -6
  159. package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +5 -6
  160. package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +5 -6
  161. package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +5 -6
  162. package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +5 -6
  163. package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +5 -6
  164. package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +5 -6
  165. package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +5 -6
  166. package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +5 -6
  167. package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +5 -6
  168. package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +5 -6
  169. package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +5 -6
  170. package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +5 -6
  171. package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +5 -6
  172. package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +5 -6
  173. package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +5 -6
  174. package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +5 -6
  175. package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +5 -6
  176. package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +5 -6
  177. package/build/libarkts-copy/src/generated/peers/TSThisType.ts +5 -6
  178. package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +5 -6
  179. package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +6 -7
  180. package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +5 -6
  181. package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +5 -6
  182. package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +5 -6
  183. package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +6 -7
  184. package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +5 -6
  185. package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +5 -6
  186. package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +5 -6
  187. package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +5 -6
  188. package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +5 -6
  189. package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +5 -6
  190. package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +5 -6
  191. package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +5 -6
  192. package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +5 -6
  193. package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +5 -6
  194. package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +6 -7
  195. package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +5 -6
  196. package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +5 -6
  197. package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +5 -6
  198. package/build/libarkts-copy/src/generated/peers/TryStatement.ts +6 -7
  199. package/build/libarkts-copy/src/generated/peers/TypeNode.ts +3 -2
  200. package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +3 -2
  201. package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +3 -2
  202. package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +5 -6
  203. package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +5 -6
  204. package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +5 -6
  205. package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +5 -6
  206. package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +3 -0
  207. package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +5 -6
  208. package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +6 -7
  209. package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +5 -6
  210. package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +5 -6
  211. package/build/libarkts-copy/src/index.ts +2 -0
  212. package/build/libarkts-copy/src/plugin-utils.ts +21 -4
  213. package/build/libarkts-copy/src/reexport-for-generated.ts +11 -0
  214. package/build/libarkts-copy/src/tracer.ts +172 -0
  215. package/lib/index.js +1523 -611
  216. package/package.json +2 -2
  217. package/build/libarkts-copy/src/arkts-api/peers/SourcePosition.ts +0 -38
  218. package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +0 -45
  219. package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +0 -45
  220. package/build/libarkts-copy/src/wrapper-compat/README.md +0 -20
  221. package/build/libarkts-copy/src/wrapper-compat/arkts-api/class-by-peer.ts +0 -46
  222. package/build/libarkts-copy/src/wrapper-compat/arkts-api/factory/nodeFactory.ts +0 -454
  223. package/build/libarkts-copy/src/wrapper-compat/arkts-api/factory/nodeTests.ts +0 -99
  224. package/build/libarkts-copy/src/wrapper-compat/arkts-api/index.ts +0 -87
  225. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ArrayExpression.ts +0 -38
  226. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ArrowFunctionExpression.ts +0 -35
  227. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/AssignmentExpression.ts +0 -38
  228. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/BlockStatement.ts +0 -27
  229. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/CallExpression.ts +0 -45
  230. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassDeclaration.ts +0 -27
  231. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassDefinition.ts +0 -73
  232. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassProperty.ts +0 -51
  233. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSFunctionType.ts +0 -42
  234. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSImportDeclaration.ts +0 -39
  235. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSParameterExpression.ts +0 -43
  236. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ExpressionStatement.ts +0 -28
  237. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/FunctionDeclaration.ts +0 -37
  238. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/FunctionExpression.ts +0 -28
  239. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/IfStatement.ts +0 -37
  240. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/MemberExpression.ts +0 -42
  241. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/MethodDefinition.ts +0 -46
  242. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/NumberLiteral.ts +0 -30
  243. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ObjectExpression.ts +0 -37
  244. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/Property.ts +0 -27
  245. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ScriptFunction.ts +0 -46
  246. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/StructDeclaration.ts +0 -28
  247. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSInterfaceDeclaration.ts +0 -47
  248. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +0 -40
  249. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSTypeParameter.ts +0 -36
  250. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TryStatement.ts +0 -41
  251. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/VariableDeclaration.ts +0 -42
  252. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/VariableDeclarator.ts +0 -39
  253. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/AstNode.ts +0 -26
  254. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Diagnostic.ts +0 -39
  255. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/DiagnosticInfo.ts +0 -33
  256. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/DiagnosticKind.ts +0 -33
  257. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Program.ts +0 -105
  258. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SourceRange.ts +0 -38
  259. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SuggestionInfo.ts +0 -33
  260. package/build/libarkts-copy/src/wrapper-compat/arkts-api/static/global.ts +0 -16
  261. package/build/libarkts-copy/src/wrapper-compat/arkts-api/to-be-generated/MemberExpression.ts +0 -108
  262. package/build/libarkts-copy/src/wrapper-compat/arkts-api/types.ts +0 -906
  263. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/nativePtrDecoder.ts +0 -69
  264. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/performance.ts +0 -190
  265. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/private.ts +0 -198
  266. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/public.ts +0 -325
  267. package/build/libarkts-copy/src/wrapper-compat/arkts-api/visitor.ts +0 -421
  268. package/build/libarkts-copy/src/wrapper-compat/index.ts +0 -20
package/lib/index.js CHANGED
@@ -3814,17 +3814,20 @@ var IDLEntity;
3814
3814
  var IDLExtendedAttributes;
3815
3815
  (function (IDLExtendedAttributes) {
3816
3816
  IDLExtendedAttributes["Accessor"] = "Accessor";
3817
+ IDLExtendedAttributes["Annotations"] = "Annotations";
3817
3818
  IDLExtendedAttributes["Async"] = "Async";
3818
3819
  IDLExtendedAttributes["CallSignature"] = "CallSignature";
3819
3820
  IDLExtendedAttributes["CommonMethod"] = "CommonMethod";
3820
3821
  IDLExtendedAttributes["Component"] = "Component";
3821
3822
  IDLExtendedAttributes["ComponentInterface"] = "ComponentInterface";
3823
+ IDLExtendedAttributes["ComponentModifier"] = "ComponentModifier";
3822
3824
  IDLExtendedAttributes["Deprecated"] = "Deprecated";
3823
3825
  IDLExtendedAttributes["Documentation"] = "Documentation";
3824
3826
  IDLExtendedAttributes["DtsName"] = "DtsName";
3825
3827
  IDLExtendedAttributes["DtsTag"] = "DtsTag";
3826
3828
  IDLExtendedAttributes["Entity"] = "Entity";
3827
3829
  IDLExtendedAttributes["Extends"] = "Extends";
3830
+ IDLExtendedAttributes["ExtensionMethod"] = "ExtensionMethod";
3828
3831
  IDLExtendedAttributes["Import"] = "Import";
3829
3832
  IDLExtendedAttributes["DefaultExport"] = "DefaultExport";
3830
3833
  IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
@@ -3838,11 +3841,14 @@ var IDLExtendedAttributes;
3838
3841
  IDLExtendedAttributes["Synthetic"] = "Synthetic";
3839
3842
  IDLExtendedAttributes["Throws"] = "Throws";
3840
3843
  IDLExtendedAttributes["TraceKey"] = "TraceKey";
3844
+ IDLExtendedAttributes["TypeAnnotations"] = "TypeAnnotations";
3841
3845
  IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
3842
3846
  IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
3843
3847
  IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
3844
3848
  IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
3845
3849
  IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
3850
+ IDLExtendedAttributes["OverloadAlias"] = "OverloadAlias";
3851
+ IDLExtendedAttributes["OverloadPriority"] = "OverloadPriority";
3846
3852
  })(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
3847
3853
  var IDLAccessorAttribute;
3848
3854
  (function (IDLAccessorAttribute) {
@@ -3862,18 +3868,18 @@ function forEachChild(node, cbEnter, cbLeave) {
3862
3868
  const cleanup = cbEnter(node);
3863
3869
  switch (node.kind) {
3864
3870
  case IDLKind.File:
3865
- node.entries.forEach((value) => forEachChild(value, cbEnter));
3871
+ node.entries.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3866
3872
  break;
3867
3873
  case IDLKind.Namespace:
3868
- node.members.forEach((value) => forEachChild(value, cbEnter));
3874
+ node.members.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3869
3875
  break;
3870
3876
  case IDLKind.Interface: {
3871
3877
  let concrete = node;
3872
- concrete.inheritance.forEach((value) => forEachChild(value, cbEnter));
3873
- concrete.constructors.forEach((value) => forEachChild(value, cbEnter));
3874
- concrete.properties.forEach((value) => forEachChild(value, cbEnter));
3875
- concrete.methods.forEach((value) => forEachChild(value, cbEnter));
3876
- concrete.callables.forEach((value) => forEachChild(value, cbEnter));
3878
+ concrete.inheritance.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3879
+ concrete.constructors.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3880
+ concrete.properties.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3881
+ concrete.methods.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3882
+ concrete.callables.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3877
3883
  break;
3878
3884
  }
3879
3885
  case IDLKind.Method:
@@ -3881,53 +3887,53 @@ function forEachChild(node, cbEnter, cbLeave) {
3881
3887
  case IDLKind.Callback:
3882
3888
  case IDLKind.Constructor: {
3883
3889
  let concrete = node;
3884
- (_a = concrete.parameters) === null || _a === void 0 ? void 0 : _a.forEach((value) => forEachChild(value, cbEnter));
3890
+ (_a = concrete.parameters) === null || _a === void 0 ? void 0 : _a.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3885
3891
  if (concrete.returnType)
3886
- forEachChild(concrete.returnType, cbEnter);
3892
+ forEachChild(concrete.returnType, cbEnter, cbLeave);
3887
3893
  break;
3888
3894
  }
3889
3895
  case IDLKind.UnionType: {
3890
3896
  let concrete = node;
3891
- (_b = concrete.types) === null || _b === void 0 ? void 0 : _b.forEach((value) => forEachChild(value, cbEnter));
3897
+ (_b = concrete.types) === null || _b === void 0 ? void 0 : _b.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3892
3898
  break;
3893
3899
  }
3894
3900
  case IDLKind.OptionalType: {
3895
3901
  let concrete = node;
3896
- forEachChild(concrete.type, cbEnter);
3902
+ forEachChild(concrete.type, cbEnter, cbLeave);
3897
3903
  break;
3898
3904
  }
3899
3905
  case IDLKind.Const: {
3900
- forEachChild(node.type, cbEnter);
3906
+ forEachChild(node.type, cbEnter, cbLeave);
3901
3907
  break;
3902
3908
  }
3903
3909
  case IDLKind.Enum: {
3904
- node.elements.forEach((value) => forEachChild(value, cbEnter));
3910
+ node.elements.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3905
3911
  break;
3906
3912
  }
3907
3913
  case IDLKind.Property: {
3908
- forEachChild(node.type, cbEnter);
3914
+ forEachChild(node.type, cbEnter, cbLeave);
3909
3915
  break;
3910
3916
  }
3911
3917
  case IDLKind.Parameter: {
3912
3918
  const concrete = node;
3913
3919
  if (concrete.type)
3914
- forEachChild(concrete.type, cbEnter);
3920
+ forEachChild(concrete.type, cbEnter, cbLeave);
3915
3921
  break;
3916
3922
  }
3917
3923
  case IDLKind.Typedef: {
3918
- forEachChild(node.type, cbEnter);
3924
+ forEachChild(node.type, cbEnter, cbLeave);
3919
3925
  break;
3920
3926
  }
3921
3927
  case IDLKind.ContainerType: {
3922
- node.elementType.forEach((value) => forEachChild(value, cbEnter));
3928
+ node.elementType.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3923
3929
  break;
3924
3930
  }
3925
3931
  case IDLKind.UnspecifiedGenericType: {
3926
- node.typeArguments.forEach((value) => forEachChild(value, cbEnter));
3932
+ node.typeArguments.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3927
3933
  break;
3928
3934
  }
3929
3935
  case IDLKind.ReferenceType: {
3930
- (_c = node.typeArguments) === null || _c === void 0 ? void 0 : _c.forEach((value) => forEachChild(value, cbEnter));
3936
+ (_c = node.typeArguments) === null || _c === void 0 ? void 0 : _c.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3931
3937
  break;
3932
3938
  }
3933
3939
  case IDLKind.TypeParameterType:
@@ -3940,6 +3946,7 @@ function forEachChild(node, cbEnter, cbLeave) {
3940
3946
  throw new Error(`Unhandled ${node.kind}`);
3941
3947
  }
3942
3948
  }
3949
+ cbLeave === null || cbLeave === void 0 ? void 0 : cbLeave(node);
3943
3950
  cleanup === null || cleanup === void 0 ? void 0 : cleanup();
3944
3951
  }
3945
3952
  /** Updates tree in place! */
@@ -4092,9 +4099,15 @@ function isInterface$1(node) {
4092
4099
  function isImport(type) {
4093
4100
  return type.kind == IDLKind.Import;
4094
4101
  }
4102
+ function isCallable(node) {
4103
+ return node.kind === IDLKind.Callable;
4104
+ }
4095
4105
  function isMethod(node) {
4096
4106
  return node.kind === IDLKind.Method;
4097
4107
  }
4108
+ function isConstructor$1(node) {
4109
+ return node.kind === IDLKind.Constructor;
4110
+ }
4098
4111
  function isProperty(node) {
4099
4112
  return node.kind === IDLKind.Property;
4100
4113
  }
@@ -4890,6 +4903,7 @@ function linearizeNamespaceMembers(entries) {
4890
4903
  return linearized;
4891
4904
  }
4892
4905
 
4906
+ const modulesCache = new Map();
4893
4907
  function isInModule(nodeOrPackage, module) {
4894
4908
  if (typeof nodeOrPackage === 'object')
4895
4909
  return isInModule(getPackageName(nodeOrPackage), module);
@@ -4903,14 +4917,27 @@ function getModuleFor(nodeOrPackage) {
4903
4917
  if (typeof nodeOrPackage === "object")
4904
4918
  return getModuleFor(getPackageName(nodeOrPackage));
4905
4919
  const packageName = nodeOrPackage;
4920
+ let module = modulesCache.get(packageName);
4921
+ if (module)
4922
+ return module;
4923
+ module = getApplicableModuleFor(packageName);
4924
+ modulesCache.set(packageName, module);
4925
+ return module;
4926
+ }
4927
+ function getApplicableModuleFor(packageName) {
4906
4928
  const config = generatorConfiguration();
4907
4929
  const applicableModules = [...config.modules.values()].filter(module => isInModule(packageName, module));
4908
4930
  if (applicableModules.length === 0) {
4909
- if (nodeOrPackage === '') {
4931
+ if (packageName === '') {
4910
4932
  console.error("WARNING: use current module for empty package");
4911
4933
  return currentModule();
4912
4934
  }
4913
- throw new Error(`Package ${packageName} is not listed in any module`);
4935
+ if (packageName.startsWith(`idlize.`)) {
4936
+ return currentModule();
4937
+ }
4938
+ const modules = [...config.modules.keys()].map(it => `"${it}"`).join(", ");
4939
+ throw new Error(`Package "${packageName}" is not listed in any module.`
4940
+ + ` Add the "${packageName}" to the existed list of modules [${modules}] or new one in the configuration file`);
4914
4941
  }
4915
4942
  if (applicableModules.length > 1)
4916
4943
  throw new Error(`Package ${packageName} listed in ${applicableModules.length} packages: ${applicableModules.map(it => it.name).join(", ")}`);
@@ -4924,10 +4951,11 @@ function currentModule() {
4924
4951
  return result;
4925
4952
  }
4926
4953
  function isInCurrentModule(nodeOrPackage) {
4927
- if (typeof nodeOrPackage === 'string')
4928
- return isInModule(nodeOrPackage, currentModule());
4929
- else
4930
- return isInModule(nodeOrPackage, currentModule());
4954
+ // check the nodeOrPackage belongs to some module
4955
+ const module = typeof nodeOrPackage === 'string'
4956
+ ? getModuleFor(nodeOrPackage)
4957
+ : getModuleFor(nodeOrPackage);
4958
+ return generatorConfiguration().moduleName == module.name;
4931
4959
  }
4932
4960
 
4933
4961
  /*
@@ -5091,13 +5119,14 @@ class ExpressionStatement {
5091
5119
  }
5092
5120
  }
5093
5121
  class BlockStatement {
5094
- constructor(statements, inScope = true) {
5122
+ constructor(statements, inScope = true, newLine = true) {
5095
5123
  this.statements = statements;
5096
5124
  this.inScope = inScope;
5125
+ this.newLine = newLine;
5097
5126
  }
5098
5127
  write(writer) {
5099
5128
  if (this.inScope) {
5100
- writer.print("{");
5129
+ this.newLine ? writer.print("{") : writer.printer.appendLastString(" {");
5101
5130
  writer.pushIndent();
5102
5131
  }
5103
5132
  this.statements.forEach(s => s.write(writer));
@@ -5123,7 +5152,12 @@ class IfStatement {
5123
5152
  }
5124
5153
  });
5125
5154
  if (this.elseStatement !== undefined) {
5126
- writer.print("else");
5155
+ if ((this.thenStatement instanceof BlockStatement) && this.thenStatement.inScope) {
5156
+ writer.printer.appendLastString(" else");
5157
+ }
5158
+ else {
5159
+ writer.print("else");
5160
+ }
5127
5161
  this.writeBody(writer, this.elseStatement, () => {
5128
5162
  if (this.insideElseOp) {
5129
5163
  this.insideElseOp();
@@ -5154,7 +5188,7 @@ class MultiBranchIfStatement {
5154
5188
  writer.print(`if (${expr.asString()}) {`);
5155
5189
  }
5156
5190
  else {
5157
- writer.print(`else if (${expr.asString()}) {`);
5191
+ writer.printer.appendLastString(` else if (${expr.asString()}) {`);
5158
5192
  }
5159
5193
  writer.pushIndent();
5160
5194
  stmt.write(writer);
@@ -5162,7 +5196,7 @@ class MultiBranchIfStatement {
5162
5196
  writer.print("}");
5163
5197
  });
5164
5198
  if (this.statements.length > 0 && this.elseStatement !== undefined) {
5165
- writer.print("else {");
5199
+ writer.printer.appendLastString(" else {");
5166
5200
  writer.pushIndent();
5167
5201
  this.elseStatement.write(writer);
5168
5202
  writer.popIndent();
@@ -5216,21 +5250,17 @@ class LambdaExpression {
5216
5250
  this.resolver = resolver;
5217
5251
  this.body = body;
5218
5252
  }
5219
- bodyAsString() {
5220
- var _a;
5253
+ bodyAsString(isScoped = false) {
5221
5254
  const writer = this.originalWriter.fork();
5222
5255
  if (this.body) {
5223
- for (const stmt of this.body) {
5224
- stmt.write(writer);
5225
- }
5256
+ writer.writeStatement(new BlockStatement(this.body, isScoped, false));
5226
5257
  }
5227
5258
  writer.features.forEach(([feature, module]) => {
5228
5259
  this.originalWriter.addFeature(feature, module);
5229
5260
  });
5230
- return (this.body ? ((_a = this.body) === null || _a === void 0 ? void 0 : _a.length) > 1 ? '\n' : '' : '').concat(writer.getOutput()
5231
- .filter(line => line !== "")
5232
- .map(line => indentedBy(line.endsWith('{') || line.endsWith('}') || line.endsWith(';') ? line : `${line};`, 1))
5233
- .join("\n"));
5261
+ return writer.getOutput()
5262
+ .map(line => (line.endsWith('{') || line.endsWith('}') || line.endsWith(';')) ? line : `${line};`)
5263
+ .join("\n");
5234
5264
  }
5235
5265
  }
5236
5266
  ////////////////////////////////////////////////////////////////
@@ -5665,9 +5695,9 @@ LanguageWriter._isReferenceRelativeToNamespaces = false;
5665
5695
  * limitations under the License.
5666
5696
  */
5667
5697
  class IndentedPrinter {
5668
- constructor(output = []) {
5698
+ constructor(output = [], indent = 0) {
5669
5699
  this.output = output;
5670
- this.indent = 0;
5700
+ this.indent = indent;
5671
5701
  }
5672
5702
  print(value) {
5673
5703
  if (value != undefined)
@@ -5685,6 +5715,13 @@ class IndentedPrinter {
5685
5715
  append(printer) {
5686
5716
  this.output = [...this.output, ...printer.output];
5687
5717
  }
5718
+ appendLastString(value) {
5719
+ if (value != undefined) {
5720
+ let last = this.output.pop();
5721
+ last = last ? last.concat(value) : value;
5722
+ this.output.push(last);
5723
+ }
5724
+ }
5688
5725
  indented(input) {
5689
5726
  return indentedBy(input, this.indent);
5690
5727
  }
@@ -6025,7 +6062,13 @@ class DiagnosticException extends Error {
6025
6062
  /**
6026
6063
  * Template for registering different kinds of messages
6027
6064
  */
6028
- class DiagnosticMessageEntry {
6065
+ class DiagnosticMessageGroup {
6066
+ /**
6067
+ * Generated diagnostic messages belonging to _any_ group
6068
+ */
6069
+ static get allGroupsEntries() {
6070
+ return DiagnosticMessageGroup.collectedResults.entries;
6071
+ }
6029
6072
  constructor(severity, code, codeDescription, mainMessageTemplate, additionalMessageTemplate) {
6030
6073
  this.severity = severity;
6031
6074
  this.code = code;
@@ -6033,10 +6076,10 @@ class DiagnosticMessageEntry {
6033
6076
  // No cases of codeUri for now, can be embedded into codeDescription later if needed
6034
6077
  this.mainMessageTemplate = mainMessageTemplate !== null && mainMessageTemplate !== void 0 ? mainMessageTemplate : codeDescription;
6035
6078
  this.additionalMessageTemplate = additionalMessageTemplate !== null && additionalMessageTemplate !== void 0 ? additionalMessageTemplate : "See";
6036
- if (DiagnosticMessageEntry.diagnosticMessageByCode.has(code)) {
6079
+ if (DiagnosticMessageGroup.diagnosticMessageByCode.has(code)) {
6037
6080
  throw new Error(`Duplicate message code ${code}`);
6038
6081
  }
6039
- DiagnosticMessageEntry.diagnosticMessageByCode.set(code, this);
6082
+ DiagnosticMessageGroup.diagnosticMessageByCode.set(code, this);
6040
6083
  }
6041
6084
  generateDiagnosticMessage(locations, mainMessage, additionalMessage) {
6042
6085
  let msg = {
@@ -6054,24 +6097,928 @@ class DiagnosticMessageEntry {
6054
6097
  return msg;
6055
6098
  }
6056
6099
  reportDiagnosticMessage(locations, mainMessage, additionalMessage) {
6057
- DiagnosticMessageEntry.collectedResults.push(this.generateDiagnosticMessage(locations, mainMessage, additionalMessage));
6100
+ const msg = this.generateDiagnosticMessage(locations, mainMessage, additionalMessage);
6101
+ DiagnosticMessageGroup.collectedResults.push(msg);
6102
+ return msg;
6058
6103
  }
6059
6104
  throwDiagnosticMessage(locations, mainMessage, additionalMessage) {
6060
- throw new DiagnosticException(this.generateDiagnosticMessage(locations, mainMessage, additionalMessage));
6061
- }
6062
- static reportCatched(diagnosticMessage) {
6063
- this.collectedResults.push(diagnosticMessage);
6105
+ throw new DiagnosticException(this.reportDiagnosticMessage(locations, mainMessage, additionalMessage));
6064
6106
  }
6065
6107
  }
6066
6108
  /**
6067
6109
  * Index for DiagnosticMessageEntry by code
6068
6110
  */
6069
- DiagnosticMessageEntry.diagnosticMessageByCode = new Map();
6070
- DiagnosticMessageEntry.collectedResults = new DiagnosticResults();
6071
- const UnknownErrorMessage = new DiagnosticMessageEntry("fatal", 0, "Unknown error");
6072
- const LoadingErrorMessage = new DiagnosticMessageEntry("fatal", 100, "Loading error");
6073
- const ParsingErrorMessage = new DiagnosticMessageEntry("fatal", 101, "Parsing error");
6074
- new DiagnosticMessageEntry("fatal", 102, "Processing error");
6111
+ DiagnosticMessageGroup.diagnosticMessageByCode = new Map();
6112
+ /**
6113
+ * Diagnostic results collected up until now
6114
+ */
6115
+ DiagnosticMessageGroup.collectedResults = new DiagnosticResults();
6116
+ const InternalFatal = new DiagnosticMessageGroup("fatal", "InternalFatal", "Unknown error");
6117
+ const LoadingFatal = new DiagnosticMessageGroup("fatal", "LoadingFatal", "Loading error");
6118
+ const ParsingFatal = new DiagnosticMessageGroup("fatal", "ParsingFatal", "Parsing error");
6119
+ new DiagnosticMessageGroup("fatal", "ProcessingFatal", "Processing error");
6120
+
6121
+ /*
6122
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
6123
+ * Licensed under the Apache License, Version 2.0 (the "License");
6124
+ * you may not use this file except in compliance with the License.
6125
+ * You may obtain a copy of the License at
6126
+ *
6127
+ * http://www.apache.org/licenses/LICENSE-2.0
6128
+ *
6129
+ * Unless required by applicable law or agreed to in writing, software
6130
+ * distributed under the License is distributed on an "AS IS" BASIS,
6131
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6132
+ * See the License for the specific language governing permissions and
6133
+ * limitations under the License.
6134
+ */
6135
+ const DuplicateModifier = new DiagnosticMessageGroup("error", "DuplicateModifier", "Duplicate modifier", "Duplicate of");
6136
+ const NotApplicableModifier = new DiagnosticMessageGroup("error", "NotApplicableModifier", "Not applicable modifier");
6137
+ const DuplicatePackageDeclaration = new DiagnosticMessageGroup("error", "DuplicatePackageDeclaration", "Duplicate package declaration", "Duplicate of");
6138
+ const DuplicateExtendedAttribute = new DiagnosticMessageGroup("error", "DuplicateExtendedAttribute", "Duplicate extended attribute", "Duplicate of");
6139
+ const DuplicateArgumentName = new DiagnosticMessageGroup("error", "DuplicateArgumentName", "Duplicate argument name", "Duplicate of");
6140
+ const IncorrectLiteral = new DiagnosticMessageGroup("error", "IncorrectLiteral", "Incorrect literal");
6141
+ const IncorrectIdentifier = new DiagnosticMessageGroup("error", "IncorrectIdentifier", "Incorrect identifier");
6142
+ const UnexpectedToken = new DiagnosticMessageGroup("error", "UnexpectedToken", "Unexpected token");
6143
+ const UnexpectedEndOfFile = new DiagnosticMessageGroup("fatal", "UnexpectedEndOfFile", "Unexpected end of file");
6144
+ const UnsupportedSyntax = new DiagnosticMessageGroup("error", "UnsupportedSyntax", "Unsupported syntax");
6145
+ const WrongDeclarationPlacement = new DiagnosticMessageGroup("error", "WrongDeclarationPlacement", "Wrong declaration placement");
6146
+ const ExpectedPrimitiveType = new DiagnosticMessageGroup("error", "ExpectedPrimitiveType", "Expected primitive type");
6147
+ const ExpectedReferenceType = new DiagnosticMessageGroup("error", "ExpectedReferenceType", "Expected reference type");
6148
+ const ExpectedGenericArguments = new DiagnosticMessageGroup("error", "ExpectedGenericArguments", "Expected generic arguments");
6149
+ const UnexpectedGenericArguments = new DiagnosticMessageGroup("error", "UnexpectedGenericArguments", "Unexpected generic arguments");
6150
+ class FatalParserException extends Error {
6151
+ constructor(diagnosticMessages) {
6152
+ super();
6153
+ this.diagnosticMessages = diagnosticMessages;
6154
+ }
6155
+ }
6156
+ var TokenKind;
6157
+ (function (TokenKind) {
6158
+ TokenKind["Words"] = "Words";
6159
+ TokenKind["Literal"] = "Literal";
6160
+ TokenKind["Symbol"] = "Symbol";
6161
+ TokenKind["Comment"] = "Comment";
6162
+ TokenKind["Whitespace"] = "Space";
6163
+ TokenKind["End"] = "End";
6164
+ })(TokenKind || (TokenKind = {}));
6165
+ const supportedDeclarations = new Set(["attribute", "callback", "const", "constructor", "dictionary",
6166
+ "enum", "import", "interface", "namespace", "package", "typedef", "version"]);
6167
+ const unsupportedDeclarations = new Set(["deleter", "getter", "includes", "inherit", "iterable", "maplike",
6168
+ "mixin", "partial", "required", "setlike", "setter", "stringifier", "unrestricted"]);
6169
+ const interfaceContent = new Set([IDLKind.Constructor, IDLKind.Const, IDLKind.Property, IDLKind.Method, IDLKind.Callable]);
6170
+ const globalContent = new Set([IDLKind.Namespace, IDLKind.Interface, IDLKind.Enum, IDLKind.Method, IDLKind.Typedef, IDLKind.Callback, IDLKind.Import, IDLKind.Version, IDLKind.Const]);
6171
+ const havingBlocks = new Set([IDLKind.Namespace, IDLKind.Interface, IDLKind.Enum]);
6172
+ const modifierTokens = new Set(["static", "readonly", "async"]);
6173
+ // Uncomment in case of parser debugging
6174
+ function trac(s) {
6175
+ // console.log(s)
6176
+ }
6177
+ class Parser {
6178
+ constructor(fileName, content) {
6179
+ var _a, _b;
6180
+ this._curOffset = 0;
6181
+ this._curLine = 0;
6182
+ // TypeParameters support
6183
+ this._generics = [];
6184
+ // TypeArguments parsing support
6185
+ this._enableInLiteralParsing = false;
6186
+ // symTokens = ["(", ")", "[", "]", "{", "}", ",", "...", ":", ";", "<", "=", ">", "?"]
6187
+ this._reDecimal = /-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y;
6188
+ this._reInteger = /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y;
6189
+ this._reString = /"[^"]*"/y;
6190
+ // -something is handled for -Infinity literal parsing, but rejected for identifiers later
6191
+ this._reWords = /[-]?[_$A-Za-z][_$0-9A-Za-z]*([.][_$A-Za-z][_$0-9A-Za-z]*)*/y;
6192
+ this._reSymbol = /\.\.\.|[()[\]{},:;<=>?]/y;
6193
+ this._reWhitespace = /[\t\n\r ]+/y;
6194
+ this._reComment = /\/\/.*|\/\*[\s\S]*?\*\//y;
6195
+ // Note no sticky behavior.
6196
+ this._reIsDocComment = /\/\/\/.*|\/\*\*[\s\S]*?\*\//;
6197
+ this.currentModifiers = {};
6198
+ this.fileName = fileName;
6199
+ if (undefined === content) {
6200
+ try {
6201
+ content = fs__namespace.readFileSync(fileName).toString();
6202
+ }
6203
+ catch (e) {
6204
+ content = "";
6205
+ throw new FatalParserException([LoadingFatal.reportDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "")]);
6206
+ }
6207
+ }
6208
+ this.content = content;
6209
+ const lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
6210
+ this.offsets = prepareOffsets$1(lines);
6211
+ this.lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
6212
+ }
6213
+ parseIDL() {
6214
+ var _a;
6215
+ const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
6216
+ try {
6217
+ trac("parseIDL");
6218
+ this._lexerNext();
6219
+ this._prevToken = this._curToken;
6220
+ let file = this.parseFile();
6221
+ file.text = this.content;
6222
+ return file;
6223
+ }
6224
+ catch (e) {
6225
+ if (!(e instanceof DiagnosticException) && !(e instanceof FatalParserException)) {
6226
+ InternalFatal.reportDiagnosticMessage([{ documentPath: this.fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "");
6227
+ }
6228
+ throw new FatalParserException(DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount));
6229
+ }
6230
+ }
6231
+ _match(re, kind) {
6232
+ re.lastIndex = this._curOffset;
6233
+ const res = re.exec(this.content);
6234
+ if (!res) {
6235
+ return undefined;
6236
+ }
6237
+ const value = res[0];
6238
+ const startLine = this._curLine + 1;
6239
+ const startCharacter = this._curOffset - this.offsets[this._curLine] + 1;
6240
+ this._curOffset = re.lastIndex;
6241
+ this._curLine += (value.match(/\n/g) || []).length;
6242
+ const endLine = this._curLine + 1;
6243
+ const endCharacter = this._curOffset - this.offsets[this._curLine];
6244
+ const location = { documentPath: this.fileName, lines: this.lines, range: { start: { line: startLine, character: startCharacter }, end: { line: endLine, character: endCharacter } } };
6245
+ this._curToken = { kind, value, location };
6246
+ return this._curToken;
6247
+ }
6248
+ _matchComment() {
6249
+ const token = this._match(this._reComment, TokenKind.Comment);
6250
+ // At any parsing moment `precedingComment` represents possible comment token just before`curToken`.
6251
+ // It can be narrowed by `_reIsDocComment` if needed.
6252
+ if (token) {
6253
+ this.precedingComment = token;
6254
+ }
6255
+ return token;
6256
+ }
6257
+ _lexerNext() {
6258
+ var _a, _b, _c, _d;
6259
+ this._prevToken = this._curToken;
6260
+ this._match(this._reWhitespace, TokenKind.Whitespace);
6261
+ this.precedingComment = undefined;
6262
+ while (this._matchComment()) {
6263
+ this._match(this._reWhitespace, TokenKind.Whitespace);
6264
+ }
6265
+ if (this._curOffset == this.content.length) {
6266
+ const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6267
+ this._curToken = { kind: TokenKind.End, value: "", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6268
+ return;
6269
+ }
6270
+ if (this._enableInLiteralParsing && this.content[this._curOffset] == "\"") {
6271
+ // TypeArguments parsing support
6272
+ const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6273
+ this._curToken = { kind: TokenKind.Symbol, value: "\"", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6274
+ this._curOffset += 1;
6275
+ return;
6276
+ }
6277
+ const token = ((_d = (_c = (_b = (_a = this._match(this._reDecimal, TokenKind.Literal)) !== null && _a !== void 0 ? _a : this._match(this._reInteger, TokenKind.Literal)) !== null && _b !== void 0 ? _b : this._match(this._reString, TokenKind.Literal)) !== null && _c !== void 0 ? _c : this._match(this._reWords, TokenKind.Words)) !== null && _d !== void 0 ? _d : this._match(this._reSymbol, TokenKind.Symbol));
6278
+ if (!token) {
6279
+ const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6280
+ ParsingFatal.throwDiagnosticMessage([{ documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } }], "Unrecognized symbols");
6281
+ }
6282
+ // Uncomment in case of parser debugging
6283
+ // if (token) {
6284
+ // const visTok = {...token, location: {...token.location, lines: undefined, documentPath: undefined}}
6285
+ // console.log(`Token: ${JSON.stringify(visTok)}`)
6286
+ // }
6287
+ }
6288
+ get curToken() {
6289
+ return this._curToken;
6290
+ }
6291
+ get curKind() {
6292
+ return this._curToken.kind;
6293
+ }
6294
+ get curValue() {
6295
+ return this._curToken.value;
6296
+ }
6297
+ get curLocation() {
6298
+ return this.curToken.location;
6299
+ }
6300
+ see(tok) {
6301
+ return this.curValue == tok;
6302
+ }
6303
+ seeAndSkip(tok) {
6304
+ if (this.curValue == tok) {
6305
+ this._lexerNext();
6306
+ return true;
6307
+ }
6308
+ return false;
6309
+ }
6310
+ seeEof() {
6311
+ return this.curToken.kind == TokenKind.End;
6312
+ }
6313
+ skip(tok) {
6314
+ if (this.curValue != tok) {
6315
+ if (this.curKind == TokenKind.End) {
6316
+ UnexpectedEndOfFile.throwDiagnosticMessage([this.curLocation], `Unexpected end of file, expected "${tok}"`);
6317
+ }
6318
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], `Unexpected token, expected "${tok}"`);
6319
+ }
6320
+ this._lexerNext();
6321
+ }
6322
+ skipToAfter(tok) {
6323
+ while (!this.see(tok) && !this.seeEof()) {
6324
+ this._lexerNext();
6325
+ }
6326
+ if (!this.seeEof()) {
6327
+ this._lexerNext();
6328
+ }
6329
+ }
6330
+ trackLocation() {
6331
+ const start = this.curLocation;
6332
+ return () => {
6333
+ const end = this._prevToken.location;
6334
+ return {
6335
+ documentPath: this.fileName,
6336
+ range: { start: start.range.start, end: end.range.end },
6337
+ lines: this.lines
6338
+ };
6339
+ };
6340
+ }
6341
+ consumeCurrentExtended() {
6342
+ const ext = this._internalCurrentExtended;
6343
+ this._internalCurrentExtended = undefined;
6344
+ return ext;
6345
+ }
6346
+ assertPossibleModifiers(...mods) {
6347
+ for (const k of Object.keys(this.currentModifiers)) {
6348
+ if (!mods.includes(k)) {
6349
+ NotApplicableModifier.reportDiagnosticMessage([this.currentModifiers[k].location]);
6350
+ }
6351
+ }
6352
+ }
6353
+ parseSingleIdentifier() {
6354
+ const token = this.parseFullIdentifier();
6355
+ if (token.value.includes(".")) {
6356
+ IncorrectIdentifier.throwDiagnosticMessage([this.curLocation]);
6357
+ }
6358
+ return token;
6359
+ }
6360
+ parseFullIdentifier() {
6361
+ if (this.curKind != TokenKind.Words || literalTypes.has(this.curValue) && this.curValue != "undefined") {
6362
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected identifier");
6363
+ }
6364
+ if (this.curValue.startsWith("-")) {
6365
+ // Valid for identifiers in WebIDL, but not in Idlize
6366
+ IncorrectIdentifier.throwDiagnosticMessage([this.curLocation]);
6367
+ }
6368
+ const token = this.curToken;
6369
+ this._lexerNext();
6370
+ return token;
6371
+ }
6372
+ parseFullIdentifierOrLiteral() {
6373
+ if (this.curKind != TokenKind.Words && this.curKind != TokenKind.Literal) {
6374
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected identifier or literal");
6375
+ }
6376
+ const token = this.curToken;
6377
+ this._lexerNext();
6378
+ return token;
6379
+ }
6380
+ parseLiteral() {
6381
+ if (this.curKind != TokenKind.Literal && !literalTypes.has(this.curValue)) {
6382
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected literal");
6383
+ }
6384
+ const token = this.curToken;
6385
+ this._lexerNext();
6386
+ return token;
6387
+ }
6388
+ parseAndPushGenerics(ext) {
6389
+ var _a;
6390
+ const gen = (_a = extractTypeParameters(ext)) !== null && _a !== void 0 ? _a : [];
6391
+ if (this.seeAndSkip("<")) {
6392
+ let next = false;
6393
+ while (!this.seeAndSkip(">")) {
6394
+ if (next) {
6395
+ this.skip(",");
6396
+ }
6397
+ next = true;
6398
+ gen.push(this.parseSingleIdentifier().value);
6399
+ }
6400
+ }
6401
+ // To be restored in parseDeclaration
6402
+ this._generics.push(gen);
6403
+ return gen;
6404
+ }
6405
+ hasGeneric(name) {
6406
+ return this._generics.some(x => x.includes(name));
6407
+ }
6408
+ parseFile() {
6409
+ var _a;
6410
+ const entries = [];
6411
+ while (!this.seeEof()) {
6412
+ const entry = this.parseDeclaration(IDLKind.File);
6413
+ if (entry) {
6414
+ entries.push(entry);
6415
+ }
6416
+ }
6417
+ return createFile(entries, this.fileName, (_a = this.currentPackage) === null || _a === void 0 ? void 0 : _a.split("."), { nodeLocation: { documentPath: this.fileName, lines: this.lines } });
6418
+ }
6419
+ parseDeclaration(scopeKind) {
6420
+ const genericsLevel = this._generics.length;
6421
+ try {
6422
+ const decl = this.parseDeclarationUnsafe(scopeKind);
6423
+ if (!decl) {
6424
+ return;
6425
+ }
6426
+ if (scopeKind == IDLKind.Interface ? !interfaceContent.has(decl.kind) : !globalContent.has(decl.kind)) {
6427
+ // Prefer shorter location ranges for blocks for now
6428
+ const location = havingBlocks.has(decl.kind) ? decl.nameLocation : decl.nodeLocation;
6429
+ WrongDeclarationPlacement.reportDiagnosticMessage([location], `Wrong declaration placement: ${decl.kind} not allowed in ${scopeKind}`);
6430
+ }
6431
+ return decl;
6432
+ }
6433
+ catch (e) {
6434
+ if (e instanceof DiagnosticException && e.diagnosticMessage.severity != "fatal") {
6435
+ this.skipToAfter(";");
6436
+ return;
6437
+ }
6438
+ throw e;
6439
+ }
6440
+ finally {
6441
+ while (this._generics.length > genericsLevel) {
6442
+ this._generics.pop();
6443
+ }
6444
+ }
6445
+ }
6446
+ parseDeclarationUnsafe(scopeKind) {
6447
+ this._internalCurrentExtended = this.parseExtendedAttributes();
6448
+ this.currentModifiers = {};
6449
+ while (modifierTokens.has(this.curValue)) {
6450
+ if (this.currentModifiers[this.curValue]) {
6451
+ DuplicateModifier.reportDiagnosticMessage([this.curLocation]);
6452
+ }
6453
+ this.currentModifiers[this.curValue] = this.curToken;
6454
+ this._lexerNext();
6455
+ }
6456
+ if (unsupportedDeclarations.has(this.curValue)) {
6457
+ UnsupportedSyntax.throwDiagnosticMessage([this.curLocation]);
6458
+ return;
6459
+ }
6460
+ if (supportedDeclarations.has(this.curValue)) {
6461
+ if (this.curValue != "attribute") {
6462
+ this.assertPossibleModifiers();
6463
+ }
6464
+ switch (this.curValue) {
6465
+ case "attribute":
6466
+ this.assertPossibleModifiers("static", "readonly");
6467
+ return this.parseAttribute();
6468
+ case "callback":
6469
+ return this.parseCallback();
6470
+ case "const":
6471
+ return this.parseConst();
6472
+ case "constructor":
6473
+ return this.parseConstructor();
6474
+ case "dictionary":
6475
+ return this.parseDictionary();
6476
+ case "enum":
6477
+ return this.parseEnum();
6478
+ case "import":
6479
+ return this.parseImport();
6480
+ case "interface":
6481
+ return this.parseInterface();
6482
+ case "namespace":
6483
+ return this.parseNamespace();
6484
+ case "package":
6485
+ {
6486
+ const pack = this.parsePackage();
6487
+ if (this.currentPackage) {
6488
+ DuplicatePackageDeclaration.reportDiagnosticMessage([pack.location]);
6489
+ }
6490
+ this.currentPackage = pack.name;
6491
+ if (scopeKind != IDLKind.File) {
6492
+ WrongDeclarationPlacement.reportDiagnosticMessage([pack.location], `Wrong declaration placement: package is not allowed in ${scopeKind}`);
6493
+ }
6494
+ return;
6495
+ }
6496
+ case "typedef":
6497
+ return this.parseTypedef();
6498
+ case "version":
6499
+ return this.parseVersion();
6500
+ }
6501
+ }
6502
+ else {
6503
+ this.assertPossibleModifiers("static", "async");
6504
+ return this.parseOperation();
6505
+ }
6506
+ }
6507
+ parseNamespace() {
6508
+ const sloc = this.trackLocation();
6509
+ const ext = this.consumeCurrentExtended();
6510
+ this.skip("namespace");
6511
+ const name = this.parseSingleIdentifier();
6512
+ const entries = [];
6513
+ this.skip("{");
6514
+ while (!this.seeAndSkip("}")) {
6515
+ const entry = this.parseDeclaration(IDLKind.Namespace);
6516
+ if (entry) {
6517
+ entries.push(entry);
6518
+ }
6519
+ }
6520
+ this.skip(";");
6521
+ return createNamespace(name.value, entries, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6522
+ }
6523
+ parseInterface() {
6524
+ const sloc = this.trackLocation();
6525
+ const ext = this.consumeCurrentExtended();
6526
+ this.skip("interface");
6527
+ const typeParameters = this.parseAndPushGenerics(ext);
6528
+ const name = this.parseSingleIdentifier();
6529
+ let bases = [];
6530
+ if (this.seeAndSkip(":")) {
6531
+ const typeList = this.parseTypeList();
6532
+ for (const type of typeList) {
6533
+ if (isReferenceType(type)) {
6534
+ bases.push(type);
6535
+ }
6536
+ else {
6537
+ ExpectedReferenceType.reportDiagnosticMessage([type.nodeLocation]);
6538
+ }
6539
+ }
6540
+ }
6541
+ const entries = [];
6542
+ this.skip("{");
6543
+ while (!this.seeAndSkip("}")) {
6544
+ const entry = this.parseDeclaration(IDLKind.Interface);
6545
+ if (entry) {
6546
+ if (isMethod(entry)) {
6547
+ entry.isFree = false;
6548
+ }
6549
+ entries.push(entry);
6550
+ }
6551
+ }
6552
+ this.skip(";");
6553
+ return createInterface(name.value, extractInterfaceSubkind(ext), bases, entries.filter(isConstructor$1), entries.filter(isConstant$1), entries.filter(isProperty), entries.filter(isMethod), entries.filter(isCallable), typeParameters, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6554
+ }
6555
+ parseExtendedAttributes() {
6556
+ // For future extensions: here is also a good point for doc comments handling
6557
+ if (!this.seeAndSkip("[")) {
6558
+ return;
6559
+ }
6560
+ const ext = [];
6561
+ const names = new Set();
6562
+ const duplicates = new Set();
6563
+ let next = false;
6564
+ while (!this.seeAndSkip("]")) {
6565
+ if (next) {
6566
+ this.skip(",");
6567
+ }
6568
+ next = true;
6569
+ const name = this.parseSingleIdentifier();
6570
+ if (names.has(name.value)) {
6571
+ duplicates.add(name.value);
6572
+ }
6573
+ names.add(name.value);
6574
+ if (name.value == IDLExtendedAttributes.TypeArguments) {
6575
+ // TypeArguments parsing support
6576
+ try {
6577
+ this._enableInLiteralParsing = true;
6578
+ this.skip("=");
6579
+ const vloc = this.trackLocation();
6580
+ const start = this._curOffset; // Already after first quote
6581
+ this.skip("\"");
6582
+ const types = this.parseTypeList();
6583
+ const end = this._curOffset - 1; // Already after second quote
6584
+ this._enableInLiteralParsing = false;
6585
+ this.skip("\"");
6586
+ const stringValue = this.content.slice(start, end);
6587
+ ext.push({ name: name.value, value: stringValue, typesValue: types, nameLocation: name.location, valueLocation: vloc() });
6588
+ }
6589
+ catch (e) {
6590
+ this.skipToAfter("\"");
6591
+ throw e;
6592
+ }
6593
+ finally {
6594
+ this._enableInLiteralParsing = false;
6595
+ }
6596
+ }
6597
+ else {
6598
+ let value;
6599
+ if (this.seeAndSkip("=")) {
6600
+ value = this.parseFullIdentifierOrLiteral();
6601
+ }
6602
+ const converted = value ? valueFromIdentifierOrLiteral(value) : undefined;
6603
+ ext.push({ name: name.value, value: converted, nameLocation: name.location, valueLocation: value === null || value === void 0 ? void 0 : value.location });
6604
+ }
6605
+ }
6606
+ for (const dup of duplicates) {
6607
+ DuplicateExtendedAttribute.reportDiagnosticMessage(ext.filter(x => x.name == dup).map(x => x.nameLocation));
6608
+ }
6609
+ return ext;
6610
+ }
6611
+ parseTypeList() {
6612
+ const types = [this.parseType()];
6613
+ while (this.seeAndSkip(",")) {
6614
+ types.push(this.parseType());
6615
+ }
6616
+ return types;
6617
+ }
6618
+ parseType(outerExt) {
6619
+ var _a;
6620
+ const parsedExt = this.parseExtendedAttributes();
6621
+ const ext = parsedExt ? (outerExt ? parsedExt.concat(outerExt) : parsedExt) : (outerExt ? [...outerExt] : undefined);
6622
+ const sloc = this.trackLocation();
6623
+ if (this.seeAndSkip("(")) {
6624
+ let combinedTypes = [];
6625
+ let next = false;
6626
+ while (!this.seeAndSkip(")")) {
6627
+ if (next) {
6628
+ this.skip("or");
6629
+ }
6630
+ next = true;
6631
+ combinedTypes.push(this.parseType());
6632
+ }
6633
+ const isNullable = this.seeAndSkip("?") || combinedTypes.includes(IDLUndefinedType);
6634
+ combinedTypes = combinedTypes.filter(x => x !== IDLUndefinedType);
6635
+ const distilledType = combinedTypes.length == 1
6636
+ ? combinedTypes[0]
6637
+ : createUnionType(combinedTypes, undefined, { extendedAttributes: ext, nodeLocation: sloc() });
6638
+ if (isNullable) {
6639
+ return createOptionalType(distilledType, { extendedAttributes: ext, nodeLocation: sloc() });
6640
+ }
6641
+ return distilledType;
6642
+ }
6643
+ const name = this.parseFullIdentifier();
6644
+ const genArgs = (_a = extractTypeArguments(ext)) !== null && _a !== void 0 ? _a : [];
6645
+ if (this.seeAndSkip("<")) {
6646
+ let next = false;
6647
+ while (!this.seeAndSkip(">")) {
6648
+ if (next) {
6649
+ this.skip(",");
6650
+ }
6651
+ next = true;
6652
+ genArgs.push(this.parseType());
6653
+ }
6654
+ }
6655
+ let type;
6656
+ if (this.hasGeneric(name.value)) {
6657
+ if (genArgs.length > 0) {
6658
+ UnexpectedGenericArguments.reportDiagnosticMessage([name.location]);
6659
+ }
6660
+ type = createTypeParameterReference(name.value, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6661
+ }
6662
+ else if (builtinTypes.has(name.value)) {
6663
+ if (genArgs.length > 0) {
6664
+ UnexpectedGenericArguments.reportDiagnosticMessage([name.location]);
6665
+ }
6666
+ type = builtinTypes.get(name.value);
6667
+ }
6668
+ else if (builtinGenericTypeNames.has(name.value)) {
6669
+ if (genArgs.length == 0) {
6670
+ ExpectedGenericArguments.reportDiagnosticMessage([name.location]);
6671
+ }
6672
+ type = createContainerType(name.value, genArgs, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6673
+ }
6674
+ else {
6675
+ type = createReferenceType(name.value, genArgs.length > 0 ? genArgs : undefined, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6676
+ }
6677
+ const isNullable = this.seeAndSkip("?");
6678
+ if (isNullable) {
6679
+ return createOptionalType(type, { extendedAttributes: ext, nodeLocation: sloc() });
6680
+ }
6681
+ else {
6682
+ return type;
6683
+ }
6684
+ }
6685
+ parseReferenceType() {
6686
+ const type = this.parseType();
6687
+ if (!isReferenceType(type)) {
6688
+ ExpectedReferenceType.reportDiagnosticMessage([type.nodeLocation]);
6689
+ }
6690
+ return type;
6691
+ }
6692
+ parsePrimitiveType() {
6693
+ const type = this.parseType();
6694
+ if (!isPrimitiveType(type)) {
6695
+ ExpectedPrimitiveType.reportDiagnosticMessage([type.nodeLocation]);
6696
+ }
6697
+ return type;
6698
+ }
6699
+ parseArgTuple() {
6700
+ const args = [];
6701
+ const names = new Set();
6702
+ const duplicates = new Set();
6703
+ this.skip("(");
6704
+ let next = false;
6705
+ while (!this.seeAndSkip(")")) {
6706
+ if (next) {
6707
+ this.skip(",");
6708
+ }
6709
+ next = true;
6710
+ const arg = this.parseArg();
6711
+ if (names.has(arg.name)) {
6712
+ duplicates.add(arg.name);
6713
+ }
6714
+ names.add(arg.name);
6715
+ args.push(arg);
6716
+ }
6717
+ for (const dup of duplicates) {
6718
+ DuplicateArgumentName.reportDiagnosticMessage(args.filter(x => x.name == dup).map(x => x.nameLocation));
6719
+ }
6720
+ return args;
6721
+ }
6722
+ parseArg() {
6723
+ const ext = this.parseExtendedAttributes();
6724
+ const sloc = this.trackLocation();
6725
+ const optional = this.seeAndSkip("optional");
6726
+ // Note `extendedAttributes` forwarding
6727
+ const type = this.parseType(ext);
6728
+ const spread = this.seeAndSkip("...");
6729
+ const name = this.parseSingleIdentifier();
6730
+ // Note absense of `extendedAttributes`, they are only forwarded to `type`, as it was in the old parsing code
6731
+ return createParameter(name.value, type, optional, spread, { nodeLocation: sloc(), nameLocation: name.location });
6732
+ }
6733
+ parseOperation() {
6734
+ const sloc = this.trackLocation();
6735
+ const ext = this.consumeCurrentExtended();
6736
+ const isStatic = !!this.currentModifiers.static;
6737
+ const isAsync = !!this.currentModifiers.async;
6738
+ const isOptional = extractOptional(ext);
6739
+ const isFree = true; // Will be set to false in parseInterface if method is declared within interface
6740
+ const typeParameters = this.parseAndPushGenerics(ext);
6741
+ // Note `extendedAttributes` forwarding
6742
+ const retType = this.parseType(ext);
6743
+ const name = this.parseSingleIdentifier();
6744
+ const args = this.parseArgTuple();
6745
+ this.skip(";");
6746
+ if (ext === null || ext === void 0 ? void 0 : ext.some(x => x.name == IDLExtendedAttributes.CallSignature)) {
6747
+ return createCallable(name.value, args, retType, { isStatic, isAsync }, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location }, typeParameters);
6748
+ }
6749
+ return createMethod(name.value, args, retType, { isStatic, isAsync, isOptional, isFree }, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location }, typeParameters);
6750
+ }
6751
+ parseConstructor() {
6752
+ const sloc = this.trackLocation();
6753
+ const ext = this.consumeCurrentExtended();
6754
+ this.skip("constructor");
6755
+ const args = this.parseArgTuple();
6756
+ this.skip(";");
6757
+ return createConstructor(args, undefined, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc() });
6758
+ }
6759
+ parseConst() {
6760
+ const sloc = this.trackLocation();
6761
+ const ext = this.consumeCurrentExtended();
6762
+ this.skip("const");
6763
+ const type = this.parseType();
6764
+ const name = this.parseSingleIdentifier();
6765
+ this.skip("=");
6766
+ const value = this.parseLiteral();
6767
+ const extracted = extractLiteral(value);
6768
+ this.skip(";");
6769
+ return createConstant(name.value, type, extracted.extractedString, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6770
+ }
6771
+ parseAttribute() {
6772
+ const sloc = this.trackLocation();
6773
+ const ext = this.consumeCurrentExtended();
6774
+ const isReadonly = !!this.currentModifiers.readonly;
6775
+ const isStatic = !!this.currentModifiers.static;
6776
+ const isOptional = extractOptional(ext);
6777
+ this.skip("attribute");
6778
+ const type = this.parseType();
6779
+ const name = this.parseSingleIdentifier();
6780
+ this.skip(";");
6781
+ return createProperty(name.value, type, isReadonly, isStatic, isOptional, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6782
+ }
6783
+ parseTypedef() {
6784
+ const sloc = this.trackLocation();
6785
+ const ext = this.consumeCurrentExtended();
6786
+ this.skip("typedef");
6787
+ const typeParameters = this.parseAndPushGenerics(ext);
6788
+ const type = this.parseType();
6789
+ const name = this.parseSingleIdentifier();
6790
+ if (isUnionType(type)) {
6791
+ type.name = name.value;
6792
+ }
6793
+ this.skip(";");
6794
+ return createTypedef(name.value, type, typeParameters, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6795
+ }
6796
+ parseCallback() {
6797
+ const sloc = this.trackLocation();
6798
+ const ext = this.consumeCurrentExtended();
6799
+ this.skip("callback");
6800
+ if (this.see("interface")) {
6801
+ UnsupportedSyntax.throwDiagnosticMessage([this.curLocation], "Unsupported syntax: callback interface");
6802
+ }
6803
+ const typeParameters = this.parseAndPushGenerics(ext);
6804
+ const name = this.parseSingleIdentifier();
6805
+ this.skip("=");
6806
+ const retType = this.parseType();
6807
+ const args = this.parseArgTuple();
6808
+ this.skip(";");
6809
+ return createCallback(name.value, args, retType, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location }, typeParameters);
6810
+ }
6811
+ parseEnum() {
6812
+ const sloc = this.trackLocation();
6813
+ const ext = this.consumeCurrentExtended();
6814
+ this.skip("enum");
6815
+ const name = this.parseSingleIdentifier();
6816
+ const items = [];
6817
+ this.skip("{");
6818
+ let next = false;
6819
+ while (!this.seeAndSkip("}")) {
6820
+ if (next) {
6821
+ this.skip(",");
6822
+ // Can have trailing comma
6823
+ if (this.seeAndSkip("}")) {
6824
+ break;
6825
+ }
6826
+ }
6827
+ next = true;
6828
+ const ext = this.parseExtendedAttributes();
6829
+ const entry = this.parseLiteral();
6830
+ const member = createEnumMember(entry.value, undefined, IDLNumberType, undefined, { extendedAttributes: ext, nodeLocation: entry.location, nameLocation: entry.location });
6831
+ items.push(member);
6832
+ }
6833
+ return createEnum(name.value, items, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6834
+ }
6835
+ parseDictionary() {
6836
+ const sloc = this.trackLocation();
6837
+ const ext = this.consumeCurrentExtended();
6838
+ this.skip("dictionary");
6839
+ const name = this.parseSingleIdentifier();
6840
+ const items = [];
6841
+ this.skip("{");
6842
+ while (!this.seeAndSkip("}")) {
6843
+ items.push(this.parseDictionaryEntry());
6844
+ }
6845
+ this.skip(";");
6846
+ return createEnum(name.value, items, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6847
+ }
6848
+ parseDictionaryEntry() {
6849
+ const ext = this.parseExtendedAttributes();
6850
+ const sloc = this.trackLocation();
6851
+ const type = this.parsePrimitiveType();
6852
+ const name = this.parseSingleIdentifier();
6853
+ this.skip("=");
6854
+ const value = this.parseLiteral();
6855
+ const extracted = extractLiteral(value);
6856
+ this.skip(";");
6857
+ return createEnumMember(name.value, undefined, type, extracted.extractedValue, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6858
+ }
6859
+ parsePackage() {
6860
+ const sloc = this.trackLocation();
6861
+ this.skip("package");
6862
+ const packagePath = this.parseFullIdentifierOrLiteral();
6863
+ this.skip(";");
6864
+ return { location: sloc(), name: valueFromIdentifierOrLiteral(packagePath) };
6865
+ }
6866
+ parseImport() {
6867
+ const sloc = this.trackLocation();
6868
+ this.skip("import");
6869
+ const importPath = this.parseFullIdentifierOrLiteral();
6870
+ let alias;
6871
+ if (this.seeAndSkip("as")) {
6872
+ alias = this.parseSingleIdentifier();
6873
+ }
6874
+ this.skip(";");
6875
+ return createImport(valueFromIdentifierOrLiteral(importPath).split("."), alias === null || alias === void 0 ? void 0 : alias.value, { nodeLocation: sloc(), nameLocation: alias === null || alias === void 0 ? void 0 : alias.location, valueLocation: importPath.location });
6876
+ }
6877
+ parseVersion() {
6878
+ const sloc = this.trackLocation();
6879
+ this.skip("version");
6880
+ const versionLiteral = this.parseLiteral();
6881
+ this.skip(";");
6882
+ return createVersion(versionLiteral.value.split("."), { nodeLocation: sloc(), valueLocation: versionLiteral.location });
6883
+ }
6884
+ }
6885
+ function prepareOffsets$1(lines) {
6886
+ let offsets = [];
6887
+ let offset = 0;
6888
+ for (let line of lines) {
6889
+ let plus = line.length;
6890
+ offsets.push(offset);
6891
+ offset += plus;
6892
+ }
6893
+ return offsets;
6894
+ }
6895
+ function valueFromIdentifierOrLiteral(token) {
6896
+ if (token.kind == TokenKind.Words && !literalTypes.has(token.value)) {
6897
+ return token.value;
6898
+ }
6899
+ return extractLiteral(token).extractedString;
6900
+ }
6901
+ const literalTypes = new Map([
6902
+ ["true", "boolean"],
6903
+ ["false", "boolean"],
6904
+ ["Infinity", "number"],
6905
+ ["-Infinity", "number"],
6906
+ ["NaN", "number"],
6907
+ ["null", "null"],
6908
+ ["undefined", "undefined"],
6909
+ ]);
6910
+ const extractedUndefined = { type: "undefined", extractedString: "undefined", extractedValue: "undefined" };
6911
+ function extractLiteral(token) {
6912
+ if (token.kind == TokenKind.Words) {
6913
+ if (!literalTypes.has(token.value)) {
6914
+ IncorrectLiteral.reportDiagnosticMessage([token.location]);
6915
+ return extractedUndefined;
6916
+ }
6917
+ const type = literalTypes.get(token.value);
6918
+ const extractedString = token.value;
6919
+ const extractedValue = type == "number" ? parseFloat(extractedString) : extractedString;
6920
+ return { type, extractedString, extractedValue };
6921
+ }
6922
+ if (token.kind != TokenKind.Literal) {
6923
+ IncorrectLiteral.reportDiagnosticMessage([token.location]);
6924
+ return extractedUndefined;
6925
+ }
6926
+ if (token.value[0] == "\"") {
6927
+ try {
6928
+ const extractedString = unescapeString(token.value);
6929
+ return { type: "string", extractedString, extractedValue: extractedString };
6930
+ }
6931
+ catch (e) {
6932
+ IncorrectLiteral.reportDiagnosticMessage([token.location], `Incorrect literal: ${e.message}`);
6933
+ return extractedUndefined;
6934
+ }
6935
+ }
6936
+ const extractedValue = parseFloat(token.value);
6937
+ if (Number.isNaN(extractedValue)) {
6938
+ // Real NaNs are handled before that, so report an error
6939
+ IncorrectLiteral.reportDiagnosticMessage([token.location]);
6940
+ }
6941
+ return { type: "number", extractedString: token.value, extractedValue };
6942
+ }
6943
+ // Taken from deserialize.ts as is
6944
+ function unescapeString(value) {
6945
+ if (!value.length || value[0] !== '"')
6946
+ return value;
6947
+ value = value.slice(1, -1);
6948
+ value = value.replace(/\\((['"\\bfnrtv])|([0-7]{1-3})|x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/g, (_, all, c, oct, h2, u4) => {
6949
+ if (c !== undefined) {
6950
+ switch (c) {
6951
+ case "'": return "'";
6952
+ case '"': return '"';
6953
+ case "\\": return "\\";
6954
+ case "b": return "\b";
6955
+ case "f": return "\f";
6956
+ case "n": return "\n";
6957
+ case "r": return "\r";
6958
+ case "t": return "\t";
6959
+ case "v": return "\v";
6960
+ }
6961
+ }
6962
+ else if (oct !== undefined) {
6963
+ return String.fromCharCode(parseInt(oct, 8));
6964
+ }
6965
+ else if (h2 !== undefined) {
6966
+ return String.fromCharCode(parseInt(h2, 16));
6967
+ }
6968
+ else if (u4 !== undefined) {
6969
+ return String.fromCharCode(parseInt(u4, 16));
6970
+ }
6971
+ throw new Error(`unknown escape sequence: ${_}`);
6972
+ });
6973
+ return value;
6974
+ }
6975
+ function extractInterfaceSubkind(ext) {
6976
+ var _a;
6977
+ const ent = (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == "Entity")) === null || _a === void 0 ? void 0 : _a.value;
6978
+ switch (ent) {
6979
+ case IDLEntity.Class: return IDLInterfaceSubkind.Class;
6980
+ case IDLEntity.Literal: return IDLInterfaceSubkind.AnonymousInterface;
6981
+ case IDLEntity.Tuple: return IDLInterfaceSubkind.Tuple;
6982
+ default: return IDLInterfaceSubkind.Interface;
6983
+ }
6984
+ }
6985
+ function extractDocumentation(ext) {
6986
+ var _a;
6987
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == "Documentation")) === null || _a === void 0 ? void 0 : _a.value;
6988
+ }
6989
+ function extractOptional(ext) {
6990
+ var _a;
6991
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.some(x => x.name.toLowerCase() == "optional")) !== null && _a !== void 0 ? _a : false;
6992
+ }
6993
+ function sanitizeTypeParameter(param) {
6994
+ const extendsIdx = param.indexOf('extends');
6995
+ if (extendsIdx !== -1) {
6996
+ return param.substring(0, extendsIdx).trim();
6997
+ }
6998
+ const eqIdx = param.indexOf('=');
6999
+ if (eqIdx !== -1) {
7000
+ return param.substring(0, eqIdx).trim();
7001
+ }
7002
+ return param;
7003
+ }
7004
+ function extractTypeParameters(ext) {
7005
+ var _a, _b, _c;
7006
+ return (_c = (_b = (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.split(",")) === null || _c === void 0 ? void 0 : _c.map(sanitizeTypeParameter);
7007
+ }
7008
+ function extractTypeArguments(ext) {
7009
+ var _a;
7010
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == IDLExtendedAttributes.TypeArguments)) === null || _a === void 0 ? void 0 : _a.typesValue;
7011
+ }
7012
+ const builtinTypesList = [IDLPointerType, IDLVoidType, IDLBooleanType,
7013
+ IDLObjectType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type,
7014
+ IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF32Type,
7015
+ IDLF64Type, IDLBigintType, IDLNumberType, IDLStringType, IDLAnyType,
7016
+ IDLUndefinedType, IDLUnknownType, IDLObjectType, IDLThisType, IDLDate,
7017
+ IDLBufferType, IDLSerializerBuffer
7018
+ ];
7019
+ // Better solution will be to make it registry in idl.ts
7020
+ const builtinTypes = new Map(builtinTypesList.map(x => [x.name, x]));
7021
+ const builtinGenericTypeNames = new Set(["sequence", "record", "Promise"]);
6075
7022
 
6076
7023
  /*
6077
7024
  * Copyright (c) 2024 Huawei Device Co., Ltd.
@@ -6198,10 +7145,9 @@ class IDLDeserializer {
6198
7145
  }
6199
7146
  const implementations = [];
6200
7147
  node.inheritance.forEach(it => {
6201
- var _a;
6202
7148
  const attributes = it.extAttrs;
6203
7149
  const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], IDLExtendedAttributes.TypeArguments);
6204
- const attrs = (_a = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : [])) === null || _a === void 0 ? void 0 : _a.filter(it => it.name !== IDLExtendedAttributes.TypeArguments);
7150
+ const attrs = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
6205
7151
  const ref = createReferenceType(it.inheritance, parentTypeArgs, {
6206
7152
  extendedAttributes: attrs
6207
7153
  });
@@ -6577,40 +7523,168 @@ class IDLDeserializer {
6577
7523
  return attr ? this.toExtendedAttributeValue(attr) : undefined;
6578
7524
  }
6579
7525
  }
6580
- function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
6581
- var _a, _b, _c;
6582
- const lexicalInfo = new Map();
6583
- const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
6584
- if (undefined === content) {
6585
- try {
6586
- content = fs__namespace.readFileSync(fileName).toString();
6587
- }
6588
- catch (e) {
6589
- content = "";
6590
- LoadingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "");
6591
- }
7526
+ const DifferenceFound = new DiagnosticMessageGroup("error", "DifferenceFound", "Difference found");
7527
+ const noCompare = new Set(["parent", "fileName", "nodeLocation", "nameLocation", "valueLocation", "typesValue"]);
7528
+ const canContainMoreCompare = new Set(["extendedAttributes", "typeParameters", "typeArguments"]);
7529
+ function safeString(value) {
7530
+ if (typeof value == "symbol") {
7531
+ return String(value);
6592
7532
  }
6593
- let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
6594
- const offsets = prepareOffsets(lines);
6595
- lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
6596
- const parsed = { fileName, lines, offsets, lexicalInfo };
6597
- let packageClause = [];
6598
- let rawParsingResults;
6599
- try {
6600
- rawParsingResults = parse$1(content);
7533
+ return JSON.stringify(value, (k, v) => { return noCompare.has(k) ? undefined : v; });
7534
+ }
7535
+ function joinPath(left, right) {
7536
+ if (!right) {
7537
+ return left;
6601
7538
  }
6602
- catch (e) {
6603
- if (e.name == "WebIDLParseError") {
6604
- let tokens = e.tokens;
6605
- let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
6606
- ParsingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName, range: range }], e.bareMessage);
7539
+ return `${left}.${right}`;
7540
+ }
7541
+ function compareDeep(oldData, newData, paths) {
7542
+ var _a;
7543
+ const location = (newData === null || newData === void 0 ? void 0 : newData.kind) && ((_a = newData === null || newData === void 0 ? void 0 : newData.nameLocation) !== null && _a !== void 0 ? _a : newData === null || newData === void 0 ? void 0 : newData.nodeLocation);
7544
+ const diffs = [];
7545
+ if (typeof oldData != typeof newData) {
7546
+ diffs.push({ path: "", oldValue: safeString(oldData), newValue: safeString(newData) });
7547
+ }
7548
+ else if (Array.isArray(oldData) && Array.isArray(newData)) {
7549
+ const len = Math.max(oldData.length, newData.length);
7550
+ if (oldData.length != newData.length) {
7551
+ diffs.push({ path: "", oldValue: `(length=${oldData.length})`, newValue: `(length=${newData.length})` });
7552
+ }
7553
+ for (let i = 0; i < len; ++i) {
7554
+ const deeperDiffs = compareDeep(oldData[i], newData[i], paths);
7555
+ if (deeperDiffs.length > 0) {
7556
+ diffs.push(...deeperDiffs.map(x => { x.path = joinPath("" + i, x.path); return x; }));
7557
+ }
6607
7558
  }
6608
- UnknownErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_c = e.message) !== null && _c !== void 0 ? _c : "");
6609
7559
  }
6610
- const entries = rawParsingResults
6611
- .filter(it => {
6612
- if (!it.type)
6613
- return false;
7560
+ else if (typeof newData == "object") {
7561
+ const keys = [...new Set([...Object.getOwnPropertyNames(oldData), ...Object.getOwnPropertyNames(newData)])].filter(x => !noCompare.has(x));
7562
+ for (const k of keys) {
7563
+ let oldValue = oldData[k];
7564
+ let newValue = newData[k];
7565
+ if (canContainMoreCompare.has(k)) {
7566
+ if (newValue == null && Array.isArray(oldValue) && oldValue.length == 0) {
7567
+ continue;
7568
+ }
7569
+ if (oldValue == null && Array.isArray(newValue)) {
7570
+ continue;
7571
+ }
7572
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
7573
+ if (newValue.length > oldValue.length) {
7574
+ // Cases when old parser takes attributes from outer declaration and ignores the right ones
7575
+ newValue = newValue.slice(newValue.length - oldValue.length);
7576
+ }
7577
+ else if (oldValue.length > newValue.length) {
7578
+ // Cases when types in parentheses have own attributes, but old parser adds attributes from outer declaration
7579
+ oldValue = oldValue.slice(0, newValue.length);
7580
+ }
7581
+ }
7582
+ }
7583
+ const deeperDiffs = compareDeep(oldValue, newValue, paths);
7584
+ if (deeperDiffs.length > 0) {
7585
+ diffs.push(...deeperDiffs.map(x => { x.path = joinPath(k, x.path); return x; }));
7586
+ }
7587
+ }
7588
+ }
7589
+ else {
7590
+ if (oldData != newData) {
7591
+ diffs.push({ path: "", oldValue: safeString(oldData), newValue: safeString(newData) });
7592
+ }
7593
+ }
7594
+ if (!location) {
7595
+ return diffs;
7596
+ }
7597
+ for (const diff of diffs) {
7598
+ paths.add(diff.path);
7599
+ DifferenceFound.reportDiagnosticMessage([location], `path: ${diff.path} oldValue: ${diff.oldValue} newValue: ${diff.newValue}`);
7600
+ }
7601
+ return [];
7602
+ }
7603
+ function compareParsingResults(oldFile, newFile) {
7604
+ const paths = new Set();
7605
+ compareDeep(oldFile, newFile, paths);
7606
+ if (paths.size > 0) {
7607
+ DifferenceFound.reportDiagnosticMessage([newFile.nodeLocation], "Differences found in those paths:\n" + [...paths].join("\n"));
7608
+ }
7609
+ }
7610
+ function parseIdlNew(fileName, content, registerSynthetics) {
7611
+ let file = new Parser(fileName, content).parseIDL();
7612
+ const ancestors = [];
7613
+ const namespaces = [];
7614
+ // Mimic old parser and deserialize.ts behavior:
7615
+ // 1. Add `fileName`.
7616
+ // 2. Add `parent`.
7617
+ // 3. Possibly register node with `addSyntheticType` if "Synthetic" is in attributes
7618
+ forEachChild(file, (node) => {
7619
+ var _a;
7620
+ if (isPrimitiveType(node)) {
7621
+ return;
7622
+ }
7623
+ node.fileName = fileName;
7624
+ if (registerSynthetics && isEntry(node) && ((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.some(it => it.name === "Synthetic"))) {
7625
+ const fqName = file.packageClause.concat(namespaces).concat([node.name]).join('.');
7626
+ addSyntheticType(fqName, node);
7627
+ }
7628
+ if (ancestors.length) {
7629
+ node.parent = ancestors[ancestors.length - 1];
7630
+ }
7631
+ if (isNamespace(node)) {
7632
+ namespaces.push(node.name);
7633
+ }
7634
+ ancestors.push(node);
7635
+ }, (node) => {
7636
+ if (isPrimitiveType(node)) {
7637
+ return;
7638
+ }
7639
+ if (isNamespace(node)) {
7640
+ namespaces.pop();
7641
+ }
7642
+ ancestors.pop();
7643
+ });
7644
+ return file;
7645
+ }
7646
+ function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
7647
+ var _a, _b, _c;
7648
+ let newFile;
7649
+ const mode = process.env.IDLPARSE;
7650
+ if (mode == "compare" || mode == "new") {
7651
+ newFile = parseIdlNew(fileName, content, mode == "new");
7652
+ if (mode == "new") {
7653
+ return [newFile, new Map()];
7654
+ }
7655
+ }
7656
+ const lexicalInfo = new Map();
7657
+ const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
7658
+ if (undefined === content) {
7659
+ try {
7660
+ content = fs__namespace.readFileSync(fileName).toString();
7661
+ }
7662
+ catch (e) {
7663
+ content = "";
7664
+ throw new FatalParserException([LoadingFatal.reportDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "")]);
7665
+ }
7666
+ }
7667
+ let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
7668
+ const offsets = prepareOffsets(lines);
7669
+ lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
7670
+ const parsed = { fileName, lines, offsets, lexicalInfo };
7671
+ let packageClause = [];
7672
+ let rawParsingResults;
7673
+ try {
7674
+ rawParsingResults = parse$1(content);
7675
+ }
7676
+ catch (e) {
7677
+ if (e.name == "WebIDLParseError") {
7678
+ let tokens = e.tokens;
7679
+ let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
7680
+ throw new FatalParserException([ParsingFatal.reportDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage)]);
7681
+ }
7682
+ throw new FatalParserException([InternalFatal.reportDiagnosticMessage([{ documentPath: fileName, lines }], (_c = e.message) !== null && _c !== void 0 ? _c : "")]);
7683
+ }
7684
+ const entries = rawParsingResults
7685
+ .filter(it => {
7686
+ if (!it.type)
7687
+ return false;
6614
7688
  if (deserializer.isPackage(it)) {
6615
7689
  packageClause = it.clause.split(".");
6616
7690
  deserializer.setPackage(packageClause);
@@ -6629,6 +7703,10 @@ function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
6629
7703
  node.nameLocation = nameLocation;
6630
7704
  }
6631
7705
  });
7706
+ if (mode == "compare") {
7707
+ compareParsingResults(file, newFile);
7708
+ return [newFile, new Map()];
7709
+ }
6632
7710
  return [file, lexicalInfo];
6633
7711
  }
6634
7712
  function prepareOffsets(lines) {
@@ -6922,18 +8000,18 @@ class CppMapResizeStatement {
6922
8000
  }
6923
8001
  }
6924
8002
  class CppMapForEachStatement {
6925
- constructor(map, key, value, op) {
8003
+ constructor(map, key, value, body) {
6926
8004
  this.map = map;
6927
8005
  this.key = key;
6928
8006
  this.value = value;
6929
- this.op = op;
8007
+ this.body = body;
6930
8008
  }
6931
8009
  write(writer) {
6932
8010
  writer.print(`for (int32_t i = 0; i < ${this.map}.size; i++) {`);
6933
8011
  writer.pushIndent();
6934
8012
  writer.print(`auto ${this.key} = ${this.map}.keys[i];`);
6935
8013
  writer.print(`auto ${this.value} = ${this.map}.values[i];`);
6936
- this.op();
8014
+ writer.writeStatement(new BlockStatement(this.body, false));
6937
8015
  writer.popIndent();
6938
8016
  writer.print(`}`);
6939
8017
  }
@@ -6978,7 +8056,7 @@ class CppLanguageWriter extends CLikeLanguageWriter {
6978
8056
  }
6979
8057
  fork(options) {
6980
8058
  var _a;
6981
- return new CppLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.primitivesTypes);
8059
+ return new CppLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.primitivesTypes);
6982
8060
  }
6983
8061
  writeDeclaration(name, signature, modifiers, postfix) {
6984
8062
  const realName = this.classMode === 'normal' ? name : `${this.currentClass.at(0)}::${name}`;
@@ -7119,8 +8197,8 @@ class CppLanguageWriter extends CLikeLanguageWriter {
7119
8197
  makeLoop(counter, limit, statement) {
7120
8198
  return new CLikeLoopStatement(counter, limit, statement);
7121
8199
  }
7122
- makeMapForEach(map, key, value, op) {
7123
- return new CppMapForEachStatement(map, key, value, op);
8200
+ makeMapForEach(map, key, value, body) {
8201
+ return new CppMapForEachStatement(map, key, value, body);
7124
8202
  }
7125
8203
  makeArrayInit(type) {
7126
8204
  return this.makeString(`{}`);
@@ -7315,7 +8393,7 @@ class TSLambdaExpression extends LambdaExpression {
7315
8393
  const maybeOptional = isOptionalType(it) ? "?" : "";
7316
8394
  return `${this.signature.argName(i)}${maybeOptional}: ${this.convertor.convert(it)}`;
7317
8395
  });
7318
- return `(${params.join(", ")}): ${this.convertor.convert(this.signature.returnType)} => { ${this.bodyAsString()} }`;
8396
+ return `(${params.join(", ")}): ${this.convertor.convert(this.signature.returnType)} =>${this.bodyAsString(true)}`;
7319
8397
  }
7320
8398
  }
7321
8399
  class TSCastExpression {
@@ -7372,16 +8450,16 @@ class TSLoopStatement {
7372
8450
  }
7373
8451
  }
7374
8452
  class TSMapForEachStatement {
7375
- constructor(map, key, value, op) {
8453
+ constructor(map, key, value, body) {
7376
8454
  this.map = map;
7377
8455
  this.key = key;
7378
8456
  this.value = value;
7379
- this.op = op;
8457
+ this.body = body;
7380
8458
  }
7381
8459
  write(writer) {
7382
8460
  writer.print(`for (const [${this.key}, ${this.value}] of ${this.map}) {`);
7383
8461
  writer.pushIndent();
7384
- this.op();
8462
+ writer.writeStatement(new BlockStatement(this.body, false));
7385
8463
  writer.popIndent();
7386
8464
  writer.print(`}`);
7387
8465
  }
@@ -7412,7 +8490,7 @@ class TSLanguageWriter extends LanguageWriter {
7412
8490
  }
7413
8491
  fork(options) {
7414
8492
  var _a;
7415
- return new TSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
8493
+ return new TSLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
7416
8494
  }
7417
8495
  getNodeName(type) {
7418
8496
  // another stub. Bad one.
@@ -7595,8 +8673,8 @@ class TSLanguageWriter extends LanguageWriter {
7595
8673
  makeLoop(counter, limit, statement) {
7596
8674
  return new TSLoopStatement(counter, limit, statement);
7597
8675
  }
7598
- makeMapForEach(map, key, value, op) {
7599
- return new TSMapForEachStatement(map, key, value, op);
8676
+ makeMapForEach(map, key, value, body) {
8677
+ return new TSMapForEachStatement(map, key, value, body);
7600
8678
  }
7601
8679
  writePrintLog(message) {
7602
8680
  this.print(`console.log("${message}")`);
@@ -7812,6 +8890,23 @@ function createDeclarationNameConvertor(language) {
7812
8890
  * limitations under the License.
7813
8891
  */
7814
8892
  ////////////////////////////////////////////////////////////////
8893
+ // EXPRESSIONS //
8894
+ ////////////////////////////////////////////////////////////////
8895
+ class ETSStringExpression {
8896
+ constructor(value) {
8897
+ this.value = value;
8898
+ }
8899
+ changeQuotes(value) {
8900
+ return `'${value.substring(1, value.length - 1)}'`;
8901
+ }
8902
+ asString() {
8903
+ if (this.value.startsWith('"') && this.value.endsWith('"')) {
8904
+ return this.changeQuotes(this.value);
8905
+ }
8906
+ return this.value;
8907
+ }
8908
+ }
8909
+ ////////////////////////////////////////////////////////////////
7815
8910
  // STATEMENTS //
7816
8911
  ////////////////////////////////////////////////////////////////
7817
8912
  class EtsAssignStatement {
@@ -7839,18 +8934,18 @@ class EtsAssignStatement {
7839
8934
  }
7840
8935
  }
7841
8936
  class ArkTSMapForEachStatement {
7842
- constructor(map, key, value, op) {
8937
+ constructor(map, key, value, body) {
7843
8938
  this.map = map;
7844
8939
  this.key = key;
7845
8940
  this.value = value;
7846
- this.op = op;
8941
+ this.body = body;
7847
8942
  }
7848
8943
  write(writer) {
7849
8944
  writer.print(`for (const pair of ${this.map}) {`);
7850
8945
  writer.pushIndent();
7851
8946
  writer.print(`const ${this.key} = pair[0]`);
7852
8947
  writer.print(`const ${this.value} = pair[1]`);
7853
- this.op();
8948
+ writer.writeStatement(new BlockStatement(this.body, false));
7854
8949
  writer.popIndent();
7855
8950
  writer.print(`}`);
7856
8951
  }
@@ -7916,7 +9011,7 @@ class ETSLambdaExpression extends LambdaExpression {
7916
9011
  isRetTypeCallback = resolved !== undefined && isCallback$1(resolved);
7917
9012
  }
7918
9013
  return `(${params.join(", ")})${isRetTypeCallback
7919
- ? "" : `:${this.convertor.convert(this.signature.returnType)}`} => { ${this.bodyAsString()} }`;
9014
+ ? "" : `:${this.convertor.convert(this.signature.returnType)}`} =>${this.bodyAsString(true)}`;
7920
9015
  }
7921
9016
  }
7922
9017
  ////////////////////////////////////////////////////////////////
@@ -7946,7 +9041,7 @@ class ETSLanguageWriter extends TSLanguageWriter {
7946
9041
  }
7947
9042
  fork(options) {
7948
9043
  var _a;
7949
- return new ETSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.arrayConvertor);
9044
+ return new ETSLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.arrayConvertor);
7950
9045
  }
7951
9046
  makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
7952
9047
  return new EtsAssignStatement(variableName, type, expr, isDeclared, isConst, options);
@@ -7954,8 +9049,11 @@ class ETSLanguageWriter extends TSLanguageWriter {
7954
9049
  makeLambda(signature, body) {
7955
9050
  return new ETSLambdaExpression(this, this.typeConvertor, signature, this.resolver, body);
7956
9051
  }
7957
- makeMapForEach(map, key, value, op) {
7958
- return new ArkTSMapForEachStatement(map, key, value, op);
9052
+ makeString(value) {
9053
+ return new ETSStringExpression(value);
9054
+ }
9055
+ makeMapForEach(map, key, value, body) {
9056
+ return new ArkTSMapForEachStatement(map, key, value, body);
7959
9057
  }
7960
9058
  makeMapSize(map) {
7961
9059
  return this.makeString(`${super.makeMapSize(map).asString()}`); // TODO: cast really needed?
@@ -8184,12 +9282,16 @@ class AggregateConvertor extends BaseArgConvertor {
8184
9282
  throw new Error("Do not use for aggregates");
8185
9283
  }
8186
9284
  convertorSerialize(param, value, printer) {
8187
- this.memberConvertors.forEach((it, index) => {
8188
- let memberName = this.members[index][0];
8189
- let memberAccess = `${value}.${printer.escapeKeyword(memberName)}`;
8190
- printer.writeStatement(printer.makeAssign(`${value}_${memberName}`, undefined, printer.makeString(memberAccess), true));
8191
- it.convertorSerialize(param, `${value}_${memberName}`, printer);
9285
+ const stmts = this.memberConvertors.flatMap((it, index) => {
9286
+ const memberName = this.members[index][0];
9287
+ const memberAccess = `${value}.${printer.escapeKeyword(memberName)}`;
9288
+ const memberMangledName = `${value}${capitalize(memberName)}`;
9289
+ return [
9290
+ printer.makeAssign(memberMangledName, undefined, printer.makeString(memberAccess), true),
9291
+ it.convertorSerialize(param, memberMangledName, printer)
9292
+ ];
8192
9293
  });
9294
+ return printer.makeBlock(stmts, false);
8193
9295
  }
8194
9296
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
8195
9297
  const statements = [];
@@ -8204,7 +9306,8 @@ class AggregateConvertor extends BaseArgConvertor {
8204
9306
  for (let i = 0; i < this.decl.properties.length; i++) {
8205
9307
  const prop = this.decl.properties[i];
8206
9308
  const propConvertor = this.memberConvertors[i];
8207
- statements.push(propConvertor.convertorDeserialize(`${bufferName}_${prop.name}_buf`, deserializerName, (expr) => {
9309
+ const propName = `${bufferName}${capitalize(prop.name)}`;
9310
+ statements.push(propConvertor.convertorDeserialize(`${propName}TempBuf`, deserializerName, (expr) => {
8208
9311
  if (writer.language === Language.CPP) {
8209
9312
  // prefix initialization for CPP, just easier. Waiting for easy work with nullables
8210
9313
  return writer.makeAssign(`${bufferName}.${writer.escapeKeyword(prop.name)}`, undefined, expr, false);
@@ -8213,7 +9316,7 @@ class AggregateConvertor extends BaseArgConvertor {
8213
9316
  * todo: check UnionType name creation for union of unnamed nodes (isNamedNode() == false)
8214
9317
  */
8215
9318
  const memberType = maybeOptional(prop.type, prop.isOptional);
8216
- return writer.makeAssign(`${bufferName}_${prop.name}`, memberType, expr, true, true);
9319
+ return writer.makeAssign(propName, memberType, expr, true, true);
8217
9320
  }, writer));
8218
9321
  }
8219
9322
  if (writer.language === Language.CPP) {
@@ -8231,7 +9334,7 @@ class AggregateConvertor extends BaseArgConvertor {
8231
9334
  }
8232
9335
  else {
8233
9336
  const resultExpression = this.makeAssigneeExpression(this.decl.properties.map(prop => {
8234
- return [prop.name, writer.makeString(`${bufferName}_${prop.name}`)];
9337
+ return [prop.name, writer.makeString(`${bufferName}${capitalize(prop.name)}`)];
8235
9338
  }), writer);
8236
9339
  statements.push(assigneer(resultExpression));
8237
9340
  }
@@ -8267,10 +9370,10 @@ class InterfaceConvertor extends BaseArgConvertor {
8267
9370
  convertorArg(param, writer) {
8268
9371
  throw new Error("Must never be used");
8269
9372
  }
8270
- convertorSerialize(param, value, printer) {
9373
+ convertorSerialize(param, value, writer) {
8271
9374
  const accessor = getSerializerName(this.declaration);
8272
- printer.addFeature(accessor, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
8273
- printer.writeStaticMethodCall(accessor, 'write', [`${param}Serializer`, value]);
9375
+ writer.addFeature(accessor, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
9376
+ return writer.makeStatement(writer.makeStaticMethodCall(accessor, 'write', [writer.makeString(`${param}Serializer`), writer.makeString(value)]));
8274
9377
  }
8275
9378
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
8276
9379
  const accessor = getSerializerName(this.declaration);
@@ -8311,7 +9414,7 @@ class CustomTypeConvertor extends BaseArgConvertor {
8311
9414
  }
8312
9415
  /** todo: check */
8313
9416
  convertorSerialize(param, value, printer) {
8314
- printer.writeMethodCall(`${param}Serializer`, `writeCustomObject`, [`"${this.customTypeName}"`, printer.makeCastCustomObject(value, this.isGenericType).asString()]);
9417
+ return printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, `writeCustomObject`, [printer.makeString(`"${this.customTypeName}"`), printer.makeCastCustomObject(value, this.isGenericType)]));
8315
9418
  }
8316
9419
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
8317
9420
  const type = writer.language === Language.CPP
@@ -8336,13 +9439,13 @@ class FunctionConvertor extends BaseArgConvertor {
8336
9439
  this.library = library;
8337
9440
  }
8338
9441
  convertorArg(param, writer) {
8339
- return writer.language == Language.CPP ? `makeArkFunctionFromId(${param})` : `registerCallback(${param})`;
9442
+ throw new Error('Shall not be used');
8340
9443
  }
8341
9444
  convertorSerialize(param, value, writer) {
8342
- writer.writeMethodCall(`${param}Serializer`, "writeFunction", [value]);
9445
+ throw new Error('Shall not be used');
8343
9446
  }
8344
9447
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
8345
- return assigneer(writer.makeCast(writer.makeString(`${deserializerName}.readFunction()`), IDLFunctionType, { optional: true }));
9448
+ throw new Error('Shall not be used');
8346
9449
  }
8347
9450
  nativeType() {
8348
9451
  return IDLFunctionType;
@@ -8379,7 +9482,7 @@ class MaterializedClassConvertor extends BaseArgConvertor {
8379
9482
  convertorSerialize(param, value, printer) {
8380
9483
  const accessorRoot = getSerializerName(this.declaration);
8381
9484
  printer.addFeature(accessorRoot, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
8382
- printer.writeStaticMethodCall(accessorRoot, 'write', [`${param}Serializer`, value]);
9485
+ return printer.makeStatement(printer.makeStaticMethodCall(accessorRoot, 'write', [printer.makeString(`${param}Serializer`), printer.makeString(value)]));
8383
9486
  }
8384
9487
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
8385
9488
  const accessorRoot = getSerializerName(this.declaration);
@@ -8631,7 +9734,7 @@ function mk(typeName, check, config) {
8631
9734
  }
8632
9735
  return new ValidationBox({
8633
9736
  success: false,
8634
- errorMessage: `Expected "${typeName}"`
9737
+ errorMessage: `Expected "${typeName}" but got "${typeof x}"`
8635
9738
  });
8636
9739
  }, () => {
8637
9740
  const base = {
@@ -8937,6 +10040,7 @@ const HookMethodSchema = D.object({
8937
10040
  replaceImplementation: D.boolean()
8938
10041
  });
8939
10042
  D.object({
10043
+ ApiKind: D.number(),
8940
10044
  TypePrefix: D.string(),
8941
10045
  LibraryPrefix: D.string(),
8942
10046
  OptionalPrefix: D.string(),
@@ -8951,13 +10055,13 @@ D.object({
8951
10055
  forceResource: T.stringArray(),
8952
10056
  forceContext: T.stringArray(),
8953
10057
  hooks: D.map(D.string(), D.map(D.string(), HookMethodSchema)).onMerge('replace'),
8954
- externalTypes: D.map(D.string(), D.string()).onMerge('replace'),
8955
- externalPackages: T.stringArray(),
8956
10058
  moduleName: D.string(),
8957
10059
  modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
10060
+ libraryNameMapping: D.maybe(D.map(D.string(), D.map(D.string(), D.string())).onMerge('replace')),
8958
10061
  globalPackages: T.stringArray()
8959
10062
  });
8960
10063
  const defaultCoreConfiguration = {
10064
+ ApiKind: 0,
8961
10065
  TypePrefix: "",
8962
10066
  LibraryPrefix: "",
8963
10067
  OptionalPrefix: "",
@@ -8972,10 +10076,9 @@ const defaultCoreConfiguration = {
8972
10076
  forceResource: [],
8973
10077
  forceContext: [],
8974
10078
  hooks: new Map(),
8975
- externalTypes: new Map(),
8976
- externalPackages: [],
8977
10079
  moduleName: "",
8978
10080
  modules: new Map(),
10081
+ libraryNameMapping: new Map(),
8979
10082
  globalPackages: []
8980
10083
  };
8981
10084
  let currentConfig = defaultCoreConfiguration;
@@ -10786,6 +11889,66 @@ const JSON5 = {
10786
11889
 
10787
11890
  var lib = JSON5;
10788
11891
 
11892
+ /*
11893
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
11894
+ * Licensed under the Apache License, Version 2.0 (the "License");
11895
+ * you may not use this file except in compliance with the License.
11896
+ * You may obtain a copy of the License at
11897
+ *
11898
+ * http://www.apache.org/licenses/LICENSE-2.0
11899
+ *
11900
+ * Unless required by applicable law or agreed to in writing, software
11901
+ * distributed under the License is distributed on an "AS IS" BASIS,
11902
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11903
+ * See the License for the specific language governing permissions and
11904
+ * limitations under the License.
11905
+ */
11906
+ class Config {
11907
+ constructor(ignore, nonNullable, irHack, fragments, parameters) {
11908
+ this.ignore = ignore;
11909
+ this.nonNullable = nonNullable;
11910
+ this.irHack = irHack;
11911
+ this.fragments = fragments;
11912
+ this.parameters = parameters;
11913
+ }
11914
+ static get createPrefix() {
11915
+ return `Create`;
11916
+ }
11917
+ static get updatePrefix() {
11918
+ return `Update`;
11919
+ }
11920
+ static get constPostfix() {
11921
+ return `Const`;
11922
+ }
11923
+ static get nodeTypeAttribute() {
11924
+ return `Es2pandaAstNodeType`;
11925
+ }
11926
+ static get nodeNamespaceAttribute() {
11927
+ return `cpp_namespace`;
11928
+ }
11929
+ static get uselessPrefix() {
11930
+ return `Get`;
11931
+ }
11932
+ static get astNodeCommonAncestor() {
11933
+ return `AstNode`;
11934
+ }
11935
+ static get context() {
11936
+ return `Context`;
11937
+ }
11938
+ static get dataClassPrefix() {
11939
+ return `es2panda_`;
11940
+ }
11941
+ static get defaultAncestor() {
11942
+ return `ArktsObject`;
11943
+ }
11944
+ static get irNamespace() {
11945
+ return `ir`;
11946
+ }
11947
+ }
11948
+ Config.DoNotPrintPeers = [
11949
+ 'es2panda_Context', // useless
11950
+ ];
11951
+
10789
11952
  /*
10790
11953
  * Copyright (c) 2024 Huawei Device Co., Ltd.
10791
11954
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -10811,7 +11974,11 @@ class BridgesConstructions {
10811
11974
  return `impl_${name}`;
10812
11975
  }
10813
11976
  static referenceType(name) {
10814
- return `es2panda_${name}*`;
11977
+ // FIXME: Rewrite CastTypeConvertors using idl.CppInteropArgConverter
11978
+ // and LanguageWriter constructions.
11979
+ // Use c_type attribute from declaration.
11980
+ const addPrefix = (n) => (n.startsWith(Config.dataClassPrefix) ? n : `${Config.dataClassPrefix}${n}`);
11981
+ return `${addPrefix(name)}*`;
10815
11982
  }
10816
11983
  static get sequenceLengthDeclaration() {
10817
11984
  return `std::size_t length`;
@@ -10852,9 +12019,6 @@ class BridgesConstructions {
10852
12019
  static get stringCast() {
10853
12020
  return `getStringCopy`;
10854
12021
  }
10855
- static resultAssignment(value) {
10856
- return `auto ${BridgesConstructions.result} = ${value}`;
10857
- }
10858
12022
  static dropConstCast(value) {
10859
12023
  return `(void*)${value}`;
10860
12024
  }
@@ -10869,63 +12033,6 @@ class BridgesConstructions {
10869
12033
  }
10870
12034
  }
10871
12035
 
10872
- /*
10873
- * Copyright (c) 2024 Huawei Device Co., Ltd.
10874
- * Licensed under the Apache License, Version 2.0 (the "License");
10875
- * you may not use this file except in compliance with the License.
10876
- * You may obtain a copy of the License at
10877
- *
10878
- * http://www.apache.org/licenses/LICENSE-2.0
10879
- *
10880
- * Unless required by applicable law or agreed to in writing, software
10881
- * distributed under the License is distributed on an "AS IS" BASIS,
10882
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10883
- * See the License for the specific language governing permissions and
10884
- * limitations under the License.
10885
- */
10886
- class Config {
10887
- constructor(ignore, nonNullable, irHack, fragments, parameters) {
10888
- this.ignore = ignore;
10889
- this.nonNullable = nonNullable;
10890
- this.irHack = irHack;
10891
- this.fragments = fragments;
10892
- this.parameters = parameters;
10893
- }
10894
- static get createPrefix() {
10895
- return `Create`;
10896
- }
10897
- static get updatePrefix() {
10898
- return `Update`;
10899
- }
10900
- static get constPostfix() {
10901
- return `Const`;
10902
- }
10903
- static get nodeTypeAttribute() {
10904
- return `Es2pandaAstNodeType`;
10905
- }
10906
- static get nodeNamespaceAttribute() {
10907
- return `cpp_namespace`;
10908
- }
10909
- static get uselessPrefix() {
10910
- return `Get`;
10911
- }
10912
- static get astNodeCommonAncestor() {
10913
- return `AstNode`;
10914
- }
10915
- static get context() {
10916
- return `Context`;
10917
- }
10918
- static get dataClassPrefix() {
10919
- return `es2panda_`;
10920
- }
10921
- static get defaultAncestor() {
10922
- return `ArktsObject`;
10923
- }
10924
- static get irNamespace() {
10925
- return `ir`;
10926
- }
10927
- }
10928
-
10929
12036
  /*
10930
12037
  * Copyright (c) 2024 Huawei Device Co., Ltd.
10931
12038
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -11078,7 +12185,7 @@ function isReal(node) {
11078
12185
  return nodeType(node) !== undefined;
11079
12186
  }
11080
12187
  function isDataClass(node) {
11081
- return parent(node) === Config.defaultAncestor;
12188
+ return node.name.startsWith(Config.dataClassPrefix) || parent(node) === Config.defaultAncestor;
11082
12189
  }
11083
12190
  function isCreate(name) {
11084
12191
  return isCreateOrUpdate(name) && name.startsWith(Config.createPrefix);
@@ -11090,6 +12197,9 @@ function isCreateOrUpdate(sourceMethodName) {
11090
12197
  const { rest } = splitCreateOrUpdate(sourceMethodName);
11091
12198
  return rest.length <= 1;
11092
12199
  }
12200
+ function isImplInterface(name) {
12201
+ return dropPrefix(name, Config.dataClassPrefix) === 'Impl';
12202
+ }
11093
12203
  function fixEnumPrefix(name) {
11094
12204
  if (name.startsWith(`es2panda_`)) {
11095
12205
  name = dropPrefix(name, `es2panda_`);
@@ -11169,10 +12279,17 @@ function nodeType(node) {
11169
12279
  var _a, _b;
11170
12280
  return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === Config.nodeTypeAttribute)) === null || _b === void 0 ? void 0 : _b.value;
11171
12281
  }
12282
+ function nativeType(node) {
12283
+ var _a, _b;
12284
+ return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === 'c_type')) === null || _b === void 0 ? void 0 : _b.value;
12285
+ }
11172
12286
  function nodeNamespace(node) {
11173
12287
  var _a;
11174
12288
  return (_a = getNamespacesPathFor(node)[0]) === null || _a === void 0 ? void 0 : _a.name;
11175
12289
  }
12290
+ function fqName(node) {
12291
+ return getQualifiedName(node, "namespace.name");
12292
+ }
11176
12293
  function parent(node) {
11177
12294
  var _a;
11178
12295
  return (_a = node.inheritance[0]) === null || _a === void 0 ? void 0 : _a.name;
@@ -11180,14 +12297,6 @@ function parent(node) {
11180
12297
  function createDefaultTypescriptWriter() {
11181
12298
  return new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => throwException(`unexpected type conversion`) });
11182
12299
  }
11183
- function isIrNamespace(node) {
11184
- var _a, _b;
11185
- let cppNamespace = (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name == Config.nodeNamespaceAttribute)) === null || _b === void 0 ? void 0 : _b.value;
11186
- return nodeNamespace(node) === Config.irNamespace || cppNamespace == Config.irNamespace;
11187
- }
11188
- function createSequence(inner) {
11189
- return createContainerType(`sequence`, [inner]);
11190
- }
11191
12300
  function innerType(node) {
11192
12301
  return node.elementType[0];
11193
12302
  }
@@ -11215,8 +12324,13 @@ function makeSignature(parameters, returnType) {
11215
12324
  .map(it => it.name)
11216
12325
  .map(mangleIfKeyword));
11217
12326
  }
11218
- function flatParents(ref, idl) {
11219
- const resolveReference = (ref) => resolveNamedNode(ref.name.split('.'), undefined, [idl]);
12327
+ function makeExpression(writer, arg) {
12328
+ return typeof arg === 'string' ? writer.makeString(arg) : arg;
12329
+ }
12330
+ function makeStatement(writer, arg) {
12331
+ return typeof arg !== 'string' && 'write' in arg ? arg : writer.makeStatement(makeExpression(writer, arg));
12332
+ }
12333
+ function flatParentsImpl(ref, resolveReference) {
11220
12334
  if (isReferenceType(ref)) {
11221
12335
  const type = resolveReference(ref);
11222
12336
  if (!type || !isInterface$1(type)) {
@@ -11229,13 +12343,21 @@ function flatParents(ref, idl) {
11229
12343
  while (queue.length) {
11230
12344
  const node = queue.shift();
11231
12345
  result.push(node);
12346
+ if (result.length > 1 && baseNameString(ref.name) === node.name) {
12347
+ //console.warn(`Cyclic dependency: ${ref.name} -> ${node.name}`);
12348
+ break;
12349
+ }
11232
12350
  node.inheritance
11233
- .map(p => resolveReference(p))
12351
+ .map(p => resolveReference(p, ref))
11234
12352
  .filter(p => p !== undefined && isInterface$1(p))
11235
12353
  .forEach(p => queue.push(p));
11236
12354
  }
11237
12355
  return result; // with self
11238
12356
  }
12357
+ function flatParents(ref, idl) {
12358
+ const resolveReference = (ref, pov) => resolveNamedNode(ref.name.split('.'), pov, [idl]);
12359
+ return flatParentsImpl(ref, resolveReference);
12360
+ }
11239
12361
 
11240
12362
  /*
11241
12363
  * Copyright (c) 2024 Huawei Device Co., Ltd.
@@ -11252,60 +12374,75 @@ function flatParents(ref, idl) {
11252
12374
  * limitations under the License.
11253
12375
  */
11254
12376
  class Typechecker {
11255
- constructor(idl) {
11256
- this.idl = idl;
11257
- this.idl = linearizeNamespaceMembers(idl);
12377
+ constructor(file) {
12378
+ this.file = file;
12379
+ this.namespaces = this.file.entries.filter(e => isNamespace(e));
12380
+ }
12381
+ resolveReference(ref) {
12382
+ const prefix = Config.dataClassPrefix;
12383
+ // XXX: This is a temporary hack until duplicates will not be removed from idl
12384
+ if (ref.name.startsWith(prefix)) {
12385
+ const entry = this.resolveReference2(createReferenceType(ref.name.slice(prefix.length)));
12386
+ if (entry) {
12387
+ return entry;
12388
+ }
12389
+ }
12390
+ return this.resolveReference2(ref);
11258
12391
  }
11259
- findRealDeclaration(name) {
11260
- // Poor man's namespace-aware resolve.
11261
- // TODO: REWORK IT ALL!
11262
- const declarations = this.idl.filter(it => (name === it.name) || (baseNameString(name) == baseNameString(it.name)));
11263
- if (declarations.length === 1) {
11264
- return declarations[0];
12392
+ resolveReference2(ref, debugPrefix = '') {
12393
+ const target = ref.name.split('.');
12394
+ let entry = undefined;
12395
+ if (target.length > 1) { // full-qualified
12396
+ entry = resolveNamedNode(target, undefined, [this.file]);
11265
12397
  }
11266
- const ir = declarations
11267
- .filter(isInterface$1)
11268
- .filter(it => isIrNamespace(it));
11269
- if (ir.length > 0) {
11270
- return ir[0];
12398
+ else {
12399
+ if (ref.parent) {
12400
+ entry = resolveNamedNode(target, ref.parent, [this.file]);
12401
+ }
12402
+ if (!entry) {
12403
+ for (const pov of this.namespaces) {
12404
+ entry = resolveNamedNode(target, pov, [this.file]);
12405
+ if (entry)
12406
+ break;
12407
+ }
12408
+ }
11271
12409
  }
11272
- return undefined;
11273
- }
11274
- isHeir(name, ancestor) {
11275
- if (name === ancestor) {
11276
- return true;
12410
+ if (debugPrefix.length) {
12411
+ console.log(`RESOLVER: ${ref.name} => ${entry ? fqName(entry) : entry}`);
11277
12412
  }
11278
- const declaration = this.findRealDeclaration(name);
11279
- if (declaration === undefined || !isInterface$1(declaration)) {
12413
+ return entry;
12414
+ }
12415
+ // All classes are consideres heirs of ArktsObject now
12416
+ isHeir(ref, ancestor) {
12417
+ const resolveReference = (r, _) => this.resolveReference(r);
12418
+ const iface = isReferenceType(ref) ? resolveReference(ref) : ref;
12419
+ if (!iface || !isInterface$1(iface)) {
11280
12420
  return false;
11281
12421
  }
11282
- let isHeir = declaration.name === ancestor;
11283
- declaration.inheritance.forEach(parent => {
11284
- isHeir || (isHeir = this.isHeir(parent.name, ancestor));
11285
- });
11286
- return isHeir;
12422
+ const parents = flatParentsImpl(iface, resolveReference);
12423
+ if (parents.map(p => p.name).includes(ancestor)) {
12424
+ return true;
12425
+ }
12426
+ return ancestor === Config.defaultAncestor;
11287
12427
  }
11288
12428
  isPeer(node) {
11289
- if (node === Config.astNodeCommonAncestor)
12429
+ if (node.name === Config.astNodeCommonAncestor)
11290
12430
  return false; // TODO: is handwritten
11291
- if (node === Config.context)
12431
+ if (node.name === Config.context)
11292
12432
  return false; // TODO: is handwritten
12433
+ if (isImplInterface(node.name))
12434
+ return false;
11293
12435
  if (this.isHeir(node, Config.astNodeCommonAncestor))
11294
12436
  return true;
11295
12437
  if (this.isHeir(node, Config.defaultAncestor))
11296
12438
  return true;
11297
- // TODO: fix
11298
- if (node === "Program")
11299
- return true;
11300
- if (node === "ArkTsConfig")
11301
- return true;
11302
12439
  return false;
11303
12440
  }
11304
12441
  isReferenceTo(type, isTarget) {
11305
12442
  if (!isReferenceType(type)) {
11306
12443
  return false;
11307
12444
  }
11308
- const declaration = this.findRealDeclaration(type.name);
12445
+ const declaration = this.resolveReference(type);
11309
12446
  return declaration !== undefined && isTarget(declaration);
11310
12447
  }
11311
12448
  isConstReturnValue(node) {
@@ -11315,35 +12452,13 @@ class Typechecker {
11315
12452
  return node.name.endsWith(Config.constPostfix);
11316
12453
  }
11317
12454
  nodeTypeName(node) {
11318
- var _a, _b;
12455
+ var _a;
11319
12456
  const value = nodeType(node);
11320
- const idlEnum = this.idl
11321
- .filter(isEnum$1)
11322
- .find(it => it.name === Config.nodeTypeAttribute);
11323
- return (_b = (_a = idlEnum === null || idlEnum === void 0 ? void 0 : idlEnum.elements) === null || _a === void 0 ? void 0 : _a.find(it => { var _a; return ((_a = it.initializer) === null || _a === void 0 ? void 0 : _a.toString()) === value; })) === null || _b === void 0 ? void 0 : _b.name;
11324
- }
11325
- parent(node) {
11326
- const parentName = parent(node);
11327
- if (parentName === undefined)
11328
- return undefined;
11329
- const decl = this.findRealDeclaration(parentName);
11330
- if (decl === undefined)
11331
- return undefined;
11332
- if (!isInterface$1(decl))
11333
- return undefined;
11334
- return decl;
11335
- }
11336
- ancestry(node) {
11337
- let current = node;
11338
- const res = [];
11339
- while (true) {
11340
- res.push(current);
11341
- const parent = this.parent(current);
11342
- if (parent === undefined) {
11343
- return res;
11344
- }
11345
- current = parent;
11346
- }
12457
+ const entry = this.resolveReference(createReferenceType(Config.nodeTypeAttribute));
12458
+ const name = entry && isEnum$1(entry)
12459
+ ? (_a = entry.elements.find(e => { var _a; return ((_a = e.initializer) === null || _a === void 0 ? void 0 : _a.toString()) === value; })) === null || _a === void 0 ? void 0 : _a.name
12460
+ : undefined;
12461
+ return name ? `${Config.nodeTypeAttribute}.${name}` : undefined; // value
11347
12462
  }
11348
12463
  }
11349
12464
 
@@ -11375,7 +12490,7 @@ class SingleFilePrinter extends AbstractVisitor {
11375
12490
  constructor(idl) {
11376
12491
  super();
11377
12492
  this.idl = idl;
11378
- this.typechecker = new Typechecker(this.idl.entries);
12493
+ this.typechecker = new Typechecker(this.idl);
11379
12494
  }
11380
12495
  printEnum(node) { }
11381
12496
  visit(node) {
@@ -11422,7 +12537,7 @@ class InteropPrinter extends AbstractVisitor {
11422
12537
  constructor(file) {
11423
12538
  super();
11424
12539
  this.file = file;
11425
- this.typechecker = new Typechecker(this.file.entries);
12540
+ this.typechecker = new Typechecker(this.file);
11426
12541
  }
11427
12542
  print() {
11428
12543
  this.file.entries.forEach(it => this.visit(it));
@@ -11512,9 +12627,6 @@ class BaseTypeConvertor {
11512
12627
  return convertType(this, type);
11513
12628
  }
11514
12629
  }
11515
- function composedConvertType(result, effect, type) {
11516
- return result.convertType(effect.convertType(type));
11517
- }
11518
12630
 
11519
12631
  /*
11520
12632
  * Copyright (c) 2024 Huawei Device Co., Ltd.
@@ -11668,7 +12780,7 @@ class CastToTypeConvertor extends BaseTypeConvertor {
11668
12780
  sequence: (type) => BridgesConstructions.arrayOf(this.convertType(innerType(type))),
11669
12781
  enum: (type) => type.name,
11670
12782
  reference: (type) => {
11671
- return BridgesConstructions.referenceType(typechecker.isHeir(type.name, Config.astNodeCommonAncestor)
12783
+ return BridgesConstructions.referenceType(typechecker.isHeir(type, Config.astNodeCommonAncestor)
11672
12784
  ? Config.astNodeCommonAncestor
11673
12785
  : baseName(type));
11674
12786
  },
@@ -11712,6 +12824,8 @@ class BridgesPrinter extends InteropPrinter {
11712
12824
  this.config = config;
11713
12825
  this.castTypeConvertor = new CastTypeConvertor(this.typechecker);
11714
12826
  this.nativeTypeConvertor = new NativeTypeConvertor(this.typechecker);
12827
+ this.returnTypeConvertor = new ReturnTypeConvertor$1(this.typechecker);
12828
+ this.interopMacroConvertor = new InteropMacroTypeConvertor(this.typechecker);
11715
12829
  this.writer = new CppLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => this.nativeTypeConvertor.convertType(node) }, new class extends PrimitiveTypeList {
11716
12830
  constructor() {
11717
12831
  super(...arguments);
@@ -11719,82 +12833,62 @@ class BridgesPrinter extends InteropPrinter {
11719
12833
  this.Void = new PrimitiveType(`void`);
11720
12834
  }
11721
12835
  }());
11722
- this.returnTypeConvertor = new ReturnTypeConvertor$1(this.typechecker);
11723
- this.interopMacroConvertor = new InteropMacroTypeConvertor(this.typechecker);
11724
- }
11725
- printInteropMacro(methodName, signature) {
11726
- this.writer.writeExpressionStatement(this.writer.makeFunctionCall(BridgesConstructions.interopMacro(isVoidType(signature.returnType), signature.args.length), [methodName]
11727
- .concat((() => {
11728
- if (isVoidType(signature.returnType)) {
11729
- return [];
11730
- }
11731
- return [this.returnTypeConvertor.convertType(signature.returnType)];
11732
- })()
11733
- .concat(signature.args)
11734
- .map(it => this.interopMacroConvertor.convertType(it)))
11735
- .map(it => this.writer.makeString(it))));
11736
12836
  }
11737
12837
  printMethod(iface, node) {
12838
+ if (this.config.ignore.isIgnoredMethod(iface.name, node.name))
12839
+ return;
11738
12840
  const [methodName, signature] = BridgesPrinter.makeFunctionDeclaration(iface, node, this.returnTypeConvertor);
11739
- this.writer.writeFunctionImplementation(BridgesConstructions.implFunction(methodName), signature, (_) => this.printBody(iface, node, signature));
12841
+ this.writer.writeFunctionImplementation(BridgesConstructions.implFunction(methodName), signature, (_) => {
12842
+ let pandaMethodName = BridgesConstructions.callMethod(methodName);
12843
+ if (this.config.irHack.isIrHackInterface(iface.name)) {
12844
+ pandaMethodName = pandaMethodName.replace(iface.name, `${iface.name}Ir`);
12845
+ }
12846
+ this.printBody(node, signature, pandaMethodName);
12847
+ });
11740
12848
  this.printInteropMacro(methodName, signature);
11741
12849
  this.writer.writeLines(``);
11742
12850
  }
12851
+ printInteropMacro(methodName, signature) {
12852
+ const isVoid = isVoidType(signature.returnType);
12853
+ const args = (isVoid ? [] : [signature.returnType])
12854
+ .concat(signature.args)
12855
+ .map(a => this.interopMacroConvertor.convertType(a));
12856
+ args.splice(0, 0, methodName);
12857
+ this.writer.writeExpressionStatement(this.writer.makeFunctionCall(BridgesConstructions.interopMacro(isVoid, signature.args.length), args.map(it => this.writer.makeString(it))));
12858
+ }
11743
12859
  static makeFunctionDeclaration(iface, node, converter) {
11744
12860
  var _a;
11745
- const signature = new MethodSignature(converter.convertType(node.returnType), node.parameters.map(it => it.type), undefined, node.parameters.map(it => it.isOptional ? ArgumentModifier.OPTIONAL : undefined), undefined, node.parameters.map(it => mangleIfKeyword(it.name)));
11746
- if (!isCreateOrUpdate(node.name)) {
12861
+ const signature = makeSignature(node.parameters.map(p => ({
12862
+ name: mangleIfKeyword(p.name),
12863
+ type: p.type,
12864
+ isOptional: p.isOptional
12865
+ })), converter.convertType(node.returnType));
12866
+ if (!isCreateOrUpdate(node.name) && !isImplInterface(iface.name)) {
11747
12867
  signature.args.splice(1, 0, createReferenceType(iface.name));
11748
12868
  signature.argNames.splice(1, 0, 'receiver');
11749
12869
  }
11750
12870
  const fixArgName = (name, prev) => name.endsWith('Len') ? (prev !== null && prev !== void 0 ? prev : name.slice(0, -3)) + 'SequenceLength' : name === 'ctx' ? 'context' : name;
11751
12871
  // Not necessary, just to keep old names
11752
12872
  signature.argNames = (_a = signature.argNames) === null || _a === void 0 ? void 0 : _a.map((v, i) => fixArgName(v, i === 0 ? undefined : signature.argNames[i - 1]));
11753
- return [InteropConstructions.method(iface.name, node.name), signature];
11754
- }
11755
- printBody(iface, node, signature) {
11756
- this.printParameters(signature);
11757
- this.printDeclarations(node);
11758
- this.printEs2pandaCall(iface, node, signature);
11759
- this.printReturn(node);
11760
- }
11761
- printParameters(signature) {
11762
- signature.args.forEach((type, index) => {
11763
- var _a, _b;
11764
- const name = (_b = (_a = signature.argNames) === null || _a === void 0 ? void 0 : _a.at(index)) !== null && _b !== void 0 ? _b : `arg${index}`;
11765
- this.writer.writeStatement(this.writer.makeAssign(BridgesConstructions.castedParameter(name), undefined, this.writer.makeFunctionCall(this.castTypeConvertor.convertType(type), [this.writer.makeString(name)])));
11766
- });
12873
+ const methodName = isImplInterface(iface.name) ? node.name : InteropConstructions.method(iface.name, node.name);
12874
+ return [methodName, signature];
11767
12875
  }
11768
- printDeclarations(node) {
12876
+ printBody(node, signature, pandaMethodName) {
12877
+ const writer = this.writer;
12878
+ const argNames = signature.argNames.map(BridgesConstructions.castedParameter);
12879
+ const statements = signature.args.map((type, index) => this.writer.makeAssign(BridgesConstructions.castedParameter(signature.argName(index)), undefined, writer.makeFunctionCall(this.castTypeConvertor.convertType(type), [writer.makeString(signature.argName(index))])));
11769
12880
  if (isSequence(node.returnType)) {
11770
- this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.sequenceLengthDeclaration));
12881
+ argNames.push(BridgesConstructions.sequenceLengthPass);
12882
+ statements.push(makeStatement(writer, BridgesConstructions.sequenceLengthDeclaration));
11771
12883
  }
11772
- }
11773
- printEs2pandaCall(iface, node, signature) {
12884
+ const nativeCall = writer.makeFunctionCall(pandaMethodName, argNames.map(a => writer.makeString(a)));
12885
+ writer.writeStatements(...statements);
11774
12886
  if (isVoidType(node.returnType)) {
11775
- this.writer.writeExpressionStatement(this.makeEs2pandaMethodCall(iface, node, signature));
11776
- return;
12887
+ writer.writeStatements(writer.makeStatement(nativeCall), writer.makeReturn(writer.makeString('')));
11777
12888
  }
11778
- this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.resultAssignment(this.makeEs2pandaMethodCall(iface, node, signature).asString())));
11779
- }
11780
- makeEs2pandaMethodCall(iface, node, signature) {
11781
- let suffix = this.config.irHack.isIrHackInterface(iface.name) ? 'Ir' : '';
11782
- let method = BridgesConstructions.callMethod(InteropConstructions.method(iface.name, node.name));
11783
- method = method.replace(iface.name, iface.name + suffix);
11784
- return this.writer.makeFunctionCall(method, signature.argNames
11785
- .map(it => ({
11786
- asString: () => BridgesConstructions.castedParameter(it),
11787
- }))
11788
- .concat(isSequence(node.returnType) // XXX: original return type
11789
- ? this.writer.makeString(BridgesConstructions.sequenceLengthPass)
11790
- : []));
11791
- }
11792
- printReturn(node) {
11793
- if (isVoidType(node.returnType)) {
11794
- this.writer.writeStatement(this.writer.makeReturn(this.writer.makeString(``)));
11795
- return;
12889
+ else {
12890
+ writer.writeStatements(writer.makeAssign(BridgesConstructions.result, undefined, nativeCall, true, false), writer.makeReturn(writer.makeString(this.maybeDropConst(this.makeReturnExpression(node.returnType), node))));
11796
12891
  }
11797
- this.writer.writeStatement(this.writer.makeReturn(this.writer.makeString(this.maybeDropConst(this.makeReturnExpression(node.returnType), node))));
11798
12892
  }
11799
12893
  makeReturnExpression(returnType) {
11800
12894
  if (isSequence(returnType)) {
@@ -11891,10 +12985,10 @@ class IndexPrinter extends SingleFilePrinter {
11891
12985
  this.writer = createDefaultTypescriptWriter();
11892
12986
  }
11893
12987
  filterInterface(node) {
11894
- return !this.typechecker.isPeer(node.name);
12988
+ return !this.typechecker.isPeer(node) || Config.DoNotPrintPeers.includes(fqName(node));
11895
12989
  }
11896
12990
  printInterface(node) {
11897
- this.writer.writeExpressionStatement(this.writer.makeString(`export * from "./peers/${node.name}"`));
12991
+ this.writer.writeExpressionStatement(this.writer.makeString(`export * from "./peers/${dropPrefix(node.name, Config.dataClassPrefix)}"`));
11898
12992
  }
11899
12993
  }
11900
12994
 
@@ -12034,7 +13128,7 @@ class MultiFilePrinter extends AbstractVisitor {
12034
13128
  constructor(idl) {
12035
13129
  super();
12036
13130
  this.idl = idl;
12037
- this.typechecker = new Typechecker(this.idl.entries);
13131
+ this.typechecker = new Typechecker(this.idl);
12038
13132
  this.output = [];
12039
13133
  }
12040
13134
  visit(node) {
@@ -12064,15 +13158,15 @@ class MultiFilePrinter extends AbstractVisitor {
12064
13158
  * limitations under the License.
12065
13159
  */
12066
13160
  class PeersConstructions {
13161
+ static peerName(name) {
13162
+ return dropPrefix(name, Config.dataClassPrefix);
13163
+ }
12067
13164
  static fileName(node) {
12068
- return `${node}.ts`;
13165
+ return `${this.peerName(node)}.ts`;
12069
13166
  }
12070
13167
  static get pointerParameter() {
12071
13168
  return `pointer`;
12072
13169
  }
12073
- static get validatePeer() {
12074
- return `assertValidPeer`;
12075
- }
12076
13170
  static get super() {
12077
13171
  return `super`;
12078
13172
  }
@@ -12091,8 +13185,8 @@ class PeersConstructions {
12091
13185
  name: parameter,
12092
13186
  type: `object | undefined`
12093
13187
  },
12094
- returnType: (type) => `${parameter} is ${type}`,
12095
- body: (type) => `${parameter} instanceof ${type}`
13188
+ returnType: (type) => `${parameter} is ${PeersConstructions.peerName(type)}`,
13189
+ body: (type) => `${parameter} instanceof ${PeersConstructions.peerName(type)}`
12096
13190
  };
12097
13191
  }
12098
13192
  static get unpackNullable() {
@@ -12147,13 +13241,13 @@ class PeersConstructions {
12147
13241
  return `setChildrenParentPtr`;
12148
13242
  }
12149
13243
  static newOf(iface) {
12150
- return `new ${iface}`;
13244
+ return `new ${this.peerName(iface)}`;
12151
13245
  }
12152
13246
  static callPeerMethod(iface, method) {
12153
13247
  return `${iface}.${method}`;
12154
13248
  }
12155
13249
  static brand(iface) {
12156
- return `brand${capitalize(iface)}`;
13250
+ return `brand${capitalize(this.peerName(iface))}`;
12157
13251
  }
12158
13252
  }
12159
13253
 
@@ -12188,9 +13282,8 @@ class Importer {
12188
13282
  if (this.seen.has(it)) {
12189
13283
  return it;
12190
13284
  }
12191
- if (!this.typechecker.isPeer(it)) {
12192
- return it;
12193
- }
13285
+ // the 'it' parameter can be a modified peer name
13286
+ // and therefor cannot be resolved here
12194
13287
  this.seen.add(it);
12195
13288
  this.import(it, it);
12196
13289
  return it;
@@ -12298,34 +13391,24 @@ class LibraryTypeConvertor extends TopLevelTypeConvertor {
12298
13391
  * See the License for the specific language governing permissions and
12299
13392
  * limitations under the License.
12300
13393
  */
12301
- class ImporterTypeConvertor extends TopLevelTypeConvertor {
12302
- constructor(importer, typechecker) {
12303
- super(typechecker, {
12304
- optional: (type) => {
12305
- this.convertType(type.type);
12306
- return type;
12307
- },
12308
- sequence: (type) => {
12309
- this.convertType(type.elementType[0]);
12310
- return type;
12311
- },
12312
- enum: (type) => {
12313
- this.importer.withEnumImport(type.name);
12314
- return type;
12315
- },
12316
- reference: (type) => {
12317
- this.importer.withPeerImport(baseName(type));
12318
- return type;
12319
- },
12320
- string: (type) => type,
12321
- number: (type) => type,
12322
- boolean: (type) => type,
12323
- void: (type) => type,
12324
- pointer: (type) => type,
12325
- undefined: (type) => type
12326
- });
12327
- this.importer = importer;
13394
+ function convertAndImport(importer, converter, type) {
13395
+ const result = converter.convertType(type);
13396
+ if (isOptionalType(type)) {
13397
+ convertAndImport(importer, converter, type.type);
13398
+ }
13399
+ else if (isContainerType(type) && IDLContainerUtils.isSequence(type)) {
13400
+ convertAndImport(importer, converter, type.elementType[0]);
13401
+ }
13402
+ else if (isReferenceType(type)) {
13403
+ const node = converter.typechecker.resolveReference(type);
13404
+ if (node && isEnum$1(node)) {
13405
+ importer.withEnumImport(result);
13406
+ }
13407
+ else if (node && isInterface$1(node) && converter.typechecker.isPeer(node)) {
13408
+ importer.withPeerImport(result);
13409
+ }
12328
13410
  }
13411
+ return result;
12329
13412
  }
12330
13413
 
12331
13414
  /*
@@ -12388,15 +13471,15 @@ class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
12388
13471
  super(typechecker, {
12389
13472
  sequence: (type) => wrap(PeersConstructions.arrayOfPointersToArrayOfPeers),
12390
13473
  string: (type) => wrap(PeersConstructions.receiveString),
12391
- reference: (type) => this.typechecker.isHeir(type.name, Config.astNodeCommonAncestor)
13474
+ reference: (type) => this.typechecker.isHeir(type, Config.astNodeCommonAncestor)
12392
13475
  ? wrap(PeersConstructions.unpackNonNullable)
12393
- : wrap(type.name),
13476
+ : wrap(baseNameString(type.name)),
12394
13477
  optional: (type) => {
12395
13478
  if (isReferenceType(type.type)) {
12396
- if (this.typechecker.isHeir(type.type.name, Config.astNodeCommonAncestor)) {
13479
+ if (this.typechecker.isHeir(type.type, Config.astNodeCommonAncestor)) {
12397
13480
  return wrap(PeersConstructions.unpackNullable);
12398
13481
  }
12399
- return wrap(PeersConstructions.newOf(type.type.name));
13482
+ return wrap(PeersConstructions.newOf(baseNameString(type.type.name)));
12400
13483
  }
12401
13484
  throwException(`unexpected optional of non-reference type`);
12402
13485
  },
@@ -12444,16 +13527,20 @@ class PeerPrinter extends SingleFilePrinter {
12444
13527
  super(idl);
12445
13528
  this.config = config;
12446
13529
  this.node = node;
12447
- this.typechecker = new Typechecker(this.idl.entries);
13530
+ this.typechecker = new Typechecker(this.idl);
12448
13531
  this.importer = new Importer(this.typechecker, `.`, this.node.name);
12449
13532
  this.bindingParameterTypeConvertor = new BindingParameterTypeConvertor(this.typechecker);
12450
13533
  this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker);
12451
13534
  this.parent = (_a = parent(this.node)) !== null && _a !== void 0 ? _a : Config.defaultAncestor;
12452
- this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
12453
- });
13535
+ this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => convertAndImport(this.importer, new class extends LibraryTypeConvertor {
13536
+ convertTypeReference(type) {
13537
+ return dropPrefix(super.convertTypeReference(type), Config.dataClassPrefix);
13538
+ }
13539
+ }(this.typechecker), node) });
12454
13540
  }
12455
13541
  printPeer() {
12456
- this.writer.writeClass(this.node.name, () => this.printBody(), this.parent ? this.importer.withPeerImport(this.parent) : undefined);
13542
+ this.writer.writeClass(PeersConstructions.peerName(this.node.name), // XXX: Change peer name
13543
+ () => this.printBody(), this.parent ? this.importer.withPeerImport(baseNameString(this.parent)) : undefined);
12457
13544
  }
12458
13545
  printBody() {
12459
13546
  this.printConstructor();
@@ -12462,21 +13549,16 @@ class PeerPrinter extends SingleFilePrinter {
12462
13549
  this.printBrand();
12463
13550
  }
12464
13551
  printConstructor() {
12465
- this.writer.writeConstructorImplementation(this.node.name, new MethodSignature(IDLVoidType, [
12466
- IDLPointerType
12467
- ], undefined, undefined, undefined, [
12468
- PeersConstructions.pointerParameter
12469
- ]), () => {
12470
- var _a;
12471
- if (isReal(this.node)) {
12472
- this.writer.writeExpressionStatement(this.writer.makeFunctionCall(PeersConstructions.validatePeer, [
12473
- this.writer.makeString(PeersConstructions.pointerParameter),
12474
- this.writer.makeString((_a = nodeType(this.node)) !== null && _a !== void 0 ? _a : throwException(`missing attribute node type: ${this.node.name}`)),
12475
- ]));
12476
- }
12477
- this.writer.writeExpressionStatements(this.writer.makeFunctionCall(PeersConstructions.super, [
12478
- this.writer.makeString(PeersConstructions.pointerParameter)
12479
- ]));
13552
+ isReal(this.node);
13553
+ const isAstNodeDescendant = this.typechecker.isHeir(this.node, Config.astNodeCommonAncestor);
13554
+ const args = [IDLPointerType];
13555
+ const argNames = [PeersConstructions.pointerParameter];
13556
+ if (isAstNodeDescendant) {
13557
+ args.push(createReferenceType(Config.nodeTypeAttribute));
13558
+ argNames.push('astNodeType');
13559
+ }
13560
+ this.writer.writeConstructorImplementation(this.node.name, new MethodSignature(IDLVoidType, args, undefined, undefined, undefined, argNames), () => {
13561
+ this.writer.writeExpressionStatements(this.writer.makeFunctionCall(PeersConstructions.super, argNames.map(n => this.writer.makeString(n))));
12480
13562
  });
12481
13563
  }
12482
13564
  printTypeGuard() {
@@ -12487,7 +13569,12 @@ class PeerPrinter extends SingleFilePrinter {
12487
13569
  printMethods() {
12488
13570
  this.node.methods.forEach(it => {
12489
13571
  if (isCreateOrUpdate(it.name)) {
12490
- if (isAbstract(this.node)) {
13572
+ // TODO: This condition is not clear - classes with c_type attribute
13573
+ // is not abstract too, is it?
13574
+ // The check for a native type allows types that is descendants of
13575
+ // AstNode but have not type attribute, for example, varbinder.FunctionDecl
13576
+ if (isAbstract(this.node) && nativeType(this.node) === undefined) {
13577
+ console.log(`Skipped ${this.node.name}.${it.name}`);
12491
13578
  return;
12492
13579
  }
12493
13580
  return this.printCreateOrUpdate(it);
@@ -12592,18 +13679,19 @@ class PeerPrinter extends SingleFilePrinter {
12592
13679
  this.writer.writeMethodImplementation(makeMethod(PeersConstructions.createOrUpdate(this.node.name, node.name), node.parameters
12593
13680
  .map(it => createParameter(it.name, flattenType(it.type)))
12594
13681
  .concat(extraParameters), flattenType(node.returnType), [MethodModifier.STATIC]), (writer) => {
12595
- const newExpr = this.writer.makeNewObject(this.node.name, [
12596
- this.writer.makeFunctionCall(this.writer.makeString(PeersConstructions.callBinding(this.node.name, node.name, nodeNamespace(this.node))), this.makeBindingArguments(node.parameters)),
12597
- ]);
13682
+ var _a;
13683
+ const nativeCall = this.writer.makeFunctionCall(this.writer.makeString(PeersConstructions.callBinding(this.node.name, node.name, nodeNamespace(this.node))), this.makeBindingArguments(node.parameters));
12598
13684
  const varName = 'result';
12599
13685
  const makeStmt = (property) => PeerPrinter.makeExtraStatement(property, PeerPrinter.resolveProperty(property, this.node, this.idl), ['should_not_be_here', varName], this.writer);
12600
13686
  const extraStatements = this.config.parameters.getParameters(this.node.name)
12601
13687
  .map(makeStmt);
12602
13688
  if (isReal(this.node)) {
13689
+ const astNodeType = (_a = this.typechecker.nodeTypeName(this.node)) !== null && _a !== void 0 ? _a : throwException(`missing attribute node type: ${this.node.name}`);
13690
+ const newExpr = writer.makeNewObject(this.node.name, [nativeCall, writer.makeString(astNodeType)]);
12603
13691
  this.writer.writeStatements(this.writer.makeAssign(varName, createReferenceType(this.node.name), newExpr, true), ...extraStatements, this.writer.makeStatement(this.writer.makeMethodCall(varName, PeersConstructions.setChildrenParentPtrMethod, [])), this.writer.makeReturn(this.writer.makeString(varName)));
12604
13692
  }
12605
13693
  else {
12606
- this.writer.writeStatement(this.writer.makeReturn(newExpr));
13694
+ writer.writeStatement(writer.makeReturn(writer.makeNewObject(this.node.name, [nativeCall])));
12607
13695
  }
12608
13696
  });
12609
13697
  }
@@ -12621,8 +13709,8 @@ class PeerPrinter extends SingleFilePrinter {
12621
13709
  if (enumValue === undefined) {
12622
13710
  return;
12623
13711
  }
12624
- const qualified = `${this.importer.withEnumImport(Config.nodeTypeAttribute)}.${enumValue}`;
12625
- this.writer.writeExpressionStatements(this.writer.makeString(`if (!nodeByType.has(${qualified})) {`), this.writer.makeString(` nodeByType.set(${qualified}, (peer: KNativePointer) => new ${this.node.name}(peer))`), this.writer.makeString(`}`));
13712
+ this.importer.withEnumImport(Config.nodeTypeAttribute);
13713
+ this.writer.writeExpressionStatements(this.writer.makeString(`if (!nodeByType.has(${enumValue})) {`), this.writer.makeString(` nodeByType.set(${enumValue}, (peer: KNativePointer) => new ${this.node.name}(peer, ${enumValue}))`), this.writer.makeString(`}`));
12626
13714
  }
12627
13715
  printBrand() {
12628
13716
  this.writer.writeProperty(PeersConstructions.brand(this.node.name), IDLUndefinedType, [FieldModifier.PROTECTED, FieldModifier.READONLY]);
@@ -12649,7 +13737,7 @@ class AllPeersPrinter extends MultiFilePrinter {
12649
13737
  this.config = config;
12650
13738
  }
12651
13739
  filterInterface(node) {
12652
- return !this.typechecker.isPeer(node.name);
13740
+ return !this.typechecker.isPeer(node) || Config.DoNotPrintPeers.includes(fqName(node));
12653
13741
  }
12654
13742
  printInterface(node) {
12655
13743
  return {
@@ -12713,8 +13801,7 @@ class FactoryPrinter extends SingleFilePrinter {
12713
13801
  super(idl);
12714
13802
  this.config = config;
12715
13803
  this.importer = new Importer(this.typechecker, `peers`);
12716
- this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
12717
- });
13804
+ this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => convertAndImport(this.importer, new LibraryTypeConvertor(this.typechecker), node) });
12718
13805
  }
12719
13806
  prologue() {
12720
13807
  this.writer.writeExpressionStatements(this.writer.makeString(FactoryConstructions.prologue));
@@ -12725,7 +13812,7 @@ class FactoryPrinter extends SingleFilePrinter {
12725
13812
  this.writer.writeExpressionStatements(this.writer.makeString(FactoryConstructions.epilogue));
12726
13813
  }
12727
13814
  filterInterface(node) {
12728
- return !this.typechecker.isPeer(node.name) || FactoryPrinter.getUniversalCreate(node) == undefined;
13815
+ return !this.typechecker.isPeer(node) || FactoryPrinter.getUniversalCreate(node) == undefined;
12729
13816
  }
12730
13817
  printInterface(node) {
12731
13818
  this.printCreate(node);
@@ -12856,15 +13943,15 @@ class Transformer {
12856
13943
  class BaseInterfaceFilterTransformer extends Transformer {
12857
13944
  constructor(file, removeNamespaces = false) {
12858
13945
  super(file, removeNamespaces);
12859
- this.typechecker = new Typechecker(this.file.entries);
13946
+ this.typechecker = new Typechecker(this.file);
12860
13947
  }
12861
13948
  transformInterface(entry) {
12862
- if (this.shouldFilterOutInterface(entry.name)) {
13949
+ if (this.shouldFilterOutInterface(entry)) {
12863
13950
  return undefined;
12864
13951
  }
12865
13952
  return createUpdatedInterface(entry, entry.methods
12866
13953
  .filter(it => !this.shouldFilterOutMethod(entry.name, it.name))
12867
- .filter(it => !this.isReferringForbiddenOrMissing(it, (name) => this.shouldFilterOutInterface(name))), entry.name, entry.inheritance, entry.extendedAttributes, entry.properties
13954
+ .filter(it => !this.isReferringForbiddenOrMissing(it, (iface) => this.shouldFilterOutInterface(iface))), entry.name, entry.inheritance, entry.extendedAttributes, entry.properties
12868
13955
  .filter(it => !this.shouldFilterOutProperty(entry.name, it.name)));
12869
13956
  }
12870
13957
  isReferringForbiddenOrMissing(node, predicate) {
@@ -12874,10 +13961,8 @@ class BaseInterfaceFilterTransformer extends Transformer {
12874
13961
  .map(innerTypeIfContainer)
12875
13962
  .filter(it => {
12876
13963
  if (isReferenceType(it)) {
12877
- if (this.typechecker.isReferenceTo(it, isInterface$1) && predicate(it.name)) {
12878
- return true;
12879
- }
12880
- if (this.typechecker.findRealDeclaration(it.name) === undefined) {
13964
+ const decl = this.typechecker.resolveReference(it);
13965
+ if (!decl || isInterface$1(decl) && predicate(decl)) {
12881
13966
  return true;
12882
13967
  }
12883
13968
  }
@@ -12905,8 +13990,10 @@ class OptionsFilterTransformer extends BaseInterfaceFilterTransformer {
12905
13990
  super(file);
12906
13991
  this.config = config;
12907
13992
  }
12908
- shouldFilterOutInterface(name) {
12909
- return this.config.ignore.isIgnoredInterface(name);
13993
+ shouldFilterOutInterface(entry) {
13994
+ var _a;
13995
+ const ns = (_a = nodeNamespace(entry)) !== null && _a !== void 0 ? _a : '';
13996
+ return this.config.ignore.isIgnoredInterface(entry.name, ns);
12910
13997
  }
12911
13998
  shouldFilterOutMethod(node, name) {
12912
13999
  return this.config.ignore.isIgnoredMethod(node, name);
@@ -12916,77 +14003,6 @@ class OptionsFilterTransformer extends BaseInterfaceFilterTransformer {
12916
14003
  }
12917
14004
  }
12918
14005
 
12919
- /*
12920
- * Copyright (c) 2024 Huawei Device Co., Ltd.
12921
- * Licensed under the Apache License, Version 2.0 (the "License");
12922
- * you may not use this file except in compliance with the License.
12923
- * You may obtain a copy of the License at
12924
- *
12925
- * http://www.apache.org/licenses/LICENSE-2.0
12926
- *
12927
- * Unless required by applicable law or agreed to in writing, software
12928
- * distributed under the License is distributed on an "AS IS" BASIS,
12929
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12930
- * See the License for the specific language governing permissions and
12931
- * limitations under the License.
12932
- */
12933
- class AddContextDeclarationTransformer extends Transformer {
12934
- constructor(file) {
12935
- super(file);
12936
- }
12937
- transformInterface(entry) {
12938
- return entry;
12939
- }
12940
- transformed() {
12941
- let file = createFile(this.file.entries
12942
- .concat(createInterface(Config.context, IDLInterfaceSubkind.Class, undefined, undefined, undefined, undefined, undefined, undefined, undefined, {
12943
- extendedAttributes: [{
12944
- name: Config.nodeNamespaceAttribute,
12945
- value: Config.irNamespace
12946
- }]
12947
- })), this.file.fileName, this.file.packageClause);
12948
- return linkParentBack(file);
12949
- }
12950
- }
12951
-
12952
- /*
12953
- * Copyright (c) 2024 Huawei Device Co., Ltd.
12954
- * Licensed under the Apache License, Version 2.0 (the "License");
12955
- * you may not use this file except in compliance with the License.
12956
- * You may obtain a copy of the License at
12957
- *
12958
- * http://www.apache.org/licenses/LICENSE-2.0
12959
- *
12960
- * Unless required by applicable law or agreed to in writing, software
12961
- * distributed under the License is distributed on an "AS IS" BASIS,
12962
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12963
- * See the License for the specific language governing permissions and
12964
- * limitations under the License.
12965
- */
12966
- class MultipleDeclarationFilterTransformer extends Transformer {
12967
- constructor(file) {
12968
- super(file);
12969
- this.seen = new Map();
12970
- // TODO: namespaces
12971
- linearizeNamespaceMembers(this.file.entries).forEach(it => {
12972
- var _a;
12973
- let name = baseNameString(it.name);
12974
- const oldValue = (_a = this.seen.get(name)) !== null && _a !== void 0 ? _a : 0;
12975
- this.seen.set(name, oldValue + 1);
12976
- });
12977
- }
12978
- transformInterface(entry) {
12979
- var _a;
12980
- const occurence = (_a = this.seen.get(baseNameString(entry.name))) !== null && _a !== void 0 ? _a : 0;
12981
- if (occurence > 1 && !isIrNamespace(entry)) {
12982
- console.log(`FILTERED (MULTIPLE) ${entry.name}`);
12983
- this.seen.set(baseNameString(entry.name), occurence - 1);
12984
- return undefined;
12985
- }
12986
- return entry;
12987
- }
12988
- }
12989
-
12990
14006
  /*
12991
14007
  * Copyright (c) 2024 Huawei Device Co., Ltd.
12992
14008
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13028,125 +14044,6 @@ class ParameterTransformer extends Transformer {
13028
14044
  }
13029
14045
  }
13030
14046
 
13031
- /*
13032
- * Copyright (c) 2024 Huawei Device Co., Ltd.
13033
- * Licensed under the Apache License, Version 2.0 (the "License");
13034
- * you may not use this file except in compliance with the License.
13035
- * You may obtain a copy of the License at
13036
- *
13037
- * http://www.apache.org/licenses/LICENSE-2.0
13038
- *
13039
- * Unless required by applicable law or agreed to in writing, software
13040
- * distributed under the License is distributed on an "AS IS" BASIS,
13041
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13042
- * See the License for the specific language governing permissions and
13043
- * limitations under the License.
13044
- */
13045
- class TwinMergeTransformer extends Transformer {
13046
- constructor(file) {
13047
- super(file);
13048
- const all = linearizeNamespaceMembers(file.entries).filter(isInterface$1);
13049
- this.twins = new Set();
13050
- all
13051
- .filter(it => this.hasPrefix(it.name))
13052
- .forEach(it => {
13053
- const twin = all.find(candidate => this.withPrefix(baseNameString(candidate.name)) === it.name);
13054
- if (twin === undefined)
13055
- return;
13056
- if (!isIrNamespace(twin))
13057
- return;
13058
- this.twins.add(twin.name);
13059
- });
13060
- }
13061
- hasTwin(name) {
13062
- name = baseNameString(name);
13063
- if (this.hasPrefix(name)) {
13064
- return this.twins.has(this.withoutPrefix(name));
13065
- }
13066
- return this.twins.has(name);
13067
- }
13068
- transformInterface(node) {
13069
- if (node.name === Config.astNodeCommonAncestor) { // TODO: is handwritten
13070
- return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)));
13071
- }
13072
- if (this.hasTwin(node.name) && this.hasPrefix(node.name)) {
13073
- return undefined;
13074
- }
13075
- if (this.hasTwin(node.name) || this.hasPrefix(node.name)) {
13076
- return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)), this.withoutPrefix(node.name), [createReferenceType(Config.defaultAncestor)]);
13077
- }
13078
- return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)));
13079
- }
13080
- transformMethod(node) {
13081
- return createUpdatedMethod(node, this.withoutPrefix(node.name), node.parameters.map(it => this.transformParameter(it)), this.transformType(node.returnType));
13082
- }
13083
- transformParameter(node) {
13084
- return createParameter(this.withoutPrefix(node.name), this.transformType(node.type), node.isOptional, node.isVariadic);
13085
- }
13086
- transformType(node) {
13087
- if (isContainerType(node)) {
13088
- if (isSequence(node)) {
13089
- return createSequence(this.transformType(innerType(node)));
13090
- }
13091
- }
13092
- if (isReferenceType(node)) {
13093
- return createReferenceType(this.withoutPrefix(node.name), node.typeArguments);
13094
- }
13095
- return node;
13096
- }
13097
- withoutPrefix(name) {
13098
- if (name.startsWith(Config.dataClassPrefix)) {
13099
- return name.slice(Config.dataClassPrefix.length);
13100
- }
13101
- return name;
13102
- }
13103
- withPrefix(name) {
13104
- return `${Config.dataClassPrefix}${name}`;
13105
- }
13106
- hasPrefix(name) {
13107
- return name.startsWith(Config.dataClassPrefix);
13108
- }
13109
- }
13110
-
13111
- /*
13112
- * Copyright (c) 2024 Huawei Device Co., Ltd.
13113
- * Licensed under the Apache License, Version 2.0 (the "License");
13114
- * you may not use this file except in compliance with the License.
13115
- * You may obtain a copy of the License at
13116
- *
13117
- * http://www.apache.org/licenses/LICENSE-2.0
13118
- *
13119
- * Unless required by applicable law or agreed to in writing, software
13120
- * distributed under the License is distributed on an "AS IS" BASIS,
13121
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13122
- * See the License for the specific language governing permissions and
13123
- * limitations under the License.
13124
- */
13125
- class AstNodeFilterTransformer extends BaseInterfaceFilterTransformer {
13126
- constructor(idl) {
13127
- super(idl, true);
13128
- }
13129
- shouldFilterOutInterface(name) {
13130
- if (this.typechecker.isHeir(name, Config.astNodeCommonAncestor))
13131
- return false;
13132
- if (this.typechecker.isHeir(name, Config.defaultAncestor))
13133
- return false;
13134
- // TODO: fix
13135
- if (name === "Program")
13136
- return false;
13137
- if (name === "ArkTsConfig")
13138
- return false;
13139
- console.log(`FILTERED (AST) ${name}`);
13140
- return true;
13141
- }
13142
- shouldFilterOutMethod(node, name) {
13143
- return false;
13144
- }
13145
- shouldFilterOutProperty(node, name) {
13146
- return false;
13147
- }
13148
- }
13149
-
13150
14047
  /*
13151
14048
  * Copyright (c) 2024 Huawei Device Co., Ltd.
13152
14049
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13165,7 +14062,7 @@ class NullabilityTransformer extends Transformer {
13165
14062
  constructor(file, config) {
13166
14063
  super(file);
13167
14064
  this.config = config;
13168
- this.typechecker = new Typechecker(this.file.entries);
14065
+ this.typechecker = new Typechecker(this.file);
13169
14066
  }
13170
14067
  transformInterface(node) {
13171
14068
  return createUpdatedInterface(node, node.methods
@@ -13189,7 +14086,7 @@ class NullabilityTransformer extends Transformer {
13189
14086
  // TODO: maybe heirs of defaultAncestors aren't nullable
13190
14087
  // TODO: handwritten
13191
14088
  if (isReferenceType(type)) {
13192
- if (this.typechecker.isPeer(type.name) || type.name === Config.astNodeCommonAncestor) {
14089
+ if (this.typechecker.isPeer(type) || type.name === Config.astNodeCommonAncestor) {
13193
14090
  return createOptionalType(type);
13194
14091
  }
13195
14092
  }
@@ -13232,7 +14129,7 @@ function remove(array, value) {
13232
14129
  class AttributeTransformer extends Transformer {
13233
14130
  constructor(file) {
13234
14131
  super(file);
13235
- this.convertor = new LibraryTypeConvertor(new Typechecker(this.file.entries));
14132
+ this.convertor = new LibraryTypeConvertor(new Typechecker(this.file));
13236
14133
  }
13237
14134
  convertToKey(type) {
13238
14135
  if (isOptionalType(type)) {
@@ -13428,10 +14325,10 @@ class DynamicEmitter {
13428
14325
  let idl = this.file;
13429
14326
  this.printFile(this.enumsPrinter, idl);
13430
14327
  idl = this.withLog(new OptionsFilterTransformer(this.config, idl));
13431
- idl = this.withLog(new AddContextDeclarationTransformer(idl));
13432
- idl = this.withLog(new TwinMergeTransformer(idl));
13433
- idl = this.withLog(new MultipleDeclarationFilterTransformer(idl));
13434
- idl = this.withLog(new AstNodeFilterTransformer(idl));
14328
+ //idl = this.withLog(new AddContextDeclarationTransformer(idl))
14329
+ //idl = this.withLog(new TwinMergeTransformer(idl))
14330
+ //idl = this.withLog(new MultipleDeclarationFilterTransformer(idl))
14331
+ //idl = this.withLog(new AstNodeFilterTransformer(idl))
13435
14332
  this.printPeers(idl);
13436
14333
  this.printInterop(idl);
13437
14334
  }
@@ -13514,14 +14411,24 @@ class DynamicEmitter {
13514
14411
  class IgnoreOptions {
13515
14412
  constructor(filePath) {
13516
14413
  var _a, _b;
13517
- this.full = [];
13518
14414
  this.partial = [];
14415
+ this.ignored = new Map();
13519
14416
  if (filePath === undefined) {
13520
14417
  return;
13521
14418
  }
13522
14419
  const ignore = lib.parse(fs__namespace$1.readFileSync(filePath).toString()).ignore;
13523
- this.full = (_a = ignore === null || ignore === void 0 ? void 0 : ignore.full) !== null && _a !== void 0 ? _a : [];
13524
- this.partial = (_b = ignore === null || ignore === void 0 ? void 0 : ignore.partial) !== null && _b !== void 0 ? _b : [];
14420
+ this.partial = (_a = ignore === null || ignore === void 0 ? void 0 : ignore.partial) !== null && _a !== void 0 ? _a : [];
14421
+ const full = (_b = ignore === null || ignore === void 0 ? void 0 : ignore.full) !== null && _b !== void 0 ? _b : [];
14422
+ full.forEach((fqName) => {
14423
+ const parts = fqName.split('.');
14424
+ const [ns, name] = parts.length === 1 ? ['', parts.at(0)] : parts;
14425
+ if (!this.ignored.has(ns)) {
14426
+ this.ignored.set(ns, new Map());
14427
+ }
14428
+ const last = name.at(-1);
14429
+ const key = last === '!' ? name.slice(0, -last.length) : name;
14430
+ this.ignored.get(ns).set(key, last !== '!');
14431
+ });
13525
14432
  }
13526
14433
  isIgnoredMethod(iface, method) {
13527
14434
  var _a;
@@ -13531,8 +14438,13 @@ class IgnoreOptions {
13531
14438
  var _a;
13532
14439
  return (_a = this.partial) === null || _a === void 0 ? void 0 : _a.some(it => { var _a; return it.interface === iface && ((_a = it.properties) === null || _a === void 0 ? void 0 : _a.includes(name)); });
13533
14440
  }
13534
- isIgnoredInterface(name) {
13535
- return this.full.includes(name);
14441
+ isIgnoredInterface(name, namespace = '') {
14442
+ var _a, _b;
14443
+ const ns = this.ignored.get(namespace);
14444
+ if (ns && ((_b = (_a = ns.get(name)) !== null && _a !== void 0 ? _a : ns.get('*')) !== null && _b !== void 0 ? _b : false)) {
14445
+ return true;
14446
+ }
14447
+ return false;
13536
14448
  }
13537
14449
  }
13538
14450
  // TODO: remove when interfaces fixed!