tsc-ts 0.0.3 → 0.0.5

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 (596) hide show
  1. package/README.md +46 -0
  2. package/dist/api/compiler/ast-utilities.d.ts +82 -0
  3. package/dist/api/compiler/ast-utilities.js +462 -0
  4. package/dist/api/compiler/ast.d.ts +2350 -0
  5. package/dist/api/compiler/ast.js +11206 -0
  6. package/dist/api/compiler/astnav.d.ts +37 -0
  7. package/dist/api/compiler/astnav.js +767 -0
  8. package/dist/api/compiler/binder-utilities.d.ts +182 -0
  9. package/dist/api/compiler/binder-utilities.js +1240 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2358 -0
  12. package/dist/api/compiler/character-codes.d.ts +161 -0
  13. package/dist/api/compiler/character-codes.js +160 -0
  14. package/dist/api/compiler/checker-calls.d.ts +46 -0
  15. package/dist/api/compiler/checker-calls.js +1640 -0
  16. package/dist/api/compiler/checker-classes.d.ts +30 -0
  17. package/dist/api/compiler/checker-classes.js +582 -0
  18. package/dist/api/compiler/checker-contextual.d.ts +77 -0
  19. package/dist/api/compiler/checker-contextual.js +1136 -0
  20. package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
  21. package/dist/api/compiler/checker-declaration-order.js +356 -0
  22. package/dist/api/compiler/checker-declarations.d.ts +33 -0
  23. package/dist/api/compiler/checker-declarations.js +888 -0
  24. package/dist/api/compiler/checker-declared-types.d.ts +48 -0
  25. package/dist/api/compiler/checker-declared-types.js +787 -0
  26. package/dist/api/compiler/checker-decorators.d.ts +26 -0
  27. package/dist/api/compiler/checker-decorators.js +562 -0
  28. package/dist/api/compiler/checker-deprecation.d.ts +33 -0
  29. package/dist/api/compiler/checker-deprecation.js +315 -0
  30. package/dist/api/compiler/checker-destructuring.d.ts +34 -0
  31. package/dist/api/compiler/checker-destructuring.js +584 -0
  32. package/dist/api/compiler/checker-elaboration.d.ts +15 -0
  33. package/dist/api/compiler/checker-elaboration.js +290 -0
  34. package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
  35. package/dist/api/compiler/checker-emit-helpers.js +154 -0
  36. package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
  37. package/dist/api/compiler/checker-emit-resolver.js +579 -0
  38. package/dist/api/compiler/checker-evaluator.d.ts +27 -0
  39. package/dist/api/compiler/checker-evaluator.js +188 -0
  40. package/dist/api/compiler/checker-expressions.d.ts +67 -0
  41. package/dist/api/compiler/checker-expressions.js +1351 -0
  42. package/dist/api/compiler/checker-features.d.ts +6 -0
  43. package/dist/api/compiler/checker-features.js +354 -0
  44. package/dist/api/compiler/checker-flow.d.ts +86 -0
  45. package/dist/api/compiler/checker-flow.js +169 -0
  46. package/dist/api/compiler/checker-functions.d.ts +43 -0
  47. package/dist/api/compiler/checker-functions.js +1002 -0
  48. package/dist/api/compiler/checker-generated-code.d.ts +25 -0
  49. package/dist/api/compiler/checker-generated-code.js +168 -0
  50. package/dist/api/compiler/checker-globals.d.ts +14 -0
  51. package/dist/api/compiler/checker-globals.js +37 -0
  52. package/dist/api/compiler/checker-grammar.d.ts +35 -0
  53. package/dist/api/compiler/checker-grammar.js +2573 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +900 -0
  56. package/dist/api/compiler/checker-inference.d.ts +179 -0
  57. package/dist/api/compiler/checker-inference.js +2105 -0
  58. package/dist/api/compiler/checker-iteration.d.ts +115 -0
  59. package/dist/api/compiler/checker-iteration.js +857 -0
  60. package/dist/api/compiler/checker-javascript.d.ts +42 -0
  61. package/dist/api/compiler/checker-javascript.js +441 -0
  62. package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
  63. package/dist/api/compiler/checker-jsdoc.js +320 -0
  64. package/dist/api/compiler/checker-jsx.d.ts +94 -0
  65. package/dist/api/compiler/checker-jsx.js +1433 -0
  66. package/dist/api/compiler/checker-literals.d.ts +6 -0
  67. package/dist/api/compiler/checker-literals.js +43 -0
  68. package/dist/api/compiler/checker-members.d.ts +198 -0
  69. package/dist/api/compiler/checker-members.js +2126 -0
  70. package/dist/api/compiler/checker-modules.d.ts +85 -0
  71. package/dist/api/compiler/checker-modules.js +2141 -0
  72. package/dist/api/compiler/checker-narrowing.d.ts +120 -0
  73. package/dist/api/compiler/checker-narrowing.js +2797 -0
  74. package/dist/api/compiler/checker-object-literals.d.ts +14 -0
  75. package/dist/api/compiler/checker-object-literals.js +479 -0
  76. package/dist/api/compiler/checker-operators.d.ts +33 -0
  77. package/dist/api/compiler/checker-operators.js +1040 -0
  78. package/dist/api/compiler/checker-overloads.d.ts +7 -0
  79. package/dist/api/compiler/checker-overloads.js +270 -0
  80. package/dist/api/compiler/checker-property-access.d.ts +34 -0
  81. package/dist/api/compiler/checker-property-access.js +672 -0
  82. package/dist/api/compiler/checker-services.d.ts +49 -0
  83. package/dist/api/compiler/checker-services.js +995 -0
  84. package/dist/api/compiler/checker-signatures.d.ts +55 -0
  85. package/dist/api/compiler/checker-signatures.js +788 -0
  86. package/dist/api/compiler/checker-source-file.d.ts +27 -0
  87. package/dist/api/compiler/checker-source-file.js +619 -0
  88. package/dist/api/compiler/checker-statements.d.ts +18 -0
  89. package/dist/api/compiler/checker-statements.js +226 -0
  90. package/dist/api/compiler/checker-super.d.ts +13 -0
  91. package/dist/api/compiler/checker-super.js +241 -0
  92. package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
  93. package/dist/api/compiler/checker-symbol-types.js +1885 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1782 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2501 -0
  98. package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
  99. package/dist/api/compiler/checker-type-nodes.js +828 -0
  100. package/dist/api/compiler/checker-type-operators.d.ts +109 -0
  101. package/dist/api/compiler/checker-type-operators.js +1842 -0
  102. package/dist/api/compiler/checker-types.d.ts +1027 -0
  103. package/dist/api/compiler/checker-types.js +1697 -0
  104. package/dist/api/compiler/checker-unused.d.ts +19 -0
  105. package/dist/api/compiler/checker-unused.js +524 -0
  106. package/dist/api/compiler/checker-utilities.d.ts +33 -0
  107. package/dist/api/compiler/checker-utilities.js +141 -0
  108. package/dist/api/compiler/checker.d.ts +491 -0
  109. package/dist/api/compiler/checker.js +912 -0
  110. package/dist/api/compiler/command-line.d.ts +32 -0
  111. package/dist/api/compiler/command-line.js +383 -0
  112. package/dist/api/compiler/compile-program.d.ts +118 -0
  113. package/dist/api/compiler/compile-program.js +384 -0
  114. package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
  115. package/dist/api/compiler/diagnostic-locales.js +64 -0
  116. package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
  117. package/dist/api/compiler/diagnostic-messages.js +184 -0
  118. package/dist/api/compiler/diagnostics.d.ts +167 -0
  119. package/dist/api/compiler/diagnostics.js +820 -0
  120. package/dist/api/compiler/emitter.d.ts +71 -0
  121. package/dist/api/compiler/emitter.js +327 -0
  122. package/dist/api/compiler/file-include.d.ts +117 -0
  123. package/dist/api/compiler/file-include.js +536 -0
  124. package/dist/api/compiler/file-loader.d.ts +261 -0
  125. package/dist/api/compiler/file-loader.js +1257 -0
  126. package/dist/api/compiler/file-system.d.ts +51 -0
  127. package/dist/api/compiler/file-system.js +132 -0
  128. package/dist/api/compiler/flow.d.ts +60 -0
  129. package/dist/api/compiler/flow.js +45 -0
  130. package/dist/api/compiler/instantiation.d.ts +74 -0
  131. package/dist/api/compiler/instantiation.js +799 -0
  132. package/dist/api/compiler/jsdoc.d.ts +75 -0
  133. package/dist/api/compiler/jsdoc.js +1229 -0
  134. package/dist/api/compiler/link-tables.d.ts +36 -0
  135. package/dist/api/compiler/link-tables.js +83 -0
  136. package/dist/api/compiler/locale-data.d.ts +24 -0
  137. package/dist/api/compiler/locale-data.js +183 -0
  138. package/dist/api/compiler/locale.d.ts +4 -0
  139. package/dist/api/compiler/locale.js +317 -0
  140. package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
  141. package/dist/api/compiler/locales/cs-CZ.js +3 -0
  142. package/dist/api/compiler/locales/de-DE.d.ts +2 -0
  143. package/dist/api/compiler/locales/de-DE.js +3 -0
  144. package/dist/api/compiler/locales/es-ES.d.ts +2 -0
  145. package/dist/api/compiler/locales/es-ES.js +3 -0
  146. package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
  147. package/dist/api/compiler/locales/fr-FR.js +3 -0
  148. package/dist/api/compiler/locales/it-IT.d.ts +2 -0
  149. package/dist/api/compiler/locales/it-IT.js +3 -0
  150. package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
  151. package/dist/api/compiler/locales/ja-JP.js +3 -0
  152. package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
  153. package/dist/api/compiler/locales/ko-KR.js +3 -0
  154. package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
  155. package/dist/api/compiler/locales/pl-PL.js +3 -0
  156. package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
  157. package/dist/api/compiler/locales/pt-BR.js +3 -0
  158. package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
  159. package/dist/api/compiler/locales/ru-RU.js +3 -0
  160. package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
  161. package/dist/api/compiler/locales/tr-TR.js +3 -0
  162. package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
  163. package/dist/api/compiler/locales/zh-CN.js +3 -0
  164. package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
  165. package/dist/api/compiler/locales/zh-TW.js +3 -0
  166. package/dist/api/compiler/module-resolution-types.d.ts +83 -0
  167. package/dist/api/compiler/module-resolution-types.js +176 -0
  168. package/dist/api/compiler/module-resolution.d.ts +71 -0
  169. package/dist/api/compiler/module-resolution.js +1598 -0
  170. package/dist/api/compiler/module-specifiers.d.ts +64 -0
  171. package/dist/api/compiler/module-specifiers.js +1101 -0
  172. package/dist/api/compiler/name-resolver.d.ts +43 -0
  173. package/dist/api/compiler/name-resolver.js +509 -0
  174. package/dist/api/compiler/node-builder-names.d.ts +32 -0
  175. package/dist/api/compiler/node-builder-names.js +854 -0
  176. package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
  177. package/dist/api/compiler/node-builder-pseudo.js +744 -0
  178. package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
  179. package/dist/api/compiler/node-builder-reuse.js +647 -0
  180. package/dist/api/compiler/node-builder.d.ts +270 -0
  181. package/dist/api/compiler/node-builder.js +2645 -0
  182. package/dist/api/compiler/option-declarations.d.ts +90 -0
  183. package/dist/api/compiler/option-declarations.js +1460 -0
  184. package/dist/api/compiler/options.d.ts +289 -0
  185. package/dist/api/compiler/options.js +1197 -0
  186. package/dist/api/compiler/output-paths.d.ts +42 -0
  187. package/dist/api/compiler/output-paths.js +195 -0
  188. package/dist/api/compiler/package-json.d.ts +175 -0
  189. package/dist/api/compiler/package-json.js +1015 -0
  190. package/dist/api/compiler/parallel-parse.d.ts +219 -0
  191. package/dist/api/compiler/parallel-parse.js +537 -0
  192. package/dist/api/compiler/parser.d.ts +587 -0
  193. package/dist/api/compiler/parser.js +6407 -0
  194. package/dist/api/compiler/path.d.ts +91 -0
  195. package/dist/api/compiler/path.js +705 -0
  196. package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
  197. package/dist/api/compiler/printer/async-helpers.js +91 -0
  198. package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
  199. package/dist/api/compiler/printer/auto-generate.js +20 -0
  200. package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
  201. package/dist/api/compiler/printer/decorator-helpers.js +118 -0
  202. package/dist/api/compiler/printer/emit-context.d.ts +154 -0
  203. package/dist/api/compiler/printer/emit-context.js +576 -0
  204. package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
  205. package/dist/api/compiler/printer/emit-flags.js +2 -0
  206. package/dist/api/compiler/printer/factory-base.d.ts +171 -0
  207. package/dist/api/compiler/printer/factory-base.js +1505 -0
  208. package/dist/api/compiler/printer/factory.d.ts +147 -0
  209. package/dist/api/compiler/printer/factory.js +542 -0
  210. package/dist/api/compiler/printer/helpers.d.ts +27 -0
  211. package/dist/api/compiler/printer/helpers.js +164 -0
  212. package/dist/api/compiler/printer/name-generator.d.ts +41 -0
  213. package/dist/api/compiler/printer/name-generator.js +283 -0
  214. package/dist/api/compiler/printer/printer.d.ts +411 -0
  215. package/dist/api/compiler/printer/printer.js +4517 -0
  216. package/dist/api/compiler/printer/text-writer.d.ts +46 -0
  217. package/dist/api/compiler/printer/text-writer.js +172 -0
  218. package/dist/api/compiler/printer/utilities.d.ts +82 -0
  219. package/dist/api/compiler/printer/utilities.js +817 -0
  220. package/dist/api/compiler/program-checker.d.ts +156 -0
  221. package/dist/api/compiler/program-checker.js +526 -0
  222. package/dist/api/compiler/program-utilities.d.ts +52 -0
  223. package/dist/api/compiler/program-utilities.js +365 -0
  224. package/dist/api/compiler/program.d.ts +180 -0
  225. package/dist/api/compiler/program.js +1011 -0
  226. package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
  227. package/dist/api/compiler/pseudo-bigint.js +61 -0
  228. package/dist/api/compiler/regexp-checker.d.ts +38 -0
  229. package/dist/api/compiler/regexp-checker.js +942 -0
  230. package/dist/api/compiler/relations.d.ts +263 -0
  231. package/dist/api/compiler/relations.js +4002 -0
  232. package/dist/api/compiler/reparser.d.ts +48 -0
  233. package/dist/api/compiler/reparser.js +1323 -0
  234. package/dist/api/compiler/scanner.d.ts +256 -0
  235. package/dist/api/compiler/scanner.js +2853 -0
  236. package/dist/api/compiler/side-state.d.ts +16 -0
  237. package/dist/api/compiler/side-state.js +89 -0
  238. package/dist/api/compiler/sourcemap.d.ts +55 -0
  239. package/dist/api/compiler/sourcemap.js +340 -0
  240. package/dist/api/compiler/spelling.d.ts +14 -0
  241. package/dist/api/compiler/spelling.js +128 -0
  242. package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
  243. package/dist/api/compiler/symbol-accessibility.js +894 -0
  244. package/dist/api/compiler/symbol.d.ts +240 -0
  245. package/dist/api/compiler/symbol.js +228 -0
  246. package/dist/api/compiler/symlinks.d.ts +32 -0
  247. package/dist/api/compiler/symlinks.js +114 -0
  248. package/dist/api/compiler/syntax-kind.d.ts +389 -0
  249. package/dist/api/compiler/syntax-kind.js +2 -0
  250. package/dist/api/compiler/timeline.d.ts +9 -0
  251. package/dist/api/compiler/timeline.js +54 -0
  252. package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
  253. package/dist/api/compiler/transformers/alias-references.js +676 -0
  254. package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
  255. package/dist/api/compiler/transformers/async-utilities.js +260 -0
  256. package/dist/api/compiler/transformers/async.d.ts +53 -0
  257. package/dist/api/compiler/transformers/async.js +645 -0
  258. package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
  259. package/dist/api/compiler/transformers/class-fields.js +2418 -0
  260. package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
  261. package/dist/api/compiler/transformers/class-utilities.js +261 -0
  262. package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
  263. package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
  264. package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
  265. package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
  266. package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
  267. package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
  270. package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
  271. package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
  272. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
  273. package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
  274. package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
  275. package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2380 -0
  278. package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
  279. package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
  280. package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
  281. package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
  282. package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
  283. package/dist/api/compiler/transformers/destructuring.js +626 -0
  284. package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
  285. package/dist/api/compiler/transformers/downlevel.js +45 -0
  286. package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
  287. package/dist/api/compiler/transformers/emit-resolver.js +197 -0
  288. package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
  289. package/dist/api/compiler/transformers/es-decorators.js +1901 -0
  290. package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
  291. package/dist/api/compiler/transformers/exponentiation.js +76 -0
  292. package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
  293. package/dist/api/compiler/transformers/external-module-info.js +351 -0
  294. package/dist/api/compiler/transformers/for-await.d.ts +43 -0
  295. package/dist/api/compiler/transformers/for-await.js +469 -0
  296. package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
  297. package/dist/api/compiler/transformers/import-elision.js +124 -0
  298. package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
  299. package/dist/api/compiler/transformers/jsx-entities.js +256 -0
  300. package/dist/api/compiler/transformers/jsx.d.ts +71 -0
  301. package/dist/api/compiler/transformers/jsx.js +700 -0
  302. package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
  303. package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
  304. package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
  305. package/dist/api/compiler/transformers/logical-assignment.js +62 -0
  306. package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
  307. package/dist/api/compiler/transformers/module-utilities.js +36 -0
  308. package/dist/api/compiler/transformers/module.d.ts +49 -0
  309. package/dist/api/compiler/transformers/module.js +296 -0
  310. package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
  311. package/dist/api/compiler/transformers/named-evaluation.js +266 -0
  312. package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
  313. package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
  314. package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
  315. package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
  316. package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
  317. package/dist/api/compiler/transformers/optional-catch.js +20 -0
  318. package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
  319. package/dist/api/compiler/transformers/optional-chain.js +188 -0
  320. package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
  322. package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
  323. package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
  324. package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +203 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +254 -0
  328. package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
  329. package/dist/api/compiler/transformers/tagged-template.js +148 -0
  330. package/dist/api/compiler/transformers/transformer.d.ts +17 -0
  331. package/dist/api/compiler/transformers/transformer.js +54 -0
  332. package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
  333. package/dist/api/compiler/transformers/type-eraser.js +346 -0
  334. package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
  335. package/dist/api/compiler/transformers/type-serialization.js +347 -0
  336. package/dist/api/compiler/transformers/using.d.ts +56 -0
  337. package/dist/api/compiler/transformers/using.js +453 -0
  338. package/dist/api/compiler/transformers/utilities.d.ts +50 -0
  339. package/dist/api/compiler/transformers/utilities.js +347 -0
  340. package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
  341. package/dist/api/compiler/transformers/visitor-base.js +817 -0
  342. package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
  343. package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
  344. package/dist/api/compiler/tsconfig.d.ts +177 -0
  345. package/dist/api/compiler/tsconfig.js +1311 -0
  346. package/dist/api/compiler/type-printer.d.ts +15 -0
  347. package/dist/api/compiler/type-printer.js +74 -0
  348. package/dist/api/compiler/types.d.ts +87 -0
  349. package/dist/api/compiler/types.js +23 -0
  350. package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
  351. package/dist/api/compiler/unicode-identifiers.js +209 -0
  352. package/dist/api/compiler/unicode-properties.d.ts +8 -0
  353. package/dist/api/compiler/unicode-properties.js +531 -0
  354. package/dist/api/compiler/vfs-match.d.ts +24 -0
  355. package/dist/api/compiler/vfs-match.js +587 -0
  356. package/dist/api/library/ast.d.ts +74 -0
  357. package/dist/api/library/ast.generated.d.ts +1145 -0
  358. package/dist/api/library/ast.generated.js +3 -0
  359. package/dist/api/library/ast.js +5 -0
  360. package/dist/api/library/checker.d.ts +51 -0
  361. package/dist/api/library/checker.js +318 -0
  362. package/dist/api/library/compiler-options.generated.d.ts +108 -0
  363. package/dist/api/library/compiler-options.generated.js +3 -0
  364. package/dist/api/library/diagnostics.d.ts +13 -0
  365. package/dist/api/library/diagnostics.js +50 -0
  366. package/dist/api/library/disk.d.ts +13 -0
  367. package/dist/api/library/disk.js +66 -0
  368. package/dist/api/library/enums.generated.d.ts +891 -0
  369. package/dist/api/library/enums.generated.js +916 -0
  370. package/dist/api/library/errors.d.ts +13 -0
  371. package/dist/api/library/errors.js +24 -0
  372. package/dist/api/library/host.d.ts +24 -0
  373. package/dist/api/library/host.js +52 -0
  374. package/dist/api/library/index.d.ts +14 -0
  375. package/dist/api/library/index.js +15 -0
  376. package/dist/api/library/nodes.d.ts +51 -0
  377. package/dist/api/library/nodes.js +196 -0
  378. package/dist/api/library/options.d.ts +144 -0
  379. package/dist/api/library/options.js +308 -0
  380. package/dist/api/library/parse.d.ts +19 -0
  381. package/dist/api/library/parse.js +41 -0
  382. package/dist/api/library/program.d.ts +21 -0
  383. package/dist/api/library/program.js +234 -0
  384. package/dist/api/library/symbols.d.ts +8 -0
  385. package/dist/api/library/symbols.js +11 -0
  386. package/dist/api/library/types.d.ts +313 -0
  387. package/dist/api/library/types.js +6 -0
  388. package/package.json +22 -8
  389. package/src/compiler/ast-utilities.ts +548 -0
  390. package/src/compiler/ast.ts +12862 -0
  391. package/src/compiler/astnav.ts +799 -0
  392. package/src/compiler/binder-utilities.ts +1392 -0
  393. package/src/compiler/binder.ts +2703 -0
  394. package/src/compiler/build-info.ts +1197 -0
  395. package/src/compiler/character-codes.ts +323 -0
  396. package/src/compiler/checker-calls.ts +2155 -0
  397. package/src/compiler/checker-classes.ts +706 -0
  398. package/src/compiler/checker-contextual.ts +1457 -0
  399. package/src/compiler/checker-declaration-order.ts +438 -0
  400. package/src/compiler/checker-declarations.ts +1194 -0
  401. package/src/compiler/checker-declared-types.ts +919 -0
  402. package/src/compiler/checker-decorators.ts +694 -0
  403. package/src/compiler/checker-deprecation.ts +359 -0
  404. package/src/compiler/checker-destructuring.ts +805 -0
  405. package/src/compiler/checker-elaboration.ts +477 -0
  406. package/src/compiler/checker-emit-helpers.ts +224 -0
  407. package/src/compiler/checker-emit-resolver.ts +769 -0
  408. package/src/compiler/checker-evaluator.ts +243 -0
  409. package/src/compiler/checker-expressions.ts +1831 -0
  410. package/src/compiler/checker-features.ts +361 -0
  411. package/src/compiler/checker-flow.ts +394 -0
  412. package/src/compiler/checker-functions.ts +1296 -0
  413. package/src/compiler/checker-generated-code.ts +227 -0
  414. package/src/compiler/checker-globals.ts +52 -0
  415. package/src/compiler/checker-grammar.ts +3584 -0
  416. package/src/compiler/checker-heritage.ts +1233 -0
  417. package/src/compiler/checker-inference.ts +2576 -0
  418. package/src/compiler/checker-iteration.ts +1206 -0
  419. package/src/compiler/checker-javascript.ts +502 -0
  420. package/src/compiler/checker-jsdoc.ts +360 -0
  421. package/src/compiler/checker-jsx.ts +1924 -0
  422. package/src/compiler/checker-literals.ts +61 -0
  423. package/src/compiler/checker-members.ts +2436 -0
  424. package/src/compiler/checker-modules.ts +2886 -0
  425. package/src/compiler/checker-narrowing.ts +3230 -0
  426. package/src/compiler/checker-object-literals.ts +575 -0
  427. package/src/compiler/checker-operators.ts +1422 -0
  428. package/src/compiler/checker-overloads.ts +328 -0
  429. package/src/compiler/checker-property-access.ts +906 -0
  430. package/src/compiler/checker-services.ts +1149 -0
  431. package/src/compiler/checker-signatures.ts +1032 -0
  432. package/src/compiler/checker-source-file.ts +732 -0
  433. package/src/compiler/checker-statements.ts +292 -0
  434. package/src/compiler/checker-super.ts +261 -0
  435. package/src/compiler/checker-symbol-types.ts +2107 -0
  436. package/src/compiler/checker-symbols.ts +2150 -0
  437. package/src/compiler/checker-type-factory.ts +2579 -0
  438. package/src/compiler/checker-type-nodes.ts +1033 -0
  439. package/src/compiler/checker-type-operators.ts +2502 -0
  440. package/src/compiler/checker-types.ts +2340 -0
  441. package/src/compiler/checker-unused.ts +642 -0
  442. package/src/compiler/checker-utilities.ts +161 -0
  443. package/src/compiler/checker.ts +1116 -0
  444. package/src/compiler/command-line.ts +436 -0
  445. package/src/compiler/compile-program.ts +439 -0
  446. package/src/compiler/decoder.ts +1209 -0
  447. package/src/compiler/diagnostic-locales.ts +86 -0
  448. package/src/compiler/diagnostic-messages.ts +2349 -0
  449. package/src/compiler/diagnostics.ts +897 -0
  450. package/src/compiler/emitter.ts +434 -0
  451. package/src/compiler/encoder.ts +1945 -0
  452. package/src/compiler/file-include.ts +673 -0
  453. package/src/compiler/file-loader.ts +1528 -0
  454. package/src/compiler/file-system.ts +143 -0
  455. package/src/compiler/flow.ts +89 -0
  456. package/src/compiler/help.ts +473 -0
  457. package/src/compiler/incremental.ts +2784 -0
  458. package/src/compiler/init.ts +141 -0
  459. package/src/compiler/instantiation.ts +894 -0
  460. package/src/compiler/jsdoc.ts +1386 -0
  461. package/src/compiler/link-tables.ts +98 -0
  462. package/src/compiler/locale-data.ts +203 -0
  463. package/src/compiler/locale.ts +307 -0
  464. package/src/compiler/locales/cs-CZ.ts +5 -0
  465. package/src/compiler/locales/de-DE.ts +5 -0
  466. package/src/compiler/locales/es-ES.ts +5 -0
  467. package/src/compiler/locales/fr-FR.ts +5 -0
  468. package/src/compiler/locales/it-IT.ts +5 -0
  469. package/src/compiler/locales/ja-JP.ts +5 -0
  470. package/src/compiler/locales/ko-KR.ts +5 -0
  471. package/src/compiler/locales/pl-PL.ts +5 -0
  472. package/src/compiler/locales/pt-BR.ts +5 -0
  473. package/src/compiler/locales/ru-RU.ts +5 -0
  474. package/src/compiler/locales/tr-TR.ts +5 -0
  475. package/src/compiler/locales/zh-CN.ts +5 -0
  476. package/src/compiler/locales/zh-TW.ts +5 -0
  477. package/src/compiler/module-resolution-types.ts +243 -0
  478. package/src/compiler/module-resolution.ts +2072 -0
  479. package/src/compiler/module-specifiers.ts +1491 -0
  480. package/src/compiler/name-resolver.ts +646 -0
  481. package/src/compiler/node-builder-names.ts +1069 -0
  482. package/src/compiler/node-builder-pseudo.ts +892 -0
  483. package/src/compiler/node-builder-reuse.ts +764 -0
  484. package/src/compiler/node-builder.ts +3425 -0
  485. package/src/compiler/option-declarations.ts +1560 -0
  486. package/src/compiler/options.ts +1576 -0
  487. package/src/compiler/output-paths.ts +334 -0
  488. package/src/compiler/package-json.ts +1083 -0
  489. package/src/compiler/parallel-check.ts +1951 -0
  490. package/src/compiler/parallel-parse.ts +590 -0
  491. package/src/compiler/parse-thread.ts +140 -0
  492. package/src/compiler/parser.ts +7716 -0
  493. package/src/compiler/path.ts +717 -0
  494. package/src/compiler/printer/async-helpers.ts +183 -0
  495. package/src/compiler/printer/auto-generate.ts +27 -0
  496. package/src/compiler/printer/decorator-helpers.ts +218 -0
  497. package/src/compiler/printer/emit-context.ts +679 -0
  498. package/src/compiler/printer/emit-flags.ts +64 -0
  499. package/src/compiler/printer/factory-base.ts +2577 -0
  500. package/src/compiler/printer/factory.ts +764 -0
  501. package/src/compiler/printer/helpers.ts +291 -0
  502. package/src/compiler/printer/name-generator.ts +372 -0
  503. package/src/compiler/printer/printer.ts +5072 -0
  504. package/src/compiler/printer/text-writer.ts +183 -0
  505. package/src/compiler/printer/utilities.ts +884 -0
  506. package/src/compiler/program-checker.ts +592 -0
  507. package/src/compiler/program-utilities.ts +435 -0
  508. package/src/compiler/program.ts +1419 -0
  509. package/src/compiler/pseudo-bigint.ts +62 -0
  510. package/src/compiler/regexp-checker.ts +1142 -0
  511. package/src/compiler/relations.ts +5149 -0
  512. package/src/compiler/reparser.ts +1566 -0
  513. package/src/compiler/scanner.ts +2951 -0
  514. package/src/compiler/show-config.ts +239 -0
  515. package/src/compiler/side-state.ts +125 -0
  516. package/src/compiler/sourcemap.ts +366 -0
  517. package/src/compiler/spelling.ts +122 -0
  518. package/src/compiler/symbol-accessibility.ts +1071 -0
  519. package/src/compiler/symbol.ts +439 -0
  520. package/src/compiler/symlinks.ts +137 -0
  521. package/src/compiler/syntax-kind.ts +391 -0
  522. package/src/compiler/thread-entry.ts +191 -0
  523. package/src/compiler/timeline.ts +53 -0
  524. package/src/compiler/transformers/alias-references.ts +757 -0
  525. package/src/compiler/transformers/async-utilities.ts +335 -0
  526. package/src/compiler/transformers/async.ts +838 -0
  527. package/src/compiler/transformers/class-fields.ts +2967 -0
  528. package/src/compiler/transformers/class-utilities.ts +324 -0
  529. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  530. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  531. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  532. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  533. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  534. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  535. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  536. package/src/compiler/transformers/declarations.ts +3120 -0
  537. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  538. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  539. package/src/compiler/transformers/destructuring.ts +708 -0
  540. package/src/compiler/transformers/downlevel.ts +50 -0
  541. package/src/compiler/transformers/emit-resolver.ts +258 -0
  542. package/src/compiler/transformers/es-decorators.ts +2682 -0
  543. package/src/compiler/transformers/exponentiation.ts +80 -0
  544. package/src/compiler/transformers/external-module-info.ts +412 -0
  545. package/src/compiler/transformers/for-await.ts +687 -0
  546. package/src/compiler/transformers/import-elision.ts +152 -0
  547. package/src/compiler/transformers/jsx-entities.ts +256 -0
  548. package/src/compiler/transformers/jsx.ts +824 -0
  549. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  550. package/src/compiler/transformers/logical-assignment.ts +75 -0
  551. package/src/compiler/transformers/module-utilities.ts +42 -0
  552. package/src/compiler/transformers/module.ts +474 -0
  553. package/src/compiler/transformers/named-evaluation.ts +389 -0
  554. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  555. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  556. package/src/compiler/transformers/optional-catch.ts +29 -0
  557. package/src/compiler/transformers/optional-chain.ts +246 -0
  558. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  559. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  560. package/src/compiler/transformers/subtree-facts.ts +245 -0
  561. package/src/compiler/transformers/syntax-facts.ts +353 -0
  562. package/src/compiler/transformers/tagged-template.ts +167 -0
  563. package/src/compiler/transformers/transformer.ts +56 -0
  564. package/src/compiler/transformers/type-eraser.ts +520 -0
  565. package/src/compiler/transformers/type-serialization.ts +374 -0
  566. package/src/compiler/transformers/using.ts +613 -0
  567. package/src/compiler/transformers/utilities.ts +419 -0
  568. package/src/compiler/transformers/visitor-base.ts +1601 -0
  569. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  570. package/src/compiler/tsc-build.ts +1418 -0
  571. package/src/compiler/tsc-cli.ts +666 -0
  572. package/src/compiler/tsc-compile.ts +437 -0
  573. package/src/compiler/tsc-watch.ts +854 -0
  574. package/src/compiler/tsconfig.ts +1574 -0
  575. package/src/compiler/type-printer.ts +110 -0
  576. package/src/compiler/types.ts +115 -0
  577. package/src/compiler/unicode-identifiers.ts +212 -0
  578. package/src/compiler/unicode-properties.ts +537 -0
  579. package/src/compiler/vfs-match.ts +597 -0
  580. package/src/compiler/xxh3.ts +650 -0
  581. package/src/library/ast.generated.ts +1685 -0
  582. package/src/library/ast.ts +104 -0
  583. package/src/library/checker.ts +384 -0
  584. package/src/library/compiler-options.generated.ts +114 -0
  585. package/src/library/diagnostics.ts +72 -0
  586. package/src/library/disk.ts +73 -0
  587. package/src/library/enums.generated.ts +1024 -0
  588. package/src/library/errors.ts +26 -0
  589. package/src/library/host.ts +63 -0
  590. package/src/library/index.ts +71 -0
  591. package/src/library/nodes.ts +232 -0
  592. package/src/library/options.ts +449 -0
  593. package/src/library/parse.ts +63 -0
  594. package/src/library/program.ts +293 -0
  595. package/src/library/symbols.ts +15 -0
  596. package/src/library/types.ts +359 -0
@@ -0,0 +1,2358 @@
1
+ // The binder: declares a symbol for each declaration in its container's table, merges
2
+ // declarations, reports binding errors, and builds the control flow graph.
3
+ //
4
+ // Fields of `instanceof`-narrowed nodes are read through `as` casts: scriptc reads them
5
+ // statically, but reads fields of a narrowed value dynamically.
6
+ import { BinaryExpression, CallExpression, ConditionalTypeNode, ElementAccessExpression, ExportAssignment, FunctionExpression, KeywordExpression, ModuleDeclaration, NodeVisitor, PatternAmbientModule, PrefixUnaryExpression, PropertyAccessExpression, TypeAliasDeclaration, VariableDeclaration, getArguments, getBody, getElements, getExpression, getInitializer, getLabel, getLocals, getModifiers, getName, getParameters, getPostfixToken, getProperties, getStatements, getSymbol, getText, isDeclarationNode, isLocalsContainer, setEndFlowNode, setFlowNode, setLocalSymbol, setLocals, setNextContainer, setReturnFlowNode, setSymbol, } from './ast.js';
7
+ import { isAmbientModule, isAssignmentOperator, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLeftHandSideExpression, isRequireCall, isStringLiteralLike, nodeIsMissing, nodeIsPresent, } from './ast-utilities.js';
8
+ import { declarationNameToString, expressionIsAlias, getAssignmentDeclarationKind, getCombinedModifierFlags, getContainingClass, getElementOrPropertyAccessName, getErrorRangeForNode, getImmediatelyInvokedFunctionExpression, getModuleInstanceState, StatementsByName, getNameOfDeclaration, getRangeOfTokenAtPosition, getSourceTextOfNode, hasDynamicName, hasSyntacticModifier, isAssignmentTarget, isAsyncFunction, isAutoAccessorPropertyDeclaration, isBlockOrCatchScoped, isBooleanLiteral, isDeclarationStatementKind, isDestructuringAssignment, isDottedName, isEntityNameExpression, isEnumConst, isExpandoInitializer, isExpressionOfOptionalChainRoot, isExternalModule, isExternalOrCommonJSModule, isIdentifierName, isImplicitlyExportedJSDocDeclaration, isInTopLevelContext, isJsonSourceFile, isLogicalExpression, isLogicalOrCoalescingAssignmentExpression, isLogicalOrCoalescingAssignmentOperator, isLogicalOrCoalescingBinaryOperator, isModuleAugmentationExternal, isNullishCoalesce, isObjectLiteralMethod, isObjectLiteralOrClassExpressionMethodOrAccessor, isOptionalChain, isOptionalChainRoot, isOutermostOptionalChain, isParameterPropertyDeclaration, isPartOfParameterDeclaration, isPartOfTypeQuery, isPotentiallyExecutableNode, isPrologueDirective, isPropertyNameLiteral, isPushOrUnshiftIdentifier, isSignedNumericLiteral, isStatic, isStringOrNumericLiteralLike, isVariableDeclarationInitializedToRequire, moduleExportNameIsDefault, nodeText, skipParentheses, } from './binder-utilities.js';
9
+ import { Diagnostic } from './diagnostics.js';
10
+ import { FlowNode, FlowReduceLabel, FlowSwitchClause } from './flow.js';
11
+ import { removeFileExtension } from './path.js';
12
+ import { getIdentifierToken, tokenToString } from './scanner.js';
13
+ import { Symbol, addDeclaration, getExports, getMembers, getSymbolId, internalSymbolNamePrefix, } from './symbol.js';
14
+ export function getContainerFlags(node) {
15
+ switch (node.kind) {
16
+ case 232 /* SyntaxKind.ClassExpression */:
17
+ case 264 /* SyntaxKind.ClassDeclaration */:
18
+ case 267 /* SyntaxKind.EnumDeclaration */:
19
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
20
+ case 188 /* SyntaxKind.TypeLiteral */:
21
+ case 293 /* SyntaxKind.JsxAttributes */:
22
+ return 1 /* ContainerFlags.IsContainer */;
23
+ case 265 /* SyntaxKind.InterfaceDeclaration */:
24
+ return 1 /* ContainerFlags.IsContainer */ | 64 /* ContainerFlags.IsInterface */;
25
+ case 268 /* SyntaxKind.ModuleDeclaration */:
26
+ case 266 /* SyntaxKind.TypeAliasDeclaration */:
27
+ case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
28
+ case 201 /* SyntaxKind.MappedType */:
29
+ case 182 /* SyntaxKind.IndexSignature */:
30
+ return 1 /* ContainerFlags.IsContainer */ | 32 /* ContainerFlags.HasLocals */;
31
+ case 307 /* SyntaxKind.SourceFile */:
32
+ return 1 /* ContainerFlags.IsContainer */ | 4 /* ContainerFlags.IsControlFlowContainer */ | 32 /* ContainerFlags.HasLocals */;
33
+ case 178 /* SyntaxKind.GetAccessor */:
34
+ case 179 /* SyntaxKind.SetAccessor */:
35
+ case 175 /* SyntaxKind.MethodDeclaration */:
36
+ if (isObjectLiteralOrClassExpressionMethodOrAccessor(node))
37
+ return (1 /* ContainerFlags.IsContainer */ |
38
+ 4 /* ContainerFlags.IsControlFlowContainer */ |
39
+ 32 /* ContainerFlags.HasLocals */ |
40
+ 8 /* ContainerFlags.IsFunctionLike */ |
41
+ 128 /* ContainerFlags.IsObjectLiteralOrClassExpressionMethodOrAccessor */ |
42
+ 256 /* ContainerFlags.IsThisContainer */);
43
+ return functionContainerFlags;
44
+ case 177 /* SyntaxKind.Constructor */:
45
+ case 263 /* SyntaxKind.FunctionDeclaration */:
46
+ case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
47
+ return functionContainerFlags;
48
+ case 174 /* SyntaxKind.MethodSignature */:
49
+ case 180 /* SyntaxKind.CallSignature */:
50
+ case 185 /* SyntaxKind.FunctionType */:
51
+ case 181 /* SyntaxKind.ConstructSignature */:
52
+ case 186 /* SyntaxKind.ConstructorType */:
53
+ return (1 /* ContainerFlags.IsContainer */ |
54
+ 4 /* ContainerFlags.IsControlFlowContainer */ |
55
+ 32 /* ContainerFlags.HasLocals */ |
56
+ 8 /* ContainerFlags.IsFunctionLike */ |
57
+ 512 /* ContainerFlags.PropagatesThisKeyword */);
58
+ case 219 /* SyntaxKind.FunctionExpression */:
59
+ return (1 /* ContainerFlags.IsContainer */ |
60
+ 4 /* ContainerFlags.IsControlFlowContainer */ |
61
+ 32 /* ContainerFlags.HasLocals */ |
62
+ 8 /* ContainerFlags.IsFunctionLike */ |
63
+ 16 /* ContainerFlags.IsFunctionExpression */ |
64
+ 256 /* ContainerFlags.IsThisContainer */);
65
+ case 220 /* SyntaxKind.ArrowFunction */:
66
+ return (1 /* ContainerFlags.IsContainer */ |
67
+ 4 /* ContainerFlags.IsControlFlowContainer */ |
68
+ 32 /* ContainerFlags.HasLocals */ |
69
+ 8 /* ContainerFlags.IsFunctionLike */ |
70
+ 16 /* ContainerFlags.IsFunctionExpression */ |
71
+ 512 /* ContainerFlags.PropagatesThisKeyword */);
72
+ case 269 /* SyntaxKind.ModuleBlock */:
73
+ return 4 /* ContainerFlags.IsControlFlowContainer */;
74
+ case 173 /* SyntaxKind.PropertyDeclaration */:
75
+ return getInitializer(node) !== undefined
76
+ ? 4 /* ContainerFlags.IsControlFlowContainer */ | 256 /* ContainerFlags.IsThisContainer */
77
+ : 0 /* ContainerFlags.None */;
78
+ case 300 /* SyntaxKind.CatchClause */:
79
+ case 249 /* SyntaxKind.ForStatement */:
80
+ case 250 /* SyntaxKind.ForInStatement */:
81
+ case 251 /* SyntaxKind.ForOfStatement */:
82
+ case 270 /* SyntaxKind.CaseBlock */:
83
+ return 2 /* ContainerFlags.IsBlockScopedContainer */ | 32 /* ContainerFlags.HasLocals */;
84
+ case 242 /* SyntaxKind.Block */: {
85
+ const parent = node.parent;
86
+ return isFunctionLike(parent) || parent.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */
87
+ ? 0 /* ContainerFlags.None */
88
+ : 2 /* ContainerFlags.IsBlockScopedContainer */ | 32 /* ContainerFlags.HasLocals */;
89
+ }
90
+ }
91
+ return 0 /* ContainerFlags.None */;
92
+ }
93
+ const functionContainerFlags = 1 /* ContainerFlags.IsContainer */ |
94
+ 4 /* ContainerFlags.IsControlFlowContainer */ |
95
+ 32 /* ContainerFlags.HasLocals */ |
96
+ 8 /* ContainerFlags.IsFunctionLike */ |
97
+ 256 /* ContainerFlags.IsThisContainer */;
98
+ /** A label in scope for `break` and `continue`. */
99
+ class ActiveLabel {
100
+ next;
101
+ name;
102
+ breakTarget;
103
+ continueTarget;
104
+ referenced;
105
+ constructor(next, name, breakTarget) {
106
+ this.next = next;
107
+ this.name = name;
108
+ this.breakTarget = breakTarget;
109
+ this.continueTarget = undefined;
110
+ this.referenced = false;
111
+ }
112
+ }
113
+ /** A JavaScript `F.x = …` assignment, bound once the whole file has its declarations. */
114
+ class ExpandoAssignment {
115
+ node;
116
+ container;
117
+ blockScopeContainer;
118
+ constructor(node, container, blockScopeContainer) {
119
+ this.node = node;
120
+ this.container = container;
121
+ this.blockScopeContainer = blockScopeContainer;
122
+ }
123
+ }
124
+ /** Binds `file` unless it is already bound. */
125
+ export function bindSourceFile(file) {
126
+ if (file.isBound)
127
+ return;
128
+ const binder = new Binder(file);
129
+ binder.bind(file);
130
+ binder.bindDeferredExpandoAssignments(binder.expandoAssignments);
131
+ file.symbolCount = binder.symbolCount;
132
+ file.isBound = true;
133
+ }
134
+ /** The name of a private member `#description` of the class with symbol `containingClassSymbol`. */
135
+ export function getSymbolNameForPrivateIdentifier(containingClassSymbol, description) {
136
+ return internalSymbolNamePrefix + '#' + getSymbolId(containingClassSymbol) + '@' + description;
137
+ }
138
+ /**
139
+ * Makes `node` the value declaration of `symbol` unless it has one already. Non-assignment
140
+ * declarations win over JavaScript assignments, and other declarations over namespaces.
141
+ */
142
+ export function setValueDeclaration(symbol, node) {
143
+ const valueDeclaration = symbol.valueDeclaration;
144
+ if (valueDeclaration === undefined ||
145
+ (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) ||
146
+ (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration)))
147
+ symbol.valueDeclaration = node;
148
+ }
149
+ function isAssignmentDeclaration(declaration) {
150
+ switch (declaration.kind) {
151
+ case 227 /* SyntaxKind.BinaryExpression */:
152
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
153
+ case 213 /* SyntaxKind.ElementAccessExpression */:
154
+ case 79 /* SyntaxKind.Identifier */:
155
+ case 214 /* SyntaxKind.CallExpression */:
156
+ return true;
157
+ }
158
+ return false;
159
+ }
160
+ function isEffectiveModuleDeclaration(node) {
161
+ return node.kind === 268 /* SyntaxKind.ModuleDeclaration */ || node.kind === 79 /* SyntaxKind.Identifier */;
162
+ }
163
+ class Binder extends NodeVisitor {
164
+ file;
165
+ unreachableFlow;
166
+ container;
167
+ thisContainer;
168
+ blockScopeContainer;
169
+ lastContainer;
170
+ currentFlow;
171
+ /**
172
+ * `currentFlow` as an optional value, shared by the nodes that store it: natively, converting a
173
+ * `FlowNode` to `FlowNode | undefined` allocates.
174
+ */
175
+ storedFlow;
176
+ storedFlowValue;
177
+ currentBreakTarget;
178
+ currentContinueTarget;
179
+ currentReturnTarget;
180
+ currentTrueTarget;
181
+ currentFalseTarget;
182
+ currentExceptionTarget;
183
+ preSwitchCaseFlow;
184
+ activeLabelList;
185
+ emitFlags;
186
+ seenThisKeyword;
187
+ hasExplicitReturn;
188
+ hasFlowEffects;
189
+ inAssignmentPattern;
190
+ seenParseError;
191
+ symbolCount;
192
+ notConstEnumOnlyModules;
193
+ expandoAssignments;
194
+ /** For the module instance states of the file's module declarations (`getModuleInstanceState`). */
195
+ statementsByName;
196
+ constructor(file) {
197
+ super();
198
+ this.file = file;
199
+ this.unreachableFlow = new FlowNode(1 /* FlowFlags.Unreachable */, undefined, undefined);
200
+ this.container = file;
201
+ this.thisContainer = undefined;
202
+ this.blockScopeContainer = file;
203
+ this.lastContainer = undefined;
204
+ this.currentFlow = this.unreachableFlow;
205
+ this.storedFlow = this.unreachableFlow;
206
+ this.storedFlowValue = this.unreachableFlow;
207
+ this.currentBreakTarget = undefined;
208
+ this.currentContinueTarget = undefined;
209
+ this.currentReturnTarget = undefined;
210
+ this.currentTrueTarget = undefined;
211
+ this.currentFalseTarget = undefined;
212
+ this.currentExceptionTarget = undefined;
213
+ this.preSwitchCaseFlow = undefined;
214
+ this.activeLabelList = undefined;
215
+ this.emitFlags = 0 /* NodeFlags.None */;
216
+ this.seenThisKeyword = false;
217
+ this.hasExplicitReturn = false;
218
+ this.hasFlowEffects = false;
219
+ this.inAssignmentPattern = false;
220
+ this.seenParseError = false;
221
+ this.symbolCount = 0;
222
+ this.notConstEnumOnlyModules = new Set();
223
+ this.expandoAssignments = [];
224
+ this.statementsByName = new StatementsByName();
225
+ }
226
+ visitNode(node) {
227
+ this.bind(node);
228
+ return false;
229
+ }
230
+ /** `currentFlow`, for storing in a node's `flowNode`. */
231
+ currentFlowValue() {
232
+ if (this.storedFlow !== this.currentFlow) {
233
+ this.storedFlow = this.currentFlow;
234
+ this.storedFlowValue = this.currentFlow;
235
+ }
236
+ return this.storedFlowValue;
237
+ }
238
+ newSymbol(flags, name) {
239
+ this.symbolCount++;
240
+ return new Symbol(flags, name);
241
+ }
242
+ // Declarations
243
+ /**
244
+ * Declares `node` in `symbolTable` with flags `includes`, merging with an existing symbol
245
+ * of the same name unless its flags intersect `excludes`, which is reported as a duplicate.
246
+ * Callers pass `parent` as read from the container rather than narrowed, so that its members
247
+ * share the stored value (see `storedFlow`).
248
+ */
249
+ declareSymbol(symbolTable, parent, node, includes, excludes) {
250
+ return this.declareSymbolEx(symbolTable, parent, node, includes, excludes, false, false);
251
+ }
252
+ declareSymbolEx(symbolTable, parent, node, includes, excludes, isReplaceableByMethod, isComputedName) {
253
+ const isDefaultExport = hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */) ||
254
+ (node.kind === 282 /* SyntaxKind.ExportSpecifier */ && moduleExportNameIsDefault(getName(node)));
255
+ // The exported symbol of `export default function/class` is always named "default".
256
+ const name = isComputedName
257
+ ? "\uFFFEcomputed" /* InternalSymbolName.Computed */
258
+ : isDefaultExport && parent !== undefined
259
+ ? "default" /* InternalSymbolName.Default */
260
+ : this.getDeclarationName(node);
261
+ let symbol;
262
+ if (name === "\uFFFEmissing" /* InternalSymbolName.Missing */)
263
+ symbol = this.newSymbol(0 /* SymbolFlags.None */, "\uFFFEmissing" /* InternalSymbolName.Missing */);
264
+ else {
265
+ // A new symbol starts without flags, so it can't conflict with `excludes`. A conflicting
266
+ // existing symbol gets errors on each declaration, and `node` gets a symbol of its own.
267
+ // A JavaScript constructor property (`isReplaceableByMethod`) always loses a conflict,
268
+ // which allows `this.method = this.method.bind(this)`.
269
+ symbol = symbolTable.get(name);
270
+ if (symbol === undefined) {
271
+ symbol = this.newSymbol(0 /* SymbolFlags.None */, name);
272
+ symbolTable.set(name, symbol);
273
+ if (isReplaceableByMethod)
274
+ symbol.flags |= 536870912 /* SymbolFlags.ReplaceableByMethod */;
275
+ }
276
+ else if (isReplaceableByMethod && (symbol.flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) === 0) {
277
+ return symbol;
278
+ }
279
+ else if ((symbol.flags & excludes) !== 0) {
280
+ if ((symbol.flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) !== 0) {
281
+ symbol = this.newSymbol(0 /* SymbolFlags.None */, name);
282
+ symbolTable.set(name, symbol);
283
+ }
284
+ else if (!(((includes & 3 /* SymbolFlags.Variable */) !== 0 && (symbol.flags & 67108864 /* SymbolFlags.Assignment */) !== 0) ||
285
+ ((includes & 67108864 /* SymbolFlags.Assignment */) !== 0 && (symbol.flags & 3 /* SymbolFlags.Variable */) !== 0))) {
286
+ // Assignment declarations merge with variables whatever their other flags.
287
+ this.reportDuplicate(symbol, node, includes, isDefaultExport);
288
+ symbol = this.newSymbol(0 /* SymbolFlags.None */, name);
289
+ }
290
+ }
291
+ }
292
+ this.addDeclarationToSymbol(symbol, node, includes);
293
+ if (symbol.parent === undefined)
294
+ symbol.parent = parent;
295
+ else if (symbol.parent !== parent)
296
+ throw new Error('Existing symbol parent should match new one');
297
+ return symbol;
298
+ }
299
+ reportDuplicate(symbol, node, includes, isDefaultExport) {
300
+ let message = (symbol.flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0
301
+ ? 619 /* Diagnostics.Cannot_redeclare_block_scoped_variable_0 */
302
+ : 478 /* Diagnostics.Duplicate_identifier_0 */;
303
+ let messageNeedsName = true;
304
+ if ((symbol.flags & 384 /* SymbolFlags.Enum */) !== 0 || (includes & 384 /* SymbolFlags.Enum */) !== 0) {
305
+ message = 721 /* Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations */;
306
+ messageNeedsName = false;
307
+ }
308
+ let multipleDefaultExports = false;
309
+ if (symbol.declarations.length !== 0) {
310
+ // A default export (by modifier, or `export default` assignment) after another one.
311
+ if (isDefaultExport || (node instanceof ExportAssignment && !node.isExportEquals)) {
312
+ message = 686 /* Diagnostics.A_module_cannot_have_multiple_default_exports */;
313
+ messageNeedsName = false;
314
+ multipleDefaultExports = true;
315
+ }
316
+ }
317
+ const declarationName = getNameOfDeclaration(node) ?? node;
318
+ const diagnostic = this.createDiagnosticForNode(declarationName, message, messageNeedsName ? [this.getDisplayName(node)] : noArgs);
319
+ if (node instanceof TypeAliasDeclaration &&
320
+ nodeIsMissing(node.type) &&
321
+ hasSyntacticModifier(node, 32 /* ModifierFlags.Export */) &&
322
+ (symbol.flags & (2097152 /* SymbolFlags.Alias */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */)) !== 0) {
323
+ // `export type T;` may have meant `export type { T }`.
324
+ diagnostic.addRelatedInfo(this.createDiagnosticForNode(node, 303 /* Diagnostics.Did_you_mean_0 */, [
325
+ 'export type { ' + node.name.text + ' }',
326
+ ]));
327
+ }
328
+ const declarations = symbol.declarations;
329
+ for (let index = 0; index < declarations.length; index++) {
330
+ const declaration = declarations[index];
331
+ const decl = getNameOfDeclaration(declaration) ?? declaration;
332
+ const d = this.createDiagnosticForNode(decl, message, messageNeedsName ? [this.getDisplayName(declaration)] : noArgs);
333
+ if (multipleDefaultExports)
334
+ d.addRelatedInfo(this.createDiagnosticForNode(declarationName, index === 0 ? 885 /* Diagnostics.Another_export_default_is_here */ : 1357 /* Diagnostics.X_and_here */, noArgs));
335
+ this.addDiagnostic(d);
336
+ if (multipleDefaultExports)
337
+ diagnostic.addRelatedInfo(this.createDiagnosticForNode(decl, 884 /* Diagnostics.The_first_export_default_is_here */, noArgs));
338
+ }
339
+ this.addDiagnostic(diagnostic);
340
+ // An accessor conflicting with a non-accessor or the other accessor kind makes the symbol a
341
+ // full accessor, so later declarations conflict too.
342
+ const accessor = symbol.flags & 98304 /* SymbolFlags.Accessor */;
343
+ if (accessor !== 0 && accessor !== (includes & 98304 /* SymbolFlags.Accessor */))
344
+ symbol.flags |= 98304 /* SymbolFlags.Accessor */;
345
+ }
346
+ /** The symbol name of a declaration. Computed names must be literals or well-known symbols. */
347
+ getDeclarationName(node) {
348
+ if (node instanceof ExportAssignment)
349
+ return node.isExportEquals ? "export=" /* InternalSymbolName.ExportEquals */ : "default" /* InternalSymbolName.Default */;
350
+ const name = getNameOfDeclaration(node);
351
+ if (name !== undefined) {
352
+ if (isAmbientModule(node)) {
353
+ if (isGlobalScopeAugmentation(node))
354
+ return "\uFFFEglobal" /* InternalSymbolName.Global */;
355
+ return '"' + nodeText(name) + '"';
356
+ }
357
+ if (name.kind === 80 /* SyntaxKind.PrivateIdentifier */) {
358
+ // Private names are only allowed in classes; elsewhere there is already a parse error.
359
+ const containingClass = getContainingClass(node);
360
+ if (containingClass === undefined)
361
+ return "\uFFFEmissing" /* InternalSymbolName.Missing */;
362
+ return getSymbolNameForPrivateIdentifier(getSymbol(containingClass), getText(name));
363
+ }
364
+ if (isPropertyNameLiteral(name) || name.kind === 296 /* SyntaxKind.JsxNamespacedName */)
365
+ return nodeText(name);
366
+ if (name.kind === 168 /* SyntaxKind.ComputedPropertyName */) {
367
+ const expression = getExpression(name);
368
+ // A literal computed name is just the literal.
369
+ if (isStringOrNumericLiteralLike(expression))
370
+ return getText(expression);
371
+ if (expression instanceof PrefixUnaryExpression && isSignedNumericLiteral(expression)) {
372
+ const unary = expression;
373
+ return tokenToString(unary.operator) + getText(unary.operand);
374
+ }
375
+ throw new Error('Only computed properties with literal names have declaration names');
376
+ }
377
+ return "\uFFFEmissing" /* InternalSymbolName.Missing */;
378
+ }
379
+ switch (node.kind) {
380
+ case 177 /* SyntaxKind.Constructor */:
381
+ return "\uFFFEconstructor" /* InternalSymbolName.Constructor */;
382
+ case 185 /* SyntaxKind.FunctionType */:
383
+ case 180 /* SyntaxKind.CallSignature */:
384
+ return "\uFFFEcall" /* InternalSymbolName.Call */;
385
+ case 186 /* SyntaxKind.ConstructorType */:
386
+ case 181 /* SyntaxKind.ConstructSignature */:
387
+ return "\uFFFEnew" /* InternalSymbolName.New */;
388
+ case 182 /* SyntaxKind.IndexSignature */:
389
+ return "\uFFFEindex" /* InternalSymbolName.Index */;
390
+ case 279 /* SyntaxKind.ExportDeclaration */:
391
+ return "\uFFFEexport" /* InternalSymbolName.ExportStar */;
392
+ case 307 /* SyntaxKind.SourceFile */:
393
+ case 227 /* SyntaxKind.BinaryExpression */:
394
+ return "export=" /* InternalSymbolName.ExportEquals */;
395
+ }
396
+ return "\uFFFEmissing" /* InternalSymbolName.Missing */;
397
+ }
398
+ getDisplayName(node) {
399
+ const name = getName(node);
400
+ if (name !== undefined)
401
+ return declarationNameToString(this.file, name);
402
+ const declarationName = this.getDeclarationName(node);
403
+ return declarationName !== "\uFFFEmissing" /* InternalSymbolName.Missing */ ? declarationName : '(Missing)';
404
+ }
405
+ /**
406
+ * Declares a module or namespace member. Exported members get two symbols: a local one
407
+ * marked `ExportValue` and the export, so locals and exports of the same name conflict and
408
+ * the checker can tell a reference to the export from its local.
409
+ */
410
+ declareModuleMember(node, symbolFlags, symbolExcludes) {
411
+ const container = this.container;
412
+ const hasExportModifier = (getCombinedModifierFlags(node) & 32 /* ModifierFlags.Export */) !== 0 || isImplicitlyExportedJSDocDeclaration(node);
413
+ if ((symbolFlags & 2097152 /* SymbolFlags.Alias */) !== 0) {
414
+ if (node.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
415
+ (node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ && hasExportModifier)) {
416
+ const containerSymbol = getSymbol(container);
417
+ return this.declareSymbol(getExports(containerSymbol), containerSymbol, node, symbolFlags, symbolExcludes);
418
+ }
419
+ return this.declareSymbol(this.localsOf(container), undefined, node, symbolFlags, symbolExcludes);
420
+ }
421
+ // Nested ambient modules (module augmentations) stay local so they never merge globally.
422
+ if (!isAmbientModule(node) && (hasExportModifier || (container.flags & 64 /* NodeFlags.ExportContext */) !== 0)) {
423
+ const containerSymbol = getSymbol(container);
424
+ // An unnamed default export has no local symbol.
425
+ if (!isLocalsContainer(container) ||
426
+ (hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */) &&
427
+ this.getDeclarationName(node) === "\uFFFEmissing" /* InternalSymbolName.Missing */))
428
+ return this.declareSymbol(getExports(containerSymbol), containerSymbol, node, symbolFlags, symbolExcludes);
429
+ const exportKind = (symbolFlags & 111551 /* SymbolFlags.Value */) !== 0 ? 1048576 /* SymbolFlags.ExportValue */ : 0 /* SymbolFlags.None */;
430
+ const local = this.declareSymbol(this.localsOf(container), undefined, node, exportKind, symbolExcludes);
431
+ local.exportSymbol = this.declareSymbol(getExports(containerSymbol), containerSymbol, node, symbolFlags, symbolExcludes);
432
+ setLocalSymbol(node, local);
433
+ return local;
434
+ }
435
+ return this.declareSymbol(this.localsOf(container), undefined, node, symbolFlags, symbolExcludes);
436
+ }
437
+ declareClassMember(node, symbolFlags, symbolExcludes) {
438
+ const classSymbol = getSymbol(this.container);
439
+ const table = isStatic(node) ? getExports(classSymbol) : getMembers(classSymbol);
440
+ return this.declareSymbol(table, classSymbol, node, symbolFlags, symbolExcludes);
441
+ }
442
+ declareSourceFileMember(node, symbolFlags, symbolExcludes) {
443
+ if (isExternalModule(this.file))
444
+ return this.declareModuleMember(node, symbolFlags, symbolExcludes);
445
+ return this.declareSymbol(this.localsOf(this.file), undefined, node, symbolFlags, symbolExcludes);
446
+ }
447
+ declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
448
+ const container = this.container;
449
+ switch (container.kind) {
450
+ case 268 /* SyntaxKind.ModuleDeclaration */:
451
+ return this.declareModuleMember(node, symbolFlags, symbolExcludes);
452
+ case 307 /* SyntaxKind.SourceFile */:
453
+ return this.declareSourceFileMember(node, symbolFlags, symbolExcludes);
454
+ case 232 /* SyntaxKind.ClassExpression */:
455
+ case 264 /* SyntaxKind.ClassDeclaration */:
456
+ return this.declareClassMember(node, symbolFlags, symbolExcludes);
457
+ case 267 /* SyntaxKind.EnumDeclaration */: {
458
+ const enumSymbol = getSymbol(container);
459
+ return this.declareSymbol(getExports(enumSymbol), enumSymbol, node, symbolFlags, symbolExcludes);
460
+ }
461
+ case 188 /* SyntaxKind.TypeLiteral */:
462
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
463
+ case 265 /* SyntaxKind.InterfaceDeclaration */:
464
+ case 293 /* SyntaxKind.JsxAttributes */: {
465
+ const containerSymbol = getSymbol(container);
466
+ return this.declareSymbol(getMembers(containerSymbol), containerSymbol, node, symbolFlags, symbolExcludes);
467
+ }
468
+ case 185 /* SyntaxKind.FunctionType */:
469
+ case 186 /* SyntaxKind.ConstructorType */:
470
+ case 180 /* SyntaxKind.CallSignature */:
471
+ case 181 /* SyntaxKind.ConstructSignature */:
472
+ case 182 /* SyntaxKind.IndexSignature */:
473
+ case 175 /* SyntaxKind.MethodDeclaration */:
474
+ case 174 /* SyntaxKind.MethodSignature */:
475
+ case 177 /* SyntaxKind.Constructor */:
476
+ case 178 /* SyntaxKind.GetAccessor */:
477
+ case 179 /* SyntaxKind.SetAccessor */:
478
+ case 263 /* SyntaxKind.FunctionDeclaration */:
479
+ case 219 /* SyntaxKind.FunctionExpression */:
480
+ case 220 /* SyntaxKind.ArrowFunction */:
481
+ case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
482
+ case 266 /* SyntaxKind.TypeAliasDeclaration */:
483
+ case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
484
+ case 201 /* SyntaxKind.MappedType */:
485
+ return this.declareSymbol(this.localsOf(container), undefined, node, symbolFlags, symbolExcludes);
486
+ }
487
+ throw new Error('Unhandled case in declareSymbolAndAddToSymbolTable');
488
+ }
489
+ /** The locals table of `container`, created if missing. */
490
+ localsOf(container) {
491
+ let locals = getLocals(container);
492
+ if (locals === undefined) {
493
+ locals = new Map();
494
+ setLocals(container, locals);
495
+ }
496
+ return locals;
497
+ }
498
+ addDeclarationToSymbol(symbol, node, symbolFlags) {
499
+ symbol.flags |= symbolFlags;
500
+ setSymbol(node, symbol);
501
+ if (symbol.declarations.indexOf(node) < 0)
502
+ addDeclaration(symbol, node);
503
+ // A const-enum-only namespace merged with a class, function or regular enum isn't one anymore.
504
+ if ((symbol.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) !== 0 &&
505
+ (symbol.flags & (16 /* SymbolFlags.Function */ | 32 /* SymbolFlags.Class */ | 256 /* SymbolFlags.RegularEnum */)) !== 0) {
506
+ symbol.flags &= ~268435456 /* SymbolFlags.ConstEnumOnlyModule */;
507
+ this.notConstEnumOnlyModules.add(symbol);
508
+ }
509
+ if ((symbolFlags & 111551 /* SymbolFlags.Value */) !== 0)
510
+ setValueDeclaration(symbol, node);
511
+ }
512
+ bindAnonymousDeclaration(node, symbolFlags, name) {
513
+ const symbol = this.newSymbol(symbolFlags, name);
514
+ if ((symbolFlags & (8 /* SymbolFlags.EnumMember */ | 106500 /* SymbolFlags.ClassMember */)) !== 0)
515
+ symbol.parent = getSymbol(this.container);
516
+ this.addDeclarationToSymbol(symbol, node, symbolFlags);
517
+ return symbol;
518
+ }
519
+ bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
520
+ const blockScopeContainer = this.blockScopeContainer;
521
+ switch (blockScopeContainer.kind) {
522
+ case 268 /* SyntaxKind.ModuleDeclaration */:
523
+ return this.declareModuleMember(node, symbolFlags, symbolExcludes);
524
+ case 307 /* SyntaxKind.SourceFile */:
525
+ if (isExternalOrCommonJSModule(this.file))
526
+ return this.declareModuleMember(node, symbolFlags, symbolExcludes);
527
+ break;
528
+ }
529
+ return this.declareSymbol(this.localsOf(blockScopeContainer), undefined, node, symbolFlags, symbolExcludes);
530
+ }
531
+ // Diagnostics
532
+ createDiagnosticForNode(node, message, args) {
533
+ const range = getErrorRangeForNode(this.file, node);
534
+ return new Diagnostic(this.file.diagnosticFile(), range.pos, range.end, message, args);
535
+ }
536
+ errorOnNode(node, message, args) {
537
+ this.addDiagnostic(this.createDiagnosticForNode(node, message, args));
538
+ }
539
+ errorOnFirstToken(node, message, args) {
540
+ const range = getRangeOfTokenAtPosition(this.file, node.pos);
541
+ this.addDiagnostic(new Diagnostic(this.file.diagnosticFile(), range.pos, range.end, message, args));
542
+ }
543
+ addDiagnostic(diagnostic) {
544
+ this.file.bindDiagnostics.push(diagnostic);
545
+ }
546
+ // Traversal
547
+ bindOptional(node) {
548
+ if (node !== undefined)
549
+ this.bind(node);
550
+ }
551
+ bind(node) {
552
+ // Declare the node's symbol in the exports or members of the container's symbol, or in
553
+ // the container's locals; anonymous declarations like type literals go in no table.
554
+ switch (node.kind) {
555
+ case 79 /* SyntaxKind.Identifier */:
556
+ node.flowNode = this.currentFlowValue();
557
+ this.checkContextualIdentifier(node);
558
+ break;
559
+ case 109 /* SyntaxKind.ThisKeyword */:
560
+ case 107 /* SyntaxKind.SuperKeyword */:
561
+ if (node.kind === 109 /* SyntaxKind.ThisKeyword */)
562
+ this.seenThisKeyword = true;
563
+ if (node instanceof KeywordExpression)
564
+ node.flowNode = this.currentFlowValue();
565
+ break;
566
+ case 167 /* SyntaxKind.QualifiedName */:
567
+ if (isPartOfTypeQuery(node))
568
+ node.flowNode = this.currentFlowValue();
569
+ break;
570
+ case 237 /* SyntaxKind.MetaProperty */:
571
+ node.flowNode = this.currentFlowValue();
572
+ break;
573
+ case 80 /* SyntaxKind.PrivateIdentifier */:
574
+ this.checkPrivateIdentifier(node);
575
+ break;
576
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
577
+ case 213 /* SyntaxKind.ElementAccessExpression */:
578
+ if (isNarrowableReference(node))
579
+ setFlowNode(node, this.currentFlowValue());
580
+ break;
581
+ case 227 /* SyntaxKind.BinaryExpression */:
582
+ switch (getAssignmentDeclarationKind(node)) {
583
+ case 1 /* JSDeclarationKind.ModuleExports */:
584
+ this.bindModuleExportsAssignment(node);
585
+ break;
586
+ case 2 /* JSDeclarationKind.ExportsProperty */:
587
+ this.bindExportsOrObjectDefineProperty(node);
588
+ break;
589
+ case 4 /* JSDeclarationKind.Property */:
590
+ this.bindExpandoPropertyAssignment(node);
591
+ break;
592
+ case 3 /* JSDeclarationKind.ThisProperty */:
593
+ this.bindThisPropertyAssignment(node);
594
+ break;
595
+ }
596
+ this.checkStrictModeBinaryExpression(node);
597
+ break;
598
+ case 300 /* SyntaxKind.CatchClause */:
599
+ this.checkStrictModeCatchClause(node);
600
+ break;
601
+ case 221 /* SyntaxKind.DeleteExpression */:
602
+ this.checkStrictModeDeleteExpression(node);
603
+ break;
604
+ case 226 /* SyntaxKind.PostfixUnaryExpression */:
605
+ this.checkStrictModeEvalOrArguments(node, node.operand);
606
+ break;
607
+ case 225 /* SyntaxKind.PrefixUnaryExpression */: {
608
+ const operator = node.operator;
609
+ if (operator === 45 /* SyntaxKind.PlusPlusToken */ || operator === 46 /* SyntaxKind.MinusMinusToken */)
610
+ this.checkStrictModeEvalOrArguments(node, node.operand);
611
+ break;
612
+ }
613
+ case 255 /* SyntaxKind.WithStatement */:
614
+ this.errorOnFirstToken(node, 70 /* Diagnostics.X_with_statements_are_not_allowed_in_strict_mode */, noArgs);
615
+ break;
616
+ case 257 /* SyntaxKind.LabeledStatement */: {
617
+ const statement = node.statement;
618
+ if (isDeclarationStatementKind(statement.kind) || statement.kind === 244 /* SyntaxKind.VariableStatement */)
619
+ this.errorOnFirstToken(node.label, 278 /* Diagnostics.A_label_is_not_allowed_here */, noArgs);
620
+ break;
621
+ }
622
+ case 198 /* SyntaxKind.ThisType */:
623
+ this.seenThisKeyword = true;
624
+ break;
625
+ case 169 /* SyntaxKind.TypeParameter */:
626
+ this.bindTypeParameter(node);
627
+ break;
628
+ case 170 /* SyntaxKind.Parameter */:
629
+ this.bindParameter(node);
630
+ break;
631
+ case 261 /* SyntaxKind.VariableDeclaration */:
632
+ this.bindVariableDeclarationOrBindingElement(node);
633
+ break;
634
+ case 209 /* SyntaxKind.BindingElement */:
635
+ node.flowNode = this.currentFlowValue();
636
+ this.bindVariableDeclarationOrBindingElement(node);
637
+ break;
638
+ case 173 /* SyntaxKind.PropertyDeclaration */:
639
+ case 172 /* SyntaxKind.PropertySignature */: {
640
+ const isAutoAccessor = isAutoAccessorPropertyDeclaration(node);
641
+ this.bindPropertyOrMethodOrAccessor(node, (isAutoAccessor ? 98304 /* SymbolFlags.Accessor */ : 4 /* SymbolFlags.Property */) | optionalSymbolFlag(node), isAutoAccessor ? 111547 /* SymbolFlags.AccessorExcludes */ : 13243 /* SymbolFlags.PropertyExcludes */);
642
+ break;
643
+ }
644
+ case 303 /* SyntaxKind.PropertyAssignment */:
645
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
646
+ this.bindPropertyOrMethodOrAccessor(node, 4 /* SymbolFlags.Property */, 13243 /* SymbolFlags.PropertyExcludes */);
647
+ break;
648
+ case 306 /* SyntaxKind.EnumMember */:
649
+ this.bindPropertyOrMethodOrAccessor(node, 8 /* SymbolFlags.EnumMember */, 900095 /* SymbolFlags.EnumMemberExcludes */);
650
+ break;
651
+ case 180 /* SyntaxKind.CallSignature */:
652
+ case 181 /* SyntaxKind.ConstructSignature */:
653
+ case 182 /* SyntaxKind.IndexSignature */:
654
+ this.declareSymbolAndAddToSymbolTable(node, 131072 /* SymbolFlags.Signature */, 0 /* SymbolFlags.None */);
655
+ break;
656
+ case 175 /* SyntaxKind.MethodDeclaration */:
657
+ case 174 /* SyntaxKind.MethodSignature */:
658
+ this.bindPropertyOrMethodOrAccessor(node, 8192 /* SymbolFlags.Method */ | optionalSymbolFlag(node), isObjectLiteralMethod(node) ? 111551 /* SymbolFlags.Value */ : 103359 /* SymbolFlags.MethodExcludes */);
659
+ break;
660
+ case 263 /* SyntaxKind.FunctionDeclaration */:
661
+ this.bindFunctionDeclaration(node);
662
+ break;
663
+ case 177 /* SyntaxKind.Constructor */:
664
+ this.declareSymbolAndAddToSymbolTable(node, 16384 /* SymbolFlags.Constructor */, 0 /* SymbolFlags.None */);
665
+ break;
666
+ case 178 /* SyntaxKind.GetAccessor */:
667
+ this.bindPropertyOrMethodOrAccessor(node, 32768 /* SymbolFlags.GetAccessor */, 46011 /* SymbolFlags.GetAccessorExcludes */);
668
+ break;
669
+ case 179 /* SyntaxKind.SetAccessor */:
670
+ this.bindPropertyOrMethodOrAccessor(node, 65536 /* SymbolFlags.SetAccessor */, 78779 /* SymbolFlags.SetAccessorExcludes */);
671
+ break;
672
+ case 185 /* SyntaxKind.FunctionType */:
673
+ case 186 /* SyntaxKind.ConstructorType */:
674
+ this.bindFunctionOrConstructorType(node);
675
+ break;
676
+ case 188 /* SyntaxKind.TypeLiteral */:
677
+ case 201 /* SyntaxKind.MappedType */:
678
+ this.bindAnonymousDeclaration(node, 2048 /* SymbolFlags.TypeLiteral */, "\uFFFEtype" /* InternalSymbolName.Type */);
679
+ break;
680
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
681
+ this.bindAnonymousDeclaration(node, 4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEobject" /* InternalSymbolName.Object */);
682
+ break;
683
+ case 219 /* SyntaxKind.FunctionExpression */:
684
+ case 220 /* SyntaxKind.ArrowFunction */:
685
+ this.bindFunctionExpression(node);
686
+ break;
687
+ case 232 /* SyntaxKind.ClassExpression */:
688
+ case 264 /* SyntaxKind.ClassDeclaration */:
689
+ this.bindClassLikeDeclaration(node);
690
+ break;
691
+ case 265 /* SyntaxKind.InterfaceDeclaration */:
692
+ this.bindBlockScopedDeclaration(node, 64 /* SymbolFlags.Interface */, 788872 /* SymbolFlags.InterfaceExcludes */);
693
+ break;
694
+ case 214 /* SyntaxKind.CallExpression */:
695
+ switch (getAssignmentDeclarationKind(node)) {
696
+ case 5 /* JSDeclarationKind.ObjectDefinePropertyValue */:
697
+ this.bindExpandoPropertyAssignment(node);
698
+ break;
699
+ case 6 /* JSDeclarationKind.ObjectDefinePropertyExports */:
700
+ this.bindExportsOrObjectDefineProperty(node);
701
+ break;
702
+ }
703
+ // Only to detect CommonJS modules.
704
+ if (isInJSFile(node) && this.file.commonJSModuleIndicator === undefined && isRequireCall(node, false))
705
+ this.setCommonJSModuleIndicator(node);
706
+ break;
707
+ case 266 /* SyntaxKind.TypeAliasDeclaration */:
708
+ this.bindBlockScopedDeclaration(node, 524288 /* SymbolFlags.TypeAlias */, 788968 /* SymbolFlags.TypeAliasExcludes */);
709
+ break;
710
+ case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
711
+ // Top-level ones are bound by bindContainer, after CommonJS module indicators.
712
+ if (this.blockScopeContainer.kind !== 307 /* SyntaxKind.SourceFile */)
713
+ this.bindBlockScopedDeclaration(node, 524288 /* SymbolFlags.TypeAlias */, 788968 /* SymbolFlags.TypeAliasExcludes */);
714
+ break;
715
+ case 267 /* SyntaxKind.EnumDeclaration */:
716
+ if (isEnumConst(node))
717
+ this.bindBlockScopedDeclaration(node, 128 /* SymbolFlags.ConstEnum */, 899967 /* SymbolFlags.ConstEnumExcludes */);
718
+ else
719
+ this.bindBlockScopedDeclaration(node, 256 /* SymbolFlags.RegularEnum */, 899327 /* SymbolFlags.RegularEnumExcludes */);
720
+ break;
721
+ case 268 /* SyntaxKind.ModuleDeclaration */:
722
+ this.bindModuleDeclaration(node);
723
+ break;
724
+ case 272 /* SyntaxKind.ImportEqualsDeclaration */:
725
+ case 275 /* SyntaxKind.NamespaceImport */:
726
+ case 277 /* SyntaxKind.ImportSpecifier */:
727
+ case 282 /* SyntaxKind.ExportSpecifier */:
728
+ this.declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */);
729
+ break;
730
+ case 271 /* SyntaxKind.NamespaceExportDeclaration */:
731
+ this.bindNamespaceExportDeclaration(node);
732
+ break;
733
+ case 274 /* SyntaxKind.ImportClause */:
734
+ if (node.name !== undefined)
735
+ this.declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */);
736
+ break;
737
+ case 279 /* SyntaxKind.ExportDeclaration */:
738
+ this.bindExportDeclaration(node);
739
+ break;
740
+ case 278 /* SyntaxKind.ExportAssignment */:
741
+ this.bindExportAssignment(node);
742
+ break;
743
+ case 307 /* SyntaxKind.SourceFile */:
744
+ this.bindSourceFileIfExternalModule(node);
745
+ break;
746
+ case 293 /* SyntaxKind.JsxAttributes */:
747
+ this.bindAnonymousDeclaration(node, 4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEjsxAttributes" /* InternalSymbolName.JSXAttributes */);
748
+ break;
749
+ case 292 /* SyntaxKind.JsxAttribute */:
750
+ this.declareSymbolAndAddToSymbolTable(node, 4 /* SymbolFlags.Property */, 13243 /* SymbolFlags.PropertyExcludes */);
751
+ break;
752
+ }
753
+ // Then bind the children, tracking the current container. Tokens have no children.
754
+ let thisNodeOrAnySubnodesHasError = (node.flags & 32768 /* NodeFlags.ThisNodeHasError */) !== 0;
755
+ if (node.kind > 166 /* SyntaxKind.LastToken */) {
756
+ const saveSeenParseError = this.seenParseError;
757
+ this.seenParseError = false;
758
+ const containerFlags = getContainerFlags(node);
759
+ if (containerFlags === 0 /* ContainerFlags.None */)
760
+ this.bindChildren(node);
761
+ else
762
+ this.bindContainer(node, containerFlags);
763
+ if (this.seenParseError)
764
+ thisNodeOrAnySubnodesHasError = true;
765
+ this.seenParseError = saveSeenParseError;
766
+ }
767
+ if (thisNodeOrAnySubnodesHasError) {
768
+ node.flags |= 131072 /* NodeFlags.ThisNodeOrAnySubNodesHasError */;
769
+ this.seenParseError = true;
770
+ }
771
+ }
772
+ /**
773
+ * Binds the children of a container. Containers are chained in declaration order for the
774
+ * checker's local name lookups.
775
+ */
776
+ bindContainer(node, containerFlags) {
777
+ const saveContainer = this.container;
778
+ const saveThisContainer = this.thisContainer;
779
+ const saveBlockScopeContainer = this.blockScopeContainer;
780
+ // Locals are created on first use, so block-scoped containers without declarations stay cheap.
781
+ if ((containerFlags & 1 /* ContainerFlags.IsContainer */) !== 0) {
782
+ this.container = node;
783
+ this.blockScopeContainer = node;
784
+ if ((containerFlags & 32 /* ContainerFlags.HasLocals */) !== 0)
785
+ this.addToContainerChain(node);
786
+ }
787
+ else if ((containerFlags & 2 /* ContainerFlags.IsBlockScopedContainer */) !== 0) {
788
+ this.blockScopeContainer = node;
789
+ this.addToContainerChain(node);
790
+ }
791
+ if ((containerFlags & 256 /* ContainerFlags.IsThisContainer */) !== 0)
792
+ this.thisContainer = node;
793
+ if ((containerFlags & 4 /* ContainerFlags.IsControlFlowContainer */) !== 0)
794
+ this.bindControlFlowContainer(node, containerFlags);
795
+ else if ((containerFlags & 64 /* ContainerFlags.IsInterface */) !== 0) {
796
+ const saveSeenThisKeyword = this.seenThisKeyword;
797
+ this.seenThisKeyword = false;
798
+ this.bindChildren(node);
799
+ // ContainsThis can't overlap with HasExtendedUnicodeEscape, which is for identifiers.
800
+ if (this.seenThisKeyword)
801
+ node.flags |= 128 /* NodeFlags.ContainsThis */;
802
+ else
803
+ node.flags &= ~128 /* NodeFlags.ContainsThis */;
804
+ this.seenThisKeyword = saveSeenThisKeyword;
805
+ }
806
+ else
807
+ this.bindChildren(node);
808
+ if (node.kind === 307 /* SyntaxKind.SourceFile */)
809
+ this.finishSourceFile(node);
810
+ else if (isAmbientModule(node))
811
+ this.bindCommonJSTypeExports(getSymbol(node));
812
+ this.container = saveContainer;
813
+ this.thisContainer = saveThisContainer;
814
+ this.blockScopeContainer = saveBlockScopeContainer;
815
+ }
816
+ bindControlFlowContainer(node, containerFlags) {
817
+ const saveCurrentFlow = this.currentFlow;
818
+ const saveBreakTarget = this.currentBreakTarget;
819
+ const saveContinueTarget = this.currentContinueTarget;
820
+ const saveReturnTarget = this.currentReturnTarget;
821
+ const saveExceptionTarget = this.currentExceptionTarget;
822
+ const saveActiveLabelList = this.activeLabelList;
823
+ const saveHasExplicitReturn = this.hasExplicitReturn;
824
+ const saveSeenThisKeyword = this.seenThisKeyword;
825
+ // A non-async, non-generator IIFE is part of the containing control flow; its returns act
826
+ // like breaks to a label past the body.
827
+ const isImmediatelyInvoked = ((containerFlags & 16 /* ContainerFlags.IsFunctionExpression */) !== 0 &&
828
+ !hasSyntacticModifier(node, 1024 /* ModifierFlags.Async */) &&
829
+ !isGeneratorFunctionExpression(node) &&
830
+ getImmediatelyInvokedFunctionExpression(node) !== undefined) ||
831
+ node.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */;
832
+ if (!isImmediatelyInvoked) {
833
+ const flowStart = new FlowNode(2 /* FlowFlags.Start */, undefined, undefined);
834
+ this.currentFlow = flowStart;
835
+ if ((containerFlags &
836
+ (16 /* ContainerFlags.IsFunctionExpression */ | 128 /* ContainerFlags.IsObjectLiteralOrClassExpressionMethodOrAccessor */)) !==
837
+ 0)
838
+ flowStart.node = node;
839
+ }
840
+ // IIFEs and constructors get a return graph; constructors use it to check property initialization.
841
+ this.currentReturnTarget =
842
+ isImmediatelyInvoked || node.kind === 177 /* SyntaxKind.Constructor */ ? this.createBranchLabel() : undefined;
843
+ this.currentExceptionTarget = undefined;
844
+ this.currentBreakTarget = undefined;
845
+ this.currentContinueTarget = undefined;
846
+ this.activeLabelList = undefined;
847
+ this.hasExplicitReturn = false;
848
+ this.seenThisKeyword = false;
849
+ this.bindChildren(node);
850
+ node.flags &= ~(262912 /* NodeFlags.ReachabilityAndEmitFlags */ | 128 /* NodeFlags.ContainsThis */);
851
+ if ((this.currentFlow.flags & 1 /* FlowFlags.Unreachable */) === 0 &&
852
+ (containerFlags & 8 /* ContainerFlags.IsFunctionLike */) !== 0 &&
853
+ node.kind !== 176 /* SyntaxKind.ClassStaticBlockDeclaration */ &&
854
+ nodeIsPresent(getBody(node))) {
855
+ node.flags |= 256 /* NodeFlags.HasImplicitReturn */;
856
+ if (this.hasExplicitReturn)
857
+ node.flags |= 512 /* NodeFlags.HasExplicitReturn */;
858
+ setEndFlowNode(node, this.currentFlow);
859
+ }
860
+ if (this.seenThisKeyword)
861
+ node.flags |= 128 /* NodeFlags.ContainsThis */;
862
+ if (node.kind === 307 /* SyntaxKind.SourceFile */) {
863
+ node.flags |= this.emitFlags;
864
+ node.endFlowNode = this.currentFlow;
865
+ }
866
+ const returnTarget = this.currentReturnTarget;
867
+ if (returnTarget !== undefined) {
868
+ this.addAntecedent(returnTarget, this.currentFlow);
869
+ this.currentFlow = this.finishFlowLabel(returnTarget);
870
+ if (node.kind === 177 /* SyntaxKind.Constructor */ || node.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */)
871
+ setReturnFlowNode(node, this.currentFlow);
872
+ }
873
+ if (!isImmediatelyInvoked)
874
+ this.currentFlow = saveCurrentFlow;
875
+ this.currentBreakTarget = saveBreakTarget;
876
+ this.currentContinueTarget = saveContinueTarget;
877
+ this.currentReturnTarget = saveReturnTarget;
878
+ this.currentExceptionTarget = saveExceptionTarget;
879
+ this.activeLabelList = saveActiveLabelList;
880
+ this.hasExplicitReturn = saveHasExplicitReturn;
881
+ this.seenThisKeyword =
882
+ (containerFlags & 512 /* ContainerFlags.PropagatesThisKeyword */) !== 0
883
+ ? saveSeenThisKeyword || this.seenThisKeyword
884
+ : saveSeenThisKeyword;
885
+ }
886
+ finishSourceFile(file) {
887
+ if (isInJSFile(file)) {
888
+ // Top-level @typedef aliases wait until CommonJS module indicators are known.
889
+ for (const statement of file.statements.nodes)
890
+ if (statement.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */)
891
+ this.bindBlockScopedDeclaration(statement, 524288 /* SymbolFlags.TypeAlias */, 788968 /* SymbolFlags.TypeAliasExcludes */);
892
+ if (file.commonJSModuleIndicator !== undefined) {
893
+ this.declareCommonJSVariable('module');
894
+ this.declareCommonJSVariable('exports');
895
+ }
896
+ }
897
+ if (isExternalOrCommonJSModule(file))
898
+ this.bindCommonJSTypeExports(file.symbol);
899
+ }
900
+ declareCommonJSVariable(name) {
901
+ const locals = this.localsOf(this.file);
902
+ if (locals.has(name))
903
+ return;
904
+ const symbol = this.newSymbol(1 /* SymbolFlags.FunctionScopedVariable */ | 134217728 /* SymbolFlags.ModuleExports */, name);
905
+ addDeclaration(symbol, this.file);
906
+ symbol.valueDeclaration = this.file;
907
+ if (name === 'module') {
908
+ const exportsProperty = this.newSymbol(134217728 /* SymbolFlags.ModuleExports */ | 4 /* SymbolFlags.Property */, 'exports');
909
+ exportsProperty.declarations = symbol.declarations;
910
+ exportsProperty.valueDeclaration = this.file;
911
+ exportsProperty.parent = symbol;
912
+ getMembers(symbol).set('exports', exportsProperty);
913
+ }
914
+ locals.set(name, symbol);
915
+ }
916
+ addToContainerChain(next) {
917
+ const last = this.lastContainer;
918
+ if (last !== undefined)
919
+ setNextContainer(last, next);
920
+ this.lastContainer = next;
921
+ }
922
+ bindChildren(node) {
923
+ const saveInAssignmentPattern = this.inAssignmentPattern;
924
+ // Most nodes can't be in an assignment pattern; those that can restore it below.
925
+ this.inAssignmentPattern = false;
926
+ if (this.currentFlow === this.unreachableFlow) {
927
+ setFlowNode(node, undefined);
928
+ if (isPotentiallyExecutableNode(node))
929
+ node.flags |= 134217728 /* NodeFlags.Unreachable */;
930
+ node.forEachChild(this);
931
+ this.inAssignmentPattern = saveInAssignmentPattern;
932
+ return;
933
+ }
934
+ if (node.kind >= 244 /* SyntaxKind.FirstStatement */ && node.kind <= 260 /* SyntaxKind.LastStatement */)
935
+ setFlowNode(node, this.currentFlowValue());
936
+ switch (node.kind) {
937
+ case 248 /* SyntaxKind.WhileStatement */:
938
+ this.bindWhileStatement(node);
939
+ break;
940
+ case 247 /* SyntaxKind.DoStatement */:
941
+ this.bindDoStatement(node);
942
+ break;
943
+ case 249 /* SyntaxKind.ForStatement */:
944
+ this.bindForStatement(node);
945
+ break;
946
+ case 250 /* SyntaxKind.ForInStatement */:
947
+ case 251 /* SyntaxKind.ForOfStatement */:
948
+ this.bindForInOrForOfStatement(node);
949
+ break;
950
+ case 246 /* SyntaxKind.IfStatement */:
951
+ this.bindIfStatement(node);
952
+ break;
953
+ case 254 /* SyntaxKind.ReturnStatement */:
954
+ this.bindOptional(getExpression(node));
955
+ if (this.currentReturnTarget !== undefined)
956
+ this.addAntecedent(this.currentReturnTarget, this.currentFlow);
957
+ this.currentFlow = this.unreachableFlow;
958
+ this.hasExplicitReturn = true;
959
+ this.hasFlowEffects = true;
960
+ break;
961
+ case 258 /* SyntaxKind.ThrowStatement */:
962
+ this.bindOptional(getExpression(node));
963
+ this.currentFlow = this.unreachableFlow;
964
+ this.hasFlowEffects = true;
965
+ break;
966
+ case 253 /* SyntaxKind.BreakStatement */:
967
+ this.bindBreakOrContinueStatement(getLabel(node), true);
968
+ break;
969
+ case 252 /* SyntaxKind.ContinueStatement */:
970
+ this.bindBreakOrContinueStatement(getLabel(node), false);
971
+ break;
972
+ case 259 /* SyntaxKind.TryStatement */:
973
+ this.bindTryStatement(node);
974
+ break;
975
+ case 256 /* SyntaxKind.SwitchStatement */:
976
+ this.bindSwitchStatement(node);
977
+ break;
978
+ case 270 /* SyntaxKind.CaseBlock */:
979
+ this.bindCaseBlock(node);
980
+ break;
981
+ case 297 /* SyntaxKind.CaseClause */:
982
+ case 298 /* SyntaxKind.DefaultClause */:
983
+ this.bindCaseOrDefaultClause(node);
984
+ break;
985
+ case 245 /* SyntaxKind.ExpressionStatement */: {
986
+ const expression = node.expression;
987
+ this.bind(expression);
988
+ this.maybeBindExpressionFlowIfCall(expression);
989
+ break;
990
+ }
991
+ case 257 /* SyntaxKind.LabeledStatement */:
992
+ this.bindLabeledStatement(node);
993
+ break;
994
+ case 225 /* SyntaxKind.PrefixUnaryExpression */:
995
+ this.bindPrefixUnaryExpressionFlow(node);
996
+ break;
997
+ case 226 /* SyntaxKind.PostfixUnaryExpression */: {
998
+ node.forEachChild(this);
999
+ const operator = node.operator;
1000
+ if (operator === 45 /* SyntaxKind.PlusPlusToken */ || operator === 46 /* SyntaxKind.MinusMinusToken */)
1001
+ this.bindAssignmentTargetFlow(node.operand);
1002
+ break;
1003
+ }
1004
+ case 227 /* SyntaxKind.BinaryExpression */:
1005
+ if (isDestructuringAssignment(node)) {
1006
+ // Carry the assignment pattern state into initializers of the pattern.
1007
+ this.inAssignmentPattern = saveInAssignmentPattern;
1008
+ this.bindDestructuringAssignmentFlow(node);
1009
+ return;
1010
+ }
1011
+ this.bindBinaryExpressionFlow(node);
1012
+ break;
1013
+ case 221 /* SyntaxKind.DeleteExpression */:
1014
+ node.forEachChild(this);
1015
+ if (node.expression.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
1016
+ this.bindAssignmentTargetFlow(node.expression);
1017
+ break;
1018
+ case 228 /* SyntaxKind.ConditionalExpression */:
1019
+ this.bindConditionalExpressionFlow(node);
1020
+ break;
1021
+ case 261 /* SyntaxKind.VariableDeclaration */:
1022
+ node.forEachChild(this);
1023
+ if (node.initializer !== undefined ||
1024
+ isForInOrOfStatementKind(node.parent.parent.kind))
1025
+ this.bindInitializedVariableFlow(node);
1026
+ break;
1027
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
1028
+ case 213 /* SyntaxKind.ElementAccessExpression */:
1029
+ case 236 /* SyntaxKind.NonNullExpression */:
1030
+ if (isOptionalChain(node))
1031
+ this.bindOptionalChainFlow(node);
1032
+ else
1033
+ node.forEachChild(this);
1034
+ break;
1035
+ case 214 /* SyntaxKind.CallExpression */:
1036
+ this.bindCallExpressionFlow(node);
1037
+ break;
1038
+ case 307 /* SyntaxKind.SourceFile */:
1039
+ this.bindEachStatementFunctionsFirst(node.statements);
1040
+ this.bind(node.endOfFileToken);
1041
+ break;
1042
+ case 242 /* SyntaxKind.Block */:
1043
+ case 269 /* SyntaxKind.ModuleBlock */:
1044
+ this.bindEachStatementFunctionsFirst(getStatements(node));
1045
+ break;
1046
+ case 209 /* SyntaxKind.BindingElement */: {
1047
+ // The initializer runs before the binding pattern.
1048
+ const element = node;
1049
+ this.bindOptional(element.dotDotDotToken);
1050
+ this.bindOptional(element.propertyName);
1051
+ this.bindInitializer(element.initializer);
1052
+ this.bindOptional(element.name);
1053
+ break;
1054
+ }
1055
+ case 170 /* SyntaxKind.Parameter */: {
1056
+ const parameter = node;
1057
+ this.bindNodes(parameter.modifiers);
1058
+ this.bindOptional(parameter.dotDotDotToken);
1059
+ this.bindOptional(parameter.questionToken);
1060
+ this.bindOptional(parameter.type);
1061
+ this.bindInitializer(parameter.initializer);
1062
+ this.bind(parameter.name);
1063
+ break;
1064
+ }
1065
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
1066
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
1067
+ case 303 /* SyntaxKind.PropertyAssignment */:
1068
+ case 231 /* SyntaxKind.SpreadElement */:
1069
+ this.inAssignmentPattern = saveInAssignmentPattern;
1070
+ node.forEachChild(this);
1071
+ break;
1072
+ default:
1073
+ node.forEachChild(this);
1074
+ }
1075
+ this.inAssignmentPattern = saveInAssignmentPattern;
1076
+ }
1077
+ bindNodes(list) {
1078
+ if (list === undefined)
1079
+ return;
1080
+ const nodes = list.nodes;
1081
+ for (let i = 0; i < nodes.length; i++)
1082
+ this.bind(nodes[i]);
1083
+ }
1084
+ bindEachStatementFunctionsFirst(statements) {
1085
+ const nodes = statements.nodes;
1086
+ for (let i = 0; i < nodes.length; i++)
1087
+ if (nodes[i].kind === 263 /* SyntaxKind.FunctionDeclaration */)
1088
+ this.bind(nodes[i]);
1089
+ for (let i = 0; i < nodes.length; i++)
1090
+ if (nodes[i].kind !== 263 /* SyntaxKind.FunctionDeclaration */)
1091
+ this.bind(nodes[i]);
1092
+ }
1093
+ // Flow graph
1094
+ createBranchLabel() {
1095
+ return new FlowNode(4 /* FlowFlags.BranchLabel */, undefined, undefined);
1096
+ }
1097
+ createLoopLabel() {
1098
+ return new FlowNode(8 /* FlowFlags.LoopLabel */, undefined, undefined);
1099
+ }
1100
+ createFlowCondition(flags, antecedent, expression) {
1101
+ if ((antecedent.flags & 1 /* FlowFlags.Unreachable */) !== 0)
1102
+ return antecedent;
1103
+ if (expression === undefined)
1104
+ return (flags & 32 /* FlowFlags.TrueCondition */) !== 0 ? antecedent : this.unreachableFlow;
1105
+ if (((expression.kind === 111 /* SyntaxKind.TrueKeyword */ && (flags & 64 /* FlowFlags.FalseCondition */) !== 0) ||
1106
+ (expression.kind === 96 /* SyntaxKind.FalseKeyword */ && (flags & 32 /* FlowFlags.TrueCondition */) !== 0)) &&
1107
+ !isExpressionOfOptionalChainRoot(expression) &&
1108
+ !isNullishCoalesce(expression.parent))
1109
+ return this.unreachableFlow;
1110
+ if (!isNarrowingExpression(expression))
1111
+ return antecedent;
1112
+ setFlowNodeReferenced(antecedent);
1113
+ return new FlowNode(flags, expression, antecedent);
1114
+ }
1115
+ createFlowMutation(flags, antecedent, node) {
1116
+ setFlowNodeReferenced(antecedent);
1117
+ this.hasFlowEffects = true;
1118
+ const result = new FlowNode(flags, node, antecedent);
1119
+ if (this.currentExceptionTarget !== undefined)
1120
+ this.addAntecedent(this.currentExceptionTarget, result);
1121
+ return result;
1122
+ }
1123
+ createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
1124
+ setFlowNodeReferenced(antecedent);
1125
+ return new FlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd);
1126
+ }
1127
+ createFlowCall(antecedent, node) {
1128
+ setFlowNodeReferenced(antecedent);
1129
+ this.hasFlowEffects = true;
1130
+ return new FlowNode(512 /* FlowFlags.Call */, node, antecedent);
1131
+ }
1132
+ /** Adds `antecedent` to the end of the label's antecedents, unless unreachable or already there. */
1133
+ addAntecedent(label, antecedent) {
1134
+ if ((antecedent.flags & 1 /* FlowFlags.Unreachable */) !== 0)
1135
+ return;
1136
+ const antecedents = label.antecedents;
1137
+ if (antecedents === undefined)
1138
+ label.antecedents = [antecedent];
1139
+ else {
1140
+ if (antecedents.indexOf(antecedent) >= 0)
1141
+ return;
1142
+ antecedents.push(antecedent);
1143
+ }
1144
+ setFlowNodeReferenced(antecedent);
1145
+ }
1146
+ /** The label, its only antecedent, or unreachable if it has none. */
1147
+ finishFlowLabel(label) {
1148
+ const antecedents = label.antecedents;
1149
+ if (antecedents === undefined)
1150
+ return this.unreachableFlow;
1151
+ if (antecedents.length === 1)
1152
+ return antecedents[0];
1153
+ return label;
1154
+ }
1155
+ setContinueTarget(node, target) {
1156
+ let label = this.activeLabelList;
1157
+ let current = node;
1158
+ while (label !== undefined && current.parent.kind === 257 /* SyntaxKind.LabeledStatement */) {
1159
+ label.continueTarget = target;
1160
+ label = label.next;
1161
+ current = current.parent;
1162
+ }
1163
+ return target;
1164
+ }
1165
+ /** Binds `node` with `trueTarget` and `falseTarget` as the condition's targets. */
1166
+ bindWithTargets(node, trueTarget, falseTarget) {
1167
+ const savedTrueTarget = this.currentTrueTarget;
1168
+ const savedFalseTarget = this.currentFalseTarget;
1169
+ this.currentTrueTarget = trueTarget;
1170
+ this.currentFalseTarget = falseTarget;
1171
+ this.bindOptional(node);
1172
+ this.currentTrueTarget = savedTrueTarget;
1173
+ this.currentFalseTarget = savedFalseTarget;
1174
+ }
1175
+ bindCondition(node, trueTarget, falseTarget) {
1176
+ this.bindWithTargets(node, trueTarget, falseTarget);
1177
+ if (node === undefined ||
1178
+ (!isLogicalOrCoalescingAssignmentExpression(skipParentheses(node)) &&
1179
+ !isLogicalExpression(node) &&
1180
+ !(isOptionalChain(node) && isOutermostOptionalChain(node)))) {
1181
+ this.addAntecedent(trueTarget, this.createFlowCondition(32 /* FlowFlags.TrueCondition */, this.currentFlow, node));
1182
+ this.addAntecedent(falseTarget, this.createFlowCondition(64 /* FlowFlags.FalseCondition */, this.currentFlow, node));
1183
+ }
1184
+ }
1185
+ bindIterativeStatement(node, breakTarget, continueTarget) {
1186
+ const saveBreakTarget = this.currentBreakTarget;
1187
+ const saveContinueTarget = this.currentContinueTarget;
1188
+ this.currentBreakTarget = breakTarget;
1189
+ this.currentContinueTarget = continueTarget;
1190
+ this.bind(node);
1191
+ this.currentBreakTarget = saveBreakTarget;
1192
+ this.currentContinueTarget = saveContinueTarget;
1193
+ }
1194
+ bindAssignmentTargetFlow(node) {
1195
+ switch (node.kind) {
1196
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
1197
+ for (const element of getElements(node).nodes) {
1198
+ if (element.kind === 231 /* SyntaxKind.SpreadElement */)
1199
+ this.bindAssignmentTargetFlow(getExpression(element));
1200
+ else
1201
+ this.bindDestructuringTargetFlow(element);
1202
+ }
1203
+ break;
1204
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
1205
+ for (const property of getProperties(node).nodes) {
1206
+ switch (property.kind) {
1207
+ case 303 /* SyntaxKind.PropertyAssignment */:
1208
+ this.bindDestructuringTargetFlow(getInitializer(property));
1209
+ break;
1210
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
1211
+ this.bindAssignmentTargetFlow(getName(property));
1212
+ break;
1213
+ case 305 /* SyntaxKind.SpreadAssignment */:
1214
+ this.bindAssignmentTargetFlow(getExpression(property));
1215
+ break;
1216
+ }
1217
+ }
1218
+ break;
1219
+ default:
1220
+ if (isNarrowableReference(node))
1221
+ this.currentFlow = this.createFlowMutation(16 /* FlowFlags.Assignment */, this.currentFlow, node);
1222
+ }
1223
+ }
1224
+ bindDestructuringTargetFlow(node) {
1225
+ if (node instanceof BinaryExpression && node.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */)
1226
+ this.bindAssignmentTargetFlow(node.left);
1227
+ else
1228
+ this.bindAssignmentTargetFlow(node);
1229
+ }
1230
+ bindWhileStatement(node) {
1231
+ const preWhileLabel = this.setContinueTarget(node, this.createLoopLabel());
1232
+ const preBodyLabel = this.createBranchLabel();
1233
+ const postWhileLabel = this.createBranchLabel();
1234
+ this.addAntecedent(preWhileLabel, this.currentFlow);
1235
+ this.currentFlow = preWhileLabel;
1236
+ this.bindCondition(node.expression, preBodyLabel, postWhileLabel);
1237
+ this.currentFlow = this.finishFlowLabel(preBodyLabel);
1238
+ this.bindIterativeStatement(node.statement, postWhileLabel, preWhileLabel);
1239
+ this.addAntecedent(preWhileLabel, this.currentFlow);
1240
+ this.currentFlow = this.finishFlowLabel(postWhileLabel);
1241
+ }
1242
+ bindDoStatement(node) {
1243
+ const preDoLabel = this.createLoopLabel();
1244
+ const preConditionLabel = this.setContinueTarget(node, this.createBranchLabel());
1245
+ const postDoLabel = this.createBranchLabel();
1246
+ this.addAntecedent(preDoLabel, this.currentFlow);
1247
+ this.currentFlow = preDoLabel;
1248
+ this.bindIterativeStatement(node.statement, postDoLabel, preConditionLabel);
1249
+ this.addAntecedent(preConditionLabel, this.currentFlow);
1250
+ this.currentFlow = this.finishFlowLabel(preConditionLabel);
1251
+ this.bindCondition(node.expression, preDoLabel, postDoLabel);
1252
+ this.currentFlow = this.finishFlowLabel(postDoLabel);
1253
+ }
1254
+ bindForStatement(node) {
1255
+ const preLoopLabel = this.setContinueTarget(node, this.createLoopLabel());
1256
+ const preBodyLabel = this.createBranchLabel();
1257
+ const preIncrementorLabel = this.createBranchLabel();
1258
+ const postLoopLabel = this.createBranchLabel();
1259
+ this.bindOptional(node.initializer);
1260
+ this.addAntecedent(preLoopLabel, this.currentFlow);
1261
+ this.currentFlow = preLoopLabel;
1262
+ this.bindCondition(node.condition, preBodyLabel, postLoopLabel);
1263
+ this.currentFlow = this.finishFlowLabel(preBodyLabel);
1264
+ this.bindIterativeStatement(node.statement, postLoopLabel, preIncrementorLabel);
1265
+ this.addAntecedent(preIncrementorLabel, this.currentFlow);
1266
+ this.currentFlow = this.finishFlowLabel(preIncrementorLabel);
1267
+ this.bindOptional(node.incrementor);
1268
+ this.addAntecedent(preLoopLabel, this.currentFlow);
1269
+ this.currentFlow = this.finishFlowLabel(postLoopLabel);
1270
+ }
1271
+ bindForInOrForOfStatement(node) {
1272
+ const preLoopLabel = this.setContinueTarget(node, this.createLoopLabel());
1273
+ const postLoopLabel = this.createBranchLabel();
1274
+ this.bind(node.expression);
1275
+ this.addAntecedent(preLoopLabel, this.currentFlow);
1276
+ this.currentFlow = preLoopLabel;
1277
+ if (node.kind === 251 /* SyntaxKind.ForOfStatement */)
1278
+ this.bindOptional(node.awaitModifier);
1279
+ this.addAntecedent(postLoopLabel, this.currentFlow);
1280
+ this.bind(node.initializer);
1281
+ if (node.initializer.kind !== 262 /* SyntaxKind.VariableDeclarationList */)
1282
+ this.bindAssignmentTargetFlow(node.initializer);
1283
+ this.bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
1284
+ this.addAntecedent(preLoopLabel, this.currentFlow);
1285
+ this.currentFlow = this.finishFlowLabel(postLoopLabel);
1286
+ }
1287
+ bindIfStatement(node) {
1288
+ const thenLabel = this.createBranchLabel();
1289
+ const elseLabel = this.createBranchLabel();
1290
+ const postIfLabel = this.createBranchLabel();
1291
+ this.bindCondition(node.expression, thenLabel, elseLabel);
1292
+ this.currentFlow = this.finishFlowLabel(thenLabel);
1293
+ this.bind(node.thenStatement);
1294
+ this.addAntecedent(postIfLabel, this.currentFlow);
1295
+ this.currentFlow = this.finishFlowLabel(elseLabel);
1296
+ this.bindOptional(node.elseStatement);
1297
+ this.addAntecedent(postIfLabel, this.currentFlow);
1298
+ this.currentFlow = this.finishFlowLabel(postIfLabel);
1299
+ }
1300
+ bindBreakOrContinueStatement(label, isBreak) {
1301
+ this.bindOptional(label);
1302
+ if (label !== undefined) {
1303
+ const name = getText(label);
1304
+ let activeLabel = this.activeLabelList;
1305
+ while (activeLabel !== undefined && activeLabel.name !== name)
1306
+ activeLabel = activeLabel.next;
1307
+ if (activeLabel !== undefined) {
1308
+ activeLabel.referenced = true;
1309
+ this.bindBreakOrContinueFlow(isBreak ? activeLabel.breakTarget : activeLabel.continueTarget);
1310
+ }
1311
+ }
1312
+ else
1313
+ this.bindBreakOrContinueFlow(isBreak ? this.currentBreakTarget : this.currentContinueTarget);
1314
+ }
1315
+ bindBreakOrContinueFlow(flowLabel) {
1316
+ if (flowLabel === undefined)
1317
+ return;
1318
+ this.addAntecedent(flowLabel, this.currentFlow);
1319
+ this.currentFlow = this.unreachableFlow;
1320
+ this.hasFlowEffects = true;
1321
+ }
1322
+ /**
1323
+ * Any code in a `try` block may throw, but only mutations change narrowed types, so the
1324
+ * exception label collects the mutations (and the flow before them) as antecedents of the
1325
+ * `catch` or `finally` block.
1326
+ */
1327
+ bindTryStatement(node) {
1328
+ const saveReturnTarget = this.currentReturnTarget;
1329
+ const saveExceptionTarget = this.currentExceptionTarget;
1330
+ const normalExitLabel = this.createBranchLabel();
1331
+ const returnLabel = this.createBranchLabel();
1332
+ let exceptionLabel = this.createBranchLabel();
1333
+ if (node.finallyBlock !== undefined)
1334
+ this.currentReturnTarget = returnLabel;
1335
+ this.addAntecedent(exceptionLabel, this.currentFlow);
1336
+ this.currentExceptionTarget = exceptionLabel;
1337
+ this.bind(node.tryBlock);
1338
+ this.addAntecedent(normalExitLabel, this.currentFlow);
1339
+ if (node.catchClause !== undefined) {
1340
+ // The catch clause starts with the exceptions of the try block and acts like a second try block.
1341
+ this.currentFlow = this.finishFlowLabel(exceptionLabel);
1342
+ exceptionLabel = this.createBranchLabel();
1343
+ this.addAntecedent(exceptionLabel, this.currentFlow);
1344
+ this.currentExceptionTarget = exceptionLabel;
1345
+ this.bind(node.catchClause);
1346
+ this.addAntecedent(normalExitLabel, this.currentFlow);
1347
+ }
1348
+ this.currentReturnTarget = saveReturnTarget;
1349
+ this.currentExceptionTarget = saveExceptionTarget;
1350
+ if (node.finallyBlock === undefined) {
1351
+ this.currentFlow = this.finishFlowLabel(normalExitLabel);
1352
+ return;
1353
+ }
1354
+ // The finally block is reached by normal completion of the try or catch block, by returns in
1355
+ // them, and by exceptions in them. Analysis that starts past the finally block only considers
1356
+ // normal completion, and returns from an IIFE only the returns, so ReduceLabel nodes give the
1357
+ // finally label a reduced set of antecedents for those paths.
1358
+ const finallyLabel = this.createBranchLabel();
1359
+ finallyLabel.antecedents = combineFlowLists(normalExitLabel.antecedents, combineFlowLists(exceptionLabel.antecedents, returnLabel.antecedents));
1360
+ this.currentFlow = finallyLabel;
1361
+ this.bind(node.finallyBlock);
1362
+ if ((this.currentFlow.flags & 1 /* FlowFlags.Unreachable */) !== 0) {
1363
+ // An unreachable end of the finally block makes the end of the try statement unreachable.
1364
+ this.currentFlow = this.unreachableFlow;
1365
+ return;
1366
+ }
1367
+ // Returns in the try or catch block of an IIFE continue through the finally block.
1368
+ if (this.currentReturnTarget !== undefined && returnLabel.antecedents !== undefined)
1369
+ this.addAntecedent(this.currentReturnTarget, new FlowReduceLabel(finallyLabel, returnLabel.antecedents, this.currentFlow));
1370
+ // So do exceptions, to an enclosing try statement.
1371
+ if (this.currentExceptionTarget !== undefined && exceptionLabel.antecedents !== undefined)
1372
+ this.addAntecedent(this.currentExceptionTarget, new FlowReduceLabel(finallyLabel, exceptionLabel.antecedents, this.currentFlow));
1373
+ // `try { return 1; } finally { … }` ends unreachable.
1374
+ this.currentFlow =
1375
+ normalExitLabel.antecedents !== undefined
1376
+ ? new FlowReduceLabel(finallyLabel, normalExitLabel.antecedents, this.currentFlow)
1377
+ : this.unreachableFlow;
1378
+ }
1379
+ bindSwitchStatement(node) {
1380
+ const postSwitchLabel = this.createBranchLabel();
1381
+ this.bind(node.expression);
1382
+ const saveBreakTarget = this.currentBreakTarget;
1383
+ const savePreSwitchCaseFlow = this.preSwitchCaseFlow;
1384
+ this.currentBreakTarget = postSwitchLabel;
1385
+ this.preSwitchCaseFlow = this.currentFlow;
1386
+ this.bind(node.caseBlock);
1387
+ this.addAntecedent(postSwitchLabel, this.currentFlow);
1388
+ let hasDefault = false;
1389
+ for (const clause of node.caseBlock.clauses.nodes)
1390
+ if (clause.kind === 298 /* SyntaxKind.DefaultClause */)
1391
+ hasDefault = true;
1392
+ if (!hasDefault)
1393
+ this.addAntecedent(postSwitchLabel, this.createFlowSwitchClause(this.preSwitchCaseFlow, node, 0, 0));
1394
+ this.currentBreakTarget = saveBreakTarget;
1395
+ this.preSwitchCaseFlow = savePreSwitchCaseFlow;
1396
+ this.currentFlow = this.finishFlowLabel(postSwitchLabel);
1397
+ }
1398
+ bindCaseBlock(node) {
1399
+ const switchStatement = node.parent;
1400
+ const clauses = node.clauses.nodes;
1401
+ const switchExpression = switchStatement.expression;
1402
+ const isNarrowingSwitch = switchExpression.kind === 111 /* SyntaxKind.TrueKeyword */ || isNarrowingExpression(switchExpression);
1403
+ let fallthroughFlow = this.unreachableFlow;
1404
+ for (let i = 0; i < clauses.length; i++) {
1405
+ const clauseStart = i;
1406
+ while (clauses[i].statements.nodes.length === 0 && i + 1 < clauses.length) {
1407
+ if (fallthroughFlow === this.unreachableFlow)
1408
+ this.currentFlow = this.preSwitchCaseFlow;
1409
+ this.bind(clauses[i]);
1410
+ i++;
1411
+ }
1412
+ const preCaseLabel = this.createBranchLabel();
1413
+ const preCaseFlow = isNarrowingSwitch
1414
+ ? this.createFlowSwitchClause(this.preSwitchCaseFlow, switchStatement, clauseStart, i + 1)
1415
+ : this.preSwitchCaseFlow;
1416
+ this.addAntecedent(preCaseLabel, preCaseFlow);
1417
+ this.addAntecedent(preCaseLabel, fallthroughFlow);
1418
+ this.currentFlow = this.finishFlowLabel(preCaseLabel);
1419
+ const clause = clauses[i];
1420
+ this.bind(clause);
1421
+ fallthroughFlow = this.currentFlow;
1422
+ if ((this.currentFlow.flags & 1 /* FlowFlags.Unreachable */) === 0 && i !== clauses.length - 1)
1423
+ clause.fallthroughFlowNode = this.currentFlow;
1424
+ }
1425
+ }
1426
+ bindCaseOrDefaultClause(node) {
1427
+ if (node.expression !== undefined) {
1428
+ const saveCurrentFlow = this.currentFlow;
1429
+ this.currentFlow = this.preSwitchCaseFlow;
1430
+ this.bind(node.expression);
1431
+ this.currentFlow = saveCurrentFlow;
1432
+ }
1433
+ this.bindNodes(node.statements);
1434
+ }
1435
+ /** A top-level or comma call with a dotted callee may be an assertion, so it joins the flow graph. */
1436
+ maybeBindExpressionFlowIfCall(node) {
1437
+ if (node instanceof CallExpression) {
1438
+ const call = node;
1439
+ const callee = call.expression;
1440
+ if (callee.kind !== 107 /* SyntaxKind.SuperKeyword */ && isDottedName(callee))
1441
+ this.currentFlow = this.createFlowCall(this.currentFlow, node);
1442
+ }
1443
+ }
1444
+ bindLabeledStatement(node) {
1445
+ const postStatementLabel = this.createBranchLabel();
1446
+ const activeLabel = new ActiveLabel(this.activeLabelList, node.label.text, postStatementLabel);
1447
+ this.activeLabelList = activeLabel;
1448
+ this.bind(node.label);
1449
+ this.bind(node.statement);
1450
+ // An unused label; the checker decides whether to report it.
1451
+ if (!activeLabel.referenced)
1452
+ node.label.flags |= 134217728 /* NodeFlags.Unreachable */;
1453
+ this.activeLabelList = activeLabel.next;
1454
+ this.addAntecedent(postStatementLabel, this.currentFlow);
1455
+ this.currentFlow = this.finishFlowLabel(postStatementLabel);
1456
+ }
1457
+ bindPrefixUnaryExpressionFlow(node) {
1458
+ if (node.operator === 53 /* SyntaxKind.ExclamationToken */) {
1459
+ const saveTrueTarget = this.currentTrueTarget;
1460
+ this.currentTrueTarget = this.currentFalseTarget;
1461
+ this.currentFalseTarget = saveTrueTarget;
1462
+ node.forEachChild(this);
1463
+ this.currentFalseTarget = this.currentTrueTarget;
1464
+ this.currentTrueTarget = saveTrueTarget;
1465
+ }
1466
+ else {
1467
+ node.forEachChild(this);
1468
+ if (node.operator === 45 /* SyntaxKind.PlusPlusToken */ || node.operator === 46 /* SyntaxKind.MinusMinusToken */)
1469
+ this.bindAssignmentTargetFlow(node.operand);
1470
+ }
1471
+ }
1472
+ bindDestructuringAssignmentFlow(node) {
1473
+ if (this.inAssignmentPattern) {
1474
+ this.inAssignmentPattern = false;
1475
+ this.bind(node.operatorToken);
1476
+ this.bind(node.right);
1477
+ this.inAssignmentPattern = true;
1478
+ this.bind(node.left);
1479
+ this.bindOptional(node.type);
1480
+ }
1481
+ else {
1482
+ this.inAssignmentPattern = true;
1483
+ this.bind(node.left);
1484
+ this.bindOptional(node.type);
1485
+ this.inAssignmentPattern = false;
1486
+ this.bind(node.operatorToken);
1487
+ this.bind(node.right);
1488
+ }
1489
+ this.bindAssignmentTargetFlow(node.left);
1490
+ }
1491
+ bindBinaryExpressionFlow(node) {
1492
+ const operator = node.operatorToken.kind;
1493
+ if (isLogicalOrCoalescingBinaryOperator(operator) || isLogicalOrCoalescingAssignmentOperator(operator)) {
1494
+ if (isTopLevelLogicalExpression(node)) {
1495
+ const postExpressionLabel = this.createBranchLabel();
1496
+ const saveCurrentFlow = this.currentFlow;
1497
+ const saveHasFlowEffects = this.hasFlowEffects;
1498
+ this.hasFlowEffects = false;
1499
+ this.bindLogicalLikeExpression(node, postExpressionLabel, postExpressionLabel);
1500
+ this.currentFlow = this.hasFlowEffects ? this.finishFlowLabel(postExpressionLabel) : saveCurrentFlow;
1501
+ this.hasFlowEffects = this.hasFlowEffects || saveHasFlowEffects;
1502
+ }
1503
+ else
1504
+ this.bindLogicalLikeExpression(node, this.currentTrueTarget, this.currentFalseTarget);
1505
+ return;
1506
+ }
1507
+ this.bind(node.left);
1508
+ this.bindOptional(node.type);
1509
+ if (operator === 27 /* SyntaxKind.CommaToken */)
1510
+ this.maybeBindExpressionFlowIfCall(node.left);
1511
+ this.bind(node.operatorToken);
1512
+ this.bind(node.right);
1513
+ if (operator === 27 /* SyntaxKind.CommaToken */)
1514
+ this.maybeBindExpressionFlowIfCall(node.right);
1515
+ if (isAssignmentOperator(operator) && !isAssignmentTarget(node)) {
1516
+ this.bindAssignmentTargetFlow(node.left);
1517
+ const left = node.left;
1518
+ if (operator === 63 /* SyntaxKind.EqualsToken */ &&
1519
+ left instanceof ElementAccessExpression &&
1520
+ isNarrowableOperand(left.expression))
1521
+ this.currentFlow = this.createFlowMutation(256 /* FlowFlags.ArrayMutation */, this.currentFlow, node);
1522
+ }
1523
+ }
1524
+ bindLogicalLikeExpression(node, trueTarget, falseTarget) {
1525
+ const preRightLabel = this.createBranchLabel();
1526
+ const operator = node.operatorToken.kind;
1527
+ if (operator === 55 /* SyntaxKind.AmpersandAmpersandToken */ || operator === 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */)
1528
+ this.bindCondition(node.left, preRightLabel, falseTarget);
1529
+ else
1530
+ this.bindCondition(node.left, trueTarget, preRightLabel);
1531
+ this.currentFlow = this.finishFlowLabel(preRightLabel);
1532
+ this.bind(node.operatorToken);
1533
+ if (isLogicalOrCoalescingAssignmentOperator(operator)) {
1534
+ this.bindWithTargets(node.right, trueTarget, falseTarget);
1535
+ this.bindAssignmentTargetFlow(node.left);
1536
+ this.addAntecedent(trueTarget, this.createFlowCondition(32 /* FlowFlags.TrueCondition */, this.currentFlow, node));
1537
+ this.addAntecedent(falseTarget, this.createFlowCondition(64 /* FlowFlags.FalseCondition */, this.currentFlow, node));
1538
+ }
1539
+ else
1540
+ this.bindCondition(node.right, trueTarget, falseTarget);
1541
+ }
1542
+ bindConditionalExpressionFlow(node) {
1543
+ const trueLabel = this.createBranchLabel();
1544
+ const falseLabel = this.createBranchLabel();
1545
+ const postExpressionLabel = this.createBranchLabel();
1546
+ const saveCurrentFlow = this.currentFlow;
1547
+ const saveHasFlowEffects = this.hasFlowEffects;
1548
+ this.hasFlowEffects = false;
1549
+ this.bindCondition(node.condition, trueLabel, falseLabel);
1550
+ this.currentFlow = this.finishFlowLabel(trueLabel);
1551
+ this.bind(node.questionToken);
1552
+ this.bind(node.whenTrue);
1553
+ this.addAntecedent(postExpressionLabel, this.currentFlow);
1554
+ this.currentFlow = this.finishFlowLabel(falseLabel);
1555
+ this.bind(node.colonToken);
1556
+ this.bind(node.whenFalse);
1557
+ this.addAntecedent(postExpressionLabel, this.currentFlow);
1558
+ this.currentFlow = this.hasFlowEffects ? this.finishFlowLabel(postExpressionLabel) : saveCurrentFlow;
1559
+ this.hasFlowEffects = this.hasFlowEffects || saveHasFlowEffects;
1560
+ }
1561
+ bindInitializedVariableFlow(node) {
1562
+ const name = getName(node);
1563
+ if (name !== undefined &&
1564
+ (name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */)) {
1565
+ for (const element of getElements(name).nodes)
1566
+ this.bindInitializedVariableFlow(element);
1567
+ }
1568
+ else
1569
+ this.currentFlow = this.createFlowMutation(16 /* FlowFlags.Assignment */, this.currentFlow, node);
1570
+ }
1571
+ bindOptionalChainFlow(node) {
1572
+ if (isTopLevelLogicalExpression(node)) {
1573
+ const postExpressionLabel = this.createBranchLabel();
1574
+ const saveCurrentFlow = this.currentFlow;
1575
+ const saveHasFlowEffects = this.hasFlowEffects;
1576
+ this.bindOptionalChain(node, postExpressionLabel, postExpressionLabel);
1577
+ this.currentFlow = this.hasFlowEffects ? this.finishFlowLabel(postExpressionLabel) : saveCurrentFlow;
1578
+ this.hasFlowEffects = this.hasFlowEffects || saveHasFlowEffects;
1579
+ }
1580
+ else
1581
+ this.bindOptionalChain(node, this.currentTrueTarget, this.currentFalseTarget);
1582
+ }
1583
+ /**
1584
+ * Binds an optional chain like a logical expression: `a?.b.c` as `a && a.b.c`. The chain's
1585
+ * root is the first condition and the rest of the chain is its true branch.
1586
+ */
1587
+ bindOptionalChain(node, trueTarget, falseTarget) {
1588
+ const preChainLabel = isOptionalChainRoot(node) ? this.createBranchLabel() : undefined;
1589
+ this.bindOptionalExpression(getExpression(node), preChainLabel ?? trueTarget, falseTarget);
1590
+ if (preChainLabel !== undefined)
1591
+ this.currentFlow = this.finishFlowLabel(preChainLabel);
1592
+ const savedTrueTarget = this.currentTrueTarget;
1593
+ const savedFalseTarget = this.currentFalseTarget;
1594
+ this.currentTrueTarget = trueTarget;
1595
+ this.currentFalseTarget = falseTarget;
1596
+ this.bindOptionalChainRest(node);
1597
+ this.currentTrueTarget = savedTrueTarget;
1598
+ this.currentFalseTarget = savedFalseTarget;
1599
+ if (isOutermostOptionalChain(node)) {
1600
+ this.addAntecedent(trueTarget, this.createFlowCondition(32 /* FlowFlags.TrueCondition */, this.currentFlow, node));
1601
+ this.addAntecedent(falseTarget, this.createFlowCondition(64 /* FlowFlags.FalseCondition */, this.currentFlow, node));
1602
+ }
1603
+ }
1604
+ bindOptionalExpression(node, trueTarget, falseTarget) {
1605
+ this.bindWithTargets(node, trueTarget, falseTarget);
1606
+ if (!isOptionalChain(node) || isOutermostOptionalChain(node)) {
1607
+ this.addAntecedent(trueTarget, this.createFlowCondition(32 /* FlowFlags.TrueCondition */, this.currentFlow, node));
1608
+ this.addAntecedent(falseTarget, this.createFlowCondition(64 /* FlowFlags.FalseCondition */, this.currentFlow, node));
1609
+ }
1610
+ }
1611
+ bindOptionalChainRest(node) {
1612
+ if (node instanceof PropertyAccessExpression) {
1613
+ this.bindOptional(node.questionDotToken);
1614
+ this.bind(node.name);
1615
+ }
1616
+ else if (node instanceof ElementAccessExpression) {
1617
+ this.bindOptional(node.questionDotToken);
1618
+ this.bind(node.argumentExpression);
1619
+ }
1620
+ else if (node instanceof CallExpression) {
1621
+ this.bindOptional(node.questionDotToken);
1622
+ this.bindNodes(node.typeArguments);
1623
+ this.bindNodes(node.arguments);
1624
+ }
1625
+ }
1626
+ bindCallExpressionFlow(node) {
1627
+ if (isOptionalChain(node))
1628
+ this.bindOptionalChainFlow(node);
1629
+ else {
1630
+ // An IIFE's flow node includes the evaluation of its arguments.
1631
+ const callee = skipParentheses(node.expression);
1632
+ if (callee.kind === 219 /* SyntaxKind.FunctionExpression */ || callee.kind === 220 /* SyntaxKind.ArrowFunction */) {
1633
+ this.bindNodes(node.typeArguments);
1634
+ this.bindNodes(node.arguments);
1635
+ this.bind(node.expression);
1636
+ }
1637
+ else {
1638
+ node.forEachChild(this);
1639
+ if (node.expression.kind === 107 /* SyntaxKind.SuperKeyword */)
1640
+ this.currentFlow = this.createFlowCall(this.currentFlow, node);
1641
+ }
1642
+ }
1643
+ const callee = node.expression;
1644
+ if (!(callee instanceof PropertyAccessExpression))
1645
+ return;
1646
+ // Typed locals keep scriptc's field reads static after `instanceof`.
1647
+ const access = callee;
1648
+ if (access.name.kind === 79 /* SyntaxKind.Identifier */ &&
1649
+ isNarrowableOperand(access.expression) &&
1650
+ isPushOrUnshiftIdentifier(access.name))
1651
+ this.currentFlow = this.createFlowMutation(256 /* FlowFlags.ArrayMutation */, this.currentFlow, node);
1652
+ }
1653
+ /** Binds a parameter or binding element initializer, which only runs when the value is `undefined`. */
1654
+ bindInitializer(node) {
1655
+ if (node === undefined)
1656
+ return;
1657
+ const entryFlow = this.currentFlow;
1658
+ this.bind(node);
1659
+ if (entryFlow === this.unreachableFlow || entryFlow === this.currentFlow)
1660
+ return;
1661
+ const exitFlow = this.createBranchLabel();
1662
+ this.addAntecedent(exitFlow, entryFlow);
1663
+ this.addAntecedent(exitFlow, this.currentFlow);
1664
+ this.currentFlow = this.finishFlowLabel(exitFlow);
1665
+ }
1666
+ // Declarations by kind
1667
+ bindSourceFileIfExternalModule(file) {
1668
+ this.setExportContextFlag(file);
1669
+ if (isExternalOrCommonJSModule(file))
1670
+ this.bindSourceFileAsExternalModule(file);
1671
+ else if (isJsonSourceFile(file)) {
1672
+ this.bindSourceFileAsExternalModule(file);
1673
+ // The equivalent of `module.exports = {…}`.
1674
+ const originalSymbol = file.symbol;
1675
+ this.declareSymbol(getExports(originalSymbol), originalSymbol, file, 4 /* SymbolFlags.Property */, 1073741823 /* SymbolFlags.All */);
1676
+ file.symbol = originalSymbol;
1677
+ }
1678
+ }
1679
+ bindSourceFileAsExternalModule(file) {
1680
+ this.bindAnonymousDeclaration(file, 512 /* SymbolFlags.ValueModule */, '"' + removeFileExtension(file.fileName) + '"');
1681
+ }
1682
+ bindModuleDeclaration(node) {
1683
+ this.setExportContextFlag(node);
1684
+ if (isAmbientModule(node)) {
1685
+ if (hasSyntacticModifier(node, 32 /* ModifierFlags.Export */))
1686
+ this.errorOnFirstToken(node, 802 /* Diagnostics.X_export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible */, noArgs);
1687
+ if (isModuleAugmentationExternal(node)) {
1688
+ this.declareModuleSymbol(node);
1689
+ return;
1690
+ }
1691
+ const symbol = this.declareSymbolAndAddToSymbolTable(node, 512 /* SymbolFlags.ValueModule */, 110735 /* SymbolFlags.ValueModuleExcludes */);
1692
+ const name = node.name;
1693
+ if (name.kind === 10 /* SyntaxKind.StringLiteral */) {
1694
+ const text = getText(name);
1695
+ const starIndex = text.indexOf('*');
1696
+ if (starIndex >= 0 && text.indexOf('*', starIndex + 1) >= 0)
1697
+ this.errorOnFirstToken(name, 1136 /* Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character */, [text]);
1698
+ else if (starIndex >= 0)
1699
+ this.file.patternAmbientModules.push(new PatternAmbientModule(text, starIndex, symbol));
1700
+ }
1701
+ return;
1702
+ }
1703
+ const state = this.declareModuleSymbol(node);
1704
+ if (state === 1 /* ModuleInstanceState.NonInstantiated */)
1705
+ return;
1706
+ const symbol = getSymbol(node);
1707
+ // A namespace merged with a function, class or regular enum isn't const-enum-only.
1708
+ const constEnumOnlyModule = (symbol.flags & (16 /* SymbolFlags.Function */ | 32 /* SymbolFlags.Class */ | 256 /* SymbolFlags.RegularEnum */)) === 0 &&
1709
+ state === 3 /* ModuleInstanceState.ConstEnumOnly */ &&
1710
+ !this.notConstEnumOnlyModules.has(symbol);
1711
+ if (constEnumOnlyModule)
1712
+ symbol.flags |= 268435456 /* SymbolFlags.ConstEnumOnlyModule */;
1713
+ else {
1714
+ symbol.flags &= ~268435456 /* SymbolFlags.ConstEnumOnlyModule */;
1715
+ this.notConstEnumOnlyModules.add(symbol);
1716
+ }
1717
+ }
1718
+ declareModuleSymbol(node) {
1719
+ const state = getModuleInstanceState(node, this.statementsByName);
1720
+ const instantiated = state !== 1 /* ModuleInstanceState.NonInstantiated */;
1721
+ this.declareSymbolAndAddToSymbolTable(node, instantiated ? 512 /* SymbolFlags.ValueModule */ : 1024 /* SymbolFlags.NamespaceModule */, instantiated ? 110735 /* SymbolFlags.ValueModuleExcludes */ : 0 /* SymbolFlags.NamespaceModuleExcludes */);
1722
+ return state;
1723
+ }
1724
+ bindNamespaceExportDeclaration(node) {
1725
+ const parent = node.parent;
1726
+ if (getModifiers(node) !== undefined)
1727
+ this.errorOnNode(node, 140 /* Diagnostics.Modifiers_cannot_appear_here */, noArgs);
1728
+ if (parent.kind !== 307 /* SyntaxKind.SourceFile */)
1729
+ this.errorOnNode(node, 252 /* Diagnostics.Global_module_exports_may_only_appear_at_top_level */, noArgs);
1730
+ else if (!isExternalModule(parent))
1731
+ this.errorOnNode(node, 250 /* Diagnostics.Global_module_exports_may_only_appear_in_module_files */, noArgs);
1732
+ else if (!parent.isDeclarationFile)
1733
+ this.errorOnNode(node, 251 /* Diagnostics.Global_module_exports_may_only_appear_in_declaration_files */, noArgs);
1734
+ else {
1735
+ const file = this.file;
1736
+ let globalExports = file.globalExports;
1737
+ if (globalExports === undefined) {
1738
+ globalExports = new Map();
1739
+ file.globalExports = globalExports;
1740
+ }
1741
+ this.declareSymbol(globalExports, file.symbol, node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */);
1742
+ }
1743
+ }
1744
+ bindExportDeclaration(node) {
1745
+ const containerSymbol = getSymbol(this.container);
1746
+ if (containerSymbol === undefined)
1747
+ // `export *` in a block.
1748
+ this.bindAnonymousDeclaration(node, 8388608 /* SymbolFlags.ExportStar */, this.getDeclarationName(node));
1749
+ else if (node.exportClause === undefined)
1750
+ // All `export *` declarations go in one symbol.
1751
+ this.declareSymbol(getExports(containerSymbol), containerSymbol, node, 8388608 /* SymbolFlags.ExportStar */, 0 /* SymbolFlags.None */);
1752
+ else if (node.exportClause.kind === 281 /* SyntaxKind.NamespaceExport */)
1753
+ this.declareSymbol(getExports(containerSymbol), containerSymbol, node.exportClause, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */);
1754
+ }
1755
+ bindExportAssignment(node) {
1756
+ const containerSymbol = getSymbol(this.container);
1757
+ if (containerSymbol === undefined) {
1758
+ // An export assignment in a block.
1759
+ this.bindAnonymousDeclaration(node, 111551 /* SymbolFlags.Value */, this.getDeclarationName(node));
1760
+ return;
1761
+ }
1762
+ // `export default x` aliases x; anything else exported as default is a property.
1763
+ const flags = expressionIsAlias(node.expression) ? 2097152 /* SymbolFlags.Alias */ : 4 /* SymbolFlags.Property */;
1764
+ const symbol = this.declareSymbol(getExports(containerSymbol), containerSymbol, node, flags, 1073741823 /* SymbolFlags.All */);
1765
+ if (node.isExportEquals)
1766
+ setValueDeclaration(symbol, node);
1767
+ }
1768
+ /** Ambient files and modules without export declarations export every declaration implicitly. */
1769
+ setExportContextFlag(node) {
1770
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && !hasExportDeclarations(node))
1771
+ node.flags |= 64 /* NodeFlags.ExportContext */;
1772
+ else
1773
+ node.flags &= ~64 /* NodeFlags.ExportContext */;
1774
+ }
1775
+ bindFunctionDeclaration(node) {
1776
+ if (!this.file.isDeclarationFile && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 && isAsyncFunction(node))
1777
+ this.emitFlags |= 262144 /* NodeFlags.HasAsyncFunctions */;
1778
+ this.checkStrictModeFunctionName(node);
1779
+ this.bindBlockScopedDeclaration(node, 16 /* SymbolFlags.Function */, 110991 /* SymbolFlags.FunctionExcludes */);
1780
+ }
1781
+ bindFunctionExpression(node) {
1782
+ if (!this.file.isDeclarationFile && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 && isAsyncFunction(node))
1783
+ this.emitFlags |= 262144 /* NodeFlags.HasAsyncFunctions */;
1784
+ setFlowNode(node, this.currentFlowValue());
1785
+ let bindingName = "\uFFFEfunction" /* InternalSymbolName.Function */;
1786
+ if (node instanceof FunctionExpression) {
1787
+ const name = node.name;
1788
+ if (name !== undefined) {
1789
+ this.checkStrictModeFunctionName(node);
1790
+ bindingName = name.text;
1791
+ }
1792
+ }
1793
+ this.bindAnonymousDeclaration(node, 16 /* SymbolFlags.Function */, bindingName);
1794
+ }
1795
+ bindClassLikeDeclaration(node) {
1796
+ if (node.kind === 264 /* SyntaxKind.ClassDeclaration */)
1797
+ this.bindBlockScopedDeclaration(node, 32 /* SymbolFlags.Class */, 899503 /* SymbolFlags.ClassExcludes */);
1798
+ else {
1799
+ const name = getName(node);
1800
+ this.bindAnonymousDeclaration(node, 32 /* SymbolFlags.Class */, name !== undefined ? getText(name) : "\uFFFEclass" /* InternalSymbolName.Class */);
1801
+ }
1802
+ // Every class has a static `prototype` property; declaring another one is an error, checked
1803
+ // here because the class may merge with a namespace that exports `prototype`.
1804
+ const symbol = getSymbol(node);
1805
+ const prototypeSymbol = this.newSymbol(4 /* SymbolFlags.Property */ | 4194304 /* SymbolFlags.Prototype */, 'prototype');
1806
+ const exports = getExports(symbol);
1807
+ const existing = exports.get('prototype');
1808
+ if (existing !== undefined)
1809
+ this.errorOnNode(existing.declarations[0], 478 /* Diagnostics.Duplicate_identifier_0 */, ['prototype']);
1810
+ exports.set('prototype', prototypeSymbol);
1811
+ prototypeSymbol.parent = symbol;
1812
+ }
1813
+ bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
1814
+ if (!this.file.isDeclarationFile && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 && isAsyncFunction(node))
1815
+ this.emitFlags |= 262144 /* NodeFlags.HasAsyncFunctions */;
1816
+ if (isObjectLiteralOrClassExpressionMethodOrAccessor(node))
1817
+ setFlowNode(node, this.currentFlowValue());
1818
+ if (hasDynamicName(node))
1819
+ this.bindAnonymousDeclaration(node, symbolFlags, "\uFFFEcomputed" /* InternalSymbolName.Computed */);
1820
+ else
1821
+ this.declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
1822
+ }
1823
+ /** Binds `(…) => T` like `{ (…): T }`: a type literal symbol whose only member is the signature. */
1824
+ bindFunctionOrConstructorType(node) {
1825
+ const symbol = this.newSymbol(131072 /* SymbolFlags.Signature */, this.getDeclarationName(node));
1826
+ this.addDeclarationToSymbol(symbol, node, 131072 /* SymbolFlags.Signature */);
1827
+ const typeLiteralSymbol = this.newSymbol(2048 /* SymbolFlags.TypeLiteral */, "\uFFFEtype" /* InternalSymbolName.Type */);
1828
+ this.addDeclarationToSymbol(typeLiteralSymbol, node, 2048 /* SymbolFlags.TypeLiteral */);
1829
+ getMembers(typeLiteralSymbol).set(symbol.name, symbol);
1830
+ }
1831
+ bindVariableDeclarationOrBindingElement(node) {
1832
+ const name = getName(node);
1833
+ this.checkStrictModeEvalOrArguments(node, name);
1834
+ if (name === undefined ||
1835
+ name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ ||
1836
+ name.kind === 208 /* SyntaxKind.ArrayBindingPattern */)
1837
+ return;
1838
+ if (isVariableDeclarationInitializedToRequire(node))
1839
+ this.declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */);
1840
+ else if (isBlockOrCatchScoped(node))
1841
+ this.bindBlockScopedDeclaration(node, 2 /* SymbolFlags.BlockScopedVariable */, 111551 /* SymbolFlags.BlockScopedVariableExcludes */);
1842
+ else if (isPartOfParameterDeclaration(node))
1843
+ // Parameter excludes report duplicates like `function f([a, a]) {}`.
1844
+ this.declareSymbolAndAddToSymbolTable(node, 1 /* SymbolFlags.FunctionScopedVariable */, 111551 /* SymbolFlags.ParameterExcludes */);
1845
+ else
1846
+ this.declareSymbolAndAddToSymbolTable(node, 1 /* SymbolFlags.FunctionScopedVariable */, 111550 /* SymbolFlags.FunctionScopedVariableExcludes */);
1847
+ }
1848
+ bindParameter(node) {
1849
+ // `eval` and `arguments` can't be parameter names in strict mode.
1850
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
1851
+ this.checkStrictModeEvalOrArguments(node, node.name);
1852
+ const name = node.name;
1853
+ if (name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */) {
1854
+ const index = getParameters(node.parent).nodes.indexOf(node);
1855
+ this.bindAnonymousDeclaration(node, 1 /* SymbolFlags.FunctionScopedVariable */, '__' + index);
1856
+ }
1857
+ else
1858
+ this.declareSymbolAndAddToSymbolTable(node, 1 /* SymbolFlags.FunctionScopedVariable */, 111551 /* SymbolFlags.ParameterExcludes */);
1859
+ // A parameter property also declares a property of the class.
1860
+ if (isParameterPropertyDeclaration(node, node.parent)) {
1861
+ const classSymbol = getSymbol(node.parent.parent);
1862
+ const flags = 4 /* SymbolFlags.Property */ | (node.questionToken !== undefined ? 16777216 /* SymbolFlags.Optional */ : 0 /* SymbolFlags.None */);
1863
+ this.declareSymbol(getMembers(classSymbol), classSymbol, node, flags, 13243 /* SymbolFlags.PropertyExcludes */);
1864
+ }
1865
+ }
1866
+ bindTypeParameter(node) {
1867
+ const parent = node.parent;
1868
+ if (parent.kind !== 196 /* SyntaxKind.InferType */) {
1869
+ this.declareSymbolAndAddToSymbolTable(node, 262144 /* SymbolFlags.TypeParameter */, 526824 /* SymbolFlags.TypeParameterExcludes */);
1870
+ return;
1871
+ }
1872
+ // `infer T` declares T in the conditional type whose extends clause contains it.
1873
+ let container;
1874
+ for (let current = parent; current !== undefined; current = current.parent) {
1875
+ const p = current.parent;
1876
+ if (p !== undefined && p.kind === 195 /* SyntaxKind.ConditionalType */ && getExtendsType(p) === current) {
1877
+ container = p;
1878
+ break;
1879
+ }
1880
+ }
1881
+ if (container !== undefined)
1882
+ this.declareSymbol(this.localsOf(container), undefined, node, 262144 /* SymbolFlags.TypeParameter */, 526824 /* SymbolFlags.TypeParameterExcludes */);
1883
+ else
1884
+ this.bindAnonymousDeclaration(node, 262144 /* SymbolFlags.TypeParameter */, this.getDeclarationName(node));
1885
+ }
1886
+ // JavaScript
1887
+ setCommonJSModuleIndicator(node) {
1888
+ const file = this.file;
1889
+ if (file.externalModuleIndicator !== undefined && file.externalModuleIndicator !== file)
1890
+ return false;
1891
+ if (file.commonJSModuleIndicator === undefined) {
1892
+ file.commonJSModuleIndicator = node;
1893
+ if (file.externalModuleIndicator === undefined)
1894
+ this.bindSourceFileAsExternalModule(file);
1895
+ }
1896
+ return true;
1897
+ }
1898
+ bindModuleExportsAssignment(node) {
1899
+ if (!this.setCommonJSModuleIndicator(node))
1900
+ return;
1901
+ const fileSymbol = this.file.symbol;
1902
+ const flags = expressionIsAlias(node.right) ? 2097152 /* SymbolFlags.Alias */ : 4 /* SymbolFlags.Property */;
1903
+ const symbol = this.declareSymbol(getExports(fileSymbol), fileSymbol, node, flags, 0 /* SymbolFlags.None */);
1904
+ setValueDeclaration(symbol, node);
1905
+ }
1906
+ bindExportsOrObjectDefineProperty(node) {
1907
+ if (!this.setCommonJSModuleIndicator(node))
1908
+ return;
1909
+ const fileSymbol = this.file.symbol;
1910
+ const flags = node instanceof BinaryExpression && expressionIsAlias(node.right)
1911
+ ? 2097152 /* SymbolFlags.Alias */
1912
+ : 1 /* SymbolFlags.FunctionScopedVariable */;
1913
+ this.declareSymbol(getExports(fileSymbol), fileSymbol, node, flags, 111550 /* SymbolFlags.FunctionScopedVariableExcludes */);
1914
+ }
1915
+ bindExpandoPropertyAssignment(node) {
1916
+ this.expandoAssignments.push(new ExpandoAssignment(node, this.container, this.blockScopeContainer));
1917
+ }
1918
+ bindDeferredExpandoAssignments(assignments) {
1919
+ for (const assignment of assignments) {
1920
+ this.container = assignment.container;
1921
+ this.blockScopeContainer = assignment.blockScopeContainer;
1922
+ this.bindDeferredExpandoAssignment(assignment.node);
1923
+ }
1924
+ }
1925
+ bindDeferredExpandoAssignment(node) {
1926
+ const target = node instanceof BinaryExpression
1927
+ ? getExpression(node.left)
1928
+ : getArguments(node).nodes[0];
1929
+ const symbol = getInitializerSymbol(this.lookupEntity(target, this.blockScopeContainer) ?? this.lookupEntity(target, this.container));
1930
+ if (symbol === undefined)
1931
+ return;
1932
+ if (hasDynamicName(node)) {
1933
+ this.bindAnonymousDeclaration(node, 4 /* SymbolFlags.Property */ | 67108864 /* SymbolFlags.Assignment */, "\uFFFEcomputed" /* InternalSymbolName.Computed */);
1934
+ this.addLateBoundAssignmentDeclarationToSymbol(node, symbol);
1935
+ return;
1936
+ }
1937
+ // Expandos are declared only where no other declaration has the name.
1938
+ const exports = getExports(symbol);
1939
+ const existing = exports.get(this.getDeclarationName(node));
1940
+ if (existing === undefined || (existing.flags & 67108864 /* SymbolFlags.Assignment */) !== 0)
1941
+ this.declareSymbol(exports, symbol, node, 4 /* SymbolFlags.Property */ | 67108864 /* SymbolFlags.Assignment */, 13243 /* SymbolFlags.PropertyExcludes */);
1942
+ }
1943
+ addLateBoundAssignmentDeclarationToSymbol(node, symbol) {
1944
+ const exports = getExports(symbol);
1945
+ let assignmentSymbol = exports.get("\uFFFEassignment" /* InternalSymbolName.AssignmentDeclaration */);
1946
+ if (assignmentSymbol === undefined) {
1947
+ assignmentSymbol = this.newSymbol(0 /* SymbolFlags.None */, "\uFFFEassignment" /* InternalSymbolName.AssignmentDeclaration */);
1948
+ exports.set("\uFFFEassignment" /* InternalSymbolName.AssignmentDeclaration */, assignmentSymbol);
1949
+ }
1950
+ addDeclaration(assignmentSymbol, node);
1951
+ }
1952
+ /**
1953
+ * With an `export=` symbol, its module's exports with a type or namespace meaning are also
1954
+ * exports of the `export=` symbol, which makes it a namespace.
1955
+ */
1956
+ bindCommonJSTypeExports(moduleSymbol) {
1957
+ if (moduleSymbol === undefined)
1958
+ return;
1959
+ const moduleExports = moduleSymbol.exports;
1960
+ if (moduleExports === undefined)
1961
+ return;
1962
+ const exportEquals = moduleExports.get("export=" /* InternalSymbolName.ExportEquals */);
1963
+ if (exportEquals === undefined)
1964
+ return;
1965
+ for (const symbol of moduleExports.values()) {
1966
+ if (symbol.name !== "export=" /* InternalSymbolName.ExportEquals */ &&
1967
+ (symbol.flags & (788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */)) !== 0) {
1968
+ getExports(exportEquals).set(symbol.name, symbol);
1969
+ exportEquals.flags |= 1024 /* SymbolFlags.NamespaceModule */;
1970
+ }
1971
+ }
1972
+ }
1973
+ bindThisPropertyAssignment(node) {
1974
+ if (!isInJSFile(node))
1975
+ return;
1976
+ const left = node.left;
1977
+ const thisContainer = this.thisContainer;
1978
+ if ((left instanceof PropertyAccessExpression &&
1979
+ left.name.kind === 80 /* SyntaxKind.PrivateIdentifier */) ||
1980
+ thisContainer === undefined)
1981
+ return;
1982
+ const symbolTable = this.thisSymbolTable();
1983
+ if (symbolTable !== undefined) {
1984
+ const classSymbol = getSymbol(thisContainer.parent);
1985
+ if (hasDynamicName(node)) {
1986
+ this.declareSymbolEx(symbolTable, classSymbol, node, 4 /* SymbolFlags.Property */, 0 /* SymbolFlags.None */, true, true);
1987
+ this.addLateBoundAssignmentDeclarationToSymbol(node, classSymbol);
1988
+ }
1989
+ else
1990
+ this.declareSymbolEx(symbolTable, classSymbol, node, 4 /* SymbolFlags.Property */ | 67108864 /* SymbolFlags.Assignment */, 0 /* SymbolFlags.None */, true, false);
1991
+ }
1992
+ else if (thisContainer.kind !== 263 /* SyntaxKind.FunctionDeclaration */ &&
1993
+ thisContainer.kind !== 219 /* SyntaxKind.FunctionExpression */)
1994
+ throw new Error('Unhandled case in bindThisPropertyAssignment');
1995
+ }
1996
+ /** For `this.x` in a class member, the class's members, or exports if the member is static. */
1997
+ thisSymbolTable() {
1998
+ const thisContainer = this.thisContainer;
1999
+ if (thisContainer === undefined)
2000
+ return undefined;
2001
+ switch (thisContainer.kind) {
2002
+ case 177 /* SyntaxKind.Constructor */:
2003
+ case 173 /* SyntaxKind.PropertyDeclaration */:
2004
+ case 175 /* SyntaxKind.MethodDeclaration */:
2005
+ case 178 /* SyntaxKind.GetAccessor */:
2006
+ case 179 /* SyntaxKind.SetAccessor */:
2007
+ case 176 /* SyntaxKind.ClassStaticBlockDeclaration */: {
2008
+ const classSymbol = getSymbol(thisContainer.parent);
2009
+ return isStatic(thisContainer) ? getExports(classSymbol) : getMembers(classSymbol);
2010
+ }
2011
+ }
2012
+ return undefined;
2013
+ }
2014
+ lookupEntity(node, container) {
2015
+ if (node.kind === 79 /* SyntaxKind.Identifier */)
2016
+ return lookupName(getText(node), container);
2017
+ const expression = getExpression(node);
2018
+ if (expression.kind === 109 /* SyntaxKind.ThisKeyword */) {
2019
+ const symbolTable = this.thisSymbolTable();
2020
+ if (symbolTable === undefined)
2021
+ return undefined;
2022
+ const name = getElementOrPropertyAccessName(node);
2023
+ return name !== undefined ? symbolTable.get(getText(name)) : undefined;
2024
+ }
2025
+ const symbol = getInitializerSymbol(this.lookupEntity(expression, container));
2026
+ if (symbol !== undefined && symbol.exports !== undefined) {
2027
+ const name = getElementOrPropertyAccessName(node);
2028
+ if (name !== undefined)
2029
+ return symbol.exports.get(getText(name));
2030
+ }
2031
+ return undefined;
2032
+ }
2033
+ // Strict mode
2034
+ /** Reports reserved words used as identifiers, and `await`/`yield` where they are keywords. */
2035
+ checkContextualIdentifier(node) {
2036
+ // Only words starting with a, i, l, p, s or y can be future reserved words, await or yield.
2037
+ const text = node.text;
2038
+ const first = text.charCodeAt(0);
2039
+ if (first !== 0x61 && first !== 0x69 && first !== 0x6c && first !== 0x70 && first !== 0x73 && first !== 0x79)
2040
+ return;
2041
+ if (this.file.diagnostics.length !== 0 ||
2042
+ (node.flags & (8388608 /* NodeFlags.Ambient */ | 4194304 /* NodeFlags.JSDoc */)) !== 0 ||
2043
+ isIdentifierName(node))
2044
+ return;
2045
+ const originalKeywordKind = getIdentifierToken(text);
2046
+ if (originalKeywordKind === 79 /* SyntaxKind.Identifier */)
2047
+ return;
2048
+ if (originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ &&
2049
+ originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */)
2050
+ this.errorOnNode(node, this.getStrictModeIdentifierMessage(node), [declarationNameToString(this.file, node)]);
2051
+ else if (originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) {
2052
+ if (isExternalModule(this.file) && isInTopLevelContext(node))
2053
+ this.errorOnNode(node, 211 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module */, [
2054
+ declarationNameToString(this.file, node),
2055
+ ]);
2056
+ else if ((node.flags & 8192 /* NodeFlags.AwaitContext */) !== 0)
2057
+ this.errorOnNode(node, 293 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here */, [
2058
+ declarationNameToString(this.file, node),
2059
+ ]);
2060
+ }
2061
+ else if (originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && (node.flags & 2048 /* NodeFlags.YieldContext */) !== 0)
2062
+ this.errorOnNode(node, 293 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here */, [
2063
+ declarationNameToString(this.file, node),
2064
+ ]);
2065
+ }
2066
+ checkPrivateIdentifier(node) {
2067
+ if (getText(node) === '#constructor' && this.file.diagnostics.length === 0)
2068
+ this.errorOnNode(node, 1834 /* Diagnostics.X_constructor_is_a_reserved_word */, [declarationNameToString(this.file, node)]);
2069
+ }
2070
+ getStrictModeIdentifierMessage(node) {
2071
+ if (getContainingClass(node) !== undefined)
2072
+ return 166 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode */;
2073
+ if (this.file.externalModuleIndicator !== undefined)
2074
+ return 167 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode */;
2075
+ return 165 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode */;
2076
+ }
2077
+ checkStrictModeFunctionName(node) {
2078
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
2079
+ this.checkStrictModeEvalOrArguments(node, getName(node));
2080
+ }
2081
+ checkStrictModeBinaryExpression(node) {
2082
+ // `eval` and `arguments` can't be assigned to.
2083
+ if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind))
2084
+ this.checkStrictModeEvalOrArguments(node, node.left);
2085
+ }
2086
+ checkStrictModeCatchClause(node) {
2087
+ const declaration = node.variableDeclaration;
2088
+ if (declaration !== undefined)
2089
+ this.checkStrictModeEvalOrArguments(node, declaration.name);
2090
+ }
2091
+ checkStrictModeDeleteExpression(node) {
2092
+ // Deleting a variable, parameter or function name is an error in strict mode.
2093
+ if (node.expression.kind === 79 /* SyntaxKind.Identifier */)
2094
+ this.errorOnNode(node.expression, 71 /* Diagnostics.X_delete_cannot_be_called_on_an_identifier_in_strict_mode */, noArgs);
2095
+ }
2096
+ checkStrictModeEvalOrArguments(contextNode, name) {
2097
+ if (name === undefined || name.kind !== 79 /* SyntaxKind.Identifier */)
2098
+ return;
2099
+ const text = getText(name);
2100
+ if (text !== 'eval' && text !== 'arguments')
2101
+ return;
2102
+ let message;
2103
+ if (getContainingClass(contextNode) !== undefined)
2104
+ message =
2105
+ 163 /* Diagnostics.Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode */;
2106
+ else if (this.file.externalModuleIndicator !== undefined)
2107
+ message = 168 /* Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode */;
2108
+ else
2109
+ message = 69 /* Diagnostics.Invalid_use_of_0_in_strict_mode */;
2110
+ this.errorOnNode(name, message, [text]);
2111
+ }
2112
+ }
2113
+ const noArgs = [];
2114
+ function optionalSymbolFlag(node) {
2115
+ const postfixToken = getPostfixToken(node);
2116
+ return postfixToken !== undefined && postfixToken.kind === 57 /* SyntaxKind.QuestionToken */
2117
+ ? 16777216 /* SymbolFlags.Optional */
2118
+ : 0 /* SymbolFlags.None */;
2119
+ }
2120
+ function getExtendsType(node) {
2121
+ return node instanceof ConditionalTypeNode ? node.extendsType : undefined;
2122
+ }
2123
+ function isGeneratorFunctionExpression(node) {
2124
+ return node instanceof FunctionExpression && node.asteriskToken !== undefined;
2125
+ }
2126
+ function isForInOrOfStatementKind(kind) {
2127
+ return kind === 250 /* SyntaxKind.ForInStatement */ || kind === 251 /* SyntaxKind.ForOfStatement */;
2128
+ }
2129
+ function hasExportDeclarations(node) {
2130
+ let statements;
2131
+ if (node.kind === 307 /* SyntaxKind.SourceFile */)
2132
+ statements = node.statements;
2133
+ else if (node instanceof ModuleDeclaration) {
2134
+ const body = node.body;
2135
+ if (body !== undefined && body.kind === 269 /* SyntaxKind.ModuleBlock */)
2136
+ statements = getStatements(body);
2137
+ }
2138
+ if (statements === undefined)
2139
+ return false;
2140
+ for (const statement of statements.nodes)
2141
+ if (statement.kind === 279 /* SyntaxKind.ExportDeclaration */ || statement.kind === 278 /* SyntaxKind.ExportAssignment */)
2142
+ return true;
2143
+ return false;
2144
+ }
2145
+ /** The symbol in `container`'s locals or its symbol's exports, preferring a local's export symbol. */
2146
+ function lookupName(name, container) {
2147
+ if (isLocalsContainer(container)) {
2148
+ const locals = getLocals(container);
2149
+ const local = locals !== undefined ? locals.get(name) : undefined;
2150
+ if (local !== undefined)
2151
+ return local.exportSymbol ?? local;
2152
+ }
2153
+ if (isDeclarationNode(container)) {
2154
+ const symbol = getSymbol(container);
2155
+ if (symbol !== undefined && symbol.exports !== undefined)
2156
+ return symbol.exports.get(name);
2157
+ }
2158
+ return undefined;
2159
+ }
2160
+ /**
2161
+ * For `fn.x = …`: the symbol that gets expando properties when `fn` is a function, a const
2162
+ * (or JavaScript) variable initialized with a function or class, or a JavaScript class.
2163
+ */
2164
+ function getInitializerSymbol(symbol) {
2165
+ if (symbol === undefined)
2166
+ return undefined;
2167
+ const declaration = symbol.valueDeclaration;
2168
+ if (declaration === undefined)
2169
+ return undefined;
2170
+ if (declaration.kind === 263 /* SyntaxKind.FunctionDeclaration */ ||
2171
+ (isInJSFile(declaration) && declaration.kind === 264 /* SyntaxKind.ClassDeclaration */))
2172
+ return symbol;
2173
+ if (declaration instanceof VariableDeclaration) {
2174
+ if ((declaration.parent.flags & 2 /* NodeFlags.Const */) !== 0 || isInJSFile(declaration)) {
2175
+ const initializer = declaration.initializer;
2176
+ if (isExpandoInitializer(declaration, initializer))
2177
+ return getSymbol(initializer);
2178
+ }
2179
+ return undefined;
2180
+ }
2181
+ if (declaration instanceof BinaryExpression && isInJSFile(declaration)) {
2182
+ const initializer = declaration.right;
2183
+ if (isExpandoInitializer(declaration, initializer))
2184
+ return getSymbol(initializer);
2185
+ }
2186
+ return undefined;
2187
+ }
2188
+ function setFlowNodeReferenced(flow) {
2189
+ // Referenced on first use, Shared after that.
2190
+ flow.flags |= (flow.flags & 2048 /* FlowFlags.Referenced */) === 0 ? 2048 /* FlowFlags.Referenced */ : 4096 /* FlowFlags.Shared */;
2191
+ }
2192
+ function combineFlowLists(head, tail) {
2193
+ if (head === undefined)
2194
+ return tail;
2195
+ return tail === undefined ? head.slice() : head.concat(tail);
2196
+ }
2197
+ function isStatementCondition(node) {
2198
+ const parent = node.parent;
2199
+ switch (parent.kind) {
2200
+ case 246 /* SyntaxKind.IfStatement */:
2201
+ case 248 /* SyntaxKind.WhileStatement */:
2202
+ case 247 /* SyntaxKind.DoStatement */:
2203
+ return getExpression(parent) === node;
2204
+ case 249 /* SyntaxKind.ForStatement */:
2205
+ return parent.condition === node;
2206
+ case 228 /* SyntaxKind.ConditionalExpression */:
2207
+ return parent.condition === node;
2208
+ }
2209
+ return false;
2210
+ }
2211
+ function isTopLevelLogicalExpression(node) {
2212
+ let current = node;
2213
+ for (;;) {
2214
+ const parent = current.parent;
2215
+ if (parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */ ||
2216
+ (parent instanceof PrefixUnaryExpression &&
2217
+ parent.operator === 53 /* SyntaxKind.ExclamationToken */))
2218
+ current = parent;
2219
+ else
2220
+ break;
2221
+ }
2222
+ const parent = current.parent;
2223
+ return (!isStatementCondition(current) &&
2224
+ !isLogicalExpression(parent) &&
2225
+ !(isOptionalChain(parent) && getExpression(parent) === current));
2226
+ }
2227
+ // Narrowing
2228
+ function isNarrowingExpression(expression) {
2229
+ switch (expression.kind) {
2230
+ case 79 /* SyntaxKind.Identifier */:
2231
+ case 109 /* SyntaxKind.ThisKeyword */:
2232
+ return true;
2233
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
2234
+ case 213 /* SyntaxKind.ElementAccessExpression */:
2235
+ return containsNarrowableReference(expression);
2236
+ case 214 /* SyntaxKind.CallExpression */:
2237
+ return hasNarrowableArgument(expression);
2238
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
2239
+ case 236 /* SyntaxKind.NonNullExpression */:
2240
+ case 222 /* SyntaxKind.TypeOfExpression */:
2241
+ return isNarrowingExpression(getExpression(expression));
2242
+ case 227 /* SyntaxKind.BinaryExpression */:
2243
+ return isNarrowingBinaryExpression(expression);
2244
+ case 225 /* SyntaxKind.PrefixUnaryExpression */: {
2245
+ const unary = expression;
2246
+ return unary.operator === 53 /* SyntaxKind.ExclamationToken */ && isNarrowingExpression(unary.operand);
2247
+ }
2248
+ }
2249
+ return false;
2250
+ }
2251
+ function containsNarrowableReference(expression) {
2252
+ if (isNarrowableReference(expression))
2253
+ return true;
2254
+ if ((expression.flags & 32 /* NodeFlags.OptionalChain */) !== 0) {
2255
+ switch (expression.kind) {
2256
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
2257
+ case 213 /* SyntaxKind.ElementAccessExpression */:
2258
+ case 214 /* SyntaxKind.CallExpression */:
2259
+ case 236 /* SyntaxKind.NonNullExpression */:
2260
+ return containsNarrowableReference(getExpression(expression));
2261
+ }
2262
+ }
2263
+ return false;
2264
+ }
2265
+ /** A reference whose type control flow analysis can narrow. */
2266
+ export function isNarrowableReference(node) {
2267
+ switch (node.kind) {
2268
+ case 79 /* SyntaxKind.Identifier */:
2269
+ case 109 /* SyntaxKind.ThisKeyword */:
2270
+ case 107 /* SyntaxKind.SuperKeyword */:
2271
+ case 237 /* SyntaxKind.MetaProperty */:
2272
+ return true;
2273
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
2274
+ return isNarrowableReference(node.expression);
2275
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
2276
+ return isNarrowableReference(node.expression);
2277
+ case 236 /* SyntaxKind.NonNullExpression */:
2278
+ return isNarrowableReference(node.expression);
2279
+ case 213 /* SyntaxKind.ElementAccessExpression */: {
2280
+ const access = node;
2281
+ return (isStringOrNumericLiteralLike(access.argumentExpression) ||
2282
+ (isEntityNameExpression(access.argumentExpression, false) && isNarrowableReference(access.expression)));
2283
+ }
2284
+ case 227 /* SyntaxKind.BinaryExpression */: {
2285
+ const binary = node;
2286
+ const operator = binary.operatorToken.kind;
2287
+ return ((operator === 27 /* SyntaxKind.CommaToken */ && isNarrowableReference(binary.right)) ||
2288
+ (isAssignmentOperator(operator) && isLeftHandSideExpression(binary.left)));
2289
+ }
2290
+ }
2291
+ return false;
2292
+ }
2293
+ function hasNarrowableArgument(call) {
2294
+ for (const argument of call.arguments.nodes)
2295
+ if (containsNarrowableReference(argument))
2296
+ return true;
2297
+ const callee = call.expression;
2298
+ return (callee instanceof PropertyAccessExpression &&
2299
+ containsNarrowableReference(callee.expression));
2300
+ }
2301
+ function isNarrowingBinaryExpression(expression) {
2302
+ switch (expression.operatorToken.kind) {
2303
+ case 63 /* SyntaxKind.EqualsToken */:
2304
+ case 75 /* SyntaxKind.BarBarEqualsToken */:
2305
+ case 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */:
2306
+ case 77 /* SyntaxKind.QuestionQuestionEqualsToken */:
2307
+ return containsNarrowableReference(expression.left);
2308
+ case 34 /* SyntaxKind.EqualsEqualsToken */:
2309
+ case 35 /* SyntaxKind.ExclamationEqualsToken */:
2310
+ case 36 /* SyntaxKind.EqualsEqualsEqualsToken */:
2311
+ case 37 /* SyntaxKind.ExclamationEqualsEqualsToken */: {
2312
+ const left = skipParentheses(expression.left);
2313
+ const right = skipParentheses(expression.right);
2314
+ return (isNarrowableOperand(left) ||
2315
+ isNarrowableOperand(right) ||
2316
+ isNarrowingTypeOfOperands(right, left) ||
2317
+ isNarrowingTypeOfOperands(left, right) ||
2318
+ (isBooleanLiteral(right) && isNarrowingExpression(left)) ||
2319
+ (isBooleanLiteral(left) && isNarrowingExpression(right)));
2320
+ }
2321
+ case 103 /* SyntaxKind.InstanceOfKeyword */:
2322
+ return isNarrowableOperand(expression.left);
2323
+ case 102 /* SyntaxKind.InKeyword */:
2324
+ case 27 /* SyntaxKind.CommaToken */:
2325
+ return isNarrowingExpression(expression.right);
2326
+ }
2327
+ return false;
2328
+ }
2329
+ function isNarrowableOperand(expression) {
2330
+ if (expression.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
2331
+ return isNarrowableOperand(getExpression(expression));
2332
+ if (expression instanceof BinaryExpression) {
2333
+ const binary = expression;
2334
+ const operator = binary.operatorToken.kind;
2335
+ if (operator === 63 /* SyntaxKind.EqualsToken */)
2336
+ return isNarrowableOperand(binary.left);
2337
+ if (operator === 27 /* SyntaxKind.CommaToken */)
2338
+ return isNarrowableOperand(binary.right);
2339
+ }
2340
+ return containsNarrowableReference(expression);
2341
+ }
2342
+ function isNarrowingTypeOfOperands(expression1, expression2) {
2343
+ return (expression1.kind === 222 /* SyntaxKind.TypeOfExpression */ &&
2344
+ isNarrowableOperand(getExpression(expression1)) &&
2345
+ isStringLiteralLike(expression2));
2346
+ }
2347
+ /** The `"use strict"` prologue directive of `statements`, if any. */
2348
+ export function findUseStrictPrologue(file, statements) {
2349
+ for (const statement of statements) {
2350
+ if (!isPrologueDirective(statement))
2351
+ return undefined;
2352
+ // Exactly `"use strict"` or `'use strict'`, without escapes.
2353
+ const text = getSourceTextOfNode(file, statement.expression);
2354
+ if (text === '"use strict"' || text === "'use strict'")
2355
+ return statement;
2356
+ }
2357
+ return undefined;
2358
+ }