@microsoft/api-extractor 7.56.3 → 7.57.1

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 (299) hide show
  1. package/CHANGELOG.json +58 -0
  2. package/CHANGELOG.md +15 -1
  3. package/bin/api-extractor +1 -1
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib-esm/aedoc/PackageDocComment.js +56 -0
  6. package/lib-esm/aedoc/PackageDocComment.js.map +1 -0
  7. package/lib-esm/analyzer/AstDeclaration.js +214 -0
  8. package/lib-esm/analyzer/AstDeclaration.js.map +1 -0
  9. package/lib-esm/analyzer/AstEntity.js +35 -0
  10. package/lib-esm/analyzer/AstEntity.js.map +1 -0
  11. package/lib-esm/analyzer/AstImport.js +76 -0
  12. package/lib-esm/analyzer/AstImport.js.map +1 -0
  13. package/lib-esm/analyzer/AstModule.js +22 -0
  14. package/lib-esm/analyzer/AstModule.js.map +1 -0
  15. package/lib-esm/analyzer/AstNamespaceExport.js +38 -0
  16. package/lib-esm/analyzer/AstNamespaceExport.js.map +1 -0
  17. package/lib-esm/analyzer/AstNamespaceImport.js +57 -0
  18. package/lib-esm/analyzer/AstNamespaceImport.js.map +1 -0
  19. package/lib-esm/analyzer/AstReferenceResolver.js +202 -0
  20. package/lib-esm/analyzer/AstReferenceResolver.js.map +1 -0
  21. package/lib-esm/analyzer/AstSymbol.js +104 -0
  22. package/lib-esm/analyzer/AstSymbol.js.map +1 -0
  23. package/lib-esm/analyzer/AstSymbolTable.js +524 -0
  24. package/lib-esm/analyzer/AstSymbolTable.js.map +1 -0
  25. package/lib-esm/analyzer/ExportAnalyzer.js +725 -0
  26. package/lib-esm/analyzer/ExportAnalyzer.js.map +1 -0
  27. package/lib-esm/analyzer/PackageMetadataManager.js +235 -0
  28. package/lib-esm/analyzer/PackageMetadataManager.js.map +1 -0
  29. package/lib-esm/analyzer/SourceFileLocationFormatter.js +44 -0
  30. package/lib-esm/analyzer/SourceFileLocationFormatter.js.map +1 -0
  31. package/lib-esm/analyzer/Span.js +545 -0
  32. package/lib-esm/analyzer/Span.js.map +1 -0
  33. package/lib-esm/analyzer/SyntaxHelpers.js +72 -0
  34. package/lib-esm/analyzer/SyntaxHelpers.js.map +1 -0
  35. package/lib-esm/analyzer/TypeScriptHelpers.js +242 -0
  36. package/lib-esm/analyzer/TypeScriptHelpers.js.map +1 -0
  37. package/lib-esm/analyzer/TypeScriptInternals.js +114 -0
  38. package/lib-esm/analyzer/TypeScriptInternals.js.map +1 -0
  39. package/lib-esm/api/CompilerState.js +149 -0
  40. package/lib-esm/api/CompilerState.js.map +1 -0
  41. package/lib-esm/api/ConsoleMessageId.js +82 -0
  42. package/lib-esm/api/ConsoleMessageId.js.map +1 -0
  43. package/lib-esm/api/Extractor.js +290 -0
  44. package/lib-esm/api/Extractor.js.map +1 -0
  45. package/lib-esm/api/ExtractorConfig.js +801 -0
  46. package/lib-esm/api/ExtractorConfig.js.map +1 -0
  47. package/lib-esm/api/ExtractorLogLevel.js +46 -0
  48. package/lib-esm/api/ExtractorLogLevel.js.map +1 -0
  49. package/lib-esm/api/ExtractorMessage.js +140 -0
  50. package/lib-esm/api/ExtractorMessage.js.map +1 -0
  51. package/lib-esm/api/ExtractorMessageId.js +128 -0
  52. package/lib-esm/api/ExtractorMessageId.js.map +1 -0
  53. package/lib-esm/api/IConfigFile.js +4 -0
  54. package/lib-esm/api/IConfigFile.js.map +1 -0
  55. package/lib-esm/cli/ApiExtractorCommandLine.js +51 -0
  56. package/lib-esm/cli/ApiExtractorCommandLine.js.map +1 -0
  57. package/lib-esm/cli/InitAction.js +35 -0
  58. package/lib-esm/cli/InitAction.js.map +1 -0
  59. package/lib-esm/cli/RunAction.js +123 -0
  60. package/lib-esm/cli/RunAction.js.map +1 -0
  61. package/lib-esm/collector/ApiItemMetadata.js +55 -0
  62. package/lib-esm/collector/ApiItemMetadata.js.map +1 -0
  63. package/lib-esm/collector/Collector.js +794 -0
  64. package/lib-esm/collector/Collector.js.map +1 -0
  65. package/lib-esm/collector/CollectorEntity.js +219 -0
  66. package/lib-esm/collector/CollectorEntity.js.map +1 -0
  67. package/lib-esm/collector/DeclarationMetadata.js +24 -0
  68. package/lib-esm/collector/DeclarationMetadata.js.map +1 -0
  69. package/lib-esm/collector/MessageRouter.js +476 -0
  70. package/lib-esm/collector/MessageRouter.js.map +1 -0
  71. package/lib-esm/collector/SourceMapper.js +171 -0
  72. package/lib-esm/collector/SourceMapper.js.map +1 -0
  73. package/lib-esm/collector/SymbolMetadata.js +12 -0
  74. package/lib-esm/collector/SymbolMetadata.js.map +1 -0
  75. package/lib-esm/collector/VisitorState.js +23 -0
  76. package/lib-esm/collector/VisitorState.js.map +1 -0
  77. package/lib-esm/collector/WorkingPackage.js +30 -0
  78. package/lib-esm/collector/WorkingPackage.js.map +1 -0
  79. package/lib-esm/enhancers/DocCommentEnhancer.js +213 -0
  80. package/lib-esm/enhancers/DocCommentEnhancer.js.map +1 -0
  81. package/lib-esm/enhancers/ValidationEnhancer.js +217 -0
  82. package/lib-esm/enhancers/ValidationEnhancer.js.map +1 -0
  83. package/lib-esm/generators/ApiModelGenerator.js +852 -0
  84. package/lib-esm/generators/ApiModelGenerator.js.map +1 -0
  85. package/lib-esm/generators/ApiReportGenerator.js +518 -0
  86. package/lib-esm/generators/ApiReportGenerator.js.map +1 -0
  87. package/lib-esm/generators/DeclarationReferenceGenerator.js +292 -0
  88. package/lib-esm/generators/DeclarationReferenceGenerator.js.map +1 -0
  89. package/lib-esm/generators/DtsEmitHelpers.js +227 -0
  90. package/lib-esm/generators/DtsEmitHelpers.js.map +1 -0
  91. package/lib-esm/generators/DtsRollupGenerator.js +391 -0
  92. package/lib-esm/generators/DtsRollupGenerator.js.map +1 -0
  93. package/lib-esm/generators/ExcerptBuilder.js +259 -0
  94. package/lib-esm/generators/ExcerptBuilder.js.map +1 -0
  95. package/lib-esm/generators/IndentedWriter.js +238 -0
  96. package/lib-esm/generators/IndentedWriter.js.map +1 -0
  97. package/lib-esm/index.js +17 -0
  98. package/lib-esm/index.js.map +1 -0
  99. package/lib-esm/schemas/api-extractor-defaults.json +94 -0
  100. package/lib-esm/schemas/api-extractor-template.json +454 -0
  101. package/lib-esm/schemas/api-extractor.schema.json +257 -0
  102. package/lib-esm/start.js +14 -0
  103. package/lib-esm/start.js.map +1 -0
  104. package/package.json +37 -9
  105. /package/{lib → lib-commonjs}/aedoc/PackageDocComment.js +0 -0
  106. /package/{lib → lib-commonjs}/aedoc/PackageDocComment.js.map +0 -0
  107. /package/{lib → lib-commonjs}/analyzer/AstDeclaration.js +0 -0
  108. /package/{lib → lib-commonjs}/analyzer/AstDeclaration.js.map +0 -0
  109. /package/{lib → lib-commonjs}/analyzer/AstEntity.js +0 -0
  110. /package/{lib → lib-commonjs}/analyzer/AstEntity.js.map +0 -0
  111. /package/{lib → lib-commonjs}/analyzer/AstImport.js +0 -0
  112. /package/{lib → lib-commonjs}/analyzer/AstImport.js.map +0 -0
  113. /package/{lib → lib-commonjs}/analyzer/AstModule.js +0 -0
  114. /package/{lib → lib-commonjs}/analyzer/AstModule.js.map +0 -0
  115. /package/{lib → lib-commonjs}/analyzer/AstNamespaceExport.js +0 -0
  116. /package/{lib → lib-commonjs}/analyzer/AstNamespaceExport.js.map +0 -0
  117. /package/{lib → lib-commonjs}/analyzer/AstNamespaceImport.js +0 -0
  118. /package/{lib → lib-commonjs}/analyzer/AstNamespaceImport.js.map +0 -0
  119. /package/{lib → lib-commonjs}/analyzer/AstReferenceResolver.js +0 -0
  120. /package/{lib → lib-commonjs}/analyzer/AstReferenceResolver.js.map +0 -0
  121. /package/{lib → lib-commonjs}/analyzer/AstSymbol.js +0 -0
  122. /package/{lib → lib-commonjs}/analyzer/AstSymbol.js.map +0 -0
  123. /package/{lib → lib-commonjs}/analyzer/AstSymbolTable.js +0 -0
  124. /package/{lib → lib-commonjs}/analyzer/AstSymbolTable.js.map +0 -0
  125. /package/{lib → lib-commonjs}/analyzer/ExportAnalyzer.js +0 -0
  126. /package/{lib → lib-commonjs}/analyzer/ExportAnalyzer.js.map +0 -0
  127. /package/{lib → lib-commonjs}/analyzer/PackageMetadataManager.js +0 -0
  128. /package/{lib → lib-commonjs}/analyzer/PackageMetadataManager.js.map +0 -0
  129. /package/{lib → lib-commonjs}/analyzer/SourceFileLocationFormatter.js +0 -0
  130. /package/{lib → lib-commonjs}/analyzer/SourceFileLocationFormatter.js.map +0 -0
  131. /package/{lib → lib-commonjs}/analyzer/Span.js +0 -0
  132. /package/{lib → lib-commonjs}/analyzer/Span.js.map +0 -0
  133. /package/{lib → lib-commonjs}/analyzer/SyntaxHelpers.js +0 -0
  134. /package/{lib → lib-commonjs}/analyzer/SyntaxHelpers.js.map +0 -0
  135. /package/{lib → lib-commonjs}/analyzer/TypeScriptHelpers.js +0 -0
  136. /package/{lib → lib-commonjs}/analyzer/TypeScriptHelpers.js.map +0 -0
  137. /package/{lib → lib-commonjs}/analyzer/TypeScriptInternals.js +0 -0
  138. /package/{lib → lib-commonjs}/analyzer/TypeScriptInternals.js.map +0 -0
  139. /package/{lib → lib-commonjs}/api/CompilerState.js +0 -0
  140. /package/{lib → lib-commonjs}/api/CompilerState.js.map +0 -0
  141. /package/{lib → lib-commonjs}/api/ConsoleMessageId.js +0 -0
  142. /package/{lib → lib-commonjs}/api/ConsoleMessageId.js.map +0 -0
  143. /package/{lib → lib-commonjs}/api/Extractor.js +0 -0
  144. /package/{lib → lib-commonjs}/api/Extractor.js.map +0 -0
  145. /package/{lib → lib-commonjs}/api/ExtractorConfig.js +0 -0
  146. /package/{lib → lib-commonjs}/api/ExtractorConfig.js.map +0 -0
  147. /package/{lib → lib-commonjs}/api/ExtractorLogLevel.js +0 -0
  148. /package/{lib → lib-commonjs}/api/ExtractorLogLevel.js.map +0 -0
  149. /package/{lib → lib-commonjs}/api/ExtractorMessage.js +0 -0
  150. /package/{lib → lib-commonjs}/api/ExtractorMessage.js.map +0 -0
  151. /package/{lib → lib-commonjs}/api/ExtractorMessageId.js +0 -0
  152. /package/{lib → lib-commonjs}/api/ExtractorMessageId.js.map +0 -0
  153. /package/{lib → lib-commonjs}/api/IConfigFile.js +0 -0
  154. /package/{lib → lib-commonjs}/api/IConfigFile.js.map +0 -0
  155. /package/{lib → lib-commonjs}/cli/ApiExtractorCommandLine.js +0 -0
  156. /package/{lib → lib-commonjs}/cli/ApiExtractorCommandLine.js.map +0 -0
  157. /package/{lib → lib-commonjs}/cli/InitAction.js +0 -0
  158. /package/{lib → lib-commonjs}/cli/InitAction.js.map +0 -0
  159. /package/{lib → lib-commonjs}/cli/RunAction.js +0 -0
  160. /package/{lib → lib-commonjs}/cli/RunAction.js.map +0 -0
  161. /package/{lib → lib-commonjs}/collector/ApiItemMetadata.js +0 -0
  162. /package/{lib → lib-commonjs}/collector/ApiItemMetadata.js.map +0 -0
  163. /package/{lib → lib-commonjs}/collector/Collector.js +0 -0
  164. /package/{lib → lib-commonjs}/collector/Collector.js.map +0 -0
  165. /package/{lib → lib-commonjs}/collector/CollectorEntity.js +0 -0
  166. /package/{lib → lib-commonjs}/collector/CollectorEntity.js.map +0 -0
  167. /package/{lib → lib-commonjs}/collector/DeclarationMetadata.js +0 -0
  168. /package/{lib → lib-commonjs}/collector/DeclarationMetadata.js.map +0 -0
  169. /package/{lib → lib-commonjs}/collector/MessageRouter.js +0 -0
  170. /package/{lib → lib-commonjs}/collector/MessageRouter.js.map +0 -0
  171. /package/{lib → lib-commonjs}/collector/SourceMapper.js +0 -0
  172. /package/{lib → lib-commonjs}/collector/SourceMapper.js.map +0 -0
  173. /package/{lib → lib-commonjs}/collector/SymbolMetadata.js +0 -0
  174. /package/{lib → lib-commonjs}/collector/SymbolMetadata.js.map +0 -0
  175. /package/{lib → lib-commonjs}/collector/VisitorState.js +0 -0
  176. /package/{lib → lib-commonjs}/collector/VisitorState.js.map +0 -0
  177. /package/{lib → lib-commonjs}/collector/WorkingPackage.js +0 -0
  178. /package/{lib → lib-commonjs}/collector/WorkingPackage.js.map +0 -0
  179. /package/{lib → lib-commonjs}/enhancers/DocCommentEnhancer.js +0 -0
  180. /package/{lib → lib-commonjs}/enhancers/DocCommentEnhancer.js.map +0 -0
  181. /package/{lib → lib-commonjs}/enhancers/ValidationEnhancer.js +0 -0
  182. /package/{lib → lib-commonjs}/enhancers/ValidationEnhancer.js.map +0 -0
  183. /package/{lib → lib-commonjs}/generators/ApiModelGenerator.js +0 -0
  184. /package/{lib → lib-commonjs}/generators/ApiModelGenerator.js.map +0 -0
  185. /package/{lib → lib-commonjs}/generators/ApiReportGenerator.js +0 -0
  186. /package/{lib → lib-commonjs}/generators/ApiReportGenerator.js.map +0 -0
  187. /package/{lib → lib-commonjs}/generators/DeclarationReferenceGenerator.js +0 -0
  188. /package/{lib → lib-commonjs}/generators/DeclarationReferenceGenerator.js.map +0 -0
  189. /package/{lib → lib-commonjs}/generators/DtsEmitHelpers.js +0 -0
  190. /package/{lib → lib-commonjs}/generators/DtsEmitHelpers.js.map +0 -0
  191. /package/{lib → lib-commonjs}/generators/DtsRollupGenerator.js +0 -0
  192. /package/{lib → lib-commonjs}/generators/DtsRollupGenerator.js.map +0 -0
  193. /package/{lib → lib-commonjs}/generators/ExcerptBuilder.js +0 -0
  194. /package/{lib → lib-commonjs}/generators/ExcerptBuilder.js.map +0 -0
  195. /package/{lib → lib-commonjs}/generators/IndentedWriter.js +0 -0
  196. /package/{lib → lib-commonjs}/generators/IndentedWriter.js.map +0 -0
  197. /package/{lib → lib-commonjs}/index.js +0 -0
  198. /package/{lib → lib-commonjs}/index.js.map +0 -0
  199. /package/{lib → lib-commonjs}/schemas/api-extractor-defaults.json +0 -0
  200. /package/{lib → lib-commonjs}/schemas/api-extractor-template.json +0 -0
  201. /package/{lib → lib-commonjs}/schemas/api-extractor.schema.json +0 -0
  202. /package/{lib → lib-commonjs}/start.js +0 -0
  203. /package/{lib → lib-commonjs}/start.js.map +0 -0
  204. /package/{lib → lib-dts}/aedoc/PackageDocComment.d.ts +0 -0
  205. /package/{lib → lib-dts}/aedoc/PackageDocComment.d.ts.map +0 -0
  206. /package/{lib → lib-dts}/analyzer/AstDeclaration.d.ts +0 -0
  207. /package/{lib → lib-dts}/analyzer/AstDeclaration.d.ts.map +0 -0
  208. /package/{lib → lib-dts}/analyzer/AstEntity.d.ts +0 -0
  209. /package/{lib → lib-dts}/analyzer/AstEntity.d.ts.map +0 -0
  210. /package/{lib → lib-dts}/analyzer/AstImport.d.ts +0 -0
  211. /package/{lib → lib-dts}/analyzer/AstImport.d.ts.map +0 -0
  212. /package/{lib → lib-dts}/analyzer/AstModule.d.ts +0 -0
  213. /package/{lib → lib-dts}/analyzer/AstModule.d.ts.map +0 -0
  214. /package/{lib → lib-dts}/analyzer/AstNamespaceExport.d.ts +0 -0
  215. /package/{lib → lib-dts}/analyzer/AstNamespaceExport.d.ts.map +0 -0
  216. /package/{lib → lib-dts}/analyzer/AstNamespaceImport.d.ts +0 -0
  217. /package/{lib → lib-dts}/analyzer/AstNamespaceImport.d.ts.map +0 -0
  218. /package/{lib → lib-dts}/analyzer/AstReferenceResolver.d.ts +0 -0
  219. /package/{lib → lib-dts}/analyzer/AstReferenceResolver.d.ts.map +0 -0
  220. /package/{lib → lib-dts}/analyzer/AstSymbol.d.ts +0 -0
  221. /package/{lib → lib-dts}/analyzer/AstSymbol.d.ts.map +0 -0
  222. /package/{lib → lib-dts}/analyzer/AstSymbolTable.d.ts +0 -0
  223. /package/{lib → lib-dts}/analyzer/AstSymbolTable.d.ts.map +0 -0
  224. /package/{lib → lib-dts}/analyzer/ExportAnalyzer.d.ts +0 -0
  225. /package/{lib → lib-dts}/analyzer/ExportAnalyzer.d.ts.map +0 -0
  226. /package/{lib → lib-dts}/analyzer/PackageMetadataManager.d.ts +0 -0
  227. /package/{lib → lib-dts}/analyzer/PackageMetadataManager.d.ts.map +0 -0
  228. /package/{lib → lib-dts}/analyzer/SourceFileLocationFormatter.d.ts +0 -0
  229. /package/{lib → lib-dts}/analyzer/SourceFileLocationFormatter.d.ts.map +0 -0
  230. /package/{lib → lib-dts}/analyzer/Span.d.ts +0 -0
  231. /package/{lib → lib-dts}/analyzer/Span.d.ts.map +0 -0
  232. /package/{lib → lib-dts}/analyzer/SyntaxHelpers.d.ts +0 -0
  233. /package/{lib → lib-dts}/analyzer/SyntaxHelpers.d.ts.map +0 -0
  234. /package/{lib → lib-dts}/analyzer/TypeScriptHelpers.d.ts +0 -0
  235. /package/{lib → lib-dts}/analyzer/TypeScriptHelpers.d.ts.map +0 -0
  236. /package/{lib → lib-dts}/analyzer/TypeScriptInternals.d.ts +0 -0
  237. /package/{lib → lib-dts}/analyzer/TypeScriptInternals.d.ts.map +0 -0
  238. /package/{lib → lib-dts}/api/CompilerState.d.ts +0 -0
  239. /package/{lib → lib-dts}/api/CompilerState.d.ts.map +0 -0
  240. /package/{lib → lib-dts}/api/ConsoleMessageId.d.ts +0 -0
  241. /package/{lib → lib-dts}/api/ConsoleMessageId.d.ts.map +0 -0
  242. /package/{lib → lib-dts}/api/Extractor.d.ts +0 -0
  243. /package/{lib → lib-dts}/api/Extractor.d.ts.map +0 -0
  244. /package/{lib → lib-dts}/api/ExtractorConfig.d.ts +0 -0
  245. /package/{lib → lib-dts}/api/ExtractorConfig.d.ts.map +0 -0
  246. /package/{lib → lib-dts}/api/ExtractorLogLevel.d.ts +0 -0
  247. /package/{lib → lib-dts}/api/ExtractorLogLevel.d.ts.map +0 -0
  248. /package/{lib → lib-dts}/api/ExtractorMessage.d.ts +0 -0
  249. /package/{lib → lib-dts}/api/ExtractorMessage.d.ts.map +0 -0
  250. /package/{lib → lib-dts}/api/ExtractorMessageId.d.ts +0 -0
  251. /package/{lib → lib-dts}/api/ExtractorMessageId.d.ts.map +0 -0
  252. /package/{lib → lib-dts}/api/IConfigFile.d.ts +0 -0
  253. /package/{lib → lib-dts}/api/IConfigFile.d.ts.map +0 -0
  254. /package/{lib → lib-dts}/cli/ApiExtractorCommandLine.d.ts +0 -0
  255. /package/{lib → lib-dts}/cli/ApiExtractorCommandLine.d.ts.map +0 -0
  256. /package/{lib → lib-dts}/cli/InitAction.d.ts +0 -0
  257. /package/{lib → lib-dts}/cli/InitAction.d.ts.map +0 -0
  258. /package/{lib → lib-dts}/cli/RunAction.d.ts +0 -0
  259. /package/{lib → lib-dts}/cli/RunAction.d.ts.map +0 -0
  260. /package/{lib → lib-dts}/collector/ApiItemMetadata.d.ts +0 -0
  261. /package/{lib → lib-dts}/collector/ApiItemMetadata.d.ts.map +0 -0
  262. /package/{lib → lib-dts}/collector/Collector.d.ts +0 -0
  263. /package/{lib → lib-dts}/collector/Collector.d.ts.map +0 -0
  264. /package/{lib → lib-dts}/collector/CollectorEntity.d.ts +0 -0
  265. /package/{lib → lib-dts}/collector/CollectorEntity.d.ts.map +0 -0
  266. /package/{lib → lib-dts}/collector/DeclarationMetadata.d.ts +0 -0
  267. /package/{lib → lib-dts}/collector/DeclarationMetadata.d.ts.map +0 -0
  268. /package/{lib → lib-dts}/collector/MessageRouter.d.ts +0 -0
  269. /package/{lib → lib-dts}/collector/MessageRouter.d.ts.map +0 -0
  270. /package/{lib → lib-dts}/collector/SourceMapper.d.ts +0 -0
  271. /package/{lib → lib-dts}/collector/SourceMapper.d.ts.map +0 -0
  272. /package/{lib → lib-dts}/collector/SymbolMetadata.d.ts +0 -0
  273. /package/{lib → lib-dts}/collector/SymbolMetadata.d.ts.map +0 -0
  274. /package/{lib → lib-dts}/collector/VisitorState.d.ts +0 -0
  275. /package/{lib → lib-dts}/collector/VisitorState.d.ts.map +0 -0
  276. /package/{lib → lib-dts}/collector/WorkingPackage.d.ts +0 -0
  277. /package/{lib → lib-dts}/collector/WorkingPackage.d.ts.map +0 -0
  278. /package/{lib → lib-dts}/enhancers/DocCommentEnhancer.d.ts +0 -0
  279. /package/{lib → lib-dts}/enhancers/DocCommentEnhancer.d.ts.map +0 -0
  280. /package/{lib → lib-dts}/enhancers/ValidationEnhancer.d.ts +0 -0
  281. /package/{lib → lib-dts}/enhancers/ValidationEnhancer.d.ts.map +0 -0
  282. /package/{lib → lib-dts}/generators/ApiModelGenerator.d.ts +0 -0
  283. /package/{lib → lib-dts}/generators/ApiModelGenerator.d.ts.map +0 -0
  284. /package/{lib → lib-dts}/generators/ApiReportGenerator.d.ts +0 -0
  285. /package/{lib → lib-dts}/generators/ApiReportGenerator.d.ts.map +0 -0
  286. /package/{lib → lib-dts}/generators/DeclarationReferenceGenerator.d.ts +0 -0
  287. /package/{lib → lib-dts}/generators/DeclarationReferenceGenerator.d.ts.map +0 -0
  288. /package/{lib → lib-dts}/generators/DtsEmitHelpers.d.ts +0 -0
  289. /package/{lib → lib-dts}/generators/DtsEmitHelpers.d.ts.map +0 -0
  290. /package/{lib → lib-dts}/generators/DtsRollupGenerator.d.ts +0 -0
  291. /package/{lib → lib-dts}/generators/DtsRollupGenerator.d.ts.map +0 -0
  292. /package/{lib → lib-dts}/generators/ExcerptBuilder.d.ts +0 -0
  293. /package/{lib → lib-dts}/generators/ExcerptBuilder.d.ts.map +0 -0
  294. /package/{lib → lib-dts}/generators/IndentedWriter.d.ts +0 -0
  295. /package/{lib → lib-dts}/generators/IndentedWriter.d.ts.map +0 -0
  296. /package/{lib → lib-dts}/index.d.ts +0 -0
  297. /package/{lib → lib-dts}/index.d.ts.map +0 -0
  298. /package/{lib → lib-dts}/start.d.ts +0 -0
  299. /package/{lib → lib-dts}/start.d.ts.map +0 -0
@@ -0,0 +1,524 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ /* eslint-disable no-bitwise */ // for ts.SymbolFlags
4
+ import * as ts from 'typescript';
5
+ import { InternalError } from '@rushstack/node-core-library';
6
+ import { AstDeclaration } from './AstDeclaration';
7
+ import { TypeScriptHelpers } from './TypeScriptHelpers';
8
+ import { AstSymbol } from './AstSymbol';
9
+ import { PackageMetadataManager } from './PackageMetadataManager';
10
+ import { ExportAnalyzer } from './ExportAnalyzer';
11
+ import { AstNamespaceImport } from './AstNamespaceImport';
12
+ import { TypeScriptInternals } from './TypeScriptInternals';
13
+ import { SyntaxHelpers } from './SyntaxHelpers';
14
+ import { SourceFileLocationFormatter } from './SourceFileLocationFormatter';
15
+ /**
16
+ * AstSymbolTable is the workhorse that builds AstSymbol and AstDeclaration objects.
17
+ * It maintains a cache of already constructed objects. AstSymbolTable constructs
18
+ * AstModule objects, but otherwise the state that it maintains is agnostic of
19
+ * any particular entry point. (For example, it does not track whether a given AstSymbol
20
+ * is "exported" or not.)
21
+ *
22
+ * Internally, AstSymbolTable relies on ExportAnalyzer to crawl import statements and determine where symbols
23
+ * are declared (i.e. the AstImport information needed to import them).
24
+ */
25
+ export class AstSymbolTable {
26
+ constructor(program, typeChecker, packageJsonLookup, bundledPackageNames, messageRouter) {
27
+ /**
28
+ * A mapping from ts.Symbol --> AstSymbol
29
+ * NOTE: The AstSymbol.followedSymbol will always be a lookup key, but additional keys
30
+ * are possible.
31
+ *
32
+ * After following type aliases, we use this map to look up the corresponding AstSymbol.
33
+ */
34
+ this._astSymbolsBySymbol = new Map();
35
+ /**
36
+ * A mapping from ts.Declaration --> AstDeclaration
37
+ */
38
+ this._astDeclarationsByDeclaration = new Map();
39
+ // Note that this is a mapping from specific AST nodes that we analyzed, based on the underlying symbol
40
+ // for that node.
41
+ this._entitiesByNode = new Map();
42
+ this._program = program;
43
+ this._typeChecker = typeChecker;
44
+ this._messageRouter = messageRouter;
45
+ this._globalVariableAnalyzer = TypeScriptInternals.getGlobalVariableAnalyzer(program);
46
+ this._packageMetadataManager = new PackageMetadataManager(packageJsonLookup, messageRouter);
47
+ this._exportAnalyzer = new ExportAnalyzer(this._program, this._typeChecker, bundledPackageNames, {
48
+ analyze: this.analyze.bind(this),
49
+ fetchAstSymbol: this._fetchAstSymbol.bind(this)
50
+ });
51
+ this._alreadyWarnedGlobalNames = new Set();
52
+ }
53
+ /**
54
+ * Used to analyze an entry point that belongs to the working package.
55
+ */
56
+ fetchAstModuleFromWorkingPackage(sourceFile) {
57
+ return this._exportAnalyzer.fetchAstModuleFromSourceFile(sourceFile, undefined, false);
58
+ }
59
+ /**
60
+ * This crawls the specified entry point and collects the full set of exported AstSymbols.
61
+ */
62
+ fetchAstModuleExportInfo(astModule) {
63
+ return this._exportAnalyzer.fetchAstModuleExportInfo(astModule);
64
+ }
65
+ /**
66
+ * Attempts to retrieve an export by name from the specified `AstModule`.
67
+ * Returns undefined if no match was found.
68
+ */
69
+ tryGetExportOfAstModule(exportName, astModule) {
70
+ return this._exportAnalyzer.tryGetExportOfAstModule(exportName, astModule);
71
+ }
72
+ /**
73
+ * Ensures that AstSymbol.analyzed is true for the provided symbol. The operation
74
+ * starts from the root symbol and then fills out all children of all declarations, and
75
+ * also calculates AstDeclaration.referencedAstSymbols for all declarations.
76
+ * If the symbol is not imported, any non-imported references are also analyzed.
77
+ *
78
+ * @remarks
79
+ * This is an expensive operation, so we only perform it for top-level exports of an
80
+ * the AstModule. For example, if some code references a nested class inside
81
+ * a namespace from another library, we do not analyze any of that class's siblings
82
+ * or members. (We do always construct its parents however, since AstDefinition.parent
83
+ * is immutable, and needed e.g. to calculate release tag inheritance.)
84
+ */
85
+ analyze(astEntity) {
86
+ if (astEntity instanceof AstSymbol) {
87
+ return this._analyzeAstSymbol(astEntity);
88
+ }
89
+ if (astEntity instanceof AstNamespaceImport) {
90
+ return this._analyzeAstNamespaceImport(astEntity);
91
+ }
92
+ }
93
+ /**
94
+ * For a given astDeclaration, this efficiently finds the child corresponding to the
95
+ * specified ts.Node. It is assumed that AstDeclaration.isSupportedSyntaxKind() would return true for
96
+ * that node type, and that the node is an immediate child of the provided AstDeclaration.
97
+ */
98
+ // NOTE: This could be a method of AstSymbol if it had a backpointer to its AstSymbolTable.
99
+ getChildAstDeclarationByNode(node, parentAstDeclaration) {
100
+ if (!parentAstDeclaration.astSymbol.analyzed) {
101
+ throw new Error('getChildDeclarationByNode() cannot be used for an AstSymbol that was not analyzed');
102
+ }
103
+ const childAstDeclaration = this._astDeclarationsByDeclaration.get(node);
104
+ if (!childAstDeclaration) {
105
+ throw new Error('Child declaration not found for the specified node');
106
+ }
107
+ if (childAstDeclaration.parent !== parentAstDeclaration) {
108
+ throw new InternalError('The found child is not attached to the parent AstDeclaration');
109
+ }
110
+ return childAstDeclaration;
111
+ }
112
+ /**
113
+ * For a given ts.Identifier that is part of an AstSymbol that we analyzed, return the AstEntity that
114
+ * it refers to. Returns undefined if it doesn't refer to anything interesting.
115
+ * @remarks
116
+ * Throws an Error if the ts.Identifier is not part of node tree that was analyzed.
117
+ */
118
+ tryGetEntityForNode(identifier) {
119
+ if (!this._entitiesByNode.has(identifier)) {
120
+ throw new InternalError('tryGetEntityForIdentifier() called for an identifier that was not analyzed');
121
+ }
122
+ return this._entitiesByNode.get(identifier);
123
+ }
124
+ /**
125
+ * Builds an AstSymbol.localName for a given ts.Symbol. In the current implementation, the localName is
126
+ * a TypeScript-like expression that may be a string literal or ECMAScript symbol expression.
127
+ *
128
+ * ```ts
129
+ * class X {
130
+ * // localName="identifier"
131
+ * public identifier: number = 1;
132
+ * // localName="\"identifier\""
133
+ * public "quoted string!": number = 2;
134
+ * // localName="[MyNamespace.MySymbol]"
135
+ * public [MyNamespace.MySymbol]: number = 3;
136
+ * }
137
+ * ```
138
+ */
139
+ static getLocalNameForSymbol(symbol) {
140
+ // TypeScript binds well-known ECMAScript symbols like "[Symbol.iterator]" as "__@iterator".
141
+ // Decode it back into "[Symbol.iterator]".
142
+ const wellKnownSymbolName = TypeScriptHelpers.tryDecodeWellKnownSymbolName(symbol.escapedName);
143
+ if (wellKnownSymbolName) {
144
+ return wellKnownSymbolName;
145
+ }
146
+ const isUniqueSymbol = TypeScriptHelpers.isUniqueSymbolName(symbol.escapedName);
147
+ // We will try to obtain the name from a declaration; otherwise we'll fall back to the symbol name.
148
+ let unquotedName = symbol.name;
149
+ for (const declaration of symbol.declarations || []) {
150
+ // Handle cases such as "export default class X { }" where the symbol name is "default"
151
+ // but the local name is "X".
152
+ const localSymbol = TypeScriptInternals.tryGetLocalSymbol(declaration);
153
+ if (localSymbol) {
154
+ unquotedName = localSymbol.name;
155
+ }
156
+ // If it is a non-well-known symbol, then return the late-bound name. For example, "X.Y.z" in this example:
157
+ //
158
+ // namespace X {
159
+ // export namespace Y {
160
+ // export const z: unique symbol = Symbol("z");
161
+ // }
162
+ // }
163
+ //
164
+ // class C {
165
+ // public [X.Y.z](): void { }
166
+ // }
167
+ //
168
+ if (isUniqueSymbol) {
169
+ const declarationName = ts.getNameOfDeclaration(declaration);
170
+ if (declarationName && ts.isComputedPropertyName(declarationName)) {
171
+ const lateBoundName = TypeScriptHelpers.tryGetLateBoundName(declarationName);
172
+ if (lateBoundName) {
173
+ // Here the string may contain an expression such as "[X.Y.z]". Names starting with "[" are always
174
+ // expressions. If a string literal contains those characters, the code below will JSON.stringify() it
175
+ // to avoid a collision.
176
+ return lateBoundName;
177
+ }
178
+ }
179
+ }
180
+ }
181
+ // Otherwise that name may come from a quoted string or pseudonym like `__constructor`.
182
+ // If the string is not a safe identifier, then we must add quotes.
183
+ // Note that if it was quoted but did not need to be quoted, here we will remove the quotes.
184
+ if (!SyntaxHelpers.isSafeUnquotedMemberIdentifier(unquotedName)) {
185
+ // For API Extractor's purposes, a canonical form is more appropriate than trying to reflect whatever
186
+ // appeared in the source code. The code is not even guaranteed to be consistent, for example:
187
+ //
188
+ // class X {
189
+ // public "f1"(x: string): void;
190
+ // public f1(x: boolean): void;
191
+ // public 'f1'(x: string | boolean): void { }
192
+ // }
193
+ return JSON.stringify(unquotedName);
194
+ }
195
+ return unquotedName;
196
+ }
197
+ _analyzeAstNamespaceImport(astNamespaceImport) {
198
+ if (astNamespaceImport.analyzed) {
199
+ return;
200
+ }
201
+ // mark before actual analyzing, to handle module cyclic reexport
202
+ astNamespaceImport.analyzed = true;
203
+ const exportedLocalEntities = this.fetchAstModuleExportInfo(astNamespaceImport.astModule).exportedLocalEntities;
204
+ for (const exportedEntity of exportedLocalEntities.values()) {
205
+ this.analyze(exportedEntity);
206
+ }
207
+ }
208
+ _analyzeAstSymbol(astSymbol) {
209
+ if (astSymbol.analyzed) {
210
+ return;
211
+ }
212
+ if (astSymbol.nominalAnalysis) {
213
+ // We don't analyze nominal symbols
214
+ astSymbol._notifyAnalyzed();
215
+ return;
216
+ }
217
+ // Start at the root of the tree
218
+ const rootAstSymbol = astSymbol.rootAstSymbol;
219
+ // Calculate the full child tree for each definition
220
+ for (const astDeclaration of rootAstSymbol.astDeclarations) {
221
+ this._analyzeChildTree(astDeclaration.declaration, astDeclaration);
222
+ }
223
+ rootAstSymbol._notifyAnalyzed();
224
+ if (!astSymbol.isExternal) {
225
+ // If this symbol is non-external (i.e. it belongs to the working package), then we also analyze any
226
+ // referencedAstSymbols that are non-external. For example, this ensures that forgotten exports
227
+ // get analyzed.
228
+ rootAstSymbol.forEachDeclarationRecursive((astDeclaration) => {
229
+ for (const referencedAstEntity of astDeclaration.referencedAstEntities) {
230
+ // Walk up to the root of the tree, looking for any imports along the way
231
+ if (referencedAstEntity instanceof AstSymbol) {
232
+ if (!referencedAstEntity.isExternal) {
233
+ this._analyzeAstSymbol(referencedAstEntity);
234
+ }
235
+ }
236
+ if (referencedAstEntity instanceof AstNamespaceImport) {
237
+ if (!referencedAstEntity.astModule.isExternal) {
238
+ this._analyzeAstNamespaceImport(referencedAstEntity);
239
+ }
240
+ }
241
+ }
242
+ });
243
+ }
244
+ }
245
+ /**
246
+ * Used by analyze to recursively analyze the entire child tree.
247
+ */
248
+ _analyzeChildTree(node, governingAstDeclaration) {
249
+ switch (node.kind) {
250
+ case ts.SyntaxKind.JSDocComment: // Skip JSDoc comments - TS considers @param tags TypeReference nodes
251
+ return;
252
+ // Is this a reference to another AstSymbol?
253
+ case ts.SyntaxKind.TypeReference: // general type references
254
+ case ts.SyntaxKind.ExpressionWithTypeArguments: // special case for e.g. the "extends" keyword
255
+ case ts.SyntaxKind.ComputedPropertyName: // used for EcmaScript "symbols", e.g. "[toPrimitive]".
256
+ case ts.SyntaxKind.TypeQuery: // represents for "typeof X" as a type
257
+ {
258
+ // Sometimes the type reference will involve multiple identifiers, e.g. "a.b.C".
259
+ // In this case, we only need to worry about importing the first identifier,
260
+ // so do a depth-first search for it:
261
+ const identifierNode = TypeScriptHelpers.findFirstChildNode(node, ts.SyntaxKind.Identifier);
262
+ if (identifierNode) {
263
+ let referencedAstEntity = this._entitiesByNode.get(identifierNode);
264
+ if (!referencedAstEntity) {
265
+ const symbol = this._typeChecker.getSymbolAtLocation(identifierNode);
266
+ if (!symbol) {
267
+ throw new Error('Symbol not found for identifier: ' + identifierNode.getText());
268
+ }
269
+ // Normally we expect getSymbolAtLocation() to take us to a declaration within the same source
270
+ // file, or else to an explicit "import" statement within the same source file. But in certain
271
+ // situations (e.g. a global variable) the symbol will refer to a declaration in some other
272
+ // source file. We'll call that case a "displaced symbol".
273
+ //
274
+ // For more info, see this discussion:
275
+ // https://github.com/microsoft/rushstack/issues/1765#issuecomment-595559849
276
+ let displacedSymbol = true;
277
+ for (const declaration of symbol.declarations || []) {
278
+ if (declaration.getSourceFile() === identifierNode.getSourceFile()) {
279
+ displacedSymbol = false;
280
+ break;
281
+ }
282
+ }
283
+ if (displacedSymbol) {
284
+ if (this._globalVariableAnalyzer.hasGlobalName(identifierNode.text)) {
285
+ // If the displaced symbol is a global variable, then API Extractor simply ignores it.
286
+ // Ambient declarations typically describe the runtime environment (provided by an API consumer),
287
+ // so we don't bother analyzing them as an API contract. (There are probably some packages
288
+ // that include interesting global variables in their API, but API Extractor doesn't support
289
+ // that yet; it would be a feature request.)
290
+ if (this._messageRouter.showDiagnostics) {
291
+ if (!this._alreadyWarnedGlobalNames.has(identifierNode.text)) {
292
+ this._alreadyWarnedGlobalNames.add(identifierNode.text);
293
+ this._messageRouter.logDiagnostic(`Ignoring reference to global variable "${identifierNode.text}"` +
294
+ ` in ` +
295
+ SourceFileLocationFormatter.formatDeclaration(identifierNode));
296
+ }
297
+ }
298
+ }
299
+ else {
300
+ // If you encounter this, please report a bug with a repro. We're interested to know
301
+ // how it can occur.
302
+ throw new InternalError(`Unable to follow symbol for "${identifierNode.text}"`);
303
+ }
304
+ }
305
+ else {
306
+ referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(symbol, governingAstDeclaration.astSymbol.isExternal);
307
+ this._entitiesByNode.set(identifierNode, referencedAstEntity);
308
+ }
309
+ }
310
+ if (referencedAstEntity) {
311
+ governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);
312
+ }
313
+ }
314
+ }
315
+ break;
316
+ // Is this the identifier for the governingAstDeclaration?
317
+ case ts.SyntaxKind.Identifier:
318
+ {
319
+ const identifierNode = node;
320
+ if (!this._entitiesByNode.has(identifierNode)) {
321
+ const symbol = this._typeChecker.getSymbolAtLocation(identifierNode);
322
+ let referencedAstEntity = undefined;
323
+ if (symbol === governingAstDeclaration.astSymbol.followedSymbol) {
324
+ referencedAstEntity = this._fetchEntityForNode(identifierNode, governingAstDeclaration);
325
+ }
326
+ this._entitiesByNode.set(identifierNode, referencedAstEntity);
327
+ }
328
+ }
329
+ break;
330
+ case ts.SyntaxKind.ImportType:
331
+ {
332
+ const importTypeNode = node;
333
+ let referencedAstEntity = this._entitiesByNode.get(importTypeNode);
334
+ if (!this._entitiesByNode.has(importTypeNode)) {
335
+ referencedAstEntity = this._fetchEntityForNode(importTypeNode, governingAstDeclaration);
336
+ if (!referencedAstEntity) {
337
+ // This should never happen
338
+ throw new Error('Failed to fetch entity for import() type node: ' + importTypeNode.getText());
339
+ }
340
+ this._entitiesByNode.set(importTypeNode, referencedAstEntity);
341
+ }
342
+ if (referencedAstEntity) {
343
+ governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);
344
+ }
345
+ }
346
+ break;
347
+ }
348
+ // Is this node declaring a new AstSymbol?
349
+ const newGoverningAstDeclaration = this._fetchAstDeclaration(node, governingAstDeclaration.astSymbol.isExternal);
350
+ for (const childNode of node.getChildren()) {
351
+ this._analyzeChildTree(childNode, newGoverningAstDeclaration || governingAstDeclaration);
352
+ }
353
+ }
354
+ _fetchEntityForNode(node, governingAstDeclaration) {
355
+ let referencedAstEntity = this._entitiesByNode.get(node);
356
+ if (!referencedAstEntity) {
357
+ if (node.kind === ts.SyntaxKind.ImportType) {
358
+ referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntityFromImportTypeNode(node, governingAstDeclaration.astSymbol.isExternal);
359
+ }
360
+ else {
361
+ const symbol = this._typeChecker.getSymbolAtLocation(node);
362
+ if (!symbol) {
363
+ throw new Error('Symbol not found for identifier: ' + node.getText());
364
+ }
365
+ referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(symbol, governingAstDeclaration.astSymbol.isExternal);
366
+ }
367
+ this._entitiesByNode.set(node, referencedAstEntity);
368
+ }
369
+ return referencedAstEntity;
370
+ }
371
+ _fetchAstDeclaration(node, isExternal) {
372
+ if (!AstDeclaration.isSupportedSyntaxKind(node.kind)) {
373
+ return undefined;
374
+ }
375
+ const symbol = TypeScriptHelpers.getSymbolForDeclaration(node, this._typeChecker);
376
+ if (!symbol) {
377
+ throw new InternalError('Unable to find symbol for node');
378
+ }
379
+ const astSymbol = this._fetchAstSymbol({
380
+ followedSymbol: symbol,
381
+ isExternal: isExternal,
382
+ includeNominalAnalysis: true,
383
+ addIfMissing: true
384
+ });
385
+ if (!astSymbol) {
386
+ return undefined;
387
+ }
388
+ const astDeclaration = this._astDeclarationsByDeclaration.get(node);
389
+ if (!astDeclaration) {
390
+ throw new InternalError('Unable to find constructed AstDeclaration');
391
+ }
392
+ return astDeclaration;
393
+ }
394
+ _fetchAstSymbol(options) {
395
+ const followedSymbol = options.followedSymbol;
396
+ // Filter out symbols representing constructs that we don't care about
397
+ const arbitraryDeclaration = TypeScriptHelpers.tryGetADeclaration(followedSymbol);
398
+ if (!arbitraryDeclaration) {
399
+ return undefined;
400
+ }
401
+ if (followedSymbol.flags &
402
+ (ts.SymbolFlags.TypeParameter | ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.Transient)) {
403
+ if (!TypeScriptInternals.isLateBoundSymbol(followedSymbol)) {
404
+ return undefined;
405
+ }
406
+ }
407
+ // API Extractor doesn't analyze ambient declarations at all
408
+ if (TypeScriptHelpers.isAmbient(followedSymbol, this._typeChecker)) {
409
+ // We make a special exemption for ambient declarations that appear in a source file containing
410
+ // an "export=" declaration that allows them to be imported as non-ambient.
411
+ if (!this._exportAnalyzer.isImportableAmbientSourceFile(arbitraryDeclaration.getSourceFile())) {
412
+ return undefined;
413
+ }
414
+ }
415
+ // Make sure followedSymbol isn't an alias for something else
416
+ if (TypeScriptHelpers.isFollowableAlias(followedSymbol, this._typeChecker)) {
417
+ // We expect the caller to have already followed any aliases
418
+ throw new InternalError('AstSymbolTable._fetchAstSymbol() cannot be called with a symbol alias');
419
+ }
420
+ let astSymbol = this._astSymbolsBySymbol.get(followedSymbol);
421
+ if (!astSymbol) {
422
+ // None of the above lookups worked, so create a new entry...
423
+ let nominalAnalysis = false;
424
+ if (options.isExternal) {
425
+ // If the file is from an external package that does not support AEDoc, normally we ignore it completely.
426
+ // But in some cases (e.g. checking star exports of an external package) we need an AstSymbol to
427
+ // represent it, but we don't need to analyze its sibling/children.
428
+ const followedSymbolSourceFileName = arbitraryDeclaration.getSourceFile().fileName;
429
+ if (!this._packageMetadataManager.isAedocSupportedFor(followedSymbolSourceFileName)) {
430
+ nominalAnalysis = true;
431
+ if (!options.includeNominalAnalysis) {
432
+ return undefined;
433
+ }
434
+ }
435
+ }
436
+ let parentAstSymbol = undefined;
437
+ if (!nominalAnalysis) {
438
+ for (const declaration of followedSymbol.declarations || []) {
439
+ if (!AstDeclaration.isSupportedSyntaxKind(declaration.kind)) {
440
+ throw new InternalError(`The "${followedSymbol.name}" symbol has a` +
441
+ ` ts.SyntaxKind.${ts.SyntaxKind[declaration.kind]} declaration which is not (yet?)` +
442
+ ` supported by API Extractor`);
443
+ }
444
+ }
445
+ // We always fetch the entire chain of parents for each declaration.
446
+ // (Children/siblings are only analyzed on demand.)
447
+ // Key assumptions behind this squirrely logic:
448
+ //
449
+ // IF a given symbol has two declarations D1 and D2; AND
450
+ // If D1 has a parent P1, then
451
+ // - D2 will also have a parent P2; AND
452
+ // - P1 and P2's symbol will be the same
453
+ // - but P1 and P2 may be different (e.g. merged namespaces containing merged interfaces)
454
+ // Is there a parent AstSymbol? First we check to see if there is a parent declaration:
455
+ if (arbitraryDeclaration) {
456
+ const arbitraryParentDeclaration = this._tryFindFirstAstDeclarationParent(arbitraryDeclaration);
457
+ if (arbitraryParentDeclaration) {
458
+ const parentSymbol = TypeScriptHelpers.getSymbolForDeclaration(arbitraryParentDeclaration, this._typeChecker);
459
+ parentAstSymbol = this._fetchAstSymbol({
460
+ followedSymbol: parentSymbol,
461
+ isExternal: options.isExternal,
462
+ includeNominalAnalysis: false,
463
+ addIfMissing: true
464
+ });
465
+ if (!parentAstSymbol) {
466
+ throw new InternalError('Unable to construct a parent AstSymbol for ' + followedSymbol.name);
467
+ }
468
+ }
469
+ }
470
+ }
471
+ const localName = options.localName || AstSymbolTable.getLocalNameForSymbol(followedSymbol);
472
+ astSymbol = new AstSymbol({
473
+ followedSymbol: followedSymbol,
474
+ localName: localName,
475
+ isExternal: options.isExternal,
476
+ nominalAnalysis: nominalAnalysis,
477
+ parentAstSymbol: parentAstSymbol,
478
+ rootAstSymbol: parentAstSymbol ? parentAstSymbol.rootAstSymbol : undefined
479
+ });
480
+ this._astSymbolsBySymbol.set(followedSymbol, astSymbol);
481
+ // Okay, now while creating the declarations we will wire them up to the
482
+ // their corresponding parent declarations
483
+ for (const declaration of followedSymbol.declarations || []) {
484
+ let parentAstDeclaration = undefined;
485
+ if (parentAstSymbol) {
486
+ const parentDeclaration = this._tryFindFirstAstDeclarationParent(declaration);
487
+ if (!parentDeclaration) {
488
+ throw new InternalError('Missing parent declaration');
489
+ }
490
+ parentAstDeclaration = this._astDeclarationsByDeclaration.get(parentDeclaration);
491
+ if (!parentAstDeclaration) {
492
+ throw new InternalError('Missing parent AstDeclaration');
493
+ }
494
+ }
495
+ const astDeclaration = new AstDeclaration({
496
+ declaration,
497
+ astSymbol,
498
+ parent: parentAstDeclaration
499
+ });
500
+ this._astDeclarationsByDeclaration.set(declaration, astDeclaration);
501
+ }
502
+ }
503
+ if (options.isExternal !== astSymbol.isExternal) {
504
+ throw new InternalError(`Cannot assign isExternal=${options.isExternal} for` +
505
+ ` the symbol ${astSymbol.localName} because it was previously registered` +
506
+ ` with isExternal=${astSymbol.isExternal}`);
507
+ }
508
+ return astSymbol;
509
+ }
510
+ /**
511
+ * Returns the first parent satisfying isAstDeclaration(), or undefined if none is found.
512
+ */
513
+ _tryFindFirstAstDeclarationParent(node) {
514
+ let currentNode = node.parent;
515
+ while (currentNode) {
516
+ if (AstDeclaration.isSupportedSyntaxKind(currentNode.kind)) {
517
+ return currentNode;
518
+ }
519
+ currentNode = currentNode.parent;
520
+ }
521
+ return undefined;
522
+ }
523
+ }
524
+ //# sourceMappingURL=AstSymbolTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AstSymbolTable.js","sourceRoot":"","sources":["../../src/analyzer/AstSymbolTable.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,+BAA+B,CAAC,qBAAqB;AAErD,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAA0B,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAErF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAgC,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EAAE,aAAa,EA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,MAAM,IAAI,aAAa,CAAC,4BAA4B,CAAC,CAAC;oBACxD,CAAC;oBAED,oBAAoB,GAAG,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;oBACjF,IAAI,CAAC,oBAAoB,EAAE,CAAC;wBAC1B,MAAM,IAAI,aAAa,CAAC,+BAA+B,CAAC,CAAC;oBAC3D,CAAC;gBACH,CAAC;gBAED,MAAM,cAAc,GAAmB,IAAI,cAAc,CAAC;oBACxD,WAAW;oBACX,SAAS;oBACT,MAAM,EAAE,oBAAoB;iBAC7B,CAAC,CAAC;gBAEH,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,UAAU,EAAE,CAAC;YAChD,MAAM,IAAI,aAAa,CACrB,4BAA4B,OAAO,CAAC,UAAU,MAAM;gBAClD,eAAe,SAAS,CAAC,SAAS,uCAAuC;gBACzE,oBAAoB,SAAS,CAAC,UAAU,EAAE,CAC7C,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACK,iCAAiC,CAAC,IAAa;QACrD,IAAI,WAAW,GAAwB,IAAI,CAAC,MAAM,CAAC;QACnD,OAAO,WAAW,EAAE,CAAC;YACnB,IAAI,cAAc,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3D,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC;QACnC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/* eslint-disable no-bitwise */ // for ts.SymbolFlags\n\nimport * as ts from 'typescript';\n\nimport { type PackageJsonLookup, InternalError } from '@rushstack/node-core-library';\n\nimport { AstDeclaration } from './AstDeclaration';\nimport { TypeScriptHelpers } from './TypeScriptHelpers';\nimport { AstSymbol } from './AstSymbol';\nimport type { AstModule, IAstModuleExportInfo } from './AstModule';\nimport { PackageMetadataManager } from './PackageMetadataManager';\nimport { ExportAnalyzer } from './ExportAnalyzer';\nimport type { AstEntity } from './AstEntity';\nimport { AstNamespaceImport } from './AstNamespaceImport';\nimport type { MessageRouter } from '../collector/MessageRouter';\nimport { TypeScriptInternals, type IGlobalVariableAnalyzer } from './TypeScriptInternals';\nimport { SyntaxHelpers } from './SyntaxHelpers';\nimport { SourceFileLocationFormatter } from './SourceFileLocationFormatter';\n\n/**\n * Options for `AstSymbolTable._fetchAstSymbol()`\n */\nexport interface IFetchAstSymbolOptions {\n /**\n * The symbol after any symbol aliases have been followed using TypeScriptHelpers.followAliases()\n */\n followedSymbol: ts.Symbol;\n /**\n * True if followedSymbol is not part of the working package\n */\n isExternal: boolean;\n\n /**\n * If true, symbols with AstSymbol.nominalAnalysis=true will be returned.\n * Otherwise `undefined` will be returned for such symbols.\n */\n includeNominalAnalysis: boolean;\n\n /**\n * True while populating the `AstSymbolTable`; false if we're doing a passive lookup\n * without adding anything new to the table\n */\n addIfMissing: boolean;\n\n /**\n * A hint to help `_fetchAstSymbol()` determine the `AstSymbol.localName`.\n */\n localName?: string;\n}\n\n/**\n * AstSymbolTable is the workhorse that builds AstSymbol and AstDeclaration objects.\n * It maintains a cache of already constructed objects. AstSymbolTable constructs\n * AstModule objects, but otherwise the state that it maintains is agnostic of\n * any particular entry point. (For example, it does not track whether a given AstSymbol\n * is \"exported\" or not.)\n *\n * Internally, AstSymbolTable relies on ExportAnalyzer to crawl import statements and determine where symbols\n * are declared (i.e. the AstImport information needed to import them).\n */\nexport class AstSymbolTable {\n private readonly _program: ts.Program;\n private readonly _typeChecker: ts.TypeChecker;\n private readonly _messageRouter: MessageRouter;\n private readonly _globalVariableAnalyzer: IGlobalVariableAnalyzer;\n private readonly _packageMetadataManager: PackageMetadataManager;\n private readonly _exportAnalyzer: ExportAnalyzer;\n private readonly _alreadyWarnedGlobalNames: Set<string>;\n\n /**\n * A mapping from ts.Symbol --> AstSymbol\n * NOTE: The AstSymbol.followedSymbol will always be a lookup key, but additional keys\n * are possible.\n *\n * After following type aliases, we use this map to look up the corresponding AstSymbol.\n */\n private readonly _astSymbolsBySymbol: Map<ts.Symbol, AstSymbol> = new Map<ts.Symbol, AstSymbol>();\n\n /**\n * A mapping from ts.Declaration --> AstDeclaration\n */\n private readonly _astDeclarationsByDeclaration: Map<ts.Node, AstDeclaration> = new Map<\n ts.Node,\n AstDeclaration\n >();\n\n // Note that this is a mapping from specific AST nodes that we analyzed, based on the underlying symbol\n // for that node.\n private readonly _entitiesByNode: Map<ts.Identifier | ts.ImportTypeNode, AstEntity | undefined> = new Map<\n ts.Identifier,\n AstEntity | undefined\n >();\n\n public constructor(\n program: ts.Program,\n typeChecker: ts.TypeChecker,\n packageJsonLookup: PackageJsonLookup,\n bundledPackageNames: ReadonlySet<string>,\n messageRouter: MessageRouter\n ) {\n this._program = program;\n this._typeChecker = typeChecker;\n this._messageRouter = messageRouter;\n this._globalVariableAnalyzer = TypeScriptInternals.getGlobalVariableAnalyzer(program);\n this._packageMetadataManager = new PackageMetadataManager(packageJsonLookup, messageRouter);\n\n this._exportAnalyzer = new ExportAnalyzer(this._program, this._typeChecker, bundledPackageNames, {\n analyze: this.analyze.bind(this),\n fetchAstSymbol: this._fetchAstSymbol.bind(this)\n });\n\n this._alreadyWarnedGlobalNames = new Set<string>();\n }\n\n /**\n * Used to analyze an entry point that belongs to the working package.\n */\n public fetchAstModuleFromWorkingPackage(sourceFile: ts.SourceFile): AstModule {\n return this._exportAnalyzer.fetchAstModuleFromSourceFile(sourceFile, undefined, false);\n }\n\n /**\n * This crawls the specified entry point and collects the full set of exported AstSymbols.\n */\n public fetchAstModuleExportInfo(astModule: AstModule): IAstModuleExportInfo {\n return this._exportAnalyzer.fetchAstModuleExportInfo(astModule);\n }\n\n /**\n * Attempts to retrieve an export by name from the specified `AstModule`.\n * Returns undefined if no match was found.\n */\n public tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined {\n return this._exportAnalyzer.tryGetExportOfAstModule(exportName, astModule);\n }\n\n /**\n * Ensures that AstSymbol.analyzed is true for the provided symbol. The operation\n * starts from the root symbol and then fills out all children of all declarations, and\n * also calculates AstDeclaration.referencedAstSymbols for all declarations.\n * If the symbol is not imported, any non-imported references are also analyzed.\n *\n * @remarks\n * This is an expensive operation, so we only perform it for top-level exports of an\n * the AstModule. For example, if some code references a nested class inside\n * a namespace from another library, we do not analyze any of that class's siblings\n * or members. (We do always construct its parents however, since AstDefinition.parent\n * is immutable, and needed e.g. to calculate release tag inheritance.)\n */\n public analyze(astEntity: AstEntity): void {\n if (astEntity instanceof AstSymbol) {\n return this._analyzeAstSymbol(astEntity);\n }\n\n if (astEntity instanceof AstNamespaceImport) {\n return this._analyzeAstNamespaceImport(astEntity);\n }\n }\n\n /**\n * For a given astDeclaration, this efficiently finds the child corresponding to the\n * specified ts.Node. It is assumed that AstDeclaration.isSupportedSyntaxKind() would return true for\n * that node type, and that the node is an immediate child of the provided AstDeclaration.\n */\n // NOTE: This could be a method of AstSymbol if it had a backpointer to its AstSymbolTable.\n public getChildAstDeclarationByNode(node: ts.Node, parentAstDeclaration: AstDeclaration): AstDeclaration {\n if (!parentAstDeclaration.astSymbol.analyzed) {\n throw new Error('getChildDeclarationByNode() cannot be used for an AstSymbol that was not analyzed');\n }\n\n const childAstDeclaration: AstDeclaration | undefined = this._astDeclarationsByDeclaration.get(node);\n if (!childAstDeclaration) {\n throw new Error('Child declaration not found for the specified node');\n }\n if (childAstDeclaration.parent !== parentAstDeclaration) {\n throw new InternalError('The found child is not attached to the parent AstDeclaration');\n }\n\n return childAstDeclaration;\n }\n\n /**\n * For a given ts.Identifier that is part of an AstSymbol that we analyzed, return the AstEntity that\n * it refers to. Returns undefined if it doesn't refer to anything interesting.\n * @remarks\n * Throws an Error if the ts.Identifier is not part of node tree that was analyzed.\n */\n public tryGetEntityForNode(identifier: ts.Identifier | ts.ImportTypeNode): AstEntity | undefined {\n if (!this._entitiesByNode.has(identifier)) {\n throw new InternalError('tryGetEntityForIdentifier() called for an identifier that was not analyzed');\n }\n return this._entitiesByNode.get(identifier);\n }\n\n /**\n * Builds an AstSymbol.localName for a given ts.Symbol. In the current implementation, the localName is\n * a TypeScript-like expression that may be a string literal or ECMAScript symbol expression.\n *\n * ```ts\n * class X {\n * // localName=\"identifier\"\n * public identifier: number = 1;\n * // localName=\"\\\"identifier\\\"\"\n * public \"quoted string!\": number = 2;\n * // localName=\"[MyNamespace.MySymbol]\"\n * public [MyNamespace.MySymbol]: number = 3;\n * }\n * ```\n */\n public static getLocalNameForSymbol(symbol: ts.Symbol): string {\n // TypeScript binds well-known ECMAScript symbols like \"[Symbol.iterator]\" as \"__@iterator\".\n // Decode it back into \"[Symbol.iterator]\".\n const wellKnownSymbolName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(\n symbol.escapedName\n );\n if (wellKnownSymbolName) {\n return wellKnownSymbolName;\n }\n\n const isUniqueSymbol: boolean = TypeScriptHelpers.isUniqueSymbolName(symbol.escapedName);\n\n // We will try to obtain the name from a declaration; otherwise we'll fall back to the symbol name.\n let unquotedName: string = symbol.name;\n\n for (const declaration of symbol.declarations || []) {\n // Handle cases such as \"export default class X { }\" where the symbol name is \"default\"\n // but the local name is \"X\".\n const localSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetLocalSymbol(declaration);\n if (localSymbol) {\n unquotedName = localSymbol.name;\n }\n\n // If it is a non-well-known symbol, then return the late-bound name. For example, \"X.Y.z\" in this example:\n //\n // namespace X {\n // export namespace Y {\n // export const z: unique symbol = Symbol(\"z\");\n // }\n // }\n //\n // class C {\n // public [X.Y.z](): void { }\n // }\n //\n if (isUniqueSymbol) {\n const declarationName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(declaration);\n if (declarationName && ts.isComputedPropertyName(declarationName)) {\n const lateBoundName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declarationName);\n if (lateBoundName) {\n // Here the string may contain an expression such as \"[X.Y.z]\". Names starting with \"[\" are always\n // expressions. If a string literal contains those characters, the code below will JSON.stringify() it\n // to avoid a collision.\n return lateBoundName;\n }\n }\n }\n }\n\n // Otherwise that name may come from a quoted string or pseudonym like `__constructor`.\n // If the string is not a safe identifier, then we must add quotes.\n // Note that if it was quoted but did not need to be quoted, here we will remove the quotes.\n if (!SyntaxHelpers.isSafeUnquotedMemberIdentifier(unquotedName)) {\n // For API Extractor's purposes, a canonical form is more appropriate than trying to reflect whatever\n // appeared in the source code. The code is not even guaranteed to be consistent, for example:\n //\n // class X {\n // public \"f1\"(x: string): void;\n // public f1(x: boolean): void;\n // public 'f1'(x: string | boolean): void { }\n // }\n return JSON.stringify(unquotedName);\n }\n\n return unquotedName;\n }\n\n private _analyzeAstNamespaceImport(astNamespaceImport: AstNamespaceImport): void {\n if (astNamespaceImport.analyzed) {\n return;\n }\n\n // mark before actual analyzing, to handle module cyclic reexport\n astNamespaceImport.analyzed = true;\n\n const exportedLocalEntities: Map<string, AstEntity> = this.fetchAstModuleExportInfo(\n astNamespaceImport.astModule\n ).exportedLocalEntities;\n\n for (const exportedEntity of exportedLocalEntities.values()) {\n this.analyze(exportedEntity);\n }\n }\n\n private _analyzeAstSymbol(astSymbol: AstSymbol): void {\n if (astSymbol.analyzed) {\n return;\n }\n\n if (astSymbol.nominalAnalysis) {\n // We don't analyze nominal symbols\n astSymbol._notifyAnalyzed();\n return;\n }\n\n // Start at the root of the tree\n const rootAstSymbol: AstSymbol = astSymbol.rootAstSymbol;\n\n // Calculate the full child tree for each definition\n for (const astDeclaration of rootAstSymbol.astDeclarations) {\n this._analyzeChildTree(astDeclaration.declaration, astDeclaration);\n }\n\n rootAstSymbol._notifyAnalyzed();\n\n if (!astSymbol.isExternal) {\n // If this symbol is non-external (i.e. it belongs to the working package), then we also analyze any\n // referencedAstSymbols that are non-external. For example, this ensures that forgotten exports\n // get analyzed.\n rootAstSymbol.forEachDeclarationRecursive((astDeclaration: AstDeclaration) => {\n for (const referencedAstEntity of astDeclaration.referencedAstEntities) {\n // Walk up to the root of the tree, looking for any imports along the way\n if (referencedAstEntity instanceof AstSymbol) {\n if (!referencedAstEntity.isExternal) {\n this._analyzeAstSymbol(referencedAstEntity);\n }\n }\n\n if (referencedAstEntity instanceof AstNamespaceImport) {\n if (!referencedAstEntity.astModule.isExternal) {\n this._analyzeAstNamespaceImport(referencedAstEntity);\n }\n }\n }\n });\n }\n }\n\n /**\n * Used by analyze to recursively analyze the entire child tree.\n */\n private _analyzeChildTree(node: ts.Node, governingAstDeclaration: AstDeclaration): void {\n switch (node.kind) {\n case ts.SyntaxKind.JSDocComment: // Skip JSDoc comments - TS considers @param tags TypeReference nodes\n return;\n\n // Is this a reference to another AstSymbol?\n case ts.SyntaxKind.TypeReference: // general type references\n case ts.SyntaxKind.ExpressionWithTypeArguments: // special case for e.g. the \"extends\" keyword\n case ts.SyntaxKind.ComputedPropertyName: // used for EcmaScript \"symbols\", e.g. \"[toPrimitive]\".\n case ts.SyntaxKind.TypeQuery: // represents for \"typeof X\" as a type\n {\n // Sometimes the type reference will involve multiple identifiers, e.g. \"a.b.C\".\n // In this case, we only need to worry about importing the first identifier,\n // so do a depth-first search for it:\n const identifierNode: ts.Identifier | undefined = TypeScriptHelpers.findFirstChildNode(\n node,\n ts.SyntaxKind.Identifier\n );\n\n if (identifierNode) {\n let referencedAstEntity: AstEntity | undefined = this._entitiesByNode.get(identifierNode);\n if (!referencedAstEntity) {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(identifierNode);\n if (!symbol) {\n throw new Error('Symbol not found for identifier: ' + identifierNode.getText());\n }\n\n // Normally we expect getSymbolAtLocation() to take us to a declaration within the same source\n // file, or else to an explicit \"import\" statement within the same source file. But in certain\n // situations (e.g. a global variable) the symbol will refer to a declaration in some other\n // source file. We'll call that case a \"displaced symbol\".\n //\n // For more info, see this discussion:\n // https://github.com/microsoft/rushstack/issues/1765#issuecomment-595559849\n let displacedSymbol: boolean = true;\n for (const declaration of symbol.declarations || []) {\n if (declaration.getSourceFile() === identifierNode.getSourceFile()) {\n displacedSymbol = false;\n break;\n }\n }\n\n if (displacedSymbol) {\n if (this._globalVariableAnalyzer.hasGlobalName(identifierNode.text)) {\n // If the displaced symbol is a global variable, then API Extractor simply ignores it.\n // Ambient declarations typically describe the runtime environment (provided by an API consumer),\n // so we don't bother analyzing them as an API contract. (There are probably some packages\n // that include interesting global variables in their API, but API Extractor doesn't support\n // that yet; it would be a feature request.)\n\n if (this._messageRouter.showDiagnostics) {\n if (!this._alreadyWarnedGlobalNames.has(identifierNode.text)) {\n this._alreadyWarnedGlobalNames.add(identifierNode.text);\n this._messageRouter.logDiagnostic(\n `Ignoring reference to global variable \"${identifierNode.text}\"` +\n ` in ` +\n SourceFileLocationFormatter.formatDeclaration(identifierNode)\n );\n }\n }\n } else {\n // If you encounter this, please report a bug with a repro. We're interested to know\n // how it can occur.\n throw new InternalError(`Unable to follow symbol for \"${identifierNode.text}\"`);\n }\n } else {\n referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(\n symbol,\n governingAstDeclaration.astSymbol.isExternal\n );\n\n this._entitiesByNode.set(identifierNode, referencedAstEntity);\n }\n }\n\n if (referencedAstEntity) {\n governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);\n }\n }\n }\n break;\n\n // Is this the identifier for the governingAstDeclaration?\n case ts.SyntaxKind.Identifier:\n {\n const identifierNode: ts.Identifier = node as ts.Identifier;\n if (!this._entitiesByNode.has(identifierNode)) {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(identifierNode);\n\n let referencedAstEntity: AstEntity | undefined = undefined;\n\n if (symbol === governingAstDeclaration.astSymbol.followedSymbol) {\n referencedAstEntity = this._fetchEntityForNode(identifierNode, governingAstDeclaration);\n }\n\n this._entitiesByNode.set(identifierNode, referencedAstEntity);\n }\n }\n break;\n\n case ts.SyntaxKind.ImportType:\n {\n const importTypeNode: ts.ImportTypeNode = node as ts.ImportTypeNode;\n let referencedAstEntity: AstEntity | undefined = this._entitiesByNode.get(importTypeNode);\n\n if (!this._entitiesByNode.has(importTypeNode)) {\n referencedAstEntity = this._fetchEntityForNode(importTypeNode, governingAstDeclaration);\n\n if (!referencedAstEntity) {\n // This should never happen\n throw new Error('Failed to fetch entity for import() type node: ' + importTypeNode.getText());\n }\n\n this._entitiesByNode.set(importTypeNode, referencedAstEntity);\n }\n\n if (referencedAstEntity) {\n governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);\n }\n }\n break;\n }\n\n // Is this node declaring a new AstSymbol?\n const newGoverningAstDeclaration: AstDeclaration | undefined = this._fetchAstDeclaration(\n node,\n governingAstDeclaration.astSymbol.isExternal\n );\n\n for (const childNode of node.getChildren()) {\n this._analyzeChildTree(childNode, newGoverningAstDeclaration || governingAstDeclaration);\n }\n }\n\n private _fetchEntityForNode(\n node: ts.Identifier | ts.ImportTypeNode,\n governingAstDeclaration: AstDeclaration\n ): AstEntity | undefined {\n let referencedAstEntity: AstEntity | undefined = this._entitiesByNode.get(node);\n if (!referencedAstEntity) {\n if (node.kind === ts.SyntaxKind.ImportType) {\n referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntityFromImportTypeNode(\n node,\n governingAstDeclaration.astSymbol.isExternal\n );\n } else {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(node);\n if (!symbol) {\n throw new Error('Symbol not found for identifier: ' + node.getText());\n }\n\n referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(\n symbol,\n governingAstDeclaration.astSymbol.isExternal\n );\n }\n\n this._entitiesByNode.set(node, referencedAstEntity);\n }\n return referencedAstEntity;\n }\n\n private _fetchAstDeclaration(node: ts.Node, isExternal: boolean): AstDeclaration | undefined {\n if (!AstDeclaration.isSupportedSyntaxKind(node.kind)) {\n return undefined;\n }\n\n const symbol: ts.Symbol | undefined = TypeScriptHelpers.getSymbolForDeclaration(\n node as ts.Declaration,\n this._typeChecker\n );\n if (!symbol) {\n throw new InternalError('Unable to find symbol for node');\n }\n\n const astSymbol: AstSymbol | undefined = this._fetchAstSymbol({\n followedSymbol: symbol,\n isExternal: isExternal,\n includeNominalAnalysis: true,\n addIfMissing: true\n });\n\n if (!astSymbol) {\n return undefined;\n }\n\n const astDeclaration: AstDeclaration | undefined = this._astDeclarationsByDeclaration.get(node);\n\n if (!astDeclaration) {\n throw new InternalError('Unable to find constructed AstDeclaration');\n }\n\n return astDeclaration;\n }\n\n private _fetchAstSymbol(options: IFetchAstSymbolOptions): AstSymbol | undefined {\n const followedSymbol: ts.Symbol = options.followedSymbol;\n\n // Filter out symbols representing constructs that we don't care about\n const arbitraryDeclaration: ts.Declaration | undefined =\n TypeScriptHelpers.tryGetADeclaration(followedSymbol);\n if (!arbitraryDeclaration) {\n return undefined;\n }\n\n if (\n followedSymbol.flags &\n (ts.SymbolFlags.TypeParameter | ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.Transient)\n ) {\n if (!TypeScriptInternals.isLateBoundSymbol(followedSymbol)) {\n return undefined;\n }\n }\n\n // API Extractor doesn't analyze ambient declarations at all\n if (TypeScriptHelpers.isAmbient(followedSymbol, this._typeChecker)) {\n // We make a special exemption for ambient declarations that appear in a source file containing\n // an \"export=\" declaration that allows them to be imported as non-ambient.\n if (!this._exportAnalyzer.isImportableAmbientSourceFile(arbitraryDeclaration.getSourceFile())) {\n return undefined;\n }\n }\n\n // Make sure followedSymbol isn't an alias for something else\n if (TypeScriptHelpers.isFollowableAlias(followedSymbol, this._typeChecker)) {\n // We expect the caller to have already followed any aliases\n throw new InternalError('AstSymbolTable._fetchAstSymbol() cannot be called with a symbol alias');\n }\n\n let astSymbol: AstSymbol | undefined = this._astSymbolsBySymbol.get(followedSymbol);\n\n if (!astSymbol) {\n // None of the above lookups worked, so create a new entry...\n let nominalAnalysis: boolean = false;\n\n if (options.isExternal) {\n // If the file is from an external package that does not support AEDoc, normally we ignore it completely.\n // But in some cases (e.g. checking star exports of an external package) we need an AstSymbol to\n // represent it, but we don't need to analyze its sibling/children.\n const followedSymbolSourceFileName: string = arbitraryDeclaration.getSourceFile().fileName;\n\n if (!this._packageMetadataManager.isAedocSupportedFor(followedSymbolSourceFileName)) {\n nominalAnalysis = true;\n\n if (!options.includeNominalAnalysis) {\n return undefined;\n }\n }\n }\n\n let parentAstSymbol: AstSymbol | undefined = undefined;\n\n if (!nominalAnalysis) {\n for (const declaration of followedSymbol.declarations || []) {\n if (!AstDeclaration.isSupportedSyntaxKind(declaration.kind)) {\n throw new InternalError(\n `The \"${followedSymbol.name}\" symbol has a` +\n ` ts.SyntaxKind.${ts.SyntaxKind[declaration.kind]} declaration which is not (yet?)` +\n ` supported by API Extractor`\n );\n }\n }\n\n // We always fetch the entire chain of parents for each declaration.\n // (Children/siblings are only analyzed on demand.)\n\n // Key assumptions behind this squirrely logic:\n //\n // IF a given symbol has two declarations D1 and D2; AND\n // If D1 has a parent P1, then\n // - D2 will also have a parent P2; AND\n // - P1 and P2's symbol will be the same\n // - but P1 and P2 may be different (e.g. merged namespaces containing merged interfaces)\n\n // Is there a parent AstSymbol? First we check to see if there is a parent declaration:\n if (arbitraryDeclaration) {\n const arbitraryParentDeclaration: ts.Node | undefined =\n this._tryFindFirstAstDeclarationParent(arbitraryDeclaration);\n\n if (arbitraryParentDeclaration) {\n const parentSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(\n arbitraryParentDeclaration as ts.Declaration,\n this._typeChecker\n );\n\n parentAstSymbol = this._fetchAstSymbol({\n followedSymbol: parentSymbol,\n isExternal: options.isExternal,\n includeNominalAnalysis: false,\n addIfMissing: true\n });\n if (!parentAstSymbol) {\n throw new InternalError('Unable to construct a parent AstSymbol for ' + followedSymbol.name);\n }\n }\n }\n }\n\n const localName: string | undefined =\n options.localName || AstSymbolTable.getLocalNameForSymbol(followedSymbol);\n\n astSymbol = new AstSymbol({\n followedSymbol: followedSymbol,\n localName: localName,\n isExternal: options.isExternal,\n nominalAnalysis: nominalAnalysis,\n parentAstSymbol: parentAstSymbol,\n rootAstSymbol: parentAstSymbol ? parentAstSymbol.rootAstSymbol : undefined\n });\n\n this._astSymbolsBySymbol.set(followedSymbol, astSymbol);\n\n // Okay, now while creating the declarations we will wire them up to the\n // their corresponding parent declarations\n for (const declaration of followedSymbol.declarations || []) {\n let parentAstDeclaration: AstDeclaration | undefined = undefined;\n if (parentAstSymbol) {\n const parentDeclaration: ts.Node | undefined = this._tryFindFirstAstDeclarationParent(declaration);\n\n if (!parentDeclaration) {\n throw new InternalError('Missing parent declaration');\n }\n\n parentAstDeclaration = this._astDeclarationsByDeclaration.get(parentDeclaration);\n if (!parentAstDeclaration) {\n throw new InternalError('Missing parent AstDeclaration');\n }\n }\n\n const astDeclaration: AstDeclaration = new AstDeclaration({\n declaration,\n astSymbol,\n parent: parentAstDeclaration\n });\n\n this._astDeclarationsByDeclaration.set(declaration, astDeclaration);\n }\n }\n\n if (options.isExternal !== astSymbol.isExternal) {\n throw new InternalError(\n `Cannot assign isExternal=${options.isExternal} for` +\n ` the symbol ${astSymbol.localName} because it was previously registered` +\n ` with isExternal=${astSymbol.isExternal}`\n );\n }\n\n return astSymbol;\n }\n\n /**\n * Returns the first parent satisfying isAstDeclaration(), or undefined if none is found.\n */\n private _tryFindFirstAstDeclarationParent(node: ts.Node): ts.Node | undefined {\n let currentNode: ts.Node | undefined = node.parent;\n while (currentNode) {\n if (AstDeclaration.isSupportedSyntaxKind(currentNode.kind)) {\n return currentNode;\n }\n currentNode = currentNode.parent;\n }\n return undefined;\n }\n}\n"]}