@teambit/typescript 0.0.0-02c0c8ffc2ebaf66ef5cbfc2e31c48e2b4acbfc7

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 (310) hide show
  1. package/cmds/check-types.cmd.ts +76 -0
  2. package/dist/cmds/check-types.cmd.d.ts +34 -0
  3. package/dist/cmds/check-types.cmd.js +101 -0
  4. package/dist/cmds/check-types.cmd.js.map +1 -0
  5. package/dist/compiler-options.d.ts +22 -0
  6. package/dist/compiler-options.js +3 -0
  7. package/dist/compiler-options.js.map +1 -0
  8. package/dist/esm.mjs +21 -0
  9. package/dist/exceptions/index.d.ts +1 -0
  10. package/dist/exceptions/index.js +20 -0
  11. package/dist/exceptions/index.js.map +1 -0
  12. package/dist/exceptions/transformer-not-found.d.ts +8 -0
  13. package/dist/exceptions/transformer-not-found.js +26 -0
  14. package/dist/exceptions/transformer-not-found.js.map +1 -0
  15. package/dist/export-identifier.d.ts +6 -0
  16. package/dist/export-identifier.js +29 -0
  17. package/dist/export-identifier.js.map +1 -0
  18. package/dist/extractor-options.d.ts +26 -0
  19. package/dist/extractor-options.js +3 -0
  20. package/dist/extractor-options.js.map +1 -0
  21. package/dist/identifier-list.d.ts +7 -0
  22. package/dist/identifier-list.js +21 -0
  23. package/dist/identifier-list.js.map +1 -0
  24. package/dist/identifier.d.ts +11 -0
  25. package/dist/identifier.js +45 -0
  26. package/dist/identifier.js.map +1 -0
  27. package/dist/index.d.ts +9 -0
  28. package/dist/index.js +91 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/preview-1752542268171.js +7 -0
  31. package/dist/remove-types-task.d.ts +12 -0
  32. package/dist/remove-types-task.js +64 -0
  33. package/dist/remove-types-task.js.map +1 -0
  34. package/dist/schema-extractor-context.d.ts +162 -0
  35. package/dist/schema-extractor-context.js +745 -0
  36. package/dist/schema-extractor-context.js.map +1 -0
  37. package/dist/schema-transformer.d.ts +19 -0
  38. package/dist/schema-transformer.js +3 -0
  39. package/dist/schema-transformer.js.map +1 -0
  40. package/dist/schema-transformer.plugin.d.ts +9 -0
  41. package/dist/schema-transformer.plugin.js +22 -0
  42. package/dist/schema-transformer.plugin.js.map +1 -0
  43. package/dist/sourceFileTransformers/class.d.ts +2 -0
  44. package/dist/sourceFileTransformers/class.js +57 -0
  45. package/dist/sourceFileTransformers/class.js.map +1 -0
  46. package/dist/sourceFileTransformers/empty-line-encoder.d.ts +14 -0
  47. package/dist/sourceFileTransformers/empty-line-encoder.js +62 -0
  48. package/dist/sourceFileTransformers/empty-line-encoder.js.map +1 -0
  49. package/dist/sourceFileTransformers/export.d.ts +2 -0
  50. package/dist/sourceFileTransformers/export.js +58 -0
  51. package/dist/sourceFileTransformers/export.js.map +1 -0
  52. package/dist/sourceFileTransformers/expression-statement.d.ts +2 -0
  53. package/dist/sourceFileTransformers/expression-statement.js +58 -0
  54. package/dist/sourceFileTransformers/expression-statement.js.map +1 -0
  55. package/dist/sourceFileTransformers/function.d.ts +2 -0
  56. package/dist/sourceFileTransformers/function.js +119 -0
  57. package/dist/sourceFileTransformers/function.js.map +1 -0
  58. package/dist/sourceFileTransformers/import.d.ts +2 -0
  59. package/dist/sourceFileTransformers/import.js +71 -0
  60. package/dist/sourceFileTransformers/import.js.map +1 -0
  61. package/dist/sourceFileTransformers/index.d.ts +12 -0
  62. package/dist/sourceFileTransformers/index.js +137 -0
  63. package/dist/sourceFileTransformers/index.js.map +1 -0
  64. package/dist/sourceFileTransformers/interface.d.ts +2 -0
  65. package/dist/sourceFileTransformers/interface.js +50 -0
  66. package/dist/sourceFileTransformers/interface.js.map +1 -0
  67. package/dist/sourceFileTransformers/replaceName.d.ts +1 -0
  68. package/dist/sourceFileTransformers/replaceName.js +19 -0
  69. package/dist/sourceFileTransformers/replaceName.js.map +1 -0
  70. package/dist/sourceFileTransformers/transform.d.ts +12 -0
  71. package/dist/sourceFileTransformers/transform.js +76 -0
  72. package/dist/sourceFileTransformers/transform.js.map +1 -0
  73. package/dist/sourceFileTransformers/type-reference.d.ts +2 -0
  74. package/dist/sourceFileTransformers/type-reference.js +38 -0
  75. package/dist/sourceFileTransformers/type-reference.js.map +1 -0
  76. package/dist/sourceFileTransformers/typeAlias.d.ts +2 -0
  77. package/dist/sourceFileTransformers/typeAlias.js +41 -0
  78. package/dist/sourceFileTransformers/typeAlias.js.map +1 -0
  79. package/dist/sourceFileTransformers/variable.d.ts +2 -0
  80. package/dist/sourceFileTransformers/variable.js +41 -0
  81. package/dist/sourceFileTransformers/variable.js.map +1 -0
  82. package/dist/transform-source-file.spec.d.ts +1 -0
  83. package/dist/transform-source-file.spec.js +182 -0
  84. package/dist/transform-source-file.spec.js.map +1 -0
  85. package/dist/transformers/array-literal-expression.d.ts +10 -0
  86. package/dist/transformers/array-literal-expression.js +51 -0
  87. package/dist/transformers/array-literal-expression.js.map +1 -0
  88. package/dist/transformers/array-type.d.ts +10 -0
  89. package/dist/transformers/array-type.js +37 -0
  90. package/dist/transformers/array-type.js.map +1 -0
  91. package/dist/transformers/binding-element.d.ts +17 -0
  92. package/dist/transformers/binding-element.js +63 -0
  93. package/dist/transformers/binding-element.js.map +1 -0
  94. package/dist/transformers/class-declaration.d.ts +12 -0
  95. package/dist/transformers/class-declaration.js +116 -0
  96. package/dist/transformers/class-declaration.js.map +1 -0
  97. package/dist/transformers/conditional-type.d.ts +10 -0
  98. package/dist/transformers/conditional-type.js +38 -0
  99. package/dist/transformers/conditional-type.js.map +1 -0
  100. package/dist/transformers/constructor.d.ts +10 -0
  101. package/dist/transformers/constructor.js +49 -0
  102. package/dist/transformers/constructor.js.map +1 -0
  103. package/dist/transformers/decorator.d.ts +10 -0
  104. package/dist/transformers/decorator.js +54 -0
  105. package/dist/transformers/decorator.js.map +1 -0
  106. package/dist/transformers/enum-declaration.d.ts +10 -0
  107. package/dist/transformers/enum-declaration.js +60 -0
  108. package/dist/transformers/enum-declaration.js.map +1 -0
  109. package/dist/transformers/export-assignment.d.ts +14 -0
  110. package/dist/transformers/export-assignment.js +52 -0
  111. package/dist/transformers/export-assignment.js.map +1 -0
  112. package/dist/transformers/export-declaration.d.ts +10 -0
  113. package/dist/transformers/export-declaration.js +154 -0
  114. package/dist/transformers/export-declaration.js.map +1 -0
  115. package/dist/transformers/expression-statement.d.ts +10 -0
  116. package/dist/transformers/expression-statement.js +36 -0
  117. package/dist/transformers/expression-statement.js.map +1 -0
  118. package/dist/transformers/function-like.d.ts +11 -0
  119. package/dist/transformers/function-like.js +81 -0
  120. package/dist/transformers/function-like.js.map +1 -0
  121. package/dist/transformers/get-accessor.d.ts +10 -0
  122. package/dist/transformers/get-accessor.js +46 -0
  123. package/dist/transformers/get-accessor.js.map +1 -0
  124. package/dist/transformers/import-declaration.d.ts +10 -0
  125. package/dist/transformers/import-declaration.js +72 -0
  126. package/dist/transformers/import-declaration.js.map +1 -0
  127. package/dist/transformers/index-signature.d.ts +10 -0
  128. package/dist/transformers/index-signature.js +41 -0
  129. package/dist/transformers/index-signature.js.map +1 -0
  130. package/dist/transformers/index.d.ts +43 -0
  131. package/dist/transformers/index.js +566 -0
  132. package/dist/transformers/index.js.map +1 -0
  133. package/dist/transformers/indexed-access-type.d.ts +10 -0
  134. package/dist/transformers/indexed-access-type.js +36 -0
  135. package/dist/transformers/indexed-access-type.js.map +1 -0
  136. package/dist/transformers/interface-declaration.d.ts +11 -0
  137. package/dist/transformers/interface-declaration.js +86 -0
  138. package/dist/transformers/interface-declaration.js.map +1 -0
  139. package/dist/transformers/intersection-type.d.ts +10 -0
  140. package/dist/transformers/intersection-type.js +47 -0
  141. package/dist/transformers/intersection-type.js.map +1 -0
  142. package/dist/transformers/keyword-type.d.ts +13 -0
  143. package/dist/transformers/keyword-type.js +54 -0
  144. package/dist/transformers/keyword-type.js.map +1 -0
  145. package/dist/transformers/literal-type.d.ts +13 -0
  146. package/dist/transformers/literal-type.js +39 -0
  147. package/dist/transformers/literal-type.js.map +1 -0
  148. package/dist/transformers/literal-value.d.ts +11 -0
  149. package/dist/transformers/literal-value.js +35 -0
  150. package/dist/transformers/literal-value.js.map +1 -0
  151. package/dist/transformers/module-declaration.d.ts +10 -0
  152. package/dist/transformers/module-declaration.js +36 -0
  153. package/dist/transformers/module-declaration.js.map +1 -0
  154. package/dist/transformers/named-tuple.d.ts +10 -0
  155. package/dist/transformers/named-tuple.js +37 -0
  156. package/dist/transformers/named-tuple.js.map +1 -0
  157. package/dist/transformers/object-literal-expression.d.ts +9 -0
  158. package/dist/transformers/object-literal-expression.js +51 -0
  159. package/dist/transformers/object-literal-expression.js.map +1 -0
  160. package/dist/transformers/parameter.d.ts +13 -0
  161. package/dist/transformers/parameter.js +109 -0
  162. package/dist/transformers/parameter.js.map +1 -0
  163. package/dist/transformers/parenthesized-type.d.ts +10 -0
  164. package/dist/transformers/parenthesized-type.js +35 -0
  165. package/dist/transformers/parenthesized-type.js.map +1 -0
  166. package/dist/transformers/property-assignment.d.ts +9 -0
  167. package/dist/transformers/property-assignment.js +39 -0
  168. package/dist/transformers/property-assignment.js.map +1 -0
  169. package/dist/transformers/property-declaration.d.ts +11 -0
  170. package/dist/transformers/property-declaration.js +56 -0
  171. package/dist/transformers/property-declaration.js.map +1 -0
  172. package/dist/transformers/set-accessor.d.ts +10 -0
  173. package/dist/transformers/set-accessor.js +44 -0
  174. package/dist/transformers/set-accessor.js.map +1 -0
  175. package/dist/transformers/source-file-transformer.d.ts +15 -0
  176. package/dist/transformers/source-file-transformer.js +108 -0
  177. package/dist/transformers/source-file-transformer.js.map +1 -0
  178. package/dist/transformers/template-literal-type-span.d.ts +10 -0
  179. package/dist/transformers/template-literal-type-span.js +36 -0
  180. package/dist/transformers/template-literal-type-span.js.map +1 -0
  181. package/dist/transformers/template-literal-type.d.ts +10 -0
  182. package/dist/transformers/template-literal-type.js +44 -0
  183. package/dist/transformers/template-literal-type.js.map +1 -0
  184. package/dist/transformers/this-type.d.ts +10 -0
  185. package/dist/transformers/this-type.js +34 -0
  186. package/dist/transformers/this-type.js.map +1 -0
  187. package/dist/transformers/tuple-type.d.ts +10 -0
  188. package/dist/transformers/tuple-type.js +46 -0
  189. package/dist/transformers/tuple-type.js.map +1 -0
  190. package/dist/transformers/type-alias.d.ts +11 -0
  191. package/dist/transformers/type-alias.js +48 -0
  192. package/dist/transformers/type-alias.js.map +1 -0
  193. package/dist/transformers/type-literal.d.ts +14 -0
  194. package/dist/transformers/type-literal.js +48 -0
  195. package/dist/transformers/type-literal.js.map +1 -0
  196. package/dist/transformers/type-operator.d.ts +14 -0
  197. package/dist/transformers/type-operator.js +51 -0
  198. package/dist/transformers/type-operator.js.map +1 -0
  199. package/dist/transformers/type-predicate.d.ts +10 -0
  200. package/dist/transformers/type-predicate.js +37 -0
  201. package/dist/transformers/type-predicate.js.map +1 -0
  202. package/dist/transformers/type-query.d.ts +13 -0
  203. package/dist/transformers/type-query.js +41 -0
  204. package/dist/transformers/type-query.js.map +1 -0
  205. package/dist/transformers/type-reference.d.ts +17 -0
  206. package/dist/transformers/type-reference.js +58 -0
  207. package/dist/transformers/type-reference.js.map +1 -0
  208. package/dist/transformers/union-type.d.ts +10 -0
  209. package/dist/transformers/union-type.js +47 -0
  210. package/dist/transformers/union-type.js.map +1 -0
  211. package/dist/transformers/utils/jsdoc-to-doc-schema.d.ts +5 -0
  212. package/dist/transformers/utils/jsdoc-to-doc-schema.js +114 -0
  213. package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -0
  214. package/dist/transformers/utils/parse-type-from-quick-info.d.ts +36 -0
  215. package/dist/transformers/utils/parse-type-from-quick-info.js +111 -0
  216. package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -0
  217. package/dist/transformers/variable-declaration.d.ts +11 -0
  218. package/dist/transformers/variable-declaration.js +102 -0
  219. package/dist/transformers/variable-declaration.js.map +1 -0
  220. package/dist/transformers/variable-statement.d.ts +14 -0
  221. package/dist/transformers/variable-statement.js +67 -0
  222. package/dist/transformers/variable-statement.js.map +1 -0
  223. package/dist/tsconfig.default.json +25 -0
  224. package/dist/typescript.aspect.d.ts +2 -0
  225. package/dist/typescript.aspect.js +18 -0
  226. package/dist/typescript.aspect.js.map +1 -0
  227. package/dist/typescript.composition.d.ts +1 -0
  228. package/dist/typescript.composition.js +29 -0
  229. package/dist/typescript.composition.js.map +1 -0
  230. package/dist/typescript.docs.mdx +8 -0
  231. package/dist/typescript.extractor.d.ts +51 -0
  232. package/dist/typescript.extractor.js +254 -0
  233. package/dist/typescript.extractor.js.map +1 -0
  234. package/dist/typescript.main.runtime.d.ts +129 -0
  235. package/dist/typescript.main.runtime.js +400 -0
  236. package/dist/typescript.main.runtime.js.map +1 -0
  237. package/dist/typescript.parser.d.ts +12 -0
  238. package/dist/typescript.parser.js +141 -0
  239. package/dist/typescript.parser.js.map +1 -0
  240. package/dist/typescript.parser.spec.d.ts +1 -0
  241. package/dist/typescript.parser.spec.js +189 -0
  242. package/dist/typescript.parser.spec.js.map +1 -0
  243. package/esm.mjs +21 -0
  244. package/exceptions/index.ts +1 -0
  245. package/exceptions/transformer-not-found.ts +19 -0
  246. package/package.json +86 -0
  247. package/sourceFileTransformers/class.ts +73 -0
  248. package/sourceFileTransformers/empty-line-encoder.ts +56 -0
  249. package/sourceFileTransformers/export.ts +65 -0
  250. package/sourceFileTransformers/expression-statement.ts +48 -0
  251. package/sourceFileTransformers/function.ts +170 -0
  252. package/sourceFileTransformers/import.ts +101 -0
  253. package/sourceFileTransformers/index.ts +14 -0
  254. package/sourceFileTransformers/interface.ts +41 -0
  255. package/sourceFileTransformers/replaceName.ts +11 -0
  256. package/sourceFileTransformers/transform.ts +70 -0
  257. package/sourceFileTransformers/type-reference.ts +19 -0
  258. package/sourceFileTransformers/typeAlias.ts +25 -0
  259. package/sourceFileTransformers/variable.ts +25 -0
  260. package/transformers/array-literal-expression.ts +33 -0
  261. package/transformers/array-type.ts +21 -0
  262. package/transformers/binding-element.ts +34 -0
  263. package/transformers/class-declaration.ts +108 -0
  264. package/transformers/conditional-type.ts +23 -0
  265. package/transformers/constructor.ts +40 -0
  266. package/transformers/decorator.ts +28 -0
  267. package/transformers/enum-declaration.ts +31 -0
  268. package/transformers/export-assignment.ts +33 -0
  269. package/transformers/export-declaration.ts +182 -0
  270. package/transformers/expression-statement.ts +20 -0
  271. package/transformers/function-like.ts +70 -0
  272. package/transformers/get-accessor.ts +24 -0
  273. package/transformers/import-declaration.ts +56 -0
  274. package/transformers/index-signature.ts +25 -0
  275. package/transformers/index.ts +43 -0
  276. package/transformers/indexed-access-type.ts +21 -0
  277. package/transformers/interface-declaration.ts +66 -0
  278. package/transformers/intersection-type.ts +25 -0
  279. package/transformers/keyword-type.ts +39 -0
  280. package/transformers/literal-type.ts +23 -0
  281. package/transformers/literal-value.ts +38 -0
  282. package/transformers/module-declaration.ts +20 -0
  283. package/transformers/named-tuple.ts +22 -0
  284. package/transformers/object-literal-expression.ts +28 -0
  285. package/transformers/parameter.ts +122 -0
  286. package/transformers/parenthesized-type.ts +20 -0
  287. package/transformers/property-assignment.ts +23 -0
  288. package/transformers/property-declaration.ts +34 -0
  289. package/transformers/set-accessor.ts +25 -0
  290. package/transformers/source-file-transformer.ts +94 -0
  291. package/transformers/template-literal-type-span.ts +21 -0
  292. package/transformers/template-literal-type.ts +24 -0
  293. package/transformers/this-type.ts +19 -0
  294. package/transformers/tuple-type.ts +24 -0
  295. package/transformers/type-alias.ts +26 -0
  296. package/transformers/type-literal.ts +26 -0
  297. package/transformers/type-operator.ts +37 -0
  298. package/transformers/type-predicate.ts +22 -0
  299. package/transformers/type-query.ts +25 -0
  300. package/transformers/type-reference.ts +36 -0
  301. package/transformers/union-type.ts +25 -0
  302. package/transformers/utils/jsdoc-to-doc-schema.ts +121 -0
  303. package/transformers/utils/parse-type-from-quick-info.ts +99 -0
  304. package/transformers/variable-declaration.ts +111 -0
  305. package/transformers/variable-statement.ts +32 -0
  306. package/tsconfig.default.json +25 -0
  307. package/types/asset.d.ts +41 -0
  308. package/types/style.d.ts +42 -0
  309. package/typescript.composition.tsx +7 -0
  310. package/typescript.docs.mdx +8 -0
