@idlizer/arktscgen 2.1.9-arktscgen-9 → 2.1.10-arktscgen-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/build/libarkts-copy/generator/options.json5 +199 -4
  2. package/build/libarkts-copy/native/meson.build +1 -0
  3. package/build/libarkts-copy/native/mingw.cross +13 -0
  4. package/build/libarkts-copy/native/src/bridges.cc +66 -229
  5. package/build/libarkts-copy/native/src/common.cc +37 -8
  6. package/build/libarkts-copy/native/src/generated/bridges.cc +2047 -766
  7. package/build/libarkts-copy/native/src/memoryTracker.cc +178 -0
  8. package/build/libarkts-copy/native/src/memoryTracker.h +52 -0
  9. package/build/libarkts-copy/package.json +11 -14
  10. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +41 -52
  11. package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +1 -1
  12. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +7 -6
  13. package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +5 -2
  14. package/build/libarkts-copy/src/arkts-api/index.ts +2 -1
  15. package/build/libarkts-copy/src/arkts-api/node-cache.ts +9 -9
  16. package/build/libarkts-copy/src/arkts-api/node-utilities/ArkTsConfig.ts +7 -6
  17. package/build/libarkts-copy/src/arkts-api/node-utilities/NumberLiteral.ts +3 -1
  18. package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +25 -6
  19. package/build/libarkts-copy/src/{wrapper-compat/arkts-api/peers/ImportPathManager.ts → arkts-api/node-utilities/OpaqueTypeNode.ts} +8 -17
  20. package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +11 -10
  21. package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +1 -1
  22. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +12 -7
  23. package/build/libarkts-copy/src/arkts-api/peers/Config.ts +6 -0
  24. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +3 -15
  25. package/build/libarkts-copy/src/{wrapper-compat/arkts-api/peers/AstNode.ts → arkts-api/peers/DiagnosticKind.ts} +6 -8
  26. package/build/libarkts-copy/src/arkts-api/static/global.ts +28 -1
  27. package/build/libarkts-copy/src/arkts-api/utilities/extensions.ts +64 -7
  28. package/build/libarkts-copy/src/{wrapper-compat/arkts-api → arkts-api}/utilities/performance.ts +122 -3
  29. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +8 -22
  30. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +95 -93
  31. package/build/libarkts-copy/src/arkts-api/visitor.ts +971 -364
  32. package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +6 -0
  33. package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +686 -185
  34. package/build/libarkts-copy/src/generated/factory.ts +2 -3
  35. package/build/libarkts-copy/src/generated/index.ts +3 -2
  36. package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +3 -3
  37. package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +3 -3
  38. package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +3 -3
  39. package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +17 -20
  40. package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +7 -9
  41. package/build/libarkts-copy/src/generated/peers/ArkTsConfig.ts +4 -1
  42. package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +6 -12
  43. package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +18 -21
  44. package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +5 -7
  45. package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +6 -8
  46. package/build/libarkts-copy/src/generated/peers/AstDumper.ts +3 -1
  47. package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +0 -1
  48. package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +0 -1
  49. package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +5 -7
  50. package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +5 -7
  51. package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +5 -7
  52. package/build/libarkts-copy/src/generated/peers/BindingProps.ts +0 -1
  53. package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +5 -7
  54. package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +5 -7
  55. package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +5 -7
  56. package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +7 -9
  57. package/build/libarkts-copy/src/generated/peers/CallExpression.ts +11 -8
  58. package/build/libarkts-copy/src/generated/peers/CatchClause.ts +6 -8
  59. package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +5 -7
  60. package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +5 -7
  61. package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +6 -30
  62. package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +35 -28
  63. package/build/libarkts-copy/src/generated/peers/ClassElement.ts +5 -32
  64. package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +6 -8
  65. package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +25 -20
  66. package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +6 -8
  67. package/build/libarkts-copy/src/generated/peers/CodeGen.ts +0 -1
  68. package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +5 -7
  69. package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +7 -9
  70. package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +5 -7
  71. package/build/libarkts-copy/src/generated/peers/Declaration.ts +0 -1
  72. package/build/libarkts-copy/src/generated/peers/Decorator.ts +5 -7
  73. package/build/libarkts-copy/src/generated/peers/DiagnosticInfo.ts +0 -1
  74. package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +5 -7
  75. package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +5 -7
  76. package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +0 -1
  77. package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +5 -7
  78. package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +14 -9
  79. package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +5 -7
  80. package/build/libarkts-copy/src/generated/peers/ETSIntrinsicNode.ts +7 -9
  81. package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +5 -7
  82. package/build/libarkts-copy/src/generated/peers/ETSModule.ts +17 -20
  83. package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +5 -7
  84. package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +6 -8
  85. package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +6 -8
  86. package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +5 -7
  87. package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +5 -7
  88. package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +20 -23
  89. package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +5 -7
  90. package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +4 -6
  91. package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +5 -7
  92. package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +5 -7
  93. package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +9 -11
  94. package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +7 -9
  95. package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +9 -11
  96. package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +5 -7
  97. package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +5 -7
  98. package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +6 -8
  99. package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +6 -8
  100. package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +0 -1
  101. package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +7 -9
  102. package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +5 -7
  103. package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +11 -13
  104. package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +7 -9
  105. package/build/libarkts-copy/src/generated/peers/Expression.ts +7 -3
  106. package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +5 -7
  107. package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +5 -7
  108. package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +5 -7
  109. package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +4 -6
  110. package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +16 -23
  111. package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +8 -10
  112. package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +5 -2
  113. package/build/libarkts-copy/src/generated/peers/IRNode.ts +0 -1
  114. package/build/libarkts-copy/src/generated/peers/Identifier.ts +7 -18
  115. package/build/libarkts-copy/src/generated/peers/IfStatement.ts +5 -7
  116. package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +6 -8
  117. package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +6 -8
  118. package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +5 -7
  119. package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +6 -8
  120. package/build/libarkts-copy/src/generated/peers/ImportSource.ts +0 -1
  121. package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +7 -9
  122. package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +0 -1
  123. package/build/libarkts-copy/src/generated/peers/LabelPair.ts +0 -1
  124. package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +6 -8
  125. package/build/libarkts-copy/src/generated/peers/Literal.ts +3 -3
  126. package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +3 -3
  127. package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +3 -3
  128. package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +5 -11
  129. package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +5 -7
  130. package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +10 -12
  131. package/build/libarkts-copy/src/generated/peers/NamedType.ts +7 -9
  132. package/build/libarkts-copy/src/generated/peers/NewExpression.ts +5 -7
  133. package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +5 -7
  134. package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +10 -10
  135. package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +0 -1
  136. package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +5 -11
  137. package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +5 -7
  138. package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +5 -7
  139. package/build/libarkts-copy/src/generated/peers/OverloadDeclaration.ts +5 -7
  140. package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +5 -7
  141. package/build/libarkts-copy/src/generated/peers/Program.ts +9 -2
  142. package/build/libarkts-copy/src/generated/peers/Property.ts +6 -8
  143. package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +5 -7
  144. package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +6 -8
  145. package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +0 -1
  146. package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +27 -23
  147. package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +0 -1
  148. package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +5 -7
  149. package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +0 -1
  150. package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +8 -1
  151. package/build/libarkts-copy/src/generated/peers/SourceRange.ts +0 -1
  152. package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +5 -11
  153. package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +3 -1
  154. package/build/libarkts-copy/src/generated/peers/Statement.ts +3 -3
  155. package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +6 -8
  156. package/build/libarkts-copy/src/generated/peers/SuggestionInfo.ts +0 -1
  157. package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +5 -7
  158. package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +5 -7
  159. package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +6 -8
  160. package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +5 -7
  161. package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +5 -7
  162. package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +5 -7
  163. package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +5 -7
  164. package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +5 -7
  165. package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +7 -9
  166. package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +5 -7
  167. package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +6 -8
  168. package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +8 -32
  169. package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +6 -8
  170. package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +5 -7
  171. package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +6 -8
  172. package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +6 -8
  173. package/build/libarkts-copy/src/generated/peers/TSImportType.ts +6 -8
  174. package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +5 -7
  175. package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +5 -7
  176. package/build/libarkts-copy/src/generated/peers/TSInferType.ts +6 -8
  177. package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +5 -7
  178. package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +19 -44
  179. package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +5 -7
  180. package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +5 -7
  181. package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +5 -7
  182. package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +6 -8
  183. package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +6 -8
  184. package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +5 -7
  185. package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +5 -7
  186. package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +5 -7
  187. package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +5 -7
  188. package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +5 -7
  189. package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +5 -7
  190. package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +5 -7
  191. package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +5 -7
  192. package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +5 -7
  193. package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +5 -7
  194. package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +5 -7
  195. package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +7 -9
  196. package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +6 -8
  197. package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +5 -7
  198. package/build/libarkts-copy/src/generated/peers/TSThisType.ts +5 -7
  199. package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +5 -7
  200. package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +32 -47
  201. package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +5 -7
  202. package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +5 -7
  203. package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +5 -7
  204. package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +17 -20
  205. package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +6 -8
  206. package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +5 -7
  207. package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +5 -7
  208. package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +5 -7
  209. package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +7 -9
  210. package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +5 -7
  211. package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +5 -7
  212. package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +5 -7
  213. package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +5 -7
  214. package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +7 -9
  215. package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +6 -8
  216. package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +6 -8
  217. package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +5 -7
  218. package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +5 -7
  219. package/build/libarkts-copy/src/generated/peers/TryStatement.ts +7 -9
  220. package/build/libarkts-copy/src/generated/peers/TypeNode.ts +13 -14
  221. package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +3 -3
  222. package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +3 -3
  223. package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +5 -7
  224. package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +5 -7
  225. package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +5 -7
  226. package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +5 -7
  227. package/build/libarkts-copy/src/generated/peers/VReg.ts +0 -1
  228. package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +3 -1
  229. package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +16 -26
  230. package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +6 -8
  231. package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +0 -1
  232. package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +0 -1
  233. package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +5 -7
  234. package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +5 -7
  235. package/build/libarkts-copy/src/index.ts +4 -1
  236. package/build/libarkts-copy/src/plugin-utils.ts +8 -11
  237. package/build/libarkts-copy/src/reexport-for-generated.ts +1 -12
  238. package/build/libarkts-copy/src/tracer.ts +172 -0
  239. package/build/libarkts-copy/src/utils.ts +3 -0
  240. package/lib/index.js +1403 -544
  241. package/package.json +4 -3
  242. package/templates/factory.ts +0 -1
  243. package/templates/peer.ts +0 -1
  244. package/build/libarkts-copy/src/arkts-api/ChainExpressionFilter.ts +0 -79
  245. package/build/libarkts-copy/src/arkts-api/peers/SourcePosition.ts +0 -38
  246. package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +0 -45
  247. package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +0 -45
  248. package/build/libarkts-copy/src/wrapper-compat/README.md +0 -20
  249. package/build/libarkts-copy/src/wrapper-compat/arkts-api/class-by-peer.ts +0 -46
  250. package/build/libarkts-copy/src/wrapper-compat/arkts-api/factory/nodeFactory.ts +0 -454
  251. package/build/libarkts-copy/src/wrapper-compat/arkts-api/factory/nodeTests.ts +0 -99
  252. package/build/libarkts-copy/src/wrapper-compat/arkts-api/index.ts +0 -88
  253. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ArrayExpression.ts +0 -38
  254. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ArrowFunctionExpression.ts +0 -35
  255. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/AssignmentExpression.ts +0 -38
  256. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/BlockStatement.ts +0 -27
  257. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/CallExpression.ts +0 -45
  258. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassDeclaration.ts +0 -27
  259. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassDefinition.ts +0 -73
  260. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassProperty.ts +0 -51
  261. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSFunctionType.ts +0 -42
  262. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSImportDeclaration.ts +0 -39
  263. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSParameterExpression.ts +0 -43
  264. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ExpressionStatement.ts +0 -28
  265. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/FunctionDeclaration.ts +0 -37
  266. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/FunctionExpression.ts +0 -28
  267. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/IfStatement.ts +0 -37
  268. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/MemberExpression.ts +0 -42
  269. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/MethodDefinition.ts +0 -46
  270. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/NumberLiteral.ts +0 -30
  271. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ObjectExpression.ts +0 -37
  272. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/Property.ts +0 -27
  273. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ScriptFunction.ts +0 -46
  274. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/StructDeclaration.ts +0 -28
  275. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSInterfaceDeclaration.ts +0 -47
  276. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +0 -40
  277. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSTypeParameter.ts +0 -36
  278. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TryStatement.ts +0 -41
  279. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/VariableDeclaration.ts +0 -42
  280. package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/VariableDeclarator.ts +0 -39
  281. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Diagnostic.ts +0 -38
  282. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/DiagnosticInfo.ts +0 -34
  283. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/DiagnosticKind.ts +0 -33
  284. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Program.ts +0 -105
  285. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SourcePosition.ts +0 -38
  286. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SourceRange.ts +0 -38
  287. package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SuggestionInfo.ts +0 -34
  288. package/build/libarkts-copy/src/wrapper-compat/arkts-api/static/global.ts +0 -16
  289. package/build/libarkts-copy/src/wrapper-compat/arkts-api/to-be-generated/MemberExpression.ts +0 -108
  290. package/build/libarkts-copy/src/wrapper-compat/arkts-api/types.ts +0 -889
  291. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/nativePtrDecoder.ts +0 -69
  292. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/private.ts +0 -198
  293. package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/public.ts +0 -327
  294. package/build/libarkts-copy/src/wrapper-compat/arkts-api/visitor.ts +0 -421
  295. package/build/libarkts-copy/src/wrapper-compat/index.ts +0 -20
  296. package/templates/node-map.ts +0 -35
package/lib/index.js CHANGED
@@ -3814,11 +3814,13 @@ 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";
@@ -3836,14 +3838,18 @@ var IDLExtendedAttributes;
3836
3838
  IDLExtendedAttributes["OriginalGenericName"] = "OriginalGenericName";
3837
3839
  IDLExtendedAttributes["Predefined"] = "Predefined";
3838
3840
  IDLExtendedAttributes["Protected"] = "Protected";
3841
+ IDLExtendedAttributes["Abstract"] = "Abstract";
3839
3842
  IDLExtendedAttributes["Synthetic"] = "Synthetic";
3840
3843
  IDLExtendedAttributes["Throws"] = "Throws";
3841
3844
  IDLExtendedAttributes["TraceKey"] = "TraceKey";
3845
+ IDLExtendedAttributes["TypeAnnotations"] = "TypeAnnotations";
3842
3846
  IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
3843
3847
  IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
3844
3848
  IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
3845
3849
  IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
3846
3850
  IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
3851
+ IDLExtendedAttributes["OverloadAlias"] = "OverloadAlias";
3852
+ IDLExtendedAttributes["OverloadPriority"] = "OverloadPriority";
3847
3853
  })(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
3848
3854
  var IDLAccessorAttribute;
3849
3855
  (function (IDLAccessorAttribute) {
@@ -3863,18 +3869,18 @@ function forEachChild(node, cbEnter, cbLeave) {
3863
3869
  const cleanup = cbEnter(node);
3864
3870
  switch (node.kind) {
3865
3871
  case IDLKind.File:
3866
- node.entries.forEach((value) => forEachChild(value, cbEnter));
3872
+ node.entries.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3867
3873
  break;
3868
3874
  case IDLKind.Namespace:
3869
- node.members.forEach((value) => forEachChild(value, cbEnter));
3875
+ node.members.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3870
3876
  break;
3871
3877
  case IDLKind.Interface: {
3872
3878
  let concrete = node;
3873
- concrete.inheritance.forEach((value) => forEachChild(value, cbEnter));
3874
- concrete.constructors.forEach((value) => forEachChild(value, cbEnter));
3875
- concrete.properties.forEach((value) => forEachChild(value, cbEnter));
3876
- concrete.methods.forEach((value) => forEachChild(value, cbEnter));
3877
- concrete.callables.forEach((value) => forEachChild(value, cbEnter));
3879
+ concrete.inheritance.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3880
+ concrete.constructors.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3881
+ concrete.properties.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3882
+ concrete.methods.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3883
+ concrete.callables.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3878
3884
  break;
3879
3885
  }
3880
3886
  case IDLKind.Method:
@@ -3882,53 +3888,53 @@ function forEachChild(node, cbEnter, cbLeave) {
3882
3888
  case IDLKind.Callback:
3883
3889
  case IDLKind.Constructor: {
3884
3890
  let concrete = node;
3885
- (_a = concrete.parameters) === null || _a === void 0 ? void 0 : _a.forEach((value) => forEachChild(value, cbEnter));
3891
+ (_a = concrete.parameters) === null || _a === void 0 ? void 0 : _a.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3886
3892
  if (concrete.returnType)
3887
- forEachChild(concrete.returnType, cbEnter);
3893
+ forEachChild(concrete.returnType, cbEnter, cbLeave);
3888
3894
  break;
3889
3895
  }
3890
3896
  case IDLKind.UnionType: {
3891
3897
  let concrete = node;
3892
- (_b = concrete.types) === null || _b === void 0 ? void 0 : _b.forEach((value) => forEachChild(value, cbEnter));
3898
+ (_b = concrete.types) === null || _b === void 0 ? void 0 : _b.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3893
3899
  break;
3894
3900
  }
3895
3901
  case IDLKind.OptionalType: {
3896
3902
  let concrete = node;
3897
- forEachChild(concrete.type, cbEnter);
3903
+ forEachChild(concrete.type, cbEnter, cbLeave);
3898
3904
  break;
3899
3905
  }
3900
3906
  case IDLKind.Const: {
3901
- forEachChild(node.type, cbEnter);
3907
+ forEachChild(node.type, cbEnter, cbLeave);
3902
3908
  break;
3903
3909
  }
3904
3910
  case IDLKind.Enum: {
3905
- node.elements.forEach((value) => forEachChild(value, cbEnter));
3911
+ node.elements.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3906
3912
  break;
3907
3913
  }
3908
3914
  case IDLKind.Property: {
3909
- forEachChild(node.type, cbEnter);
3915
+ forEachChild(node.type, cbEnter, cbLeave);
3910
3916
  break;
3911
3917
  }
3912
3918
  case IDLKind.Parameter: {
3913
3919
  const concrete = node;
3914
3920
  if (concrete.type)
3915
- forEachChild(concrete.type, cbEnter);
3921
+ forEachChild(concrete.type, cbEnter, cbLeave);
3916
3922
  break;
3917
3923
  }
3918
3924
  case IDLKind.Typedef: {
3919
- forEachChild(node.type, cbEnter);
3925
+ forEachChild(node.type, cbEnter, cbLeave);
3920
3926
  break;
3921
3927
  }
3922
3928
  case IDLKind.ContainerType: {
3923
- node.elementType.forEach((value) => forEachChild(value, cbEnter));
3929
+ node.elementType.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3924
3930
  break;
3925
3931
  }
3926
3932
  case IDLKind.UnspecifiedGenericType: {
3927
- node.typeArguments.forEach((value) => forEachChild(value, cbEnter));
3933
+ node.typeArguments.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3928
3934
  break;
3929
3935
  }
3930
3936
  case IDLKind.ReferenceType: {
3931
- (_c = node.typeArguments) === null || _c === void 0 ? void 0 : _c.forEach((value) => forEachChild(value, cbEnter));
3937
+ (_c = node.typeArguments) === null || _c === void 0 ? void 0 : _c.forEach((value) => forEachChild(value, cbEnter, cbLeave));
3932
3938
  break;
3933
3939
  }
3934
3940
  case IDLKind.TypeParameterType:
@@ -3941,6 +3947,7 @@ function forEachChild(node, cbEnter, cbLeave) {
3941
3947
  throw new Error(`Unhandled ${node.kind}`);
3942
3948
  }
3943
3949
  }
3950
+ cbLeave === null || cbLeave === void 0 ? void 0 : cbLeave(node);
3944
3951
  cleanup === null || cleanup === void 0 ? void 0 : cleanup();
3945
3952
  }
3946
3953
  /** Updates tree in place! */
@@ -4093,9 +4100,15 @@ function isInterface$1(node) {
4093
4100
  function isImport(type) {
4094
4101
  return type.kind == IDLKind.Import;
4095
4102
  }
4103
+ function isCallable(node) {
4104
+ return node.kind === IDLKind.Callable;
4105
+ }
4096
4106
  function isMethod(node) {
4097
4107
  return node.kind === IDLKind.Method;
4098
4108
  }
4109
+ function isConstructor$1(node) {
4110
+ return node.kind === IDLKind.Constructor;
4111
+ }
4099
4112
  function isProperty(node) {
4100
4113
  return node.kind === IDLKind.Property;
4101
4114
  }
@@ -5398,7 +5411,9 @@ class LanguageWriter {
5398
5411
  fs__namespace.writeFileSync(file, this.getOutput().join("\n"));
5399
5412
  }
5400
5413
  writeLines(lines) {
5401
- lines.split("\n").forEach(it => this.print(it));
5414
+ if (typeof lines === 'string')
5415
+ lines = lines.split("\n");
5416
+ lines.forEach(it => this.print(it));
5402
5417
  }
5403
5418
  writeGetterImplementation(method, op) {
5404
5419
  var _a;
@@ -6050,7 +6065,13 @@ class DiagnosticException extends Error {
6050
6065
  /**
6051
6066
  * Template for registering different kinds of messages
6052
6067
  */
6053
- class DiagnosticMessageEntry {
6068
+ class DiagnosticMessageGroup {
6069
+ /**
6070
+ * Generated diagnostic messages belonging to _any_ group
6071
+ */
6072
+ static get allGroupsEntries() {
6073
+ return DiagnosticMessageGroup.collectedResults.entries;
6074
+ }
6054
6075
  constructor(severity, code, codeDescription, mainMessageTemplate, additionalMessageTemplate) {
6055
6076
  this.severity = severity;
6056
6077
  this.code = code;
@@ -6058,10 +6079,10 @@ class DiagnosticMessageEntry {
6058
6079
  // No cases of codeUri for now, can be embedded into codeDescription later if needed
6059
6080
  this.mainMessageTemplate = mainMessageTemplate !== null && mainMessageTemplate !== void 0 ? mainMessageTemplate : codeDescription;
6060
6081
  this.additionalMessageTemplate = additionalMessageTemplate !== null && additionalMessageTemplate !== void 0 ? additionalMessageTemplate : "See";
6061
- if (DiagnosticMessageEntry.diagnosticMessageByCode.has(code)) {
6082
+ if (DiagnosticMessageGroup.diagnosticMessageByCode.has(code)) {
6062
6083
  throw new Error(`Duplicate message code ${code}`);
6063
6084
  }
6064
- DiagnosticMessageEntry.diagnosticMessageByCode.set(code, this);
6085
+ DiagnosticMessageGroup.diagnosticMessageByCode.set(code, this);
6065
6086
  }
6066
6087
  generateDiagnosticMessage(locations, mainMessage, additionalMessage) {
6067
6088
  let msg = {
@@ -6079,24 +6100,927 @@ class DiagnosticMessageEntry {
6079
6100
  return msg;
6080
6101
  }
6081
6102
  reportDiagnosticMessage(locations, mainMessage, additionalMessage) {
6082
- DiagnosticMessageEntry.collectedResults.push(this.generateDiagnosticMessage(locations, mainMessage, additionalMessage));
6103
+ const msg = this.generateDiagnosticMessage(locations, mainMessage, additionalMessage);
6104
+ DiagnosticMessageGroup.collectedResults.push(msg);
6105
+ return msg;
6083
6106
  }
6084
6107
  throwDiagnosticMessage(locations, mainMessage, additionalMessage) {
6085
- throw new DiagnosticException(this.generateDiagnosticMessage(locations, mainMessage, additionalMessage));
6086
- }
6087
- static reportCatched(diagnosticMessage) {
6088
- this.collectedResults.push(diagnosticMessage);
6108
+ throw new DiagnosticException(this.reportDiagnosticMessage(locations, mainMessage, additionalMessage));
6089
6109
  }
6090
6110
  }
6091
6111
  /**
6092
6112
  * Index for DiagnosticMessageEntry by code
6093
6113
  */
6094
- DiagnosticMessageEntry.diagnosticMessageByCode = new Map();
6095
- DiagnosticMessageEntry.collectedResults = new DiagnosticResults();
6096
- const UnknownErrorMessage = new DiagnosticMessageEntry("fatal", 0, "Unknown error");
6097
- const LoadingErrorMessage = new DiagnosticMessageEntry("fatal", 100, "Loading error");
6098
- const ParsingErrorMessage = new DiagnosticMessageEntry("fatal", 101, "Parsing error");
6099
- new DiagnosticMessageEntry("fatal", 102, "Processing error");
6114
+ DiagnosticMessageGroup.diagnosticMessageByCode = new Map();
6115
+ /**
6116
+ * Diagnostic results collected up until now
6117
+ */
6118
+ DiagnosticMessageGroup.collectedResults = new DiagnosticResults();
6119
+ const InternalFatal = new DiagnosticMessageGroup("fatal", "InternalFatal", "Unknown error");
6120
+ const LoadingFatal = new DiagnosticMessageGroup("fatal", "LoadingFatal", "Loading error");
6121
+ const ParsingFatal = new DiagnosticMessageGroup("fatal", "ParsingFatal", "Parsing error");
6122
+ new DiagnosticMessageGroup("fatal", "ProcessingFatal", "Processing error");
6123
+
6124
+ /*
6125
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
6126
+ * Licensed under the Apache License, Version 2.0 (the "License");
6127
+ * you may not use this file except in compliance with the License.
6128
+ * You may obtain a copy of the License at
6129
+ *
6130
+ * http://www.apache.org/licenses/LICENSE-2.0
6131
+ *
6132
+ * Unless required by applicable law or agreed to in writing, software
6133
+ * distributed under the License is distributed on an "AS IS" BASIS,
6134
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6135
+ * See the License for the specific language governing permissions and
6136
+ * limitations under the License.
6137
+ */
6138
+ const DuplicateModifier = new DiagnosticMessageGroup("error", "DuplicateModifier", "Duplicate modifier", "Duplicate of");
6139
+ const NotApplicableModifier = new DiagnosticMessageGroup("error", "NotApplicableModifier", "Not applicable modifier");
6140
+ const DuplicatePackageDeclaration = new DiagnosticMessageGroup("error", "DuplicatePackageDeclaration", "Duplicate package declaration", "Duplicate of");
6141
+ const DuplicateExtendedAttribute = new DiagnosticMessageGroup("error", "DuplicateExtendedAttribute", "Duplicate extended attribute", "Duplicate of");
6142
+ const DuplicateArgumentName = new DiagnosticMessageGroup("error", "DuplicateArgumentName", "Duplicate argument name", "Duplicate of");
6143
+ const IncorrectLiteral = new DiagnosticMessageGroup("error", "IncorrectLiteral", "Incorrect literal");
6144
+ const IncorrectIdentifier = new DiagnosticMessageGroup("error", "IncorrectIdentifier", "Incorrect identifier");
6145
+ const UnexpectedToken = new DiagnosticMessageGroup("error", "UnexpectedToken", "Unexpected token");
6146
+ const UnexpectedEndOfFile = new DiagnosticMessageGroup("fatal", "UnexpectedEndOfFile", "Unexpected end of file");
6147
+ const UnsupportedSyntax = new DiagnosticMessageGroup("error", "UnsupportedSyntax", "Unsupported syntax");
6148
+ const WrongDeclarationPlacement = new DiagnosticMessageGroup("error", "WrongDeclarationPlacement", "Wrong declaration placement");
6149
+ const ExpectedPrimitiveType = new DiagnosticMessageGroup("error", "ExpectedPrimitiveType", "Expected primitive type");
6150
+ const ExpectedReferenceType = new DiagnosticMessageGroup("error", "ExpectedReferenceType", "Expected reference type");
6151
+ const ExpectedGenericArguments = new DiagnosticMessageGroup("error", "ExpectedGenericArguments", "Expected generic arguments");
6152
+ const UnexpectedGenericArguments = new DiagnosticMessageGroup("error", "UnexpectedGenericArguments", "Unexpected generic arguments");
6153
+ class FatalParserException extends Error {
6154
+ constructor(diagnosticMessages) {
6155
+ super();
6156
+ this.diagnosticMessages = diagnosticMessages;
6157
+ }
6158
+ }
6159
+ var TokenKind;
6160
+ (function (TokenKind) {
6161
+ TokenKind[TokenKind["Words"] = 0] = "Words";
6162
+ TokenKind[TokenKind["Literal"] = 1] = "Literal";
6163
+ TokenKind[TokenKind["Symbol"] = 2] = "Symbol";
6164
+ TokenKind[TokenKind["Comment"] = 3] = "Comment";
6165
+ TokenKind[TokenKind["Whitespace"] = 4] = "Whitespace";
6166
+ TokenKind[TokenKind["End"] = 5] = "End";
6167
+ })(TokenKind || (TokenKind = {}));
6168
+ const supportedDeclarations = new Set(["attribute", "callback", "const", "constructor", "dictionary",
6169
+ "enum", "import", "interface", "namespace", "package", "typedef", "version"]);
6170
+ const unsupportedDeclarations = new Set(["deleter", "getter", "includes", "inherit", "iterable", "maplike",
6171
+ "mixin", "partial", "required", "setlike", "setter", "stringifier", "unrestricted"]);
6172
+ const interfaceContent = new Set([IDLKind.Constructor, IDLKind.Const, IDLKind.Property, IDLKind.Method, IDLKind.Callable]);
6173
+ const globalContent = new Set([IDLKind.Namespace, IDLKind.Interface, IDLKind.Enum, IDLKind.Method, IDLKind.Typedef, IDLKind.Callback, IDLKind.Import, IDLKind.Version, IDLKind.Const]);
6174
+ const havingBlocks = new Set([IDLKind.Namespace, IDLKind.Interface, IDLKind.Enum]);
6175
+ const modifierTokens = new Set(["static", "readonly", "async"]);
6176
+ class Parser {
6177
+ constructor(fileName, content) {
6178
+ var _a, _b;
6179
+ this._curOffset = 0;
6180
+ this._curLine = 0;
6181
+ // TypeParameters support
6182
+ this._generics = [];
6183
+ // TypeArguments parsing support
6184
+ this._enableInLiteralParsing = false;
6185
+ // symTokens = ["(", ")", "[", "]", "{", "}", ",", "...", ":", ";", "<", "=", ">", "?"]
6186
+ this._reDecimal = /-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y;
6187
+ this._reInteger = /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y;
6188
+ this._reString = /"[^"]*"/y;
6189
+ // -something is handled for -Infinity literal parsing, but rejected for identifiers later
6190
+ this._reWords = /[-]?[_$A-Za-z][_$0-9A-Za-z]*([.][_$A-Za-z][_$0-9A-Za-z]*)*/y;
6191
+ this._reSymbol = /\.\.\.|[()[\]{},:;<=>?]/y;
6192
+ this._reWhitespace = /[\t\n\r ]+/y;
6193
+ this._reComment = /\/\/.*|\/\*[\s\S]*?\*\//y;
6194
+ // Note no sticky behavior.
6195
+ this._reIsDocComment = /\/\/\/.*|\/\*\*[\s\S]*?\*\//;
6196
+ this.currentModifiers = {};
6197
+ this.fileName = fileName;
6198
+ if (undefined === content) {
6199
+ try {
6200
+ content = fs__namespace.readFileSync(fileName).toString();
6201
+ }
6202
+ catch (e) {
6203
+ content = "";
6204
+ throw new FatalParserException([LoadingFatal.reportDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "")]);
6205
+ }
6206
+ }
6207
+ this.content = content;
6208
+ const lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
6209
+ this.offsets = prepareOffsets$1(lines);
6210
+ this.lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
6211
+ }
6212
+ parseIDL() {
6213
+ var _a;
6214
+ const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
6215
+ try {
6216
+ this._lexerNext();
6217
+ this._prevToken = this._curToken;
6218
+ let file = this.parseFile();
6219
+ file.text = this.content;
6220
+ if (DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
6221
+ // Empty for now, messages will be added in following `catch`.
6222
+ throw new FatalParserException();
6223
+ }
6224
+ return file;
6225
+ }
6226
+ catch (e) {
6227
+ if (!(e instanceof DiagnosticException) && !(e instanceof FatalParserException)) {
6228
+ InternalFatal.reportDiagnosticMessage([{ documentPath: this.fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "");
6229
+ }
6230
+ throw new FatalParserException(DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount));
6231
+ }
6232
+ }
6233
+ _match(re, kind) {
6234
+ re.lastIndex = this._curOffset;
6235
+ const res = re.exec(this.content);
6236
+ if (!res) {
6237
+ return undefined;
6238
+ }
6239
+ const value = res[0];
6240
+ const startLine = this._curLine + 1;
6241
+ const startCharacter = this._curOffset - this.offsets[this._curLine] + 1;
6242
+ this._curOffset = re.lastIndex;
6243
+ this._curLine += (value.match(/\n/g) || []).length;
6244
+ const endLine = this._curLine + 1;
6245
+ const endCharacter = this._curOffset - this.offsets[this._curLine];
6246
+ const location = { documentPath: this.fileName, lines: this.lines, range: { start: { line: startLine, character: startCharacter }, end: { line: endLine, character: endCharacter } } };
6247
+ this._curToken = { kind, value, location };
6248
+ return this._curToken;
6249
+ }
6250
+ _matchComment() {
6251
+ const token = this._match(this._reComment, TokenKind.Comment);
6252
+ // At any parsing moment `precedingComment` represents possible comment token just before`curToken`.
6253
+ // It can be narrowed by `_reIsDocComment` if needed.
6254
+ if (token) {
6255
+ this.precedingComment = token;
6256
+ }
6257
+ return token;
6258
+ }
6259
+ _lexerNext() {
6260
+ var _a, _b, _c, _d;
6261
+ this._prevToken = this._curToken;
6262
+ this._match(this._reWhitespace, TokenKind.Whitespace);
6263
+ this.precedingComment = undefined;
6264
+ while (this._matchComment()) {
6265
+ this._match(this._reWhitespace, TokenKind.Whitespace);
6266
+ }
6267
+ if (this._curOffset == this.content.length) {
6268
+ const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6269
+ this._curToken = { kind: TokenKind.End, value: "", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6270
+ return;
6271
+ }
6272
+ if (this._enableInLiteralParsing && this.content[this._curOffset] == "\"") {
6273
+ // TypeArguments parsing support
6274
+ const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6275
+ this._curToken = { kind: TokenKind.Symbol, value: "\"", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6276
+ this._curOffset += 1;
6277
+ return;
6278
+ }
6279
+ 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));
6280
+ if (!token) {
6281
+ const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6282
+ ParsingFatal.throwDiagnosticMessage([{ documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } }], "Unrecognized symbols");
6283
+ }
6284
+ // Uncomment in case of parser debugging
6285
+ // if (token) {
6286
+ // const visTok = {...token, location: {...token.location, lines: undefined, documentPath: undefined}}
6287
+ // console.log(`Token: ${JSON.stringify(visTok)}`)
6288
+ // }
6289
+ }
6290
+ get curToken() {
6291
+ return this._curToken;
6292
+ }
6293
+ get curKind() {
6294
+ return this._curToken.kind;
6295
+ }
6296
+ get curValue() {
6297
+ return this._curToken.value;
6298
+ }
6299
+ get curLocation() {
6300
+ return this.curToken.location;
6301
+ }
6302
+ see(tok) {
6303
+ return this.curValue == tok;
6304
+ }
6305
+ seeAndSkip(tok) {
6306
+ if (this.curValue == tok) {
6307
+ this._lexerNext();
6308
+ return true;
6309
+ }
6310
+ return false;
6311
+ }
6312
+ seeEof() {
6313
+ return this.curToken.kind == TokenKind.End;
6314
+ }
6315
+ skip(tok) {
6316
+ if (this.curValue != tok) {
6317
+ if (this.curKind == TokenKind.End) {
6318
+ UnexpectedEndOfFile.throwDiagnosticMessage([this.curLocation], `Unexpected end of file, expected "${tok}"`);
6319
+ }
6320
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], `Unexpected token, expected "${tok}"`);
6321
+ }
6322
+ this._lexerNext();
6323
+ }
6324
+ skipToAfter(tok) {
6325
+ while (!this.see(tok) && !this.seeEof()) {
6326
+ this._lexerNext();
6327
+ }
6328
+ if (!this.seeEof()) {
6329
+ this._lexerNext();
6330
+ }
6331
+ }
6332
+ trackLocation() {
6333
+ const start = this.curLocation;
6334
+ return () => {
6335
+ const end = this._prevToken.location;
6336
+ return {
6337
+ documentPath: this.fileName,
6338
+ range: { start: start.range.start, end: end.range.end },
6339
+ lines: this.lines
6340
+ };
6341
+ };
6342
+ }
6343
+ consumeCurrentExtended() {
6344
+ const ext = this._internalCurrentExtended;
6345
+ this._internalCurrentExtended = undefined;
6346
+ return ext;
6347
+ }
6348
+ assertPossibleModifiers(...mods) {
6349
+ for (const k of Object.keys(this.currentModifiers)) {
6350
+ if (!mods.includes(k)) {
6351
+ NotApplicableModifier.reportDiagnosticMessage([this.currentModifiers[k].location]);
6352
+ }
6353
+ }
6354
+ }
6355
+ parseSingleIdentifier() {
6356
+ const token = this.parseFullIdentifier();
6357
+ if (token.value.includes(".")) {
6358
+ IncorrectIdentifier.throwDiagnosticMessage([this.curLocation]);
6359
+ }
6360
+ return token;
6361
+ }
6362
+ parseFullIdentifier() {
6363
+ if (this.curKind != TokenKind.Words || literalTypes.has(this.curValue) && this.curValue != "undefined") {
6364
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected identifier");
6365
+ }
6366
+ if (this.curValue.startsWith("-")) {
6367
+ // Valid for identifiers in WebIDL, but not in Idlize
6368
+ IncorrectIdentifier.throwDiagnosticMessage([this.curLocation]);
6369
+ }
6370
+ const token = this.curToken;
6371
+ this._lexerNext();
6372
+ return token;
6373
+ }
6374
+ parseFullIdentifierOrLiteral() {
6375
+ if (this.curKind != TokenKind.Words && this.curKind != TokenKind.Literal) {
6376
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected identifier or literal");
6377
+ }
6378
+ const token = this.curToken;
6379
+ this._lexerNext();
6380
+ return token;
6381
+ }
6382
+ parseLiteral() {
6383
+ if (this.curKind != TokenKind.Literal && !literalTypes.has(this.curValue)) {
6384
+ UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected literal");
6385
+ }
6386
+ const token = this.curToken;
6387
+ this._lexerNext();
6388
+ return token;
6389
+ }
6390
+ parseAndPushGenerics(ext) {
6391
+ var _a;
6392
+ const gen = (_a = extractTypeParameters(ext)) !== null && _a !== void 0 ? _a : [];
6393
+ if (this.seeAndSkip("<")) {
6394
+ let next = false;
6395
+ while (!this.seeAndSkip(">")) {
6396
+ if (next) {
6397
+ this.skip(",");
6398
+ }
6399
+ next = true;
6400
+ gen.push(this.parseSingleIdentifier().value);
6401
+ }
6402
+ }
6403
+ // To be restored in parseDeclaration
6404
+ this._generics.push(gen);
6405
+ return gen;
6406
+ }
6407
+ hasGeneric(name) {
6408
+ return this._generics.some(x => x.includes(name));
6409
+ }
6410
+ parseFile() {
6411
+ var _a;
6412
+ const entries = [];
6413
+ while (!this.seeEof()) {
6414
+ const entry = this.parseDeclaration(IDLKind.File);
6415
+ if (entry) {
6416
+ entries.push(entry);
6417
+ }
6418
+ }
6419
+ return createFile(entries, this.fileName, (_a = this.currentPackage) === null || _a === void 0 ? void 0 : _a.split("."), { nodeLocation: { documentPath: this.fileName, lines: this.lines } });
6420
+ }
6421
+ parseDeclaration(scopeKind) {
6422
+ const genericsLevel = this._generics.length;
6423
+ try {
6424
+ const decl = this.parseDeclarationUnsafe(scopeKind);
6425
+ if (!decl) {
6426
+ return;
6427
+ }
6428
+ if (scopeKind == IDLKind.Interface ? !interfaceContent.has(decl.kind) : !globalContent.has(decl.kind)) {
6429
+ // Prefer shorter location ranges for blocks for now
6430
+ const location = havingBlocks.has(decl.kind) ? decl.nameLocation : decl.nodeLocation;
6431
+ WrongDeclarationPlacement.reportDiagnosticMessage([location], `Wrong declaration placement: ${decl.kind} not allowed in ${scopeKind}`);
6432
+ }
6433
+ return decl;
6434
+ }
6435
+ catch (e) {
6436
+ if (e instanceof DiagnosticException && e.diagnosticMessage.severity != "fatal") {
6437
+ this.skipToAfter(";");
6438
+ return;
6439
+ }
6440
+ throw e;
6441
+ }
6442
+ finally {
6443
+ while (this._generics.length > genericsLevel) {
6444
+ this._generics.pop();
6445
+ }
6446
+ }
6447
+ }
6448
+ parseDeclarationUnsafe(scopeKind) {
6449
+ this._internalCurrentExtended = this.parseExtendedAttributes();
6450
+ this.currentModifiers = {};
6451
+ while (modifierTokens.has(this.curValue)) {
6452
+ if (this.currentModifiers[this.curValue]) {
6453
+ DuplicateModifier.reportDiagnosticMessage([this.curLocation]);
6454
+ }
6455
+ this.currentModifiers[this.curValue] = this.curToken;
6456
+ this._lexerNext();
6457
+ }
6458
+ if (unsupportedDeclarations.has(this.curValue)) {
6459
+ UnsupportedSyntax.throwDiagnosticMessage([this.curLocation]);
6460
+ return;
6461
+ }
6462
+ if (supportedDeclarations.has(this.curValue)) {
6463
+ if (this.curValue != "attribute") {
6464
+ this.assertPossibleModifiers();
6465
+ }
6466
+ switch (this.curValue) {
6467
+ case "attribute":
6468
+ this.assertPossibleModifiers("static", "readonly");
6469
+ return this.parseAttribute();
6470
+ case "callback":
6471
+ return this.parseCallback();
6472
+ case "const":
6473
+ return this.parseConst();
6474
+ case "constructor":
6475
+ return this.parseConstructor();
6476
+ case "dictionary":
6477
+ return this.parseDictionary();
6478
+ case "enum":
6479
+ return this.parseEnum();
6480
+ case "import":
6481
+ return this.parseImport();
6482
+ case "interface":
6483
+ return this.parseInterface();
6484
+ case "namespace":
6485
+ return this.parseNamespace();
6486
+ case "package":
6487
+ {
6488
+ const pack = this.parsePackage();
6489
+ if (this.currentPackage) {
6490
+ DuplicatePackageDeclaration.reportDiagnosticMessage([pack.location]);
6491
+ }
6492
+ this.currentPackage = pack.name;
6493
+ if (scopeKind != IDLKind.File) {
6494
+ WrongDeclarationPlacement.reportDiagnosticMessage([pack.location], `Wrong declaration placement: package is not allowed in ${scopeKind}`);
6495
+ }
6496
+ return;
6497
+ }
6498
+ case "typedef":
6499
+ return this.parseTypedef();
6500
+ case "version":
6501
+ return this.parseVersion();
6502
+ }
6503
+ }
6504
+ else {
6505
+ this.assertPossibleModifiers("static", "async");
6506
+ return this.parseOperation();
6507
+ }
6508
+ }
6509
+ parseNamespace() {
6510
+ const sloc = this.trackLocation();
6511
+ const ext = this.consumeCurrentExtended();
6512
+ this.skip("namespace");
6513
+ const name = this.parseSingleIdentifier();
6514
+ const entries = [];
6515
+ this.skip("{");
6516
+ while (!this.seeAndSkip("}")) {
6517
+ const entry = this.parseDeclaration(IDLKind.Namespace);
6518
+ if (entry) {
6519
+ entries.push(entry);
6520
+ }
6521
+ }
6522
+ this.skip(";");
6523
+ return createNamespace(name.value, entries, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6524
+ }
6525
+ parseInterface() {
6526
+ const sloc = this.trackLocation();
6527
+ const ext = this.consumeCurrentExtended();
6528
+ this.skip("interface");
6529
+ const typeParameters = this.parseAndPushGenerics(ext);
6530
+ const name = this.parseSingleIdentifier();
6531
+ let bases = [];
6532
+ if (this.seeAndSkip(":")) {
6533
+ const typeList = this.parseTypeList();
6534
+ for (const type of typeList) {
6535
+ if (isReferenceType(type)) {
6536
+ bases.push(type);
6537
+ }
6538
+ else {
6539
+ ExpectedReferenceType.reportDiagnosticMessage([type.nodeLocation]);
6540
+ }
6541
+ }
6542
+ }
6543
+ const entries = [];
6544
+ this.skip("{");
6545
+ while (!this.seeAndSkip("}")) {
6546
+ const entry = this.parseDeclaration(IDLKind.Interface);
6547
+ if (entry) {
6548
+ if (isMethod(entry)) {
6549
+ entry.isFree = false;
6550
+ }
6551
+ entries.push(entry);
6552
+ }
6553
+ }
6554
+ this.skip(";");
6555
+ 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 });
6556
+ }
6557
+ parseExtendedAttributes() {
6558
+ // For future extensions: here is also a good point for doc comments handling
6559
+ if (!this.seeAndSkip("[")) {
6560
+ return;
6561
+ }
6562
+ const ext = [];
6563
+ const names = new Set();
6564
+ const duplicates = new Set();
6565
+ let next = false;
6566
+ while (!this.seeAndSkip("]")) {
6567
+ if (next) {
6568
+ this.skip(",");
6569
+ }
6570
+ next = true;
6571
+ const name = this.parseSingleIdentifier();
6572
+ if (names.has(name.value)) {
6573
+ duplicates.add(name.value);
6574
+ }
6575
+ names.add(name.value);
6576
+ if (name.value == IDLExtendedAttributes.TypeArguments) {
6577
+ // TypeArguments parsing support
6578
+ try {
6579
+ this._enableInLiteralParsing = true;
6580
+ this.skip("=");
6581
+ const vloc = this.trackLocation();
6582
+ const start = this._curOffset; // Already after first quote
6583
+ this.skip("\"");
6584
+ const types = this.parseTypeList();
6585
+ const end = this._curOffset - 1; // Already after second quote
6586
+ this._enableInLiteralParsing = false;
6587
+ this.skip("\"");
6588
+ const stringValue = this.content.slice(start, end);
6589
+ ext.push({ name: name.value, value: stringValue, typesValue: types, nameLocation: name.location, valueLocation: vloc() });
6590
+ }
6591
+ catch (e) {
6592
+ this.skipToAfter("\"");
6593
+ throw e;
6594
+ }
6595
+ finally {
6596
+ this._enableInLiteralParsing = false;
6597
+ }
6598
+ }
6599
+ else {
6600
+ let value;
6601
+ if (this.seeAndSkip("=")) {
6602
+ value = this.parseFullIdentifierOrLiteral();
6603
+ }
6604
+ const converted = value ? valueFromIdentifierOrLiteral(value) : undefined;
6605
+ ext.push({ name: name.value, value: converted, nameLocation: name.location, valueLocation: value === null || value === void 0 ? void 0 : value.location });
6606
+ }
6607
+ }
6608
+ for (const dup of duplicates) {
6609
+ DuplicateExtendedAttribute.reportDiagnosticMessage(ext.filter(x => x.name == dup).map(x => x.nameLocation));
6610
+ }
6611
+ return ext;
6612
+ }
6613
+ parseTypeList() {
6614
+ const types = [this.parseType()];
6615
+ while (this.seeAndSkip(",")) {
6616
+ types.push(this.parseType());
6617
+ }
6618
+ return types;
6619
+ }
6620
+ parseType(outerExt) {
6621
+ var _a;
6622
+ const parsedExt = this.parseExtendedAttributes();
6623
+ const ext = parsedExt ? (outerExt ? parsedExt.concat(outerExt) : parsedExt) : (outerExt ? [...outerExt] : undefined);
6624
+ const sloc = this.trackLocation();
6625
+ if (this.seeAndSkip("(")) {
6626
+ let combinedTypes = [];
6627
+ let next = false;
6628
+ while (!this.seeAndSkip(")")) {
6629
+ if (next) {
6630
+ this.skip("or");
6631
+ }
6632
+ next = true;
6633
+ combinedTypes.push(this.parseType());
6634
+ }
6635
+ const isNullable = this.seeAndSkip("?") || combinedTypes.includes(IDLUndefinedType);
6636
+ combinedTypes = combinedTypes.filter(x => x !== IDLUndefinedType);
6637
+ const distilledType = combinedTypes.length == 1
6638
+ ? combinedTypes[0]
6639
+ : createUnionType(combinedTypes, undefined, { extendedAttributes: ext, nodeLocation: sloc() });
6640
+ if (isNullable) {
6641
+ return createOptionalType(distilledType, { extendedAttributes: ext, nodeLocation: sloc() });
6642
+ }
6643
+ return distilledType;
6644
+ }
6645
+ const name = this.parseFullIdentifier();
6646
+ const genArgs = (_a = extractTypeArguments(ext)) !== null && _a !== void 0 ? _a : [];
6647
+ if (this.seeAndSkip("<")) {
6648
+ let next = false;
6649
+ while (!this.seeAndSkip(">")) {
6650
+ if (next) {
6651
+ this.skip(",");
6652
+ }
6653
+ next = true;
6654
+ genArgs.push(this.parseType());
6655
+ }
6656
+ }
6657
+ let type;
6658
+ if (this.hasGeneric(name.value)) {
6659
+ if (genArgs.length > 0) {
6660
+ UnexpectedGenericArguments.reportDiagnosticMessage([name.location]);
6661
+ }
6662
+ type = createTypeParameterReference(name.value, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6663
+ }
6664
+ else if (builtinTypes.has(name.value)) {
6665
+ if (genArgs.length > 0) {
6666
+ UnexpectedGenericArguments.reportDiagnosticMessage([name.location]);
6667
+ }
6668
+ type = builtinTypes.get(name.value);
6669
+ }
6670
+ else if (builtinGenericTypeNames.has(name.value)) {
6671
+ if (genArgs.length == 0) {
6672
+ ExpectedGenericArguments.reportDiagnosticMessage([name.location]);
6673
+ }
6674
+ type = createContainerType(name.value, genArgs, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6675
+ }
6676
+ else {
6677
+ type = createReferenceType(name.value, genArgs.length > 0 ? genArgs : undefined, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location });
6678
+ }
6679
+ const isNullable = this.seeAndSkip("?");
6680
+ if (isNullable) {
6681
+ return createOptionalType(type, { extendedAttributes: ext, nodeLocation: sloc() });
6682
+ }
6683
+ else {
6684
+ return type;
6685
+ }
6686
+ }
6687
+ parseReferenceType() {
6688
+ const type = this.parseType();
6689
+ if (!isReferenceType(type)) {
6690
+ ExpectedReferenceType.reportDiagnosticMessage([type.nodeLocation]);
6691
+ }
6692
+ return type;
6693
+ }
6694
+ parsePrimitiveType() {
6695
+ const type = this.parseType();
6696
+ if (!isPrimitiveType(type)) {
6697
+ ExpectedPrimitiveType.reportDiagnosticMessage([type.nodeLocation]);
6698
+ }
6699
+ return type;
6700
+ }
6701
+ parseArgTuple() {
6702
+ const args = [];
6703
+ const names = new Set();
6704
+ const duplicates = new Set();
6705
+ this.skip("(");
6706
+ let next = false;
6707
+ while (!this.seeAndSkip(")")) {
6708
+ if (next) {
6709
+ this.skip(",");
6710
+ }
6711
+ next = true;
6712
+ const arg = this.parseArg();
6713
+ if (names.has(arg.name)) {
6714
+ duplicates.add(arg.name);
6715
+ }
6716
+ names.add(arg.name);
6717
+ args.push(arg);
6718
+ }
6719
+ for (const dup of duplicates) {
6720
+ DuplicateArgumentName.reportDiagnosticMessage(args.filter(x => x.name == dup).map(x => x.nameLocation));
6721
+ }
6722
+ return args;
6723
+ }
6724
+ parseArg() {
6725
+ const ext = this.parseExtendedAttributes();
6726
+ const sloc = this.trackLocation();
6727
+ const optional = this.seeAndSkip("optional");
6728
+ // Note `extendedAttributes` forwarding
6729
+ const type = this.parseType(ext);
6730
+ const spread = this.seeAndSkip("...");
6731
+ const name = this.parseSingleIdentifier();
6732
+ // Note absense of `extendedAttributes`, they are only forwarded to `type`, as it was in the old parsing code
6733
+ return createParameter(name.value, type, optional, spread, { nodeLocation: sloc(), nameLocation: name.location });
6734
+ }
6735
+ parseOperation() {
6736
+ const sloc = this.trackLocation();
6737
+ const ext = this.consumeCurrentExtended();
6738
+ const isStatic = !!this.currentModifiers.static;
6739
+ const isAsync = !!this.currentModifiers.async;
6740
+ const isOptional = extractOptional(ext);
6741
+ const isFree = true; // Will be set to false in parseInterface if method is declared within interface
6742
+ const typeParameters = this.parseAndPushGenerics(ext);
6743
+ // Note `extendedAttributes` forwarding
6744
+ const retType = this.parseType(ext);
6745
+ const name = this.parseSingleIdentifier();
6746
+ const args = this.parseArgTuple();
6747
+ this.skip(";");
6748
+ if (ext === null || ext === void 0 ? void 0 : ext.some(x => x.name == IDLExtendedAttributes.CallSignature)) {
6749
+ return createCallable(name.value, args, retType, { isStatic, isAsync }, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location }, typeParameters);
6750
+ }
6751
+ return createMethod(name.value, args, retType, { isStatic, isAsync, isOptional, isFree }, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location }, typeParameters);
6752
+ }
6753
+ parseConstructor() {
6754
+ const sloc = this.trackLocation();
6755
+ const ext = this.consumeCurrentExtended();
6756
+ this.skip("constructor");
6757
+ const args = this.parseArgTuple();
6758
+ this.skip(";");
6759
+ return createConstructor(args, undefined, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc() });
6760
+ }
6761
+ parseConst() {
6762
+ const sloc = this.trackLocation();
6763
+ const ext = this.consumeCurrentExtended();
6764
+ this.skip("const");
6765
+ const type = this.parseType();
6766
+ const name = this.parseSingleIdentifier();
6767
+ this.skip("=");
6768
+ const value = this.parseLiteral();
6769
+ const extracted = extractLiteral(value);
6770
+ this.skip(";");
6771
+ return createConstant(name.value, type, extracted.extractedString, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6772
+ }
6773
+ parseAttribute() {
6774
+ const sloc = this.trackLocation();
6775
+ const ext = this.consumeCurrentExtended();
6776
+ const isReadonly = !!this.currentModifiers.readonly;
6777
+ const isStatic = !!this.currentModifiers.static;
6778
+ const isOptional = extractOptional(ext);
6779
+ this.skip("attribute");
6780
+ const type = this.parseType();
6781
+ const name = this.parseSingleIdentifier();
6782
+ this.skip(";");
6783
+ return createProperty(name.value, type, isReadonly, isStatic, isOptional, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6784
+ }
6785
+ parseTypedef() {
6786
+ const sloc = this.trackLocation();
6787
+ const ext = this.consumeCurrentExtended();
6788
+ this.skip("typedef");
6789
+ const typeParameters = this.parseAndPushGenerics(ext);
6790
+ const type = this.parseType();
6791
+ const name = this.parseSingleIdentifier();
6792
+ if (isUnionType(type)) {
6793
+ type.name = name.value;
6794
+ }
6795
+ this.skip(";");
6796
+ return createTypedef(name.value, type, typeParameters, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6797
+ }
6798
+ parseCallback() {
6799
+ const sloc = this.trackLocation();
6800
+ const ext = this.consumeCurrentExtended();
6801
+ this.skip("callback");
6802
+ if (this.see("interface")) {
6803
+ UnsupportedSyntax.throwDiagnosticMessage([this.curLocation], "Unsupported syntax: callback interface");
6804
+ }
6805
+ const typeParameters = this.parseAndPushGenerics(ext);
6806
+ const name = this.parseSingleIdentifier();
6807
+ this.skip("=");
6808
+ const retType = this.parseType();
6809
+ const args = this.parseArgTuple();
6810
+ this.skip(";");
6811
+ return createCallback(name.value, args, retType, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location }, typeParameters);
6812
+ }
6813
+ parseEnum() {
6814
+ const sloc = this.trackLocation();
6815
+ const ext = this.consumeCurrentExtended();
6816
+ this.skip("enum");
6817
+ const name = this.parseSingleIdentifier();
6818
+ const items = [];
6819
+ this.skip("{");
6820
+ let next = false;
6821
+ while (!this.seeAndSkip("}")) {
6822
+ if (next) {
6823
+ this.skip(",");
6824
+ // Can have trailing comma
6825
+ if (this.seeAndSkip("}")) {
6826
+ break;
6827
+ }
6828
+ }
6829
+ next = true;
6830
+ const ext = this.parseExtendedAttributes();
6831
+ const entry = this.parseLiteral();
6832
+ const member = createEnumMember(entry.value, undefined, IDLNumberType, undefined, { extendedAttributes: ext, nodeLocation: entry.location, nameLocation: entry.location });
6833
+ items.push(member);
6834
+ }
6835
+ return createEnum(name.value, items, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6836
+ }
6837
+ parseDictionary() {
6838
+ const sloc = this.trackLocation();
6839
+ const ext = this.consumeCurrentExtended();
6840
+ this.skip("dictionary");
6841
+ const name = this.parseSingleIdentifier();
6842
+ const items = [];
6843
+ this.skip("{");
6844
+ while (!this.seeAndSkip("}")) {
6845
+ items.push(this.parseDictionaryEntry());
6846
+ }
6847
+ this.skip(";");
6848
+ return createEnum(name.value, items, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
6849
+ }
6850
+ parseDictionaryEntry() {
6851
+ const ext = this.parseExtendedAttributes();
6852
+ const sloc = this.trackLocation();
6853
+ const type = this.parsePrimitiveType();
6854
+ const name = this.parseSingleIdentifier();
6855
+ this.skip("=");
6856
+ const value = this.parseLiteral();
6857
+ const extracted = extractLiteral(value);
6858
+ this.skip(";");
6859
+ return createEnumMember(name.value, undefined, type, extracted.extractedValue, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6860
+ }
6861
+ parsePackage() {
6862
+ const sloc = this.trackLocation();
6863
+ this.skip("package");
6864
+ const packagePath = this.parseFullIdentifierOrLiteral();
6865
+ this.skip(";");
6866
+ return { location: sloc(), name: valueFromIdentifierOrLiteral(packagePath) };
6867
+ }
6868
+ parseImport() {
6869
+ const sloc = this.trackLocation();
6870
+ this.skip("import");
6871
+ const importPath = this.parseFullIdentifierOrLiteral();
6872
+ let alias;
6873
+ if (this.seeAndSkip("as")) {
6874
+ alias = this.parseSingleIdentifier();
6875
+ }
6876
+ this.skip(";");
6877
+ 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 });
6878
+ }
6879
+ parseVersion() {
6880
+ const sloc = this.trackLocation();
6881
+ this.skip("version");
6882
+ const versionLiteral = this.parseLiteral();
6883
+ this.skip(";");
6884
+ return createVersion(versionLiteral.value.split("."), { nodeLocation: sloc(), valueLocation: versionLiteral.location });
6885
+ }
6886
+ }
6887
+ function prepareOffsets$1(lines) {
6888
+ let offsets = [];
6889
+ let offset = 0;
6890
+ for (let line of lines) {
6891
+ let plus = line.length;
6892
+ offsets.push(offset);
6893
+ offset += plus;
6894
+ }
6895
+ return offsets;
6896
+ }
6897
+ function valueFromIdentifierOrLiteral(token) {
6898
+ if (token.kind == TokenKind.Words && !literalTypes.has(token.value)) {
6899
+ return token.value;
6900
+ }
6901
+ return extractLiteral(token).extractedString;
6902
+ }
6903
+ const literalTypes = new Map([
6904
+ ["true", "boolean"],
6905
+ ["false", "boolean"],
6906
+ ["Infinity", "number"],
6907
+ ["-Infinity", "number"],
6908
+ ["NaN", "number"],
6909
+ ["null", "null"],
6910
+ ["undefined", "undefined"],
6911
+ ]);
6912
+ const extractedUndefined = { type: "undefined", extractedString: "undefined", extractedValue: "undefined" };
6913
+ function extractLiteral(token) {
6914
+ if (token.kind == TokenKind.Words) {
6915
+ if (!literalTypes.has(token.value)) {
6916
+ IncorrectLiteral.reportDiagnosticMessage([token.location]);
6917
+ return extractedUndefined;
6918
+ }
6919
+ const type = literalTypes.get(token.value);
6920
+ const extractedString = token.value;
6921
+ const extractedValue = type == "number" ? parseFloat(extractedString) : extractedString;
6922
+ return { type, extractedString, extractedValue };
6923
+ }
6924
+ if (token.kind != TokenKind.Literal) {
6925
+ IncorrectLiteral.reportDiagnosticMessage([token.location]);
6926
+ return extractedUndefined;
6927
+ }
6928
+ if (token.value[0] == "\"") {
6929
+ try {
6930
+ const extractedString = unescapeString(token.value);
6931
+ return { type: "string", extractedString, extractedValue: extractedString };
6932
+ }
6933
+ catch (e) {
6934
+ IncorrectLiteral.reportDiagnosticMessage([token.location], `Incorrect literal: ${e.message}`);
6935
+ return extractedUndefined;
6936
+ }
6937
+ }
6938
+ const extractedValue = parseFloat(token.value);
6939
+ if (Number.isNaN(extractedValue)) {
6940
+ // Real NaNs are handled before that, so report an error
6941
+ IncorrectLiteral.reportDiagnosticMessage([token.location]);
6942
+ }
6943
+ return { type: "number", extractedString: token.value, extractedValue };
6944
+ }
6945
+ // Taken from deserialize.ts as is
6946
+ function unescapeString(value) {
6947
+ if (!value.length || value[0] !== '"')
6948
+ return value;
6949
+ value = value.slice(1, -1);
6950
+ 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) => {
6951
+ if (c !== undefined) {
6952
+ switch (c) {
6953
+ case "'": return "'";
6954
+ case '"': return '"';
6955
+ case "\\": return "\\";
6956
+ case "b": return "\b";
6957
+ case "f": return "\f";
6958
+ case "n": return "\n";
6959
+ case "r": return "\r";
6960
+ case "t": return "\t";
6961
+ case "v": return "\v";
6962
+ }
6963
+ }
6964
+ else if (oct !== undefined) {
6965
+ return String.fromCharCode(parseInt(oct, 8));
6966
+ }
6967
+ else if (h2 !== undefined) {
6968
+ return String.fromCharCode(parseInt(h2, 16));
6969
+ }
6970
+ else if (u4 !== undefined) {
6971
+ return String.fromCharCode(parseInt(u4, 16));
6972
+ }
6973
+ throw new Error(`unknown escape sequence: ${_}`);
6974
+ });
6975
+ return value;
6976
+ }
6977
+ function extractInterfaceSubkind(ext) {
6978
+ var _a;
6979
+ const ent = (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == "Entity")) === null || _a === void 0 ? void 0 : _a.value;
6980
+ switch (ent) {
6981
+ case IDLEntity.Class: return IDLInterfaceSubkind.Class;
6982
+ case IDLEntity.Literal: return IDLInterfaceSubkind.AnonymousInterface;
6983
+ case IDLEntity.Tuple: return IDLInterfaceSubkind.Tuple;
6984
+ default: return IDLInterfaceSubkind.Interface;
6985
+ }
6986
+ }
6987
+ function extractDocumentation(ext) {
6988
+ var _a;
6989
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == "Documentation")) === null || _a === void 0 ? void 0 : _a.value;
6990
+ }
6991
+ function extractOptional(ext) {
6992
+ var _a;
6993
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.some(x => x.name.toLowerCase() == "optional")) !== null && _a !== void 0 ? _a : false;
6994
+ }
6995
+ function sanitizeTypeParameter(param) {
6996
+ const extendsIdx = param.indexOf('extends');
6997
+ if (extendsIdx !== -1) {
6998
+ return param.substring(0, extendsIdx).trim();
6999
+ }
7000
+ const eqIdx = param.indexOf('=');
7001
+ if (eqIdx !== -1) {
7002
+ return param.substring(0, eqIdx).trim();
7003
+ }
7004
+ return param;
7005
+ }
7006
+ function extractTypeParameters(ext) {
7007
+ var _a, _b, _c;
7008
+ 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);
7009
+ }
7010
+ function extractTypeArguments(ext) {
7011
+ var _a;
7012
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == IDLExtendedAttributes.TypeArguments)) === null || _a === void 0 ? void 0 : _a.typesValue;
7013
+ }
7014
+ const builtinTypesList = [IDLPointerType, IDLVoidType, IDLBooleanType,
7015
+ IDLObjectType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type,
7016
+ IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF32Type,
7017
+ IDLF64Type, IDLBigintType, IDLNumberType, IDLStringType, IDLAnyType,
7018
+ IDLUndefinedType, IDLUnknownType, IDLObjectType, IDLThisType, IDLDate,
7019
+ IDLBufferType, IDLSerializerBuffer
7020
+ ];
7021
+ // Better solution will be to make it registry in idl.ts
7022
+ const builtinTypes = new Map(builtinTypesList.map(x => [x.name, x]));
7023
+ const builtinGenericTypeNames = new Set(["sequence", "record", "Promise"]);
6100
7024
 
6101
7025
  /*
6102
7026
  * Copyright (c) 2024 Huawei Device Co., Ltd.
@@ -6223,10 +7147,9 @@ class IDLDeserializer {
6223
7147
  }
6224
7148
  const implementations = [];
6225
7149
  node.inheritance.forEach(it => {
6226
- var _a;
6227
7150
  const attributes = it.extAttrs;
6228
7151
  const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], IDLExtendedAttributes.TypeArguments);
6229
- const attrs = (_a = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : [])) === null || _a === void 0 ? void 0 : _a.filter(it => it.name !== IDLExtendedAttributes.TypeArguments);
7152
+ const attrs = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
6230
7153
  const ref = createReferenceType(it.inheritance, parentTypeArgs, {
6231
7154
  extendedAttributes: attrs
6232
7155
  });
@@ -6377,6 +7300,7 @@ class IDLDeserializer {
6377
7300
  toIDLConstructor(file, node) {
6378
7301
  return this.withInfo(node, createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
6379
7302
  documentation: this.makeDocs(node),
7303
+ extendedAttributes: this.toExtendedAttributes(node.extAttrs),
6380
7304
  }));
6381
7305
  }
6382
7306
  toIDLParameter(file, node) {
@@ -6602,38 +7526,166 @@ class IDLDeserializer {
6602
7526
  return attr ? this.toExtendedAttributeValue(attr) : undefined;
6603
7527
  }
6604
7528
  }
6605
- function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
6606
- var _a, _b, _c;
6607
- const lexicalInfo = new Map();
6608
- const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
6609
- if (undefined === content) {
6610
- try {
6611
- content = fs__namespace.readFileSync(fileName).toString();
6612
- }
6613
- catch (e) {
6614
- content = "";
6615
- LoadingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "");
7529
+ const DifferenceFound = new DiagnosticMessageGroup("error", "DifferenceFound", "Difference found");
7530
+ const noCompare = new Set(["parent", "fileName", "nodeLocation", "nameLocation", "valueLocation", "typesValue"]);
7531
+ const canContainMoreCompare = new Set(["extendedAttributes", "typeParameters", "typeArguments"]);
7532
+ function safeString(value) {
7533
+ if (typeof value == "symbol") {
7534
+ return String(value);
7535
+ }
7536
+ return JSON.stringify(value, (k, v) => { return noCompare.has(k) ? undefined : v; });
7537
+ }
7538
+ function joinPath(left, right) {
7539
+ if (!right) {
7540
+ return left;
7541
+ }
7542
+ return `${left}.${right}`;
7543
+ }
7544
+ function compareDeep(oldData, newData, paths) {
7545
+ var _a;
7546
+ 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);
7547
+ const diffs = [];
7548
+ if (typeof oldData != typeof newData) {
7549
+ diffs.push({ path: "", oldValue: safeString(oldData), newValue: safeString(newData) });
7550
+ }
7551
+ else if (Array.isArray(oldData) && Array.isArray(newData)) {
7552
+ const len = Math.max(oldData.length, newData.length);
7553
+ if (oldData.length != newData.length) {
7554
+ diffs.push({ path: "", oldValue: `(length=${oldData.length})`, newValue: `(length=${newData.length})` });
7555
+ }
7556
+ for (let i = 0; i < len; ++i) {
7557
+ const deeperDiffs = compareDeep(oldData[i], newData[i], paths);
7558
+ if (deeperDiffs.length > 0) {
7559
+ diffs.push(...deeperDiffs.map(x => { x.path = joinPath("" + i, x.path); return x; }));
7560
+ }
6616
7561
  }
6617
7562
  }
6618
- let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
6619
- const offsets = prepareOffsets(lines);
6620
- lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
6621
- const parsed = { fileName, lines, offsets, lexicalInfo };
6622
- let packageClause = [];
6623
- let rawParsingResults;
6624
- try {
6625
- rawParsingResults = parse$1(content);
7563
+ else if (typeof newData == "object") {
7564
+ const keys = [...new Set([...Object.getOwnPropertyNames(oldData), ...Object.getOwnPropertyNames(newData)])].filter(x => !noCompare.has(x));
7565
+ for (const k of keys) {
7566
+ let oldValue = oldData[k];
7567
+ let newValue = newData[k];
7568
+ if (canContainMoreCompare.has(k)) {
7569
+ if (newValue == null && Array.isArray(oldValue) && oldValue.length == 0) {
7570
+ continue;
7571
+ }
7572
+ if (oldValue == null && Array.isArray(newValue)) {
7573
+ continue;
7574
+ }
7575
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
7576
+ if (newValue.length > oldValue.length) {
7577
+ // Cases when old parser takes attributes from outer declaration and ignores the right ones
7578
+ newValue = newValue.slice(newValue.length - oldValue.length);
7579
+ }
7580
+ else if (oldValue.length > newValue.length) {
7581
+ // Cases when types in parentheses have own attributes, but old parser adds attributes from outer declaration
7582
+ oldValue = oldValue.slice(0, newValue.length);
7583
+ }
7584
+ }
7585
+ }
7586
+ const deeperDiffs = compareDeep(oldValue, newValue, paths);
7587
+ if (deeperDiffs.length > 0) {
7588
+ diffs.push(...deeperDiffs.map(x => { x.path = joinPath(k, x.path); return x; }));
7589
+ }
7590
+ }
6626
7591
  }
6627
- catch (e) {
6628
- if (e.name == "WebIDLParseError") {
6629
- let tokens = e.tokens;
6630
- let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
6631
- ParsingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage);
7592
+ else {
7593
+ if (oldData != newData) {
7594
+ diffs.push({ path: "", oldValue: safeString(oldData), newValue: safeString(newData) });
6632
7595
  }
6633
- UnknownErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_c = e.message) !== null && _c !== void 0 ? _c : "");
6634
7596
  }
6635
- const entries = rawParsingResults
6636
- .filter(it => {
7597
+ if (!location) {
7598
+ return diffs;
7599
+ }
7600
+ for (const diff of diffs) {
7601
+ paths.add(diff.path);
7602
+ DifferenceFound.reportDiagnosticMessage([location], `path: ${diff.path} oldValue: ${diff.oldValue} newValue: ${diff.newValue}`);
7603
+ }
7604
+ return [];
7605
+ }
7606
+ function compareParsingResults(oldFile, newFile) {
7607
+ const paths = new Set();
7608
+ compareDeep(oldFile, newFile, paths);
7609
+ if (paths.size > 0) {
7610
+ DifferenceFound.reportDiagnosticMessage([newFile.nodeLocation], "Differences found in those paths:\n" + [...paths].join("\n"));
7611
+ }
7612
+ }
7613
+ function parseIdlNew(fileName, content, registerSynthetics) {
7614
+ let file = new Parser(fileName, content).parseIDL();
7615
+ const ancestors = [];
7616
+ const namespaces = [];
7617
+ // Mimic old parser and deserialize.ts behavior:
7618
+ // 1. Add `fileName`.
7619
+ // 2. Add `parent`.
7620
+ // 3. Possibly register node with `addSyntheticType` if "Synthetic" is in attributes
7621
+ forEachChild(file, (node) => {
7622
+ var _a;
7623
+ if (isPrimitiveType(node)) {
7624
+ return;
7625
+ }
7626
+ node.fileName = fileName;
7627
+ if (registerSynthetics && isEntry(node) && ((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.some(it => it.name === "Synthetic"))) {
7628
+ const fqName = file.packageClause.concat(namespaces).concat([node.name]).join('.');
7629
+ addSyntheticType(fqName, node);
7630
+ }
7631
+ if (ancestors.length) {
7632
+ node.parent = ancestors[ancestors.length - 1];
7633
+ }
7634
+ if (isNamespace(node)) {
7635
+ namespaces.push(node.name);
7636
+ }
7637
+ ancestors.push(node);
7638
+ }, (node) => {
7639
+ if (isPrimitiveType(node)) {
7640
+ return;
7641
+ }
7642
+ if (isNamespace(node)) {
7643
+ namespaces.pop();
7644
+ }
7645
+ ancestors.pop();
7646
+ });
7647
+ return file;
7648
+ }
7649
+ function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
7650
+ var _a, _b, _c;
7651
+ let newFile;
7652
+ const mode = process.env.IDLPARSE;
7653
+ if (mode == "compare" || mode == "new") {
7654
+ newFile = parseIdlNew(fileName, content, mode == "new");
7655
+ if (mode == "new") {
7656
+ return [newFile, new Map()];
7657
+ }
7658
+ }
7659
+ const lexicalInfo = new Map();
7660
+ const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
7661
+ if (undefined === content) {
7662
+ try {
7663
+ content = fs__namespace.readFileSync(fileName).toString();
7664
+ }
7665
+ catch (e) {
7666
+ content = "";
7667
+ throw new FatalParserException([LoadingFatal.reportDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "")]);
7668
+ }
7669
+ }
7670
+ let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
7671
+ const offsets = prepareOffsets(lines);
7672
+ lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
7673
+ const parsed = { fileName, lines, offsets, lexicalInfo };
7674
+ let packageClause = [];
7675
+ let rawParsingResults;
7676
+ try {
7677
+ rawParsingResults = parse$1(content);
7678
+ }
7679
+ catch (e) {
7680
+ if (e.name == "WebIDLParseError") {
7681
+ let tokens = e.tokens;
7682
+ let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
7683
+ throw new FatalParserException([ParsingFatal.reportDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage)]);
7684
+ }
7685
+ throw new FatalParserException([InternalFatal.reportDiagnosticMessage([{ documentPath: fileName, lines }], (_c = e.message) !== null && _c !== void 0 ? _c : "")]);
7686
+ }
7687
+ const entries = rawParsingResults
7688
+ .filter(it => {
6637
7689
  if (!it.type)
6638
7690
  return false;
6639
7691
  if (deserializer.isPackage(it)) {
@@ -6654,6 +7706,10 @@ function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
6654
7706
  node.nameLocation = nameLocation;
6655
7707
  }
6656
7708
  });
7709
+ if (mode == "compare") {
7710
+ compareParsingResults(file, newFile);
7711
+ return [newFile, new Map()];
7712
+ }
6657
7713
  return [file, lexicalInfo];
6658
7714
  }
6659
7715
  function prepareOffsets(lines) {
@@ -7986,6 +9042,12 @@ class ETSLanguageWriter extends TSLanguageWriter {
7986
9042
  super(printer, resolver, typeConvertor, Language.ARKTS);
7987
9043
  this.arrayConvertor = arrayConvertor;
7988
9044
  }
9045
+ pushNamespace(namespace, options) {
9046
+ if (options.isDefault) {
9047
+ this.print(`export default ${namespace}`);
9048
+ }
9049
+ super.pushNamespace(namespace, options);
9050
+ }
7989
9051
  fork(options) {
7990
9052
  var _a;
7991
9053
  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);
@@ -8270,7 +9332,7 @@ class AggregateConvertor extends BaseArgConvertor {
8270
9332
  statements.push(assigneer(writer.makeString(bufferName)));
8271
9333
  }
8272
9334
  else if (writer.language == Language.CJ) {
8273
- const resultExpression = writer.makeString(`${writer.getNodeName(this.idlType)}(${this.decl.properties.map(prop => `${bufferName}_${prop.name}`).join(", ")})`);
9335
+ const resultExpression = writer.makeString(`${writer.getNodeName(this.idlType)}(${this.decl.properties.map(prop => `${bufferName}${capitalize(prop.name)}`).join(", ")})`);
8274
9336
  statements.push(assigneer(resultExpression));
8275
9337
  }
8276
9338
  else if (writer.language == Language.KOTLIN) {
@@ -8681,7 +9743,7 @@ function mk(typeName, check, config) {
8681
9743
  }
8682
9744
  return new ValidationBox({
8683
9745
  success: false,
8684
- errorMessage: `Expected "${typeName}"`
9746
+ errorMessage: `Expected "${typeName}" but got "${typeof x}"`
8685
9747
  });
8686
9748
  }, () => {
8687
9749
  const base = {
@@ -8987,6 +10049,7 @@ const HookMethodSchema = D.object({
8987
10049
  replaceImplementation: D.boolean()
8988
10050
  });
8989
10051
  D.object({
10052
+ ApiKind: D.number(),
8990
10053
  TypePrefix: D.string(),
8991
10054
  LibraryPrefix: D.string(),
8992
10055
  OptionalPrefix: D.string(),
@@ -9007,6 +10070,7 @@ D.object({
9007
10070
  globalPackages: T.stringArray()
9008
10071
  });
9009
10072
  const defaultCoreConfiguration = {
10073
+ ApiKind: 0,
9010
10074
  TypePrefix: "",
9011
10075
  LibraryPrefix: "",
9012
10076
  OptionalPrefix: "",
@@ -10834,6 +11898,66 @@ const JSON5 = {
10834
11898
 
10835
11899
  var lib = JSON5;
10836
11900
 
11901
+ /*
11902
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
11903
+ * Licensed under the Apache License, Version 2.0 (the "License");
11904
+ * you may not use this file except in compliance with the License.
11905
+ * You may obtain a copy of the License at
11906
+ *
11907
+ * http://www.apache.org/licenses/LICENSE-2.0
11908
+ *
11909
+ * Unless required by applicable law or agreed to in writing, software
11910
+ * distributed under the License is distributed on an "AS IS" BASIS,
11911
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11912
+ * See the License for the specific language governing permissions and
11913
+ * limitations under the License.
11914
+ */
11915
+ class Config {
11916
+ constructor(ignore, nonNullable, irHack, fragments, parameters) {
11917
+ this.ignore = ignore;
11918
+ this.nonNullable = nonNullable;
11919
+ this.irHack = irHack;
11920
+ this.fragments = fragments;
11921
+ this.parameters = parameters;
11922
+ }
11923
+ static get createPrefix() {
11924
+ return `Create`;
11925
+ }
11926
+ static get updatePrefix() {
11927
+ return `Update`;
11928
+ }
11929
+ static get constPostfix() {
11930
+ return `Const`;
11931
+ }
11932
+ static get nodeTypeAttribute() {
11933
+ return `Es2pandaAstNodeType`;
11934
+ }
11935
+ static get nodeNamespaceAttribute() {
11936
+ return `cpp_namespace`;
11937
+ }
11938
+ static get uselessPrefix() {
11939
+ return `Get`;
11940
+ }
11941
+ static get astNodeCommonAncestor() {
11942
+ return `AstNode`;
11943
+ }
11944
+ static get context() {
11945
+ return `Context`;
11946
+ }
11947
+ static get dataClassPrefix() {
11948
+ return `es2panda_`;
11949
+ }
11950
+ static get defaultAncestor() {
11951
+ return `ArktsObject`;
11952
+ }
11953
+ static get irNamespace() {
11954
+ return `ir`;
11955
+ }
11956
+ }
11957
+ Config.DoNotPrintPeers = [
11958
+ 'es2panda_Context', // useless
11959
+ ];
11960
+
10837
11961
  /*
10838
11962
  * Copyright (c) 2024 Huawei Device Co., Ltd.
10839
11963
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -10859,7 +11983,11 @@ class BridgesConstructions {
10859
11983
  return `impl_${name}`;
10860
11984
  }
10861
11985
  static referenceType(name) {
10862
- return `es2panda_${name}*`;
11986
+ // FIXME: Rewrite CastTypeConvertors using idl.CppInteropArgConverter
11987
+ // and LanguageWriter constructions.
11988
+ // Use c_type attribute from declaration.
11989
+ const addPrefix = (n) => (n.startsWith(Config.dataClassPrefix) ? n : `${Config.dataClassPrefix}${n}`);
11990
+ return `${addPrefix(name)}*`;
10863
11991
  }
10864
11992
  static get sequenceLengthDeclaration() {
10865
11993
  return `std::size_t length`;
@@ -10900,9 +12028,6 @@ class BridgesConstructions {
10900
12028
  static get stringCast() {
10901
12029
  return `getStringCopy`;
10902
12030
  }
10903
- static resultAssignment(value) {
10904
- return `auto ${BridgesConstructions.result} = ${value}`;
10905
- }
10906
12031
  static dropConstCast(value) {
10907
12032
  return `(void*)${value}`;
10908
12033
  }
@@ -10917,63 +12042,6 @@ class BridgesConstructions {
10917
12042
  }
10918
12043
  }
10919
12044
 
10920
- /*
10921
- * Copyright (c) 2024 Huawei Device Co., Ltd.
10922
- * Licensed under the Apache License, Version 2.0 (the "License");
10923
- * you may not use this file except in compliance with the License.
10924
- * You may obtain a copy of the License at
10925
- *
10926
- * http://www.apache.org/licenses/LICENSE-2.0
10927
- *
10928
- * Unless required by applicable law or agreed to in writing, software
10929
- * distributed under the License is distributed on an "AS IS" BASIS,
10930
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10931
- * See the License for the specific language governing permissions and
10932
- * limitations under the License.
10933
- */
10934
- class Config {
10935
- constructor(ignore, nonNullable, irHack, fragments, parameters) {
10936
- this.ignore = ignore;
10937
- this.nonNullable = nonNullable;
10938
- this.irHack = irHack;
10939
- this.fragments = fragments;
10940
- this.parameters = parameters;
10941
- }
10942
- static get createPrefix() {
10943
- return `Create`;
10944
- }
10945
- static get updatePrefix() {
10946
- return `Update`;
10947
- }
10948
- static get constPostfix() {
10949
- return `Const`;
10950
- }
10951
- static get nodeTypeAttribute() {
10952
- return `Es2pandaAstNodeType`;
10953
- }
10954
- static get nodeNamespaceAttribute() {
10955
- return `cpp_namespace`;
10956
- }
10957
- static get uselessPrefix() {
10958
- return `Get`;
10959
- }
10960
- static get astNodeCommonAncestor() {
10961
- return `AstNode`;
10962
- }
10963
- static get context() {
10964
- return `Context`;
10965
- }
10966
- static get dataClassPrefix() {
10967
- return `es2panda_`;
10968
- }
10969
- static get defaultAncestor() {
10970
- return `ArktsObject`;
10971
- }
10972
- static get irNamespace() {
10973
- return `ir`;
10974
- }
10975
- }
10976
-
10977
12045
  /*
10978
12046
  * Copyright (c) 2024 Huawei Device Co., Ltd.
10979
12047
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -11126,7 +12194,7 @@ function isReal(node) {
11126
12194
  return nodeType(node) !== undefined;
11127
12195
  }
11128
12196
  function isDataClass(node) {
11129
- return parent(node) === Config.defaultAncestor;
12197
+ return node.name.startsWith(Config.dataClassPrefix) || parent(node) === Config.defaultAncestor;
11130
12198
  }
11131
12199
  function isCreate(name) {
11132
12200
  return isCreateOrUpdate(name) && name.startsWith(Config.createPrefix);
@@ -11138,6 +12206,9 @@ function isCreateOrUpdate(sourceMethodName) {
11138
12206
  const { rest } = splitCreateOrUpdate(sourceMethodName);
11139
12207
  return rest.length <= 1;
11140
12208
  }
12209
+ function isImplInterface(name) {
12210
+ return dropPrefix(name, Config.dataClassPrefix) === 'Impl';
12211
+ }
11141
12212
  function fixEnumPrefix(name) {
11142
12213
  if (name.startsWith(`es2panda_`)) {
11143
12214
  name = dropPrefix(name, `es2panda_`);
@@ -11225,6 +12296,9 @@ function nodeNamespace(node) {
11225
12296
  var _a;
11226
12297
  return (_a = getNamespacesPathFor(node)[0]) === null || _a === void 0 ? void 0 : _a.name;
11227
12298
  }
12299
+ function fqName(node) {
12300
+ return getQualifiedName(node, "namespace.name");
12301
+ }
11228
12302
  function parent(node) {
11229
12303
  var _a;
11230
12304
  return (_a = node.inheritance[0]) === null || _a === void 0 ? void 0 : _a.name;
@@ -11232,14 +12306,6 @@ function parent(node) {
11232
12306
  function createDefaultTypescriptWriter() {
11233
12307
  return new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => throwException(`unexpected type conversion`) });
11234
12308
  }
11235
- function isIrNamespace(node) {
11236
- var _a, _b;
11237
- 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;
11238
- return nodeNamespace(node) === Config.irNamespace || cppNamespace == Config.irNamespace;
11239
- }
11240
- function createSequence(inner) {
11241
- return createContainerType(`sequence`, [inner]);
11242
- }
11243
12309
  function innerType(node) {
11244
12310
  return node.elementType[0];
11245
12311
  }
@@ -11267,8 +12333,13 @@ function makeSignature(parameters, returnType) {
11267
12333
  .map(it => it.name)
11268
12334
  .map(mangleIfKeyword));
11269
12335
  }
11270
- function flatParents(ref, idl) {
11271
- const resolveReference = (ref) => resolveNamedNode(ref.name.split('.'), undefined, [idl]);
12336
+ function makeExpression(writer, arg) {
12337
+ return typeof arg === 'string' ? writer.makeString(arg) : arg;
12338
+ }
12339
+ function makeStatement(writer, arg) {
12340
+ return typeof arg !== 'string' && 'write' in arg ? arg : writer.makeStatement(makeExpression(writer, arg));
12341
+ }
12342
+ function flatParentsImpl(ref, resolveReference) {
11272
12343
  if (isReferenceType(ref)) {
11273
12344
  const type = resolveReference(ref);
11274
12345
  if (!type || !isInterface$1(type)) {
@@ -11281,13 +12352,21 @@ function flatParents(ref, idl) {
11281
12352
  while (queue.length) {
11282
12353
  const node = queue.shift();
11283
12354
  result.push(node);
12355
+ if (result.length > 1 && baseNameString(ref.name) === node.name) {
12356
+ //console.warn(`Cyclic dependency: ${ref.name} -> ${node.name}`);
12357
+ break;
12358
+ }
11284
12359
  node.inheritance
11285
- .map(p => resolveReference(p))
12360
+ .map(p => resolveReference(p, ref))
11286
12361
  .filter(p => p !== undefined && isInterface$1(p))
11287
12362
  .forEach(p => queue.push(p));
11288
12363
  }
11289
12364
  return result; // with self
11290
12365
  }
12366
+ function flatParents(ref, idl) {
12367
+ const resolveReference = (ref, pov) => resolveNamedNode(ref.name.split('.'), pov, [idl]);
12368
+ return flatParentsImpl(ref, resolveReference);
12369
+ }
11291
12370
 
11292
12371
  /*
11293
12372
  * Copyright (c) 2024 Huawei Device Co., Ltd.
@@ -11304,54 +12383,64 @@ function flatParents(ref, idl) {
11304
12383
  * limitations under the License.
11305
12384
  */
11306
12385
  class Typechecker {
11307
- constructor(idl) {
11308
- this.idl = idl;
11309
- this.idl = linearizeNamespaceMembers(idl);
12386
+ constructor(file) {
12387
+ this.file = file;
12388
+ this.namespaces = this.file.entries.filter(e => isNamespace(e));
12389
+ }
12390
+ resolveReference(ref) {
12391
+ const prefix = Config.dataClassPrefix;
12392
+ // XXX: This is a temporary hack until duplicates will not be removed from idl
12393
+ if (ref.name.startsWith(prefix)) {
12394
+ const entry = this.resolveReference2(createReferenceType(ref.name.slice(prefix.length)));
12395
+ if (entry) {
12396
+ return entry;
12397
+ }
12398
+ }
12399
+ return this.resolveReference2(ref);
11310
12400
  }
11311
- findRealDeclaration(name) {
11312
- // Poor man's namespace-aware resolve.
11313
- // TODO: REWORK IT ALL!
11314
- const declarations = this.idl.filter(it => (name === it.name) || (baseNameString(name) == baseNameString(it.name)));
11315
- if (declarations.length === 1) {
11316
- return declarations[0];
12401
+ resolveReference2(ref, debugPrefix = '') {
12402
+ const target = ref.name.split('.');
12403
+ let entry = undefined;
12404
+ if (target.length > 1) { // full-qualified
12405
+ entry = resolveNamedNode(target, undefined, [this.file]);
11317
12406
  }
11318
- const ir = declarations
11319
- .filter(isInterface$1)
11320
- .filter(it => isIrNamespace(it));
11321
- if (ir.length > 0) {
11322
- return ir[0];
12407
+ else {
12408
+ if (ref.parent) {
12409
+ entry = resolveNamedNode(target, ref.parent, [this.file]);
12410
+ }
12411
+ if (!entry) {
12412
+ for (const pov of this.namespaces) {
12413
+ entry = resolveNamedNode(target, pov, [this.file]);
12414
+ if (entry)
12415
+ break;
12416
+ }
12417
+ }
11323
12418
  }
11324
- return undefined;
11325
- }
11326
- isHeir(name, ancestor) {
11327
- if (name === ancestor) {
11328
- return true;
12419
+ if (debugPrefix.length) {
12420
+ console.log(`RESOLVER: ${ref.name} => ${entry ? fqName(entry) : entry}`);
11329
12421
  }
11330
- const declaration = this.findRealDeclaration(name);
11331
- if (declaration === undefined || !isInterface$1(declaration)) {
12422
+ return entry;
12423
+ }
12424
+ // All classes are consideres heirs of ArktsObject now
12425
+ isHeir(ref, ancestor) {
12426
+ const resolveReference = (r, _) => this.resolveReference(r);
12427
+ const iface = isReferenceType(ref) ? resolveReference(ref) : ref;
12428
+ if (!iface || !isInterface$1(iface)) {
11332
12429
  return false;
11333
12430
  }
11334
- let isHeir = declaration.name === ancestor;
11335
- declaration.inheritance.forEach(parent => {
11336
- isHeir || (isHeir = this.isHeir(parent.name, ancestor));
11337
- });
11338
- // TODO: Should be fixed or moved to config
11339
- const objects = [
11340
- "Program", "ArkTsConfig", "AstDumper", "SrcDumper",
11341
- "FunctionSignature", "ValidationInfo"
11342
- ];
11343
- if (!isHeir) {
11344
- if (ancestor === Config.defaultAncestor &&
11345
- objects.includes(declaration.name))
11346
- return true;
12431
+ const parents = flatParentsImpl(iface, resolveReference);
12432
+ if (parents.map(p => p.name).includes(ancestor)) {
12433
+ return true;
11347
12434
  }
11348
- return isHeir;
12435
+ return ancestor === Config.defaultAncestor;
11349
12436
  }
11350
12437
  isPeer(node) {
11351
- if (node === Config.astNodeCommonAncestor)
12438
+ if (node.name === Config.astNodeCommonAncestor)
11352
12439
  return false; // TODO: is handwritten
11353
- if (node === Config.context)
12440
+ if (node.name === Config.context)
11354
12441
  return false; // TODO: is handwritten
12442
+ if (isImplInterface(node.name))
12443
+ return false;
11355
12444
  if (this.isHeir(node, Config.astNodeCommonAncestor))
11356
12445
  return true;
11357
12446
  if (this.isHeir(node, Config.defaultAncestor))
@@ -11362,7 +12451,7 @@ class Typechecker {
11362
12451
  if (!isReferenceType(type)) {
11363
12452
  return false;
11364
12453
  }
11365
- const declaration = this.findRealDeclaration(type.name);
12454
+ const declaration = this.resolveReference(type);
11366
12455
  return declaration !== undefined && isTarget(declaration);
11367
12456
  }
11368
12457
  isConstReturnValue(node) {
@@ -11372,35 +12461,13 @@ class Typechecker {
11372
12461
  return node.name.endsWith(Config.constPostfix);
11373
12462
  }
11374
12463
  nodeTypeName(node) {
11375
- var _a, _b;
12464
+ var _a;
11376
12465
  const value = nodeType(node);
11377
- const idlEnum = this.idl
11378
- .filter(isEnum$1)
11379
- .find(it => it.name === Config.nodeTypeAttribute);
11380
- 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;
11381
- }
11382
- parent(node) {
11383
- const parentName = parent(node);
11384
- if (parentName === undefined)
11385
- return undefined;
11386
- const decl = this.findRealDeclaration(parentName);
11387
- if (decl === undefined)
11388
- return undefined;
11389
- if (!isInterface$1(decl))
11390
- return undefined;
11391
- return decl;
11392
- }
11393
- ancestry(node) {
11394
- let current = node;
11395
- const res = [];
11396
- while (true) {
11397
- res.push(current);
11398
- const parent = this.parent(current);
11399
- if (parent === undefined) {
11400
- return res;
11401
- }
11402
- current = parent;
11403
- }
12466
+ const entry = this.resolveReference(createReferenceType(Config.nodeTypeAttribute));
12467
+ const name = entry && isEnum$1(entry)
12468
+ ? (_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
12469
+ : undefined;
12470
+ return name ? `${Config.nodeTypeAttribute}.${name}` : undefined; // value
11404
12471
  }
11405
12472
  }
11406
12473
 
@@ -11432,7 +12499,7 @@ class SingleFilePrinter extends AbstractVisitor {
11432
12499
  constructor(idl) {
11433
12500
  super();
11434
12501
  this.idl = idl;
11435
- this.typechecker = new Typechecker(this.idl.entries);
12502
+ this.typechecker = new Typechecker(this.idl);
11436
12503
  }
11437
12504
  printEnum(node) { }
11438
12505
  visit(node) {
@@ -11479,7 +12546,7 @@ class InteropPrinter extends AbstractVisitor {
11479
12546
  constructor(file) {
11480
12547
  super();
11481
12548
  this.file = file;
11482
- this.typechecker = new Typechecker(this.file.entries);
12549
+ this.typechecker = new Typechecker(this.file);
11483
12550
  }
11484
12551
  print() {
11485
12552
  this.file.entries.forEach(it => this.visit(it));
@@ -11569,9 +12636,6 @@ class BaseTypeConvertor {
11569
12636
  return convertType(this, type);
11570
12637
  }
11571
12638
  }
11572
- function composedConvertType(result, effect, type) {
11573
- return result.convertType(effect.convertType(type));
11574
- }
11575
12639
 
11576
12640
  /*
11577
12641
  * Copyright (c) 2024 Huawei Device Co., Ltd.
@@ -11725,7 +12789,7 @@ class CastToTypeConvertor extends BaseTypeConvertor {
11725
12789
  sequence: (type) => BridgesConstructions.arrayOf(this.convertType(innerType(type))),
11726
12790
  enum: (type) => type.name,
11727
12791
  reference: (type) => {
11728
- return BridgesConstructions.referenceType(typechecker.isHeir(type.name, Config.astNodeCommonAncestor)
12792
+ return BridgesConstructions.referenceType(typechecker.isHeir(type, Config.astNodeCommonAncestor)
11729
12793
  ? Config.astNodeCommonAncestor
11730
12794
  : baseName(type));
11731
12795
  },
@@ -11769,6 +12833,8 @@ class BridgesPrinter extends InteropPrinter {
11769
12833
  this.config = config;
11770
12834
  this.castTypeConvertor = new CastTypeConvertor(this.typechecker);
11771
12835
  this.nativeTypeConvertor = new NativeTypeConvertor(this.typechecker);
12836
+ this.returnTypeConvertor = new ReturnTypeConvertor$1(this.typechecker);
12837
+ this.interopMacroConvertor = new InteropMacroTypeConvertor(this.typechecker);
11772
12838
  this.writer = new CppLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => this.nativeTypeConvertor.convertType(node) }, new class extends PrimitiveTypeList {
11773
12839
  constructor() {
11774
12840
  super(...arguments);
@@ -11776,93 +12842,76 @@ class BridgesPrinter extends InteropPrinter {
11776
12842
  this.Void = new PrimitiveType(`void`);
11777
12843
  }
11778
12844
  }());
11779
- this.returnTypeConvertor = new ReturnTypeConvertor$1(this.typechecker);
11780
- this.interopMacroConvertor = new InteropMacroTypeConvertor(this.typechecker);
11781
- }
11782
- printInteropMacro(methodName, signature) {
11783
- this.writer.writeExpressionStatement(this.writer.makeFunctionCall(BridgesConstructions.interopMacro(isVoidType(signature.returnType), signature.args.length), [methodName]
11784
- .concat((() => {
11785
- if (isVoidType(signature.returnType)) {
11786
- return [];
11787
- }
11788
- return [this.returnTypeConvertor.convertType(signature.returnType)];
11789
- })()
11790
- .concat(signature.args)
11791
- .map(it => this.interopMacroConvertor.convertType(it)))
11792
- .map(it => this.writer.makeString(it))));
11793
12845
  }
11794
12846
  printMethod(iface, node) {
12847
+ if (this.config.ignore.isIgnoredMethod(iface.name, node.name))
12848
+ return;
11795
12849
  const [methodName, signature] = BridgesPrinter.makeFunctionDeclaration(iface, node, this.returnTypeConvertor);
11796
- this.writer.writeFunctionImplementation(BridgesConstructions.implFunction(methodName), signature, (_) => this.printBody(iface, node, signature));
12850
+ this.writer.writeFunctionImplementation(BridgesConstructions.implFunction(methodName), signature, (_) => {
12851
+ let pandaMethodName = BridgesConstructions.callMethod(methodName);
12852
+ if (this.config.irHack.isIrHackInterface(iface.name)) {
12853
+ pandaMethodName = pandaMethodName.replace(iface.name, `${iface.name}Ir`);
12854
+ }
12855
+ this.printBody(node, signature, pandaMethodName);
12856
+ });
11797
12857
  this.printInteropMacro(methodName, signature);
11798
12858
  this.writer.writeLines(``);
11799
12859
  }
12860
+ printInteropMacro(methodName, signature) {
12861
+ const isVoid = isVoidType(signature.returnType);
12862
+ const args = (isVoid ? [] : [signature.returnType])
12863
+ .concat(signature.args)
12864
+ .map(a => this.interopMacroConvertor.convertType(a));
12865
+ args.splice(0, 0, methodName);
12866
+ this.writer.writeExpressionStatement(this.writer.makeFunctionCall(BridgesConstructions.interopMacro(isVoid, signature.args.length), args.map(it => this.writer.makeString(it))));
12867
+ }
11800
12868
  static makeFunctionDeclaration(iface, node, converter) {
11801
12869
  var _a;
11802
- 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)));
11803
- if (!isCreateOrUpdate(node.name)) {
12870
+ const signature = makeSignature(node.parameters.map(p => ({
12871
+ name: mangleIfKeyword(p.name),
12872
+ type: p.type,
12873
+ isOptional: p.isOptional
12874
+ })), converter.convertType(node.returnType));
12875
+ if (!isCreateOrUpdate(node.name) && !isImplInterface(iface.name)) {
11804
12876
  signature.args.splice(1, 0, createReferenceType(iface.name));
11805
12877
  signature.argNames.splice(1, 0, 'receiver');
11806
12878
  }
11807
12879
  const fixArgName = (name, prev) => name.endsWith('Len') ? (prev !== null && prev !== void 0 ? prev : name.slice(0, -3)) + 'SequenceLength' : name === 'ctx' ? 'context' : name;
11808
12880
  // Not necessary, just to keep old names
11809
12881
  signature.argNames = (_a = signature.argNames) === null || _a === void 0 ? void 0 : _a.map((v, i) => fixArgName(v, i === 0 ? undefined : signature.argNames[i - 1]));
11810
- return [InteropConstructions.method(iface.name, node.name), signature];
11811
- }
11812
- printBody(iface, node, signature) {
11813
- this.printParameters(signature);
11814
- this.printDeclarations(node);
11815
- this.printEs2pandaCall(iface, node, signature);
11816
- this.printReturn(node);
11817
- }
11818
- printParameters(signature) {
11819
- signature.args.forEach((type, index) => {
11820
- var _a, _b;
11821
- const name = (_b = (_a = signature.argNames) === null || _a === void 0 ? void 0 : _a.at(index)) !== null && _b !== void 0 ? _b : `arg${index}`;
11822
- this.writer.writeStatement(this.writer.makeAssign(BridgesConstructions.castedParameter(name), undefined, this.writer.makeFunctionCall(this.castTypeConvertor.convertType(type), [this.writer.makeString(name)])));
11823
- });
12882
+ const methodName = isImplInterface(iface.name) ? node.name : InteropConstructions.method(iface.name, node.name);
12883
+ return [methodName, signature];
11824
12884
  }
11825
- printDeclarations(node) {
12885
+ printBody(node, signature, pandaMethodName) {
12886
+ const writer = this.writer;
12887
+ const argNames = signature.argNames.map(BridgesConstructions.castedParameter);
12888
+ 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))])));
11826
12889
  if (isSequence(node.returnType)) {
11827
- this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.sequenceLengthDeclaration));
12890
+ argNames.push(BridgesConstructions.sequenceLengthPass);
12891
+ statements.push(makeStatement(writer, BridgesConstructions.sequenceLengthDeclaration));
11828
12892
  }
11829
- }
11830
- printEs2pandaCall(iface, node, signature) {
12893
+ const nativeCall = writer.makeFunctionCall(pandaMethodName, argNames.map(a => writer.makeString(a)));
12894
+ writer.writeStatements(...statements);
11831
12895
  if (isVoidType(node.returnType)) {
11832
- this.writer.writeExpressionStatement(this.makeEs2pandaMethodCall(iface, node, signature));
11833
- return;
12896
+ writer.writeStatements(writer.makeStatement(nativeCall), writer.makeReturn(writer.makeString('')));
11834
12897
  }
11835
- this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.resultAssignment(this.makeEs2pandaMethodCall(iface, node, signature).asString())));
11836
- }
11837
- makeEs2pandaMethodCall(iface, node, signature) {
11838
- let suffix = this.config.irHack.isIrHackInterface(iface.name) ? 'Ir' : '';
11839
- let method = BridgesConstructions.callMethod(InteropConstructions.method(iface.name, node.name));
11840
- method = method.replace(iface.name, iface.name + suffix);
11841
- return this.writer.makeFunctionCall(method, signature.argNames
11842
- .map(it => ({
11843
- asString: () => BridgesConstructions.castedParameter(it),
11844
- }))
11845
- .concat(isSequence(node.returnType) // XXX: original return type
11846
- ? this.writer.makeString(BridgesConstructions.sequenceLengthPass)
11847
- : []));
11848
- }
11849
- printReturn(node) {
11850
- if (isVoidType(node.returnType)) {
11851
- this.writer.writeStatement(this.writer.makeReturn(this.writer.makeString(``)));
11852
- return;
12898
+ else {
12899
+ writer.writeStatements(writer.makeAssign(BridgesConstructions.result, undefined, nativeCall, true, false), writer.makeReturn(this.makeReturnExpression(node)));
11853
12900
  }
11854
- this.writer.writeStatement(this.writer.makeReturn(this.writer.makeString(this.maybeDropConst(this.makeReturnExpression(node.returnType), node))));
11855
12901
  }
11856
- makeReturnExpression(returnType) {
11857
- if (isSequence(returnType)) {
11858
- return BridgesConstructions.sequenceConstructor(BridgesConstructions.result, BridgesConstructions.sequenceLengthUsage);
11859
- }
11860
- if (isString(returnType)) {
11861
- return BridgesConstructions.stringConstructor(BridgesConstructions.result);
12902
+ makeReturnExpression(node) {
12903
+ const makeStringCtor = () => BridgesConstructions.stringConstructor(BridgesConstructions.result);
12904
+ const makeSequenceCtor = () => BridgesConstructions.sequenceConstructor(BridgesConstructions.result, BridgesConstructions.sequenceLengthUsage);
12905
+ const expr = this.maybeDropConst(node, isSequence(node.returnType) ? makeSequenceCtor() :
12906
+ isString(node.returnType) ? makeStringCtor() :
12907
+ BridgesConstructions.result);
12908
+ if (isSequence(node.returnType)) {
12909
+ // writer.makeTernary annoys by adding the extra parentheses
12910
+ return this.writer.makeString(`${BridgesConstructions.sequenceLengthUsage} ? ${expr} : nullptr`);
11862
12911
  }
11863
- return BridgesConstructions.result;
12912
+ return this.writer.makeString(expr);
11864
12913
  }
11865
- maybeDropConst(value, node) {
12914
+ maybeDropConst(node, value) {
11866
12915
  if (this.typechecker.isConstReturnValue(node)) {
11867
12916
  return BridgesConstructions.dropConstCast(value);
11868
12917
  }
@@ -11948,10 +12997,10 @@ class IndexPrinter extends SingleFilePrinter {
11948
12997
  this.writer = createDefaultTypescriptWriter();
11949
12998
  }
11950
12999
  filterInterface(node) {
11951
- return !this.typechecker.isPeer(node.name);
13000
+ return !this.typechecker.isPeer(node) || Config.DoNotPrintPeers.includes(fqName(node));
11952
13001
  }
11953
13002
  printInterface(node) {
11954
- this.writer.writeExpressionStatement(this.writer.makeString(`export * from "./peers/${node.name}"`));
13003
+ this.writer.writeExpressionStatement(this.writer.makeString(`export * from "./peers/${dropPrefix(node.name, Config.dataClassPrefix)}"`));
11955
13004
  }
11956
13005
  }
11957
13006
 
@@ -12091,7 +13140,7 @@ class MultiFilePrinter extends AbstractVisitor {
12091
13140
  constructor(idl) {
12092
13141
  super();
12093
13142
  this.idl = idl;
12094
- this.typechecker = new Typechecker(this.idl.entries);
13143
+ this.typechecker = new Typechecker(this.idl);
12095
13144
  this.output = [];
12096
13145
  }
12097
13146
  visit(node) {
@@ -12121,15 +13170,15 @@ class MultiFilePrinter extends AbstractVisitor {
12121
13170
  * limitations under the License.
12122
13171
  */
12123
13172
  class PeersConstructions {
13173
+ static peerName(name) {
13174
+ return dropPrefix(name, Config.dataClassPrefix);
13175
+ }
12124
13176
  static fileName(node) {
12125
- return `${node}.ts`;
13177
+ return `${this.peerName(node)}.ts`;
12126
13178
  }
12127
13179
  static get pointerParameter() {
12128
13180
  return `pointer`;
12129
13181
  }
12130
- static get validatePeer() {
12131
- return `assertValidPeer`;
12132
- }
12133
13182
  static get super() {
12134
13183
  return `super`;
12135
13184
  }
@@ -12148,8 +13197,8 @@ class PeersConstructions {
12148
13197
  name: parameter,
12149
13198
  type: `object | undefined`
12150
13199
  },
12151
- returnType: (type) => `${parameter} is ${type}`,
12152
- body: (type) => `${parameter} instanceof ${type}`
13200
+ returnType: (type) => `${parameter} is ${PeersConstructions.peerName(type)}`,
13201
+ body: (type) => `${parameter} instanceof ${PeersConstructions.peerName(type)}`
12153
13202
  };
12154
13203
  }
12155
13204
  static get unpackNullable() {
@@ -12204,13 +13253,13 @@ class PeersConstructions {
12204
13253
  return `setChildrenParentPtr`;
12205
13254
  }
12206
13255
  static newOf(iface) {
12207
- return `new ${iface}`;
13256
+ return `new ${this.peerName(iface)}`;
12208
13257
  }
12209
13258
  static callPeerMethod(iface, method) {
12210
13259
  return `${iface}.${method}`;
12211
13260
  }
12212
13261
  static brand(iface) {
12213
- return `brand${capitalize(iface)}`;
13262
+ return `brand${capitalize(this.peerName(iface))}`;
12214
13263
  }
12215
13264
  }
12216
13265
 
@@ -12245,9 +13294,8 @@ class Importer {
12245
13294
  if (this.seen.has(it)) {
12246
13295
  return it;
12247
13296
  }
12248
- if (!this.typechecker.isPeer(it)) {
12249
- return it;
12250
- }
13297
+ // the 'it' parameter can be a modified peer name
13298
+ // and therefor cannot be resolved here
12251
13299
  this.seen.add(it);
12252
13300
  this.import(it, it);
12253
13301
  return it;
@@ -12355,34 +13403,24 @@ class LibraryTypeConvertor extends TopLevelTypeConvertor {
12355
13403
  * See the License for the specific language governing permissions and
12356
13404
  * limitations under the License.
12357
13405
  */
12358
- class ImporterTypeConvertor extends TopLevelTypeConvertor {
12359
- constructor(importer, typechecker) {
12360
- super(typechecker, {
12361
- optional: (type) => {
12362
- this.convertType(type.type);
12363
- return type;
12364
- },
12365
- sequence: (type) => {
12366
- this.convertType(type.elementType[0]);
12367
- return type;
12368
- },
12369
- enum: (type) => {
12370
- this.importer.withEnumImport(type.name);
12371
- return type;
12372
- },
12373
- reference: (type) => {
12374
- this.importer.withPeerImport(baseName(type));
12375
- return type;
12376
- },
12377
- string: (type) => type,
12378
- number: (type) => type,
12379
- boolean: (type) => type,
12380
- void: (type) => type,
12381
- pointer: (type) => type,
12382
- undefined: (type) => type
12383
- });
12384
- this.importer = importer;
13406
+ function convertAndImport(importer, converter, type) {
13407
+ const result = converter.convertType(type);
13408
+ if (isOptionalType(type)) {
13409
+ convertAndImport(importer, converter, type.type);
13410
+ }
13411
+ else if (isContainerType(type) && IDLContainerUtils.isSequence(type)) {
13412
+ convertAndImport(importer, converter, type.elementType[0]);
13413
+ }
13414
+ else if (isReferenceType(type)) {
13415
+ const node = converter.typechecker.resolveReference(type);
13416
+ if (node && isEnum$1(node)) {
13417
+ importer.withEnumImport(result);
13418
+ }
13419
+ else if (node && isInterface$1(node) && converter.typechecker.isPeer(node)) {
13420
+ importer.withPeerImport(result);
13421
+ }
12385
13422
  }
13423
+ return result;
12386
13424
  }
12387
13425
 
12388
13426
  /*
@@ -12445,12 +13483,12 @@ class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
12445
13483
  super(typechecker, {
12446
13484
  sequence: (type) => wrap(PeersConstructions.arrayOfPointersToArrayOfPeers),
12447
13485
  string: (type) => wrap(PeersConstructions.receiveString),
12448
- reference: (type) => this.typechecker.isHeir(type.name, Config.astNodeCommonAncestor)
13486
+ reference: (type) => this.typechecker.isHeir(type, Config.astNodeCommonAncestor)
12449
13487
  ? wrap(PeersConstructions.unpackNonNullable)
12450
13488
  : wrap(baseNameString(type.name)),
12451
13489
  optional: (type) => {
12452
13490
  if (isReferenceType(type.type)) {
12453
- if (this.typechecker.isHeir(type.type.name, Config.astNodeCommonAncestor)) {
13491
+ if (this.typechecker.isHeir(type.type, Config.astNodeCommonAncestor)) {
12454
13492
  return wrap(PeersConstructions.unpackNullable);
12455
13493
  }
12456
13494
  return wrap(PeersConstructions.newOf(baseNameString(type.type.name)));
@@ -12501,16 +13539,20 @@ class PeerPrinter extends SingleFilePrinter {
12501
13539
  super(idl);
12502
13540
  this.config = config;
12503
13541
  this.node = node;
12504
- this.typechecker = new Typechecker(this.idl.entries);
13542
+ this.typechecker = new Typechecker(this.idl);
12505
13543
  this.importer = new Importer(this.typechecker, `.`, this.node.name);
12506
13544
  this.bindingParameterTypeConvertor = new BindingParameterTypeConvertor(this.typechecker);
12507
13545
  this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker);
12508
13546
  this.parent = (_a = parent(this.node)) !== null && _a !== void 0 ? _a : Config.defaultAncestor;
12509
- this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
12510
- });
13547
+ this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => convertAndImport(this.importer, new class extends LibraryTypeConvertor {
13548
+ convertTypeReference(type) {
13549
+ return dropPrefix(super.convertTypeReference(type), Config.dataClassPrefix);
13550
+ }
13551
+ }(this.typechecker), node) });
12511
13552
  }
12512
13553
  printPeer() {
12513
- this.writer.writeClass(this.node.name, () => this.printBody(), this.parent ? this.importer.withPeerImport(baseNameString(this.parent)) : undefined);
13554
+ this.writer.writeClass(PeersConstructions.peerName(this.node.name), // XXX: Change peer name
13555
+ () => this.printBody(), this.parent ? this.importer.withPeerImport(baseNameString(this.parent)) : undefined);
12514
13556
  }
12515
13557
  printBody() {
12516
13558
  this.printConstructor();
@@ -12519,21 +13561,16 @@ class PeerPrinter extends SingleFilePrinter {
12519
13561
  this.printBrand();
12520
13562
  }
12521
13563
  printConstructor() {
12522
- this.writer.writeConstructorImplementation(this.node.name, new MethodSignature(IDLVoidType, [
12523
- IDLPointerType
12524
- ], undefined, undefined, undefined, [
12525
- PeersConstructions.pointerParameter
12526
- ]), () => {
12527
- var _a;
12528
- if (isReal(this.node)) {
12529
- this.writer.writeExpressionStatement(this.writer.makeFunctionCall(PeersConstructions.validatePeer, [
12530
- this.writer.makeString(PeersConstructions.pointerParameter),
12531
- this.writer.makeString((_a = nodeType(this.node)) !== null && _a !== void 0 ? _a : throwException(`missing attribute node type: ${this.node.name}`)),
12532
- ]));
12533
- }
12534
- this.writer.writeExpressionStatements(this.writer.makeFunctionCall(PeersConstructions.super, [
12535
- this.writer.makeString(PeersConstructions.pointerParameter)
12536
- ]));
13564
+ isReal(this.node);
13565
+ const isAstNodeDescendant = this.typechecker.isHeir(this.node, Config.astNodeCommonAncestor);
13566
+ const args = [IDLPointerType];
13567
+ const argNames = [PeersConstructions.pointerParameter];
13568
+ if (isAstNodeDescendant) {
13569
+ args.push(createReferenceType(Config.nodeTypeAttribute));
13570
+ argNames.push('astNodeType');
13571
+ }
13572
+ this.writer.writeConstructorImplementation(this.node.name, new MethodSignature(IDLVoidType, args, undefined, undefined, undefined, argNames), () => {
13573
+ this.writer.writeExpressionStatements(this.writer.makeFunctionCall(PeersConstructions.super, argNames.map(n => this.writer.makeString(n))));
12537
13574
  });
12538
13575
  }
12539
13576
  printTypeGuard() {
@@ -12546,7 +13583,10 @@ class PeerPrinter extends SingleFilePrinter {
12546
13583
  if (isCreateOrUpdate(it.name)) {
12547
13584
  // TODO: This condition is not clear - classes with c_type attribute
12548
13585
  // is not abstract too, is it?
13586
+ // The check for a native type allows types that is descendants of
13587
+ // AstNode but have not type attribute, for example, varbinder.FunctionDecl
12549
13588
  if (isAbstract(this.node) && nativeType(this.node) === undefined) {
13589
+ console.log(`Skipped ${this.node.name}.${it.name}`);
12550
13590
  return;
12551
13591
  }
12552
13592
  return this.printCreateOrUpdate(it);
@@ -12651,18 +13691,19 @@ class PeerPrinter extends SingleFilePrinter {
12651
13691
  this.writer.writeMethodImplementation(makeMethod(PeersConstructions.createOrUpdate(this.node.name, node.name), node.parameters
12652
13692
  .map(it => createParameter(it.name, flattenType(it.type)))
12653
13693
  .concat(extraParameters), flattenType(node.returnType), [MethodModifier.STATIC]), (writer) => {
12654
- const newExpr = this.writer.makeNewObject(this.node.name, [
12655
- this.writer.makeFunctionCall(this.writer.makeString(PeersConstructions.callBinding(this.node.name, node.name, nodeNamespace(this.node))), this.makeBindingArguments(node.parameters)),
12656
- ]);
13694
+ var _a;
13695
+ const nativeCall = this.writer.makeFunctionCall(this.writer.makeString(PeersConstructions.callBinding(this.node.name, node.name, nodeNamespace(this.node))), this.makeBindingArguments(node.parameters));
12657
13696
  const varName = 'result';
12658
13697
  const makeStmt = (property) => PeerPrinter.makeExtraStatement(property, PeerPrinter.resolveProperty(property, this.node, this.idl), ['should_not_be_here', varName], this.writer);
12659
13698
  const extraStatements = this.config.parameters.getParameters(this.node.name)
12660
13699
  .map(makeStmt);
12661
13700
  if (isReal(this.node)) {
13701
+ const astNodeType = (_a = this.typechecker.nodeTypeName(this.node)) !== null && _a !== void 0 ? _a : throwException(`missing attribute node type: ${this.node.name}`);
13702
+ const newExpr = writer.makeNewObject(this.node.name, [nativeCall, writer.makeString(astNodeType)]);
12662
13703
  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)));
12663
13704
  }
12664
13705
  else {
12665
- this.writer.writeStatement(this.writer.makeReturn(newExpr));
13706
+ writer.writeStatement(writer.makeReturn(writer.makeNewObject(this.node.name, [nativeCall])));
12666
13707
  }
12667
13708
  });
12668
13709
  }
@@ -12680,8 +13721,8 @@ class PeerPrinter extends SingleFilePrinter {
12680
13721
  if (enumValue === undefined) {
12681
13722
  return;
12682
13723
  }
12683
- const qualified = `${this.importer.withEnumImport(Config.nodeTypeAttribute)}.${enumValue}`;
12684
- 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(`}`));
13724
+ this.importer.withEnumImport(Config.nodeTypeAttribute);
13725
+ 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(`}`));
12685
13726
  }
12686
13727
  printBrand() {
12687
13728
  this.writer.writeProperty(PeersConstructions.brand(this.node.name), IDLUndefinedType, [FieldModifier.PROTECTED, FieldModifier.READONLY]);
@@ -12708,7 +13749,7 @@ class AllPeersPrinter extends MultiFilePrinter {
12708
13749
  this.config = config;
12709
13750
  }
12710
13751
  filterInterface(node) {
12711
- return !this.typechecker.isPeer(node.name);
13752
+ return !this.typechecker.isPeer(node) || Config.DoNotPrintPeers.includes(fqName(node));
12712
13753
  }
12713
13754
  printInterface(node) {
12714
13755
  return {
@@ -12772,8 +13813,7 @@ class FactoryPrinter extends SingleFilePrinter {
12772
13813
  super(idl);
12773
13814
  this.config = config;
12774
13815
  this.importer = new Importer(this.typechecker, `peers`);
12775
- this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
12776
- });
13816
+ this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => convertAndImport(this.importer, new LibraryTypeConvertor(this.typechecker), node) });
12777
13817
  }
12778
13818
  prologue() {
12779
13819
  this.writer.writeExpressionStatements(this.writer.makeString(FactoryConstructions.prologue));
@@ -12784,7 +13824,7 @@ class FactoryPrinter extends SingleFilePrinter {
12784
13824
  this.writer.writeExpressionStatements(this.writer.makeString(FactoryConstructions.epilogue));
12785
13825
  }
12786
13826
  filterInterface(node) {
12787
- return !this.typechecker.isPeer(node.name) || FactoryPrinter.getUniversalCreate(node) == undefined;
13827
+ return !this.typechecker.isPeer(node) || FactoryPrinter.getUniversalCreate(node) == undefined;
12788
13828
  }
12789
13829
  printInterface(node) {
12790
13830
  this.printCreate(node);
@@ -12915,7 +13955,7 @@ class Transformer {
12915
13955
  class BaseInterfaceFilterTransformer extends Transformer {
12916
13956
  constructor(file, removeNamespaces = false) {
12917
13957
  super(file, removeNamespaces);
12918
- this.typechecker = new Typechecker(this.file.entries);
13958
+ this.typechecker = new Typechecker(this.file);
12919
13959
  }
12920
13960
  transformInterface(entry) {
12921
13961
  if (this.shouldFilterOutInterface(entry)) {
@@ -12933,7 +13973,7 @@ class BaseInterfaceFilterTransformer extends Transformer {
12933
13973
  .map(innerTypeIfContainer)
12934
13974
  .filter(it => {
12935
13975
  if (isReferenceType(it)) {
12936
- const decl = this.typechecker.findRealDeclaration(it.name);
13976
+ const decl = this.typechecker.resolveReference(it);
12937
13977
  if (!decl || isInterface$1(decl) && predicate(decl)) {
12938
13978
  return true;
12939
13979
  }
@@ -12975,77 +14015,6 @@ class OptionsFilterTransformer extends BaseInterfaceFilterTransformer {
12975
14015
  }
12976
14016
  }
12977
14017
 
12978
- /*
12979
- * Copyright (c) 2024 Huawei Device Co., Ltd.
12980
- * Licensed under the Apache License, Version 2.0 (the "License");
12981
- * you may not use this file except in compliance with the License.
12982
- * You may obtain a copy of the License at
12983
- *
12984
- * http://www.apache.org/licenses/LICENSE-2.0
12985
- *
12986
- * Unless required by applicable law or agreed to in writing, software
12987
- * distributed under the License is distributed on an "AS IS" BASIS,
12988
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12989
- * See the License for the specific language governing permissions and
12990
- * limitations under the License.
12991
- */
12992
- class AddContextDeclarationTransformer extends Transformer {
12993
- constructor(file) {
12994
- super(file);
12995
- }
12996
- transformInterface(entry) {
12997
- return entry;
12998
- }
12999
- transformed() {
13000
- let file = createFile(this.file.entries
13001
- .concat(createInterface(Config.context, IDLInterfaceSubkind.Class, undefined, undefined, undefined, undefined, undefined, undefined, undefined, {
13002
- extendedAttributes: [{
13003
- name: Config.nodeNamespaceAttribute,
13004
- value: Config.irNamespace
13005
- }]
13006
- })), this.file.fileName, this.file.packageClause);
13007
- return linkParentBack(file);
13008
- }
13009
- }
13010
-
13011
- /*
13012
- * Copyright (c) 2024 Huawei Device Co., Ltd.
13013
- * Licensed under the Apache License, Version 2.0 (the "License");
13014
- * you may not use this file except in compliance with the License.
13015
- * You may obtain a copy of the License at
13016
- *
13017
- * http://www.apache.org/licenses/LICENSE-2.0
13018
- *
13019
- * Unless required by applicable law or agreed to in writing, software
13020
- * distributed under the License is distributed on an "AS IS" BASIS,
13021
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13022
- * See the License for the specific language governing permissions and
13023
- * limitations under the License.
13024
- */
13025
- class MultipleDeclarationFilterTransformer extends Transformer {
13026
- constructor(file) {
13027
- super(file);
13028
- this.seen = new Map();
13029
- // TODO: namespaces
13030
- linearizeNamespaceMembers(this.file.entries).forEach(it => {
13031
- var _a;
13032
- let name = baseNameString(it.name);
13033
- const oldValue = (_a = this.seen.get(name)) !== null && _a !== void 0 ? _a : 0;
13034
- this.seen.set(name, oldValue + 1);
13035
- });
13036
- }
13037
- transformInterface(entry) {
13038
- var _a;
13039
- const occurence = (_a = this.seen.get(baseNameString(entry.name))) !== null && _a !== void 0 ? _a : 0;
13040
- if (occurence > 1 && !isIrNamespace(entry)) {
13041
- console.log(`FILTERED (MULTIPLE) ${entry.name}`);
13042
- this.seen.set(baseNameString(entry.name), occurence - 1);
13043
- return undefined;
13044
- }
13045
- return entry;
13046
- }
13047
- }
13048
-
13049
14018
  /*
13050
14019
  * Copyright (c) 2024 Huawei Device Co., Ltd.
13051
14020
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13087,120 +14056,6 @@ class ParameterTransformer extends Transformer {
13087
14056
  }
13088
14057
  }
13089
14058
 
13090
- /*
13091
- * Copyright (c) 2024 Huawei Device Co., Ltd.
13092
- * Licensed under the Apache License, Version 2.0 (the "License");
13093
- * you may not use this file except in compliance with the License.
13094
- * You may obtain a copy of the License at
13095
- *
13096
- * http://www.apache.org/licenses/LICENSE-2.0
13097
- *
13098
- * Unless required by applicable law or agreed to in writing, software
13099
- * distributed under the License is distributed on an "AS IS" BASIS,
13100
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13101
- * See the License for the specific language governing permissions and
13102
- * limitations under the License.
13103
- */
13104
- class TwinMergeTransformer extends Transformer {
13105
- constructor(file) {
13106
- super(file);
13107
- const all = linearizeNamespaceMembers(file.entries).filter(isInterface$1);
13108
- this.twins = new Set();
13109
- all
13110
- .filter(it => this.hasPrefix(it.name))
13111
- .forEach(it => {
13112
- const twin = all.find(candidate => this.withPrefix(baseNameString(candidate.name)) === it.name);
13113
- if (twin === undefined)
13114
- return;
13115
- if (!isIrNamespace(twin))
13116
- return;
13117
- this.twins.add(twin.name);
13118
- });
13119
- }
13120
- hasTwin(name) {
13121
- name = baseNameString(name);
13122
- if (this.hasPrefix(name)) {
13123
- return this.twins.has(this.withoutPrefix(name));
13124
- }
13125
- return this.twins.has(name);
13126
- }
13127
- transformInterface(node) {
13128
- if (node.name === Config.astNodeCommonAncestor) { // TODO: is handwritten
13129
- return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)));
13130
- }
13131
- if (this.hasTwin(node.name) && this.hasPrefix(node.name)) {
13132
- return undefined;
13133
- }
13134
- if (this.hasTwin(node.name) || this.hasPrefix(node.name)) {
13135
- return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)), this.withoutPrefix(node.name), [createReferenceType(Config.defaultAncestor)]);
13136
- }
13137
- return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)));
13138
- }
13139
- transformMethod(node) {
13140
- return createUpdatedMethod(node, this.withoutPrefix(node.name), node.parameters.map(it => this.transformParameter(it)), this.transformType(node.returnType));
13141
- }
13142
- transformParameter(node) {
13143
- return createParameter(this.withoutPrefix(node.name), this.transformType(node.type), node.isOptional, node.isVariadic);
13144
- }
13145
- transformType(node) {
13146
- if (isContainerType(node)) {
13147
- if (isSequence(node)) {
13148
- return createSequence(this.transformType(innerType(node)));
13149
- }
13150
- }
13151
- if (isReferenceType(node)) {
13152
- return createReferenceType(this.withoutPrefix(node.name), node.typeArguments);
13153
- }
13154
- return node;
13155
- }
13156
- withoutPrefix(name) {
13157
- if (name.startsWith(Config.dataClassPrefix)) {
13158
- return name.slice(Config.dataClassPrefix.length);
13159
- }
13160
- return name;
13161
- }
13162
- withPrefix(name) {
13163
- return `${Config.dataClassPrefix}${name}`;
13164
- }
13165
- hasPrefix(name) {
13166
- return name.startsWith(Config.dataClassPrefix);
13167
- }
13168
- }
13169
-
13170
- /*
13171
- * Copyright (c) 2024 Huawei Device Co., Ltd.
13172
- * Licensed under the Apache License, Version 2.0 (the "License");
13173
- * you may not use this file except in compliance with the License.
13174
- * You may obtain a copy of the License at
13175
- *
13176
- * http://www.apache.org/licenses/LICENSE-2.0
13177
- *
13178
- * Unless required by applicable law or agreed to in writing, software
13179
- * distributed under the License is distributed on an "AS IS" BASIS,
13180
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13181
- * See the License for the specific language governing permissions and
13182
- * limitations under the License.
13183
- */
13184
- class AstNodeFilterTransformer extends BaseInterfaceFilterTransformer {
13185
- constructor(idl) {
13186
- super(idl, true);
13187
- }
13188
- shouldFilterOutInterface(node) {
13189
- if (this.typechecker.isHeir(node.name, Config.astNodeCommonAncestor))
13190
- return false;
13191
- if (this.typechecker.isHeir(node.name, Config.defaultAncestor))
13192
- return false;
13193
- console.log(`FILTERED (AST) ${node.name}`);
13194
- return true;
13195
- }
13196
- shouldFilterOutMethod(node, name) {
13197
- return false;
13198
- }
13199
- shouldFilterOutProperty(node, name) {
13200
- return false;
13201
- }
13202
- }
13203
-
13204
14059
  /*
13205
14060
  * Copyright (c) 2024 Huawei Device Co., Ltd.
13206
14061
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13219,7 +14074,7 @@ class NullabilityTransformer extends Transformer {
13219
14074
  constructor(file, config) {
13220
14075
  super(file);
13221
14076
  this.config = config;
13222
- this.typechecker = new Typechecker(this.file.entries);
14077
+ this.typechecker = new Typechecker(this.file);
13223
14078
  }
13224
14079
  transformInterface(node) {
13225
14080
  return createUpdatedInterface(node, node.methods
@@ -13243,7 +14098,7 @@ class NullabilityTransformer extends Transformer {
13243
14098
  // TODO: maybe heirs of defaultAncestors aren't nullable
13244
14099
  // TODO: handwritten
13245
14100
  if (isReferenceType(type)) {
13246
- if (this.typechecker.isPeer(type.name) || type.name === Config.astNodeCommonAncestor) {
14101
+ if (this.typechecker.isPeer(type) || type.name === Config.astNodeCommonAncestor) {
13247
14102
  return createOptionalType(type);
13248
14103
  }
13249
14104
  }
@@ -13286,7 +14141,7 @@ function remove(array, value) {
13286
14141
  class AttributeTransformer extends Transformer {
13287
14142
  constructor(file) {
13288
14143
  super(file);
13289
- this.convertor = new LibraryTypeConvertor(new Typechecker(this.file.entries));
14144
+ this.convertor = new LibraryTypeConvertor(new Typechecker(this.file));
13290
14145
  }
13291
14146
  convertToKey(type) {
13292
14147
  if (isOptionalType(type)) {
@@ -13482,10 +14337,10 @@ class DynamicEmitter {
13482
14337
  let idl = this.file;
13483
14338
  this.printFile(this.enumsPrinter, idl);
13484
14339
  idl = this.withLog(new OptionsFilterTransformer(this.config, idl));
13485
- idl = this.withLog(new AddContextDeclarationTransformer(idl));
13486
- idl = this.withLog(new TwinMergeTransformer(idl));
13487
- idl = this.withLog(new MultipleDeclarationFilterTransformer(idl));
13488
- idl = this.withLog(new AstNodeFilterTransformer(idl));
14340
+ //idl = this.withLog(new AddContextDeclarationTransformer(idl))
14341
+ //idl = this.withLog(new TwinMergeTransformer(idl))
14342
+ //idl = this.withLog(new MultipleDeclarationFilterTransformer(idl))
14343
+ //idl = this.withLog(new AstNodeFilterTransformer(idl))
13489
14344
  this.printPeers(idl);
13490
14345
  this.printInterop(idl);
13491
14346
  }
@@ -13583,8 +14438,8 @@ class IgnoreOptions {
13583
14438
  this.ignored.set(ns, new Map());
13584
14439
  }
13585
14440
  const last = name.at(-1);
13586
- const key = last === '-' || last === '+' ? name.slice(0, -1) : name;
13587
- this.ignored.get(ns).set(key, last !== '+');
14441
+ const key = last === '!' ? name.slice(0, -last.length) : name;
14442
+ this.ignored.get(ns).set(key, last !== '!');
13588
14443
  });
13589
14444
  }
13590
14445
  isIgnoredMethod(iface, method) {
@@ -13595,9 +14450,13 @@ class IgnoreOptions {
13595
14450
  var _a;
13596
14451
  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)); });
13597
14452
  }
13598
- isIgnoredInterface(name, ns = '') {
14453
+ isIgnoredInterface(name, namespace = '') {
13599
14454
  var _a, _b;
13600
- return (_b = (_a = this.ignored.get(ns)) === null || _a === void 0 ? void 0 : _a.get(name)) !== null && _b !== void 0 ? _b : false;
14455
+ const ns = this.ignored.get(namespace);
14456
+ if (ns && ((_b = (_a = ns.get(name)) !== null && _a !== void 0 ? _a : ns.get('*')) !== null && _b !== void 0 ? _b : false)) {
14457
+ return true;
14458
+ }
14459
+ return false;
13601
14460
  }
13602
14461
  }
13603
14462
  // TODO: remove when interfaces fixed!