@@ -0,0 +1,745 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SchemaExtractorContext = void 0;
7
+ function _tsutils() {
8
+ const data = require("tsutils");
9
+ _tsutils = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _typescript() {
15
+ const data = _interopRequireWildcard(require("typescript"));
16
+ _typescript = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _lodash() {
22
+ const data = require("lodash");
23
+ _lodash = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _legacy() {
29
+ const data = require("@teambit/legacy.utils");
30
+ _legacy = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _path() {
36
+ const data = require("path");
37
+ _path = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _semanticsEntities() {
43
+ const data = require("@teambit/semantics.entities.semantic-schema");
44
+ _semanticsEntities = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _pMapSeries() {
50
+ const data = _interopRequireDefault(require("p-map-series"));
51
+ _pMapSeries = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ function _identifierList() {
57
+ const data = require("./identifier-list");
58
+ _identifierList = function () {
59
+ return data;
60
+ };
61
+ return data;
62
+ }
63
+ function _parseTypeFromQuickInfo() {
64
+ const data = require("./transformers/utils/parse-type-from-quick-info");
65
+ _parseTypeFromQuickInfo = function () {
66
+ return data;
67
+ };
68
+ return data;
69
+ }
70
+ function _jsdocToDocSchema() {
71
+ const data = require("./transformers/utils/jsdoc-to-doc-schema");
72
+ _jsdocToDocSchema = function () {
73
+ return data;
74
+ };
75
+ return data;
76
+ }
77
+ function _identifier() {
78
+ const data = require("./identifier");
79
+ _identifier = function () {
80
+ return data;
81
+ };
82
+ return data;
83
+ }
84
+ function _exportIdentifier() {
85
+ const data = require("./export-identifier");
86
+ _exportIdentifier = function () {
87
+ return data;
88
+ };
89
+ return data;
90
+ }
91
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
92
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
93
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
94
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
95
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // @ts-ignore david we should figure fix this.
96
+ // eslint-disable-next-line import/no-unresolved
97
+ class SchemaExtractorContext {
98
+ get mainFile() {
99
+ return (0, _legacy().pathNormalizeToLinux)(this.getPathRelativeToComponent(this.component.mainFile.path));
100
+ }
101
+ get identifiers() {
102
+ return this._identifiers;
103
+ }
104
+ get internalIdentifiers() {
105
+ return this._internalIdentifiers;
106
+ }
107
+ get computed() {
108
+ return this._computed;
109
+ }
110
+ get mainFileIdentifierKey() {
111
+ const mainFile = this.component.mainFile;
112
+ return this.getIdentifierKey(mainFile.path);
113
+ }
114
+ get mainModuleIdentifiers() {
115
+ return this.identifiers.get(this.mainFileIdentifierKey);
116
+ }
117
+ constructor(tsserver, component, extractor, componentDeps, componentRootPath, hostRootPath, formatter) {
118
+ this.tsserver = tsserver;
119
+ this.component = component;
120
+ this.extractor = extractor;
121
+ this.componentDeps = componentDeps;
122
+ this.componentRootPath = componentRootPath;
123
+ this.hostRootPath = hostRootPath;
124
+ this.formatter = formatter;
125
+ /**
126
+ * list of all declared identifiers (exported and internal) by filename
127
+ */
128
+ _defineProperty(this, "_identifiers", new Map());
129
+ _defineProperty(this, "_internalIdentifiers", new Map());
130
+ /**
131
+ * computed nodes by filename and (position (line:character))
132
+ */
133
+ _defineProperty(this, "_computed", new Map());
134
+ this.componentRootPath = (0, _legacy().pathNormalizeToLinux)(componentRootPath);
135
+ this.hostRootPath = (0, _legacy().pathNormalizeToLinux)(hostRootPath);
136
+ }
137
+ getComputedNodeKey({
138
+ filePath,
139
+ line,
140
+ character
141
+ }, schema) {
142
+ return `${filePath}:${line}:${character}__${schema}`;
143
+ }
144
+ getIdentifierKeyForNode(node) {
145
+ const filePath = node.getSourceFile().fileName;
146
+ return this.getIdentifierKey(filePath);
147
+ }
148
+ getIdentifierKey(filePath) {
149
+ return (0, _legacy().pathNormalizeToLinux)(filePath);
150
+ }
151
+ setComputed(node) {
152
+ const {
153
+ location,
154
+ __schema
155
+ } = node;
156
+ const key = this.getComputedNodeKey(location, __schema);
157
+ this.computed.set(key, node);
158
+ }
159
+ setIdentifiers(filePath, identifiers) {
160
+ this._identifiers.set(this.getIdentifierKey(filePath), identifiers);
161
+ }
162
+ setInternalIdentifiers(filePath, identifiers) {
163
+ const existing = this._internalIdentifiers.get(filePath);
164
+ if (!existing) {
165
+ this._internalIdentifiers.set(filePath, identifiers);
166
+ } else {
167
+ const uniqueIdentifiers = (0, _lodash().uniqBy)(existing.identifiers.concat(identifiers.identifiers), k => k.aliasId || k.id);
168
+ this._internalIdentifiers.set(filePath, new (_identifierList().IdentifierList)(uniqueIdentifiers));
169
+ }
170
+ }
171
+ findComputedSchemaByName(name) {
172
+ const computed = Array.from(this.computed.values());
173
+ return computed.filter(schema => schema.name === name);
174
+ }
175
+ async computeSchema(node) {
176
+ const location = this.getLocation(node);
177
+ const key = this.getComputedNodeKey(location, _typescript().SyntaxKind[node.kind]);
178
+ const existingComputedSchema = this.computed.get(key);
179
+ if (existingComputedSchema) {
180
+ return existingComputedSchema;
181
+ }
182
+ const computedSchema = await this.extractor.computeSchema(node, this);
183
+ this.setComputed(computedSchema);
184
+ return computedSchema;
185
+ }
186
+ async transformSchemaNode(schema) {
187
+ return this.extractor.transformAPI(schema, this);
188
+ }
189
+
190
+ /**
191
+ * returns the location of a node in a source file.
192
+ */
193
+ getLocation(node, targetSourceFile, absolutePath = false) {
194
+ const sourceFile = targetSourceFile || node.getSourceFile();
195
+ const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);
196
+ const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
197
+ const line = position.line + 1;
198
+ const character = position.character + 1;
199
+ return {
200
+ filePath: (0, _legacy().pathNormalizeToLinux)(filePath),
201
+ line,
202
+ character
203
+ };
204
+ }
205
+ getLocationAsString(node) {
206
+ const location = this.getLocation(node);
207
+ return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;
208
+ }
209
+ getPathRelativeToComponent(filePath) {
210
+ const basePath = this.component.filesystem.files[0].base;
211
+ return (0, _path().relative)(basePath, filePath);
212
+ }
213
+
214
+ /**
215
+ * returns a signature for a node.
216
+ */
217
+ async getSignature(node) {
218
+ return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));
219
+ }
220
+
221
+ /**
222
+ * get the position for the tsserver.
223
+ */
224
+ getPosition(sourceFile, line, offset) {
225
+ return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);
226
+ }
227
+
228
+ /**
229
+ * get the path for a source file.
230
+ */
231
+ getPath(node) {
232
+ const sourceFile = node.getSourceFile();
233
+ const fileName = sourceFile.fileName;
234
+ if (!fileName.startsWith(this.componentRootPath) && !fileName.startsWith(this.hostRootPath)) {
235
+ return (0, _path().join)(this.componentRootPath, fileName);
236
+ }
237
+ return sourceFile.fileName;
238
+ }
239
+ async getQuickInfo(node) {
240
+ const location = this.getLocation(node);
241
+ try {
242
+ return await this.tsserver.getQuickInfo(this.getPath(node), location);
243
+ } catch (err) {
244
+ if (err.message === 'No content available.') {
245
+ throw new Error(`unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${location.character}`);
246
+ }
247
+ throw err;
248
+ }
249
+ }
250
+ async getQuickInfoDisplayString(node) {
251
+ const quickInfo = await this.getQuickInfo(node);
252
+ return quickInfo?.body?.displayString || '';
253
+ }
254
+
255
+ /**
256
+ * returns the type definition for a type.
257
+ */
258
+ typeDefinition(node) {
259
+ return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));
260
+ }
261
+ visitTypeDefinition() {}
262
+ getPathWithoutExtension(filePath) {
263
+ const knownExtensions = ['ts', 'js', 'jsx', 'tsx'];
264
+ const fileExtension = (0, _path().extname)(filePath).substring(1);
265
+ const filePathWithoutExtension = () => {
266
+ if (knownExtensions.includes(fileExtension)) {
267
+ return filePath.replace(new RegExp(`\\.${fileExtension}$`), '');
268
+ }
269
+ return filePath;
270
+ };
271
+ if (!(0, _path().isAbsolute)(filePath)) {
272
+ return filePathWithoutExtension();
273
+ }
274
+ if (filePath.startsWith(this.componentRootPath)) {
275
+ return (0, _path().relative)(this.componentRootPath, filePathWithoutExtension());
276
+ }
277
+ if (filePath.startsWith(this.hostRootPath)) {
278
+ return (0, _path().relative)(this.hostRootPath, filePathWithoutExtension());
279
+ }
280
+ return filePathWithoutExtension();
281
+ }
282
+ isIndexFile(filePath, currentFilePath) {
283
+ const indexFilePath = (0, _path().join)(filePath, 'index');
284
+ return (0, _legacy().pathNormalizeToLinux)(indexFilePath) === currentFilePath;
285
+ }
286
+ findFileInComponent(filePath) {
287
+ const normalizedFilePath = (0, _legacy().pathNormalizeToLinux)(filePath);
288
+ const pathToCompareWithoutExtension = this.getPathWithoutExtension(normalizedFilePath);
289
+ const matchingFile = this.component.filesystem.files.find(file => {
290
+ const currentFilePath = (0, _legacy().pathNormalizeToLinux)(file.path);
291
+ const currentFilePathWithoutExtension = this.getPathWithoutExtension(currentFilePath);
292
+ const isSameFilePath = pathToCompareWithoutExtension === currentFilePathWithoutExtension;
293
+ const matches = isSameFilePath || this.isIndexFile(pathToCompareWithoutExtension, currentFilePathWithoutExtension);
294
+ return matches;
295
+ });
296
+ return matchingFile;
297
+ }
298
+ parsePackageNameFromPath(path) {
299
+ const parts = path.split('node_modules');
300
+ if (parts.length === 1) {
301
+ return path;
302
+ }
303
+ const lastPart = parts[parts.length - 1].replace(_path().sep, '');
304
+ const pkgParts = lastPart.split('/');
305
+ if (lastPart.startsWith('@')) {
306
+ // scoped package
307
+ return `${pkgParts[0]}/${pkgParts[1]}`;
308
+ }
309
+ const pkgName = pkgParts[0];
310
+ if (pkgName === 'typescript') {
311
+ // it's a built-in type, such as "string".
312
+ return '';
313
+ }
314
+ return pkgName;
315
+ }
316
+
317
+ /**
318
+ * return the file if part of the component.
319
+ * otherwise, a reference to the target package and the type name.
320
+ */
321
+ getSourceFileInsideComponent(filePath) {
322
+ const file = this.findFileInComponent(filePath);
323
+ return file && this.extractor.parseSourceFile(file);
324
+ }
325
+ async getSourceFileFromNode(node) {
326
+ const filePath = await this.getFilePathByNode(node);
327
+ if (!filePath) {
328
+ return undefined;
329
+ }
330
+ return this.getSourceFileInsideComponent(filePath);
331
+ }
332
+ async getFilePathByNode(node) {
333
+ const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));
334
+ const firstDef = (0, _lodash().head)(def?.body);
335
+ return firstDef?.file;
336
+ }
337
+ async definitionInfo(node) {
338
+ const location = this.getLocation(node);
339
+ const filePath = this.getPath(node);
340
+ const def = await this.tsserver.getDefinition(filePath, location);
341
+ const firstDef = (0, _lodash().head)(def?.body);
342
+ return firstDef;
343
+ }
344
+
345
+ /**
346
+ * get a definition for a given node.
347
+ */
348
+ async definition(definition) {
349
+ const startPosition = definition.start;
350
+ const sourceFile = this.getSourceFileInsideComponent(definition.file);
351
+ if (!sourceFile) {
352
+ // it might be an external reference, cant get the node
353
+ return undefined;
354
+ }
355
+ const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);
356
+ const nodeAtPos = (0, _tsutils().getTokenAtPosition)(sourceFile, pos);
357
+ return nodeAtPos;
358
+ }
359
+
360
+ /**
361
+ * visit a definition for node - e.g. return it's schema.
362
+ */
363
+ async visitDefinition(node) {
364
+ const definitionInfo = await this.definitionInfo(node);
365
+ if (!definitionInfo) {
366
+ return undefined;
367
+ }
368
+ const definition = await this.definition(definitionInfo);
369
+ if (!definition) {
370
+ return this.getTypeRefForExternalNode(node);
371
+ }
372
+ return this.visit(definition.parent);
373
+ }
374
+ async visit(node) {
375
+ if (node.kind === _typescript().SyntaxKind.Identifier && node.parent.parent.kind !== _typescript().SyntaxKind.SourceFile) {
376
+ return this.visit(node.parent);
377
+ }
378
+ return this.extractor.computeSchema(node, this);
379
+ }
380
+ references() {}
381
+ isExported() {}
382
+ isFromComponent() {}
383
+ async getFileIdentifiers(exportDec) {
384
+ const file = exportDec.getSourceFile().fileName;
385
+ const specifierPathStr = exportDec.kind === _typescript().SyntaxKind.ExportDeclaration && exportDec.moduleSpecifier?.getText() || '';
386
+ const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);
387
+ const absPath = (0, _path().resolve)(file, '..', specifierPath);
388
+ const sourceFile = this.getSourceFileInsideComponent(absPath);
389
+ if (!sourceFile) return [];
390
+ return this.getIdentifiers(sourceFile);
391
+ }
392
+ async getFileExports(exportDec) {
393
+ const identifiers = await this.getFileIdentifiers(exportDec);
394
+ return identifiers.filter(identifier => _exportIdentifier().ExportIdentifier.isExportIdentifier(identifier));
395
+ }
396
+ async getFileInternals(exportDec) {
397
+ const identifiers = await this.getFileIdentifiers(exportDec);
398
+ return identifiers.filter(identifier => !_exportIdentifier().ExportIdentifier.isExportIdentifier(identifier));
399
+ }
400
+ getIdentifiers(node) {
401
+ return this.extractor.computeIdentifiers(node, this);
402
+ }
403
+
404
+ /**
405
+ * tsserver has two different calls: "definition" and "typeDefinition".
406
+ * normally, we need the "typeDefinition" to get the type data of a node.
407
+ * sometimes, it has no data, for example when the node is of type TypeReference, and then using "definition" is
408
+ * helpful. (couldn't find a rule when to use each one. e.g. "VariableDeclaration" sometimes has data only in
409
+ * "definition" but it's not clear when/why).
410
+ */
411
+ async getDefinition(node) {
412
+ const typeDefinition = await this.typeDefinition(node);
413
+ const headTypeDefinition = (0, _lodash().head)(typeDefinition?.body);
414
+ if (headTypeDefinition) {
415
+ return headTypeDefinition;
416
+ }
417
+ const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));
418
+ const headDefinition = (0, _lodash().head)(definition?.body);
419
+ return headDefinition;
420
+ }
421
+
422
+ /**
423
+ * Handles type resolution for unknown or external types.
424
+ * Attempts to:
425
+ * 1. Get type references when possible
426
+ * 2. Fall back to inference when references can't be found
427
+ */
428
+ async unknownExactType(node, location, typeStr = 'any') {
429
+ try {
430
+ if (this.isArrayType(typeStr)) {
431
+ const baseType = this.getArrayBaseType(typeStr);
432
+ const currentFilePath = node.getSourceFile().fileName;
433
+ const baseTypeRef = await this.getTypeRef(baseType, this.getIdentifierKey(currentFilePath), location);
434
+ if (baseTypeRef) {
435
+ return new (_semanticsEntities().TypeArraySchema)(location, baseTypeRef);
436
+ }
437
+ return new (_semanticsEntities().TypeArraySchema)(location, new (_semanticsEntities().InferenceTypeSchema)(location, baseType));
438
+ }
439
+ const currentFilePath = node.getSourceFile().fileName;
440
+ const typeRef = await this.getTypeRef(typeStr, this.getIdentifierKey(currentFilePath), location);
441
+ if (typeRef) {
442
+ return typeRef;
443
+ }
444
+ const info = await this.getQuickInfo(node);
445
+ if (!info?.body?.displayString) {
446
+ return new (_semanticsEntities().InferenceTypeSchema)(location, typeStr || 'any');
447
+ }
448
+ const {
449
+ displayString,
450
+ kind
451
+ } = info.body;
452
+ if (kind === 'method') {
453
+ const returnType = this.extractMethodReturnType(displayString);
454
+ return await this.createMethodReturnSchema(node, location, returnType);
455
+ }
456
+ if (kind === 'function' || displayString.includes('=>')) {
457
+ return await this.createFunctionSchema(node, location, displayString);
458
+ }
459
+ if (displayString.includes('{') && displayString.includes('}')) {
460
+ return this.createObjectSchema(node, location, displayString);
461
+ }
462
+ if (displayString.includes('Promise<')) {
463
+ const innerType = this.extractGenericType(displayString, 'Promise');
464
+ return await this.createPromiseSchema(node, location, innerType);
465
+ }
466
+ return new (_semanticsEntities().InferenceTypeSchema)(location, typeStr || 'any');
467
+ } catch {
468
+ return new (_semanticsEntities().InferenceTypeSchema)(location, typeStr || 'any');
469
+ }
470
+ }
471
+
472
+ /**
473
+ * Check if type is an array type (either T[] or Array<T>)
474
+ */
475
+ isArrayType(typeStr) {
476
+ return typeStr.endsWith('[]') || typeStr.startsWith('Array<');
477
+ }
478
+
479
+ /**
480
+ * Extract base type from array type
481
+ */
482
+ getArrayBaseType(typeStr) {
483
+ if (typeStr.endsWith('[]')) {
484
+ return typeStr.slice(0, -2);
485
+ }
486
+ if (typeStr.startsWith('Array<')) {
487
+ const match = /Array<(.+)>/.exec(typeStr);
488
+ return match?.[1] || 'any';
489
+ }
490
+ return typeStr;
491
+ }
492
+
493
+ /**
494
+ * Extract return type from method signature
495
+ */
496
+ extractMethodReturnType(displayString) {
497
+ const returnTypeMatch = displayString.match(/\):\s*(.+)$/);
498
+ return returnTypeMatch ? returnTypeMatch[1].trim() : 'any';
499
+ }
500
+
501
+ /**
502
+ * Extract content from generic type
503
+ */
504
+ extractGenericType(type, wrapper) {
505
+ const match = new RegExp(`${wrapper}<(.+)>`).exec(type);
506
+ return match ? match[1].trim() : type;
507
+ }
508
+
509
+ /**
510
+ * Create schema for method return type, attempting to get type reference
511
+ */
512
+ async createMethodReturnSchema(node, location, returnType) {
513
+ if (this.isArrayType(returnType)) {
514
+ const baseType = this.getArrayBaseType(returnType);
515
+ const currentFilePath = node.getSourceFile().fileName;
516
+ const baseTypeRef = await this.getTypeRef(baseType, this.getIdentifierKey(currentFilePath), location);
517
+ if (baseTypeRef) {
518
+ return new (_semanticsEntities().TypeArraySchema)(location, baseTypeRef);
519
+ }
520
+ return new (_semanticsEntities().TypeArraySchema)(location, new (_semanticsEntities().InferenceTypeSchema)(location, baseType));
521
+ }
522
+ const typeRef = await this.getTypeRef(returnType, this.getIdentifierKeyForNode(node), location);
523
+ return typeRef || new (_semanticsEntities().InferenceTypeSchema)(location, returnType);
524
+ }
525
+
526
+ /**
527
+ * Create schema for function type, handling params and return type
528
+ */
529
+ async createFunctionSchema(node, location, signature) {
530
+ const match = signature.match(/\((.*)\)\s*(?:=>|:)\s*(.+)/);
531
+ if (!match) {
532
+ return new (_semanticsEntities().FunctionLikeSchema)(location, 'anonymous', [], new (_semanticsEntities().InferenceTypeSchema)(location, 'any'), signature);
533
+ }
534
+ const [, paramsStr, returnTypeStr] = match;
535
+ const params = await this.createFunctionParameters(node, location, paramsStr);
536
+ const returnType = await this.createMethodReturnSchema(node, location, returnTypeStr.trim());
537
+ return new (_semanticsEntities().FunctionLikeSchema)(location, 'anonymous', params, returnType, signature);
538
+ }
539
+
540
+ /**
541
+ * Create parameters for function schema, attempting to get type references for param types
542
+ */
543
+ async createFunctionParameters(node, location, paramsStr) {
544
+ if (!paramsStr.trim()) return [];
545
+ const params = paramsStr.split(',');
546
+ const paramSchemas = [];
547
+ for (const param of params) {
548
+ const [nameWithOptional, type] = param.split(':').map(s => s.trim());
549
+ const isOptional = nameWithOptional.includes('?');
550
+ const name = nameWithOptional.replace('?', '');
551
+ if (!type) {
552
+ paramSchemas.push(new (_semanticsEntities().ParameterSchema)(location, name, new (_semanticsEntities().InferenceTypeSchema)(location, 'any'), isOptional));
553
+ continue;
554
+ }
555
+ const currentFilePath = node.getSourceFile().fileName;
556
+ const typeRef = await this.getTypeRef(type, this.getIdentifierKey(currentFilePath), location);
557
+ paramSchemas.push(new (_semanticsEntities().ParameterSchema)(location, name, typeRef || new (_semanticsEntities().InferenceTypeSchema)(location, type), isOptional));
558
+ }
559
+ return paramSchemas;
560
+ }
561
+
562
+ /**
563
+ * Create schema for object literal type
564
+ */
565
+ createObjectSchema(node, location, displayString) {
566
+ const objMatch = displayString.match(/{([^}]+)}/);
567
+ if (!objMatch) {
568
+ return new (_semanticsEntities().InferenceTypeSchema)(location, 'object');
569
+ }
570
+ const objContent = objMatch[1];
571
+ const properties = objContent.split(';').map(prop => prop.trim()).filter(Boolean).map(prop => new (_semanticsEntities().InferenceTypeSchema)(location, prop));
572
+ return new (_semanticsEntities().ArrayLiteralExpressionSchema)(properties, location);
573
+ }
574
+
575
+ /**
576
+ * Create schema for Promise type, attempting to get type reference for the contained type
577
+ */
578
+ async createPromiseSchema(node, location, innerType) {
579
+ const typeRef = await this.getTypeRef(innerType, this.getIdentifierKeyForNode(node), location);
580
+ return typeRef || new (_semanticsEntities().InferenceTypeSchema)(location, innerType);
581
+ }
582
+
583
+ // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location
584
+ isDefInSameLocation(node, definition) {
585
+ if (definition.file !== node.getSourceFile().fileName) {
586
+ return false;
587
+ }
588
+ const loc = this.getLocation(node);
589
+ return loc.line === definition.start.line && loc.character === definition.start.offset;
590
+ }
591
+
592
+ /**
593
+ * resolve a type by a node and its identifier.
594
+ */
595
+ async resolveType(node, typeStr) {
596
+ const location = this.getLocation(node);
597
+
598
+ // check if internal ref with typeInfo
599
+ const internalRef = await this.getTypeRef(typeStr, this.getIdentifierKeyForNode(node), location);
600
+ if (internalRef) return internalRef;
601
+
602
+ // if a node has "type" prop, it has the type data of the node. this normally happens when the code has the type
603
+ // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have "type"
604
+ if (node.type && _typescript().default.isTypeNode(node.type)) {
605
+ return this.computeSchema(node.type);
606
+ }
607
+ const definition = await this.getDefinition(node);
608
+ if (!definition) {
609
+ return this.unknownExactType(node, location, typeStr);
610
+ }
611
+ if (this.isDefInSameLocation(node, definition)) {
612
+ return this.unknownExactType(node, location, typeStr);
613
+ }
614
+ const definitionNode = await this.definition(definition);
615
+ if (!definitionNode) {
616
+ return this.unknownExactType(node, location, typeStr);
617
+ }
618
+ const definitionNodeName = definitionNode?.getText();
619
+
620
+ // check if internal ref with definition info
621
+ const definitionInternalRef = await this.getTypeRef(definitionNodeName, this.getIdentifierKeyForNode(definitionNode), location);
622
+ if (definitionInternalRef) return definitionInternalRef;
623
+ const transformer = this.extractor.getTransformer(definitionNode, this);
624
+ if (transformer === undefined) {
625
+ const file = this.findFileInComponent(definition.file);
626
+ if (!file) return this.getTypeRefForExternalPath(typeStr, definition.file, location);
627
+ return this.unknownExactType(node, location, typeStr);
628
+ }
629
+ const schemaNode = await this.visit(definitionNode);
630
+ if (!schemaNode) {
631
+ return this.unknownExactType(node, location, typeStr);
632
+ }
633
+ const apiTransformer = this.extractor.getAPITransformer(schemaNode);
634
+ let transformedApi = apiTransformer ? await apiTransformer.transform(schemaNode, this) : schemaNode;
635
+ if (!transformedApi) {
636
+ transformedApi = new (_semanticsEntities().IgnoredSchema)(schemaNode);
637
+ }
638
+ return transformedApi;
639
+ }
640
+ getCompIdByPkgName(pkgName) {
641
+ return this.componentDeps.find(dep => dep.packageName === pkgName)?.componentId;
642
+ }
643
+ async getTypeRef(typeStr, filePath, location) {
644
+ const nodeIdentifierKey = this.getIdentifierKey(filePath);
645
+ const mainFileIdentifierKey = this.mainFileIdentifierKey;
646
+ const nodeIdentifierList = this.identifiers.get(nodeIdentifierKey);
647
+ const mainIdentifierList = this.identifiers.get(mainFileIdentifierKey);
648
+ const nodeIdentifier = new (_identifier().Identifier)(typeStr, nodeIdentifierKey);
649
+ const mainIdentifier = new (_identifier().Identifier)(typeStr, mainFileIdentifierKey);
650
+ const parsedNodeIdentifier = nodeIdentifierList?.find(nodeIdentifier);
651
+ const parsedMainIdentifier = mainIdentifierList?.find(mainIdentifier);
652
+ const isExportedFromMain = parsedMainIdentifier && _exportIdentifier().ExportIdentifier.isExportIdentifier(parsedMainIdentifier);
653
+ if (!parsedNodeIdentifier) return undefined;
654
+ const internalRef = !isExportedFromMain;
655
+ if (internalRef) {
656
+ this.setInternalIdentifiers(parsedNodeIdentifier.normalizedPath, new (_identifierList().IdentifierList)([parsedNodeIdentifier]));
657
+ }
658
+ return this.resolveTypeRef(parsedNodeIdentifier, location, isExportedFromMain);
659
+ }
660
+ async resolveTypeRef(identifier, location, isExportedFromMain) {
661
+ const sourceFilePath = identifier.sourceFilePath;
662
+ if (!sourceFilePath || isExportedFromMain && (0, _legacy().isRelativeImport)(sourceFilePath)) {
663
+ return new (_semanticsEntities().TypeRefSchema)(location, identifier.id, undefined, undefined, !isExportedFromMain ? this.getPathRelativeToComponent(identifier.filePath) : undefined);
664
+ }
665
+ if (!(0, _legacy().isRelativeImport)(sourceFilePath)) {
666
+ const pkgName = this.parsePackageNameFromPath(sourceFilePath);
667
+ const compIdByPkg = this.getCompIdByPkgName(pkgName);
668
+ const compIdByPath = await this.extractor.getComponentIDByPath(sourceFilePath);
669
+ if (compIdByPath) {
670
+ return new (_semanticsEntities().TypeRefSchema)(location, identifier.id, compIdByPath);
671
+ }
672
+ if (compIdByPkg) {
673
+ return new (_semanticsEntities().TypeRefSchema)(location, identifier.id, compIdByPkg);
674
+ }
675
+
676
+ // package without comp id
677
+ return new (_semanticsEntities().TypeRefSchema)(location, identifier.id, undefined, pkgName);
678
+ }
679
+ const relativeDir = identifier.filePath.substring(0, identifier.filePath.lastIndexOf('/'));
680
+ const absFilePath = (0, _path().resolve)(this.componentRootPath, relativeDir, sourceFilePath);
681
+ const compFilePath = this.findFileInComponent(absFilePath);
682
+ if (!compFilePath) {
683
+ // @todo handle this better
684
+ throw new Error(`cannot find file in component \n source file path ${sourceFilePath}\n
685
+ identifier file path ${identifier.filePath}\nrelative dir ${relativeDir}\n
686
+ absFilePath ${absFilePath}`);
687
+ return new (_semanticsEntities().TypeRefSchema)(location, identifier.id);
688
+ }
689
+ const idKey = this.getIdentifierKey(compFilePath?.path);
690
+
691
+ // if re exported from a file, recurse until definition
692
+ const exportedIdentifier = (this.identifiers.get(idKey)?.identifiers || []).find(i => i.id === identifier.id);
693
+ if (exportedIdentifier) {
694
+ return this.resolveTypeRef(exportedIdentifier, location, isExportedFromMain);
695
+ }
696
+ return new (_semanticsEntities().TypeRefSchema)(location, identifier.id);
697
+ }
698
+ async getTypeRefForExternalNode(node) {
699
+ const info = await this.getQuickInfo(node);
700
+ const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
701
+ const location = this.getLocation(node);
702
+ const filePath = this.getPath(node);
703
+ return this.getTypeRefForExternalPath(typeStr, filePath, location);
704
+ }
705
+ async getTypeRefForExternalPath(typeStr, filePath, location) {
706
+ const compIdByPath = await this.extractor.getComponentIDByPath(filePath);
707
+ if (compIdByPath) {
708
+ return new (_semanticsEntities().TypeRefSchema)(location, typeStr, compIdByPath);
709
+ }
710
+ const pkgName = this.parsePackageNameFromPath(filePath);
711
+ const compIdByPkg = this.getCompIdByPkgName(pkgName);
712
+ if (compIdByPkg) {
713
+ return new (_semanticsEntities().TypeRefSchema)(location, typeStr, compIdByPkg);
714
+ }
715
+ return new (_semanticsEntities().TypeRefSchema)(location, typeStr, undefined, pkgName);
716
+ }
717
+ async jsDocToDocSchema(node) {
718
+ if (!(0, _tsutils().canHaveJsDoc)(node)) {
719
+ return undefined;
720
+ }
721
+ const jsDocs = (0, _tsutils().getJsDoc)(node);
722
+ if (!jsDocs.length) {
723
+ return undefined;
724
+ }
725
+ // not sure how common it is to have multiple JSDocs. never seen it before.
726
+ // regardless, in typescript implementation of methods like `getJSDocDeprecatedTag()`, they use the first one. (`getFirstJSDocTag()`)
727
+ const jsDoc = jsDocs[0];
728
+ const location = this.getLocation(jsDoc);
729
+ // Extract link comments and filter them out from the main comment
730
+ const linkComments = typeof jsDoc.comment !== 'string' ? jsDoc.comment?.filter(c => c.kind === _typescript().default.SyntaxKind.JSDocLink) ?? [] : [];
731
+ const linkTags = linkComments.map(linkComment => {
732
+ const tagName = 'link';
733
+ const tagText = `${linkComment.name?.getText() ?? ''}${linkComment.text ?? ''}`;
734
+ const tagLocation = this.getLocation(linkComment);
735
+ return new (_semanticsEntities().TagSchema)(tagLocation, tagName, tagText);
736
+ });
737
+ const commentsWithoutLink = typeof jsDoc.comment !== 'string' ? jsDoc.comment?.filter(c => c.kind !== _typescript().default.SyntaxKind.JSDocLink) ?? '' : jsDoc.comment;
738
+ const comment = (0, _typescript().getTextOfJSDocComment)(commentsWithoutLink);
739
+ const tags = (jsDoc.tags ? await (0, _pMapSeries().default)(jsDoc.tags, tag => (0, _jsdocToDocSchema().tagParser)(tag, this, this.formatter)) : []).concat(linkTags);
740
+ return new (_semanticsEntities().DocSchema)(location, jsDoc.getText(), comment, tags);
741
+ }
742
+ }
743
+ exports.SchemaExtractorContext = SchemaExtractorContext;
744
+
745
+ //# sourceMappingURL=schema-extractor-context.js.map