tsc-ts 0.0.4 → 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 (584) hide show
  1. package/README.md +33 -1
  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 +3 -2
  357. package/dist/api/library/ast.generated.d.ts +127 -139
  358. package/dist/api/library/checker.d.ts +51 -0
  359. package/dist/api/library/checker.js +318 -0
  360. package/dist/api/library/diagnostics.d.ts +13 -0
  361. package/dist/api/library/diagnostics.js +50 -0
  362. package/dist/api/library/disk.d.ts +13 -0
  363. package/dist/api/library/disk.js +66 -0
  364. package/dist/api/library/errors.d.ts +13 -0
  365. package/dist/api/library/errors.js +24 -0
  366. package/dist/api/library/host.d.ts +24 -0
  367. package/dist/api/library/host.js +52 -0
  368. package/dist/api/library/index.d.ts +5 -1
  369. package/dist/api/library/index.js +4 -0
  370. package/dist/api/library/nodes.d.ts +51 -0
  371. package/dist/api/library/nodes.js +196 -0
  372. package/dist/api/library/options.d.ts +144 -0
  373. package/dist/api/library/options.js +308 -0
  374. package/dist/api/library/parse.d.ts +19 -0
  375. package/dist/api/library/parse.js +41 -0
  376. package/dist/api/library/program.d.ts +21 -0
  377. package/dist/api/library/program.js +234 -0
  378. package/dist/api/library/types.d.ts +14 -1
  379. package/package.json +12 -8
  380. package/src/compiler/ast-utilities.ts +548 -0
  381. package/src/compiler/ast.ts +12862 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2703 -0
  385. package/src/compiler/build-info.ts +1197 -0
  386. package/src/compiler/character-codes.ts +323 -0
  387. package/src/compiler/checker-calls.ts +2155 -0
  388. package/src/compiler/checker-classes.ts +706 -0
  389. package/src/compiler/checker-contextual.ts +1457 -0
  390. package/src/compiler/checker-declaration-order.ts +438 -0
  391. package/src/compiler/checker-declarations.ts +1194 -0
  392. package/src/compiler/checker-declared-types.ts +919 -0
  393. package/src/compiler/checker-decorators.ts +694 -0
  394. package/src/compiler/checker-deprecation.ts +359 -0
  395. package/src/compiler/checker-destructuring.ts +805 -0
  396. package/src/compiler/checker-elaboration.ts +477 -0
  397. package/src/compiler/checker-emit-helpers.ts +224 -0
  398. package/src/compiler/checker-emit-resolver.ts +769 -0
  399. package/src/compiler/checker-evaluator.ts +243 -0
  400. package/src/compiler/checker-expressions.ts +1831 -0
  401. package/src/compiler/checker-features.ts +361 -0
  402. package/src/compiler/checker-flow.ts +394 -0
  403. package/src/compiler/checker-functions.ts +1296 -0
  404. package/src/compiler/checker-generated-code.ts +227 -0
  405. package/src/compiler/checker-globals.ts +52 -0
  406. package/src/compiler/checker-grammar.ts +3584 -0
  407. package/src/compiler/checker-heritage.ts +1233 -0
  408. package/src/compiler/checker-inference.ts +2576 -0
  409. package/src/compiler/checker-iteration.ts +1206 -0
  410. package/src/compiler/checker-javascript.ts +502 -0
  411. package/src/compiler/checker-jsdoc.ts +360 -0
  412. package/src/compiler/checker-jsx.ts +1924 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2436 -0
  415. package/src/compiler/checker-modules.ts +2886 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +575 -0
  418. package/src/compiler/checker-operators.ts +1422 -0
  419. package/src/compiler/checker-overloads.ts +328 -0
  420. package/src/compiler/checker-property-access.ts +906 -0
  421. package/src/compiler/checker-services.ts +1149 -0
  422. package/src/compiler/checker-signatures.ts +1032 -0
  423. package/src/compiler/checker-source-file.ts +732 -0
  424. package/src/compiler/checker-statements.ts +292 -0
  425. package/src/compiler/checker-super.ts +261 -0
  426. package/src/compiler/checker-symbol-types.ts +2107 -0
  427. package/src/compiler/checker-symbols.ts +2150 -0
  428. package/src/compiler/checker-type-factory.ts +2579 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2502 -0
  431. package/src/compiler/checker-types.ts +2340 -0
  432. package/src/compiler/checker-unused.ts +642 -0
  433. package/src/compiler/checker-utilities.ts +161 -0
  434. package/src/compiler/checker.ts +1116 -0
  435. package/src/compiler/command-line.ts +436 -0
  436. package/src/compiler/compile-program.ts +439 -0
  437. package/src/compiler/decoder.ts +1209 -0
  438. package/src/compiler/diagnostic-locales.ts +86 -0
  439. package/src/compiler/diagnostic-messages.ts +2349 -0
  440. package/src/compiler/diagnostics.ts +897 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +673 -0
  444. package/src/compiler/file-loader.ts +1528 -0
  445. package/src/compiler/file-system.ts +143 -0
  446. package/src/compiler/flow.ts +89 -0
  447. package/src/compiler/help.ts +473 -0
  448. package/src/compiler/incremental.ts +2784 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +894 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +98 -0
  453. package/src/compiler/locale-data.ts +203 -0
  454. package/src/compiler/locale.ts +307 -0
  455. package/src/compiler/locales/cs-CZ.ts +5 -0
  456. package/src/compiler/locales/de-DE.ts +5 -0
  457. package/src/compiler/locales/es-ES.ts +5 -0
  458. package/src/compiler/locales/fr-FR.ts +5 -0
  459. package/src/compiler/locales/it-IT.ts +5 -0
  460. package/src/compiler/locales/ja-JP.ts +5 -0
  461. package/src/compiler/locales/ko-KR.ts +5 -0
  462. package/src/compiler/locales/pl-PL.ts +5 -0
  463. package/src/compiler/locales/pt-BR.ts +5 -0
  464. package/src/compiler/locales/ru-RU.ts +5 -0
  465. package/src/compiler/locales/tr-TR.ts +5 -0
  466. package/src/compiler/locales/zh-CN.ts +5 -0
  467. package/src/compiler/locales/zh-TW.ts +5 -0
  468. package/src/compiler/module-resolution-types.ts +243 -0
  469. package/src/compiler/module-resolution.ts +2072 -0
  470. package/src/compiler/module-specifiers.ts +1491 -0
  471. package/src/compiler/name-resolver.ts +646 -0
  472. package/src/compiler/node-builder-names.ts +1069 -0
  473. package/src/compiler/node-builder-pseudo.ts +892 -0
  474. package/src/compiler/node-builder-reuse.ts +764 -0
  475. package/src/compiler/node-builder.ts +3425 -0
  476. package/src/compiler/option-declarations.ts +1560 -0
  477. package/src/compiler/options.ts +1576 -0
  478. package/src/compiler/output-paths.ts +334 -0
  479. package/src/compiler/package-json.ts +1083 -0
  480. package/src/compiler/parallel-check.ts +1951 -0
  481. package/src/compiler/parallel-parse.ts +590 -0
  482. package/src/compiler/parse-thread.ts +140 -0
  483. package/src/compiler/parser.ts +7716 -0
  484. package/src/compiler/path.ts +717 -0
  485. package/src/compiler/printer/async-helpers.ts +183 -0
  486. package/src/compiler/printer/auto-generate.ts +27 -0
  487. package/src/compiler/printer/decorator-helpers.ts +218 -0
  488. package/src/compiler/printer/emit-context.ts +679 -0
  489. package/src/compiler/printer/emit-flags.ts +64 -0
  490. package/src/compiler/printer/factory-base.ts +2577 -0
  491. package/src/compiler/printer/factory.ts +764 -0
  492. package/src/compiler/printer/helpers.ts +291 -0
  493. package/src/compiler/printer/name-generator.ts +372 -0
  494. package/src/compiler/printer/printer.ts +5072 -0
  495. package/src/compiler/printer/text-writer.ts +183 -0
  496. package/src/compiler/printer/utilities.ts +884 -0
  497. package/src/compiler/program-checker.ts +592 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1419 -0
  500. package/src/compiler/pseudo-bigint.ts +62 -0
  501. package/src/compiler/regexp-checker.ts +1142 -0
  502. package/src/compiler/relations.ts +5149 -0
  503. package/src/compiler/reparser.ts +1566 -0
  504. package/src/compiler/scanner.ts +2951 -0
  505. package/src/compiler/show-config.ts +239 -0
  506. package/src/compiler/side-state.ts +125 -0
  507. package/src/compiler/sourcemap.ts +366 -0
  508. package/src/compiler/spelling.ts +122 -0
  509. package/src/compiler/symbol-accessibility.ts +1071 -0
  510. package/src/compiler/symbol.ts +439 -0
  511. package/src/compiler/symlinks.ts +137 -0
  512. package/src/compiler/syntax-kind.ts +391 -0
  513. package/src/compiler/thread-entry.ts +191 -0
  514. package/src/compiler/timeline.ts +53 -0
  515. package/src/compiler/transformers/alias-references.ts +757 -0
  516. package/src/compiler/transformers/async-utilities.ts +335 -0
  517. package/src/compiler/transformers/async.ts +838 -0
  518. package/src/compiler/transformers/class-fields.ts +2967 -0
  519. package/src/compiler/transformers/class-utilities.ts +324 -0
  520. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  521. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  522. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  526. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  527. package/src/compiler/transformers/declarations.ts +3120 -0
  528. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  529. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  530. package/src/compiler/transformers/destructuring.ts +708 -0
  531. package/src/compiler/transformers/downlevel.ts +50 -0
  532. package/src/compiler/transformers/emit-resolver.ts +258 -0
  533. package/src/compiler/transformers/es-decorators.ts +2682 -0
  534. package/src/compiler/transformers/exponentiation.ts +80 -0
  535. package/src/compiler/transformers/external-module-info.ts +412 -0
  536. package/src/compiler/transformers/for-await.ts +687 -0
  537. package/src/compiler/transformers/import-elision.ts +152 -0
  538. package/src/compiler/transformers/jsx-entities.ts +256 -0
  539. package/src/compiler/transformers/jsx.ts +824 -0
  540. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  541. package/src/compiler/transformers/logical-assignment.ts +75 -0
  542. package/src/compiler/transformers/module-utilities.ts +42 -0
  543. package/src/compiler/transformers/module.ts +474 -0
  544. package/src/compiler/transformers/named-evaluation.ts +389 -0
  545. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  546. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  547. package/src/compiler/transformers/optional-catch.ts +29 -0
  548. package/src/compiler/transformers/optional-chain.ts +246 -0
  549. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +245 -0
  552. package/src/compiler/transformers/syntax-facts.ts +353 -0
  553. package/src/compiler/transformers/tagged-template.ts +167 -0
  554. package/src/compiler/transformers/transformer.ts +56 -0
  555. package/src/compiler/transformers/type-eraser.ts +520 -0
  556. package/src/compiler/transformers/type-serialization.ts +374 -0
  557. package/src/compiler/transformers/using.ts +613 -0
  558. package/src/compiler/transformers/utilities.ts +419 -0
  559. package/src/compiler/transformers/visitor-base.ts +1601 -0
  560. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  561. package/src/compiler/tsc-build.ts +1418 -0
  562. package/src/compiler/tsc-cli.ts +666 -0
  563. package/src/compiler/tsc-compile.ts +437 -0
  564. package/src/compiler/tsc-watch.ts +854 -0
  565. package/src/compiler/tsconfig.ts +1574 -0
  566. package/src/compiler/type-printer.ts +110 -0
  567. package/src/compiler/types.ts +115 -0
  568. package/src/compiler/unicode-identifiers.ts +212 -0
  569. package/src/compiler/unicode-properties.ts +537 -0
  570. package/src/compiler/vfs-match.ts +597 -0
  571. package/src/compiler/xxh3.ts +650 -0
  572. package/src/library/ast.generated.ts +141 -167
  573. package/src/library/ast.ts +4 -1
  574. package/src/library/checker.ts +384 -0
  575. package/src/library/diagnostics.ts +72 -0
  576. package/src/library/disk.ts +73 -0
  577. package/src/library/errors.ts +26 -0
  578. package/src/library/host.ts +63 -0
  579. package/src/library/index.ts +21 -0
  580. package/src/library/nodes.ts +232 -0
  581. package/src/library/options.ts +449 -0
  582. package/src/library/parse.ts +63 -0
  583. package/src/library/program.ts +293 -0
  584. package/src/library/types.ts +14 -1
@@ -0,0 +1,2573 @@
1
+ // Grammar checks: errors for syntax the parser accepts but the language disallows.
2
+ //
3
+ // `checkGrammarSourceFile` walks a file once after it is type checked and runs the grammar checks
4
+ // of each node in the order tsgo's checker runs them. Checks that need types read the checker's
5
+ // caches. Errors reported with `grammarError*` are dropped when the file has parse errors.
6
+ import { ElementAccessExpression, Identifier, NodeVisitor, StringLiteral, getAsteriskToken, getBody, getElements, getExpression, getHeritageClauses, getInitializer, getLabel, getIsTypeOnly, getLocals, getMembers, getModifiers, getName, getNodeId, getParameters, getPostfixToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, isDeclarationNode, } from './ast.js';
7
+ import { canHaveDecorators, canHaveIllegalDecorators, getExternalModuleName, getTextOfNodeFromSourceText, isAmbientModule, isFunctionLike, isFunctionLikeDeclarationKind, isModifierKind, isStringLiteralLike, modifierToFlag, nodeIsPresent, isInJSFile, } from './ast-utilities.js';
8
+ import { getCombinedModifierFlags, getCombinedNodeFlags, getContainingClass, getRangeOfTokenAtPosition, getSourceFileOfNode, hasSyntacticModifier, isAutoAccessorPropertyDeclaration, isClassLike, isDynamicName, isEntityNameExpression, isExternalModule, isInTopLevelContext, isModuleAugmentationExternal, isPrivateIdentifierClassElementDeclaration, isStatic, skipParentheses, } from './binder-utilities.js';
9
+ import { findUseStrictPrologue } from './binder.js';
10
+ import { createDiagnosticForNode } from './checker.js';
11
+ import { checkComputedPropertyName, checkExpressionCached, getTypeOfExpression } from './checker-expressions.js';
12
+ import { isArrayLikeType } from './checker-members.js';
13
+ import { getNullableType } from './checker-symbol-types.js';
14
+ import { getTupleElementFlags, getTypeFromTypeNode } from './checker-type-nodes.js';
15
+ import { isArrayType, isTupleType, tupleTargetOf } from './checker-type-factory.js';
16
+ import { isGenericType } from './checker-type-operators.js';
17
+ import { getPropertyNameFromType, isTypeUsableAsPropertyName, isValidIndexKeyType } from './checker-utilities.js';
18
+ import { getSymbolOfDeclaration, resolveAlias } from './checker-symbols.js';
19
+ import { Diagnostic, messageCategory } from './diagnostics.js';
20
+ import { ModuleKind, ScriptTarget, getEmitModuleKind } from './options.js';
21
+ import { fileExtensionIsOneOf, isExternalModuleNameRelative } from './path.js';
22
+ import { SourceFileMetadata, getEmitModuleFormatOfFile, getImpliedNodeFormatForEmit } from './program-utilities.js';
23
+ import { Scanner, ScannerErrorReporter, computeLineOfPosition, skipTrivia, tokenToString } from './scanner.js';
24
+ import { typeToString } from './type-printer.js';
25
+ import { findMismatchedAugmentsTag } from './checker-jsdoc.js';
26
+ /** Runs the grammar checks of every node of `file`. */
27
+ export function checkGrammarSourceFile(c, file) {
28
+ const g = new GrammarChecker(c, file);
29
+ if ((file.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
30
+ checkGrammarTopLevelElementsForRequiredDeclareModifier(g, file);
31
+ file.forEachChild(g);
32
+ }
33
+ /** The grammar checker of the file of `node`, for grammar checks run while checking expressions. */
34
+ function grammarCheckerOf(c, node) {
35
+ const file = getSourceFileOfNode(node);
36
+ const cached = c.grammarChecker;
37
+ if (cached !== undefined && cached.file === file)
38
+ return cached;
39
+ const g = new GrammarChecker(c, file);
40
+ c.grammarChecker = g;
41
+ return g;
42
+ }
43
+ /** Checks the grammar of an object literal each time it is checked, as tsgo does. */
44
+ export function checkGrammarObjectLiteralOfExpression(c, node, inDestructuring) {
45
+ checkGrammarObjectLiteralExpression(grammarCheckerOf(c, node), node, inDestructuring);
46
+ }
47
+ /** Reports a trailing comma after the rest element of a destructuring assignment. */
48
+ export function checkGrammarRestTrailingComma(c, node, list) {
49
+ checkGrammarForDisallowedTrailingComma(grammarCheckerOf(c, node), list, 9 /* Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma */);
50
+ }
51
+ /** Checks the grammar of a function expression or arrow function each time it is checked. */
52
+ export function checkGrammarFunctionExpression(c, node) {
53
+ const g = grammarCheckerOf(c, node);
54
+ if (!checkGrammarFunctionLikeDeclaration(g, node) && node.kind === 219 /* SyntaxKind.FunctionExpression */)
55
+ checkGrammarForGenerator(g, node);
56
+ }
57
+ /** Checks the grammar of an `await` expression each time it is checked. */
58
+ export function checkGrammarAwaitExpression(c, node) {
59
+ checkGrammarAwaitOrAwaitUsing(grammarCheckerOf(c, node), node);
60
+ }
61
+ /** Checks the grammar of a `yield` expression each time it is checked. */
62
+ export function checkGrammarYieldOfExpression(c, node) {
63
+ checkGrammarYieldExpression(grammarCheckerOf(c, node), node);
64
+ }
65
+ /** Per-file state of the grammar walk. */
66
+ export class GrammarChecker extends NodeVisitor {
67
+ c;
68
+ file;
69
+ /** Grammar errors are only reported in files without parse errors. */
70
+ hasParseErrors;
71
+ moduleKind;
72
+ metadata;
73
+ legacyDecorators;
74
+ /** Blocks and statements that already reported a statement in an ambient context. */
75
+ reportedAmbientStatements = new Set();
76
+ scanner = undefined;
77
+ constructor(c, file) {
78
+ super();
79
+ this.c = c;
80
+ this.file = file;
81
+ this.hasParseErrors = file.diagnostics.length > 0;
82
+ this.moduleKind = getEmitModuleKind(c.compilerOptions);
83
+ this.metadata = c.host.getSourceFileMetadata(file) ?? new SourceFileMetadata('', '', ModuleKind.None);
84
+ this.legacyDecorators = c.compilerOptions.experimentalDecorators === true;
85
+ }
86
+ visitNode(node) {
87
+ if (checkGrammarNode(this, node))
88
+ node.forEachChild(this);
89
+ return false;
90
+ }
91
+ /** A scanner over the file's text, for rescanning tokens. */
92
+ getScanner() {
93
+ let scanner = this.scanner;
94
+ if (scanner === undefined) {
95
+ scanner = new Scanner(this.file.text);
96
+ scanner.setLanguageVariant(this.file.languageVariant);
97
+ // The scanner's target enum has the same values as the option's.
98
+ scanner.setScriptTarget(this.c.languageVersion);
99
+ this.scanner = scanner;
100
+ }
101
+ return scanner;
102
+ }
103
+ }
104
+ // ---- Reporting
105
+ function grammarErrorOnNode(g, node, message, ...args) {
106
+ if (g.hasParseErrors)
107
+ return false;
108
+ g.c.error(node, message, ...args);
109
+ return true;
110
+ }
111
+ function grammarErrorOnFirstToken(g, node, message, ...args) {
112
+ if (g.hasParseErrors)
113
+ return false;
114
+ const range = getRangeOfTokenAtPosition(g.file, node.pos);
115
+ g.c.addDiagnostic(new Diagnostic(g.file.diagnosticFile(), range.pos, range.end, message, args));
116
+ return true;
117
+ }
118
+ function grammarErrorAtPos(g, start, length, message, ...args) {
119
+ if (g.hasParseErrors)
120
+ return false;
121
+ g.c.addDiagnostic(new Diagnostic(g.file.diagnosticFile(), start, start + length, message, args));
122
+ return true;
123
+ }
124
+ /** A diagnostic at the first token of `node`. */
125
+ function diagnosticAtFirstToken(g, node, message) {
126
+ const range = getRangeOfTokenAtPosition(g.file, node.pos);
127
+ return new Diagnostic(g.file.diagnosticFile(), range.pos, range.end, message);
128
+ }
129
+ function addRelated(diagnostic, node, message) {
130
+ diagnostic.relatedInformation.push(createDiagnosticForNode(node, message, []));
131
+ }
132
+ // ---- Dispatch
133
+ /** Runs the grammar checks of `node`; returns whether its children are checked too. */
134
+ function checkGrammarNode(g, node) {
135
+ switch (node.kind) {
136
+ // Declarations and members
137
+ case 169 /* SyntaxKind.TypeParameter */: {
138
+ checkGrammarModifiers(g, node);
139
+ const expression = node.expression;
140
+ if (expression !== undefined)
141
+ grammarErrorOnFirstToken(g, expression, 79 /* Diagnostics.Type_expected */);
142
+ return true;
143
+ }
144
+ case 170 /* SyntaxKind.Parameter */:
145
+ checkGrammarModifiers(g, node);
146
+ checkGrammarDecorators(g, node);
147
+ return true;
148
+ case 172 /* SyntaxKind.PropertySignature */:
149
+ checkGrammarPropertyDeclaration(g, node);
150
+ return true;
151
+ case 173 /* SyntaxKind.PropertyDeclaration */:
152
+ checkGrammarPropertyDeclaration(g, node);
153
+ checkGrammarDecorators(g, node);
154
+ return true;
155
+ case 186 /* SyntaxKind.ConstructorType */:
156
+ case 185 /* SyntaxKind.FunctionType */:
157
+ case 180 /* SyntaxKind.CallSignature */:
158
+ case 181 /* SyntaxKind.ConstructSignature */:
159
+ checkGrammarFunctionLikeDeclaration(g, node);
160
+ return true;
161
+ case 182 /* SyntaxKind.IndexSignature */:
162
+ if (!checkGrammarModifiers(g, node))
163
+ checkGrammarIndexSignatureParameters(g, node);
164
+ return true;
165
+ case 175 /* SyntaxKind.MethodDeclaration */:
166
+ case 174 /* SyntaxKind.MethodSignature */:
167
+ checkGrammarMethodDeclaration(g, node);
168
+ return true;
169
+ case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
170
+ checkGrammarModifiers(g, node);
171
+ return true;
172
+ case 177 /* SyntaxKind.Constructor */:
173
+ checkGrammarFunctionLikeDeclaration(g, node);
174
+ if (!checkGrammarConstructorTypeParameters(g, node)) {
175
+ const type = node.type;
176
+ if (type !== undefined)
177
+ grammarErrorOnNode(g, type, 62 /* Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration */);
178
+ }
179
+ return true;
180
+ case 178 /* SyntaxKind.GetAccessor */:
181
+ case 179 /* SyntaxKind.SetAccessor */:
182
+ checkGrammarAccessorDeclaration(g, node);
183
+ return true;
184
+ case 263 /* SyntaxKind.FunctionDeclaration */:
185
+ checkGrammarDecorators(g, node);
186
+ checkGrammarFunctionLikeDeclaration(g, node);
187
+ checkGrammarForGenerator(g, node);
188
+ return true;
189
+ case 264 /* SyntaxKind.ClassDeclaration */:
190
+ checkGrammarClassDeclaration(g, node);
191
+ return true;
192
+ case 232 /* SyntaxKind.ClassExpression */:
193
+ checkGrammarClassLikeDeclaration(g, node);
194
+ return true;
195
+ case 265 /* SyntaxKind.InterfaceDeclaration */:
196
+ checkGrammarInterfaceDeclaration(g, node);
197
+ return true;
198
+ case 266 /* SyntaxKind.TypeAliasDeclaration */:
199
+ checkGrammarModifiers(g, node);
200
+ if (!containerAllowsBlockScopedVariable(node.parent))
201
+ grammarErrorOnNode(g, node, 116 /* Diagnostics.X_0_declarations_can_only_be_declared_inside_a_block */, 'type');
202
+ return true;
203
+ case 267 /* SyntaxKind.EnumDeclaration */:
204
+ checkGrammarModifiers(g, node);
205
+ return true;
206
+ case 268 /* SyntaxKind.ModuleDeclaration */:
207
+ return checkGrammarModuleDeclaration(g, node);
208
+ case 273 /* SyntaxKind.ImportDeclaration */:
209
+ case 346 /* SyntaxKind.JSImportDeclaration */:
210
+ checkGrammarImportDeclaration(g, node);
211
+ return false;
212
+ case 272 /* SyntaxKind.ImportEqualsDeclaration */:
213
+ checkGrammarImportEqualsDeclaration(g, node);
214
+ return false;
215
+ case 279 /* SyntaxKind.ExportDeclaration */:
216
+ checkGrammarExportDeclaration(g, node);
217
+ return false;
218
+ case 278 /* SyntaxKind.ExportAssignment */:
219
+ return checkGrammarExportAssignment(g, node);
220
+ case 261 /* SyntaxKind.VariableDeclaration */:
221
+ // Catch clause variables are checked with the clause.
222
+ if (node.parent.kind !== 300 /* SyntaxKind.CatchClause */)
223
+ checkGrammarVariableDeclaration(g, node);
224
+ return true;
225
+ case 209 /* SyntaxKind.BindingElement */:
226
+ checkGrammarBindingElement(g, node);
227
+ return true;
228
+ // Statements
229
+ case 242 /* SyntaxKind.Block */:
230
+ case 243 /* SyntaxKind.EmptyStatement */:
231
+ case 260 /* SyntaxKind.DebuggerStatement */:
232
+ case 245 /* SyntaxKind.ExpressionStatement */:
233
+ case 247 /* SyntaxKind.DoStatement */:
234
+ case 248 /* SyntaxKind.WhileStatement */:
235
+ case 259 /* SyntaxKind.TryStatement */:
236
+ checkGrammarStatementInAmbientContext(g, node);
237
+ return true;
238
+ case 246 /* SyntaxKind.IfStatement */: {
239
+ checkGrammarStatementInAmbientContext(g, node);
240
+ return true;
241
+ }
242
+ case 244 /* SyntaxKind.VariableStatement */:
243
+ checkGrammarVariableStatement(g, node);
244
+ return true;
245
+ case 249 /* SyntaxKind.ForStatement */: {
246
+ const initializer = node.initializer;
247
+ if (!checkGrammarStatementInAmbientContext(g, node) &&
248
+ initializer !== undefined &&
249
+ initializer.kind === 262 /* SyntaxKind.VariableDeclarationList */)
250
+ checkGrammarVariableDeclarationList(g, initializer);
251
+ return true;
252
+ }
253
+ case 250 /* SyntaxKind.ForInStatement */:
254
+ case 251 /* SyntaxKind.ForOfStatement */:
255
+ checkGrammarForInOrForOfStatement(g, node);
256
+ return true;
257
+ case 253 /* SyntaxKind.BreakStatement */:
258
+ case 252 /* SyntaxKind.ContinueStatement */:
259
+ if (!checkGrammarStatementInAmbientContext(g, node))
260
+ checkGrammarBreakOrContinueStatement(g, node);
261
+ return true;
262
+ case 254 /* SyntaxKind.ReturnStatement */:
263
+ return checkGrammarReturnStatement(g, node);
264
+ case 255 /* SyntaxKind.WithStatement */:
265
+ checkGrammarWithStatement(g, node);
266
+ return false;
267
+ case 256 /* SyntaxKind.SwitchStatement */:
268
+ checkGrammarSwitchStatement(g, node);
269
+ return true;
270
+ case 257 /* SyntaxKind.LabeledStatement */:
271
+ checkGrammarLabeledStatement(g, node);
272
+ return true;
273
+ case 258 /* SyntaxKind.ThrowStatement */: {
274
+ const expression = node.expression;
275
+ if (!checkGrammarStatementInAmbientContext(g, node) &&
276
+ expression instanceof Identifier &&
277
+ expression.text.length === 0)
278
+ grammarErrorAtPos(g, expression.pos, 0, 108 /* Diagnostics.Line_break_not_permitted_here */);
279
+ return true;
280
+ }
281
+ case 300 /* SyntaxKind.CatchClause */:
282
+ checkGrammarCatchClause(g, node);
283
+ return true;
284
+ // Type nodes
285
+ case 184 /* SyntaxKind.TypeReference */:
286
+ checkGrammarTypeReference(g, node);
287
+ return true;
288
+ case 187 /* SyntaxKind.TypeQuery */:
289
+ checkGrammarTypeArguments(g, getTypeArguments(node));
290
+ return true;
291
+ case 199 /* SyntaxKind.TypeOperator */:
292
+ checkGrammarTypeOperatorNode(g, node);
293
+ return true;
294
+ case 196 /* SyntaxKind.InferType */:
295
+ checkGrammarInferType(g, node);
296
+ return true;
297
+ case 206 /* SyntaxKind.ImportType */: {
298
+ const attributes = node.attributes;
299
+ if (attributes !== undefined)
300
+ getResolutionModeOverride(g, attributes, true);
301
+ return true;
302
+ }
303
+ case 190 /* SyntaxKind.TupleType */:
304
+ checkGrammarTupleType(g, node);
305
+ return true;
306
+ case 203 /* SyntaxKind.NamedTupleMember */:
307
+ checkGrammarNamedTupleMember(g, node);
308
+ return true;
309
+ case 312 /* SyntaxKind.JSDocNonNullableType */:
310
+ case 311 /* SyntaxKind.JSDocNullableType */:
311
+ case 310 /* SyntaxKind.JSDocAllType */:
312
+ case 317 /* SyntaxKind.JSDocTypeLiteral */:
313
+ checkGrammarJSDocTypeInTypeScript(g, node);
314
+ return true;
315
+ case 201 /* SyntaxKind.MappedType */: {
316
+ const members = node.members;
317
+ if (members !== undefined && members.nodes.length > 0)
318
+ grammarErrorOnNode(g, members.nodes[0], 1732 /* Diagnostics.A_mapped_type_may_not_declare_properties_or_methods */);
319
+ return true;
320
+ }
321
+ // Expressions
322
+ case 234 /* SyntaxKind.ExpressionWithTypeArguments */:
323
+ // Heritage clause elements are checked with their class or interface.
324
+ if (node.parent.kind !== 299 /* SyntaxKind.HeritageClause */)
325
+ checkGrammarExpressionWithTypeArguments(g, node);
326
+ return true;
327
+ case 219 /* SyntaxKind.FunctionExpression */:
328
+ case 220 /* SyntaxKind.ArrowFunction */:
329
+ // Checked by the checker each time the function is checked.
330
+ return true;
331
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
332
+ // Checked by the checker each time the literal is checked.
333
+ return true;
334
+ case 214 /* SyntaxKind.CallExpression */:
335
+ checkGrammarCallExpression(g, node);
336
+ return true;
337
+ case 215 /* SyntaxKind.NewExpression */:
338
+ checkGrammarTypeArguments(g, getTypeArguments(node));
339
+ return true;
340
+ case 216 /* SyntaxKind.TaggedTemplateExpression */:
341
+ if (!checkGrammarTaggedTemplateChain(g, node))
342
+ checkGrammarTypeArguments(g, getTypeArguments(node));
343
+ return true;
344
+ case 237 /* SyntaxKind.MetaProperty */:
345
+ checkGrammarMetaProperty(g, node);
346
+ return true;
347
+ case 224 /* SyntaxKind.AwaitExpression */:
348
+ case 230 /* SyntaxKind.YieldExpression */:
349
+ case 227 /* SyntaxKind.BinaryExpression */:
350
+ // Checked by the checker each time the expression is checked.
351
+ return true;
352
+ case 80 /* SyntaxKind.PrivateIdentifier */:
353
+ checkGrammarPrivateIdentifierExpression(g, node);
354
+ return false;
355
+ case 9 /* SyntaxKind.BigIntLiteral */:
356
+ checkGrammarBigIntLiteral(g, node);
357
+ return false;
358
+ case 13 /* SyntaxKind.RegularExpressionLiteral */:
359
+ checkGrammarRegularExpressionLiteral(g, node);
360
+ return false;
361
+ case 171 /* SyntaxKind.Decorator */: {
362
+ // Decorators are only checked on valid targets.
363
+ const target = node.parent;
364
+ return (canHaveDecorators(target) &&
365
+ nodeCanBeDecorated(g.legacyDecorators, target, target.parent, target.parent.parent));
366
+ }
367
+ }
368
+ return true;
369
+ }
370
+ // ---- Modifiers and decorators
371
+ function checkGrammarModifiers(g, node) {
372
+ const modifiers = getModifiers(node);
373
+ if (modifiers === undefined)
374
+ return false;
375
+ if (reportObviousDecoratorErrors(g, node, modifiers) || reportObviousModifierErrors(g, node, modifiers))
376
+ return true;
377
+ if (isThisParameter(node))
378
+ return grammarErrorOnFirstToken(g, node, 359 /* Diagnostics.Neither_decorators_nor_modifiers_may_be_applied_to_this_parameters */);
379
+ const blockScopeKind = node.kind === 244 /* SyntaxKind.VariableStatement */
380
+ ? node.declarationList.flags & 7 /* NodeFlags.BlockScoped */
381
+ : 0 /* NodeFlags.None */;
382
+ const parent = node.parent;
383
+ let lastStatic;
384
+ let lastDeclare;
385
+ let lastAsync;
386
+ let lastOverride;
387
+ let firstDecorator;
388
+ let flags = 0 /* ModifierFlags.None */;
389
+ let sawExportBeforeDecorators = false;
390
+ // Decorators and modifiers come in four chunks: leading decorators, leading modifiers,
391
+ // trailing decorators and trailing modifiers. Leading and trailing decorators can't both appear.
392
+ let hasLeadingDecorators = false;
393
+ for (const modifier of modifiers.nodes) {
394
+ if (modifier.kind === 171 /* SyntaxKind.Decorator */) {
395
+ if (!nodeCanBeDecorated(g.legacyDecorators, node, parent, parent.parent)) {
396
+ if (node.kind === 175 /* SyntaxKind.MethodDeclaration */ && !nodeIsPresent(getBody(node)))
397
+ return grammarErrorOnFirstToken(g, node, 199 /* Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload */);
398
+ return grammarErrorOnFirstToken(g, node, 160 /* Diagnostics.Decorators_are_not_valid_here */);
399
+ }
400
+ else if (g.legacyDecorators && (node.kind === 178 /* SyntaxKind.GetAccessor */ || node.kind === 179 /* SyntaxKind.SetAccessor */)) {
401
+ const first = getFirstAccessorOfPair(g.c, node);
402
+ if (first !== node && hasDecorators(first))
403
+ return grammarErrorOnFirstToken(g, node, 161 /* Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name */);
404
+ }
405
+ // Decorators can only follow `export` and `default`.
406
+ if ((flags & ~(2080 /* ModifierFlags.ExportDefault */ | 32768 /* ModifierFlags.Decorator */)) !== 0)
407
+ return grammarErrorOnNode(g, modifier, 160 /* Diagnostics.Decorators_are_not_valid_here */);
408
+ if (hasLeadingDecorators && (flags & 98303 /* ModifierFlags.Modifier */) !== 0) {
409
+ if (g.hasParseErrors)
410
+ return false;
411
+ const diagnostic = g.c.error(modifier, 1767 /* Diagnostics.Decorators_may_not_appear_after_export_or_export_default_if_they_also_appear_before_export */);
412
+ addRelated(diagnostic, firstDecorator, 401 /* Diagnostics.Decorator_used_before_export_here */);
413
+ return true;
414
+ }
415
+ flags |= 32768 /* ModifierFlags.Decorator */;
416
+ if ((flags & 98303 /* ModifierFlags.Modifier */) === 0)
417
+ hasLeadingDecorators = true;
418
+ else if ((flags & 32 /* ModifierFlags.Export */) !== 0)
419
+ sawExportBeforeDecorators = true;
420
+ if (firstDecorator === undefined)
421
+ firstDecorator = modifier;
422
+ continue;
423
+ }
424
+ const kind = modifier.kind;
425
+ const reparsed = (modifier.flags & 8 /* NodeFlags.Reparsed */) !== 0;
426
+ if (kind !== 148 /* SyntaxKind.ReadonlyKeyword */) {
427
+ if (node.kind === 172 /* SyntaxKind.PropertySignature */ || node.kind === 174 /* SyntaxKind.MethodSignature */)
428
+ return grammarErrorOnNode(g, modifier, 54 /* Diagnostics.X_0_modifier_cannot_appear_on_a_type_member */, tokenToString(kind));
429
+ if (node.kind === 182 /* SyntaxKind.IndexSignature */ && (kind !== 125 /* SyntaxKind.StaticKeyword */ || !isClassLike(parent)))
430
+ return grammarErrorOnNode(g, modifier, 55 /* Diagnostics.X_0_modifier_cannot_appear_on_an_index_signature */, tokenToString(kind));
431
+ }
432
+ if (kind !== 102 /* SyntaxKind.InKeyword */ &&
433
+ kind !== 147 /* SyntaxKind.OutKeyword */ &&
434
+ kind !== 86 /* SyntaxKind.ConstKeyword */ &&
435
+ node.kind === 169 /* SyntaxKind.TypeParameter */)
436
+ return grammarErrorOnNode(g, modifier, 222 /* Diagnostics.X_0_modifier_cannot_appear_on_a_type_parameter */, tokenToString(kind));
437
+ switch (kind) {
438
+ case 86 /* SyntaxKind.ConstKeyword */:
439
+ if (node.kind !== 267 /* SyntaxKind.EnumDeclaration */ && node.kind !== 169 /* SyntaxKind.TypeParameter */)
440
+ return grammarErrorOnNode(g, node, 198 /* Diagnostics.A_class_member_cannot_have_the_0_keyword */, tokenToString(kind));
441
+ if (node.kind === 169 /* SyntaxKind.TypeParameter */ && !isConstTypeParameterContainer(parent))
442
+ return grammarErrorOnNode(g, modifier, 226 /* Diagnostics.X_0_modifier_can_only_appear_on_a_type_parameter_of_a_function_method_or_class */, tokenToString(kind));
443
+ break;
444
+ case 164 /* SyntaxKind.OverrideKeyword */:
445
+ // Parameters that aren't parameter properties are reported by the parameter check.
446
+ if ((flags & 16 /* ModifierFlags.Override */) !== 0)
447
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'override');
448
+ if ((flags & 128 /* ModifierFlags.Ambient */) !== 0)
449
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'override', 'declare');
450
+ if ((flags & 8 /* ModifierFlags.Readonly */) !== 0 && !reparsed)
451
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'override', 'readonly');
452
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0 && !reparsed)
453
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'override', 'accessor');
454
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0 && !reparsed)
455
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'override', 'async');
456
+ flags |= 16 /* ModifierFlags.Override */;
457
+ lastOverride = modifier;
458
+ break;
459
+ case 124 /* SyntaxKind.PublicKeyword */:
460
+ case 123 /* SyntaxKind.ProtectedKeyword */:
461
+ case 122 /* SyntaxKind.PrivateKeyword */: {
462
+ const text = tokenToString(kind);
463
+ if ((flags & 7 /* ModifierFlags.AccessibilityModifier */) !== 0)
464
+ return grammarErrorOnNode(g, modifier, 21 /* Diagnostics.Accessibility_modifier_already_seen */);
465
+ if ((flags & 16 /* ModifierFlags.Override */) !== 0 && !reparsed)
466
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, text, 'override');
467
+ if ((flags & 256 /* ModifierFlags.Static */) !== 0 && !reparsed)
468
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, text, 'static');
469
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0 && !reparsed)
470
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, text, 'accessor');
471
+ if ((flags & 8 /* ModifierFlags.Readonly */) !== 0 && !reparsed)
472
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, text, 'readonly');
473
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0 && !reparsed)
474
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, text, 'async');
475
+ if (parent.kind === 269 /* SyntaxKind.ModuleBlock */ || parent.kind === 307 /* SyntaxKind.SourceFile */)
476
+ return grammarErrorOnNode(g, modifier, 32 /* Diagnostics.X_0_modifier_cannot_appear_on_a_module_or_namespace_element */, text);
477
+ if ((flags & 64 /* ModifierFlags.Abstract */) !== 0) {
478
+ if (kind === 122 /* SyntaxKind.PrivateKeyword */)
479
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, text, 'abstract');
480
+ if (!reparsed)
481
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, text, 'abstract');
482
+ }
483
+ else if (isPrivateIdentifierClassElementDeclaration(node))
484
+ return grammarErrorOnNode(g, modifier, 1832 /* Diagnostics.An_accessibility_modifier_cannot_be_used_with_a_private_identifier */);
485
+ flags |= modifierToFlag(kind);
486
+ break;
487
+ }
488
+ case 125 /* SyntaxKind.StaticKeyword */:
489
+ if ((flags & 256 /* ModifierFlags.Static */) !== 0)
490
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'static');
491
+ if ((flags & 8 /* ModifierFlags.Readonly */) !== 0 && !reparsed)
492
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'static', 'readonly');
493
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0 && !reparsed)
494
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'static', 'async');
495
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0 && !reparsed)
496
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'static', 'accessor');
497
+ if (parent.kind === 269 /* SyntaxKind.ModuleBlock */ || parent.kind === 307 /* SyntaxKind.SourceFile */)
498
+ return grammarErrorOnNode(g, modifier, 32 /* Diagnostics.X_0_modifier_cannot_appear_on_a_module_or_namespace_element */, 'static');
499
+ if (node.kind === 170 /* SyntaxKind.Parameter */)
500
+ return grammarErrorOnNode(g, modifier, 59 /* Diagnostics.X_0_modifier_cannot_appear_on_a_parameter */, 'static');
501
+ if ((flags & 64 /* ModifierFlags.Abstract */) !== 0)
502
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'static', 'abstract');
503
+ if ((flags & 16 /* ModifierFlags.Override */) !== 0 && !reparsed)
504
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'static', 'override');
505
+ flags |= 256 /* ModifierFlags.Static */;
506
+ lastStatic = modifier;
507
+ break;
508
+ case 128 /* SyntaxKind.AccessorKeyword */:
509
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0)
510
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'accessor');
511
+ if ((flags & 8 /* ModifierFlags.Readonly */) !== 0)
512
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'accessor', 'readonly');
513
+ if ((flags & 128 /* ModifierFlags.Ambient */) !== 0)
514
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'accessor', 'declare');
515
+ if (node.kind !== 173 /* SyntaxKind.PropertyDeclaration */)
516
+ return grammarErrorOnNode(g, modifier, 224 /* Diagnostics.X_accessor_modifier_can_only_appear_on_a_property_declaration */);
517
+ flags |= 512 /* ModifierFlags.Accessor */;
518
+ break;
519
+ case 148 /* SyntaxKind.ReadonlyKeyword */:
520
+ if ((flags & 8 /* ModifierFlags.Readonly */) !== 0)
521
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'readonly');
522
+ // Parameters that aren't parameter properties are reported by the parameter check.
523
+ if (node.kind !== 173 /* SyntaxKind.PropertyDeclaration */ &&
524
+ node.kind !== 172 /* SyntaxKind.PropertySignature */ &&
525
+ node.kind !== 182 /* SyntaxKind.IndexSignature */ &&
526
+ node.kind !== 170 /* SyntaxKind.Parameter */)
527
+ return grammarErrorOnNode(g, modifier, 19 /* Diagnostics.X_readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature */);
528
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0)
529
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'readonly', 'accessor');
530
+ flags |= 8 /* ModifierFlags.Readonly */;
531
+ break;
532
+ case 94 /* SyntaxKind.ExportKeyword */:
533
+ if (g.c.compilerOptions.verbatimModuleSyntax === true &&
534
+ (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 &&
535
+ node.kind !== 266 /* SyntaxKind.TypeAliasDeclaration */ &&
536
+ node.kind !== 265 /* SyntaxKind.InterfaceDeclaration */ &&
537
+ node.kind !== 268 /* SyntaxKind.ModuleDeclaration */ &&
538
+ parent.kind === 307 /* SyntaxKind.SourceFile */ &&
539
+ getEmitModuleFormat(g) === ModuleKind.CommonJS)
540
+ return grammarErrorOnNode(g, modifier, 236 /* Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled */);
541
+ if ((flags & 32 /* ModifierFlags.Export */) !== 0)
542
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'export');
543
+ if ((flags & 128 /* ModifierFlags.Ambient */) !== 0 && !reparsed)
544
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'export', 'declare');
545
+ if ((flags & 64 /* ModifierFlags.Abstract */) !== 0 && !reparsed)
546
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'export', 'abstract');
547
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0 && !reparsed)
548
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'export', 'async');
549
+ if (isClassLike(parent) && node.kind !== 345 /* SyntaxKind.JSTypeAliasDeclaration */)
550
+ return grammarErrorOnNode(g, modifier, 24 /* Diagnostics.X_0_modifier_cannot_appear_on_class_elements_of_this_kind */, 'export');
551
+ if (node.kind === 170 /* SyntaxKind.Parameter */)
552
+ return grammarErrorOnNode(g, modifier, 59 /* Diagnostics.X_0_modifier_cannot_appear_on_a_parameter */, 'export');
553
+ if (blockScopeKind === 4 /* NodeFlags.Using */)
554
+ return grammarErrorOnNode(g, modifier, 406 /* Diagnostics.X_0_modifier_cannot_appear_on_a_using_declaration */, 'export');
555
+ if (blockScopeKind === 6 /* NodeFlags.AwaitUsing */)
556
+ return grammarErrorOnNode(g, modifier, 410 /* Diagnostics.X_0_modifier_cannot_appear_on_an_await_using_declaration */, 'export');
557
+ flags |= 32 /* ModifierFlags.Export */;
558
+ break;
559
+ case 89 /* SyntaxKind.DefaultKeyword */: {
560
+ const container = parent.kind === 307 /* SyntaxKind.SourceFile */ ? parent : parent.parent;
561
+ if (container.kind === 268 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container))
562
+ return grammarErrorOnNode(g, modifier, 255 /* Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module */);
563
+ if (blockScopeKind === 4 /* NodeFlags.Using */)
564
+ return grammarErrorOnNode(g, modifier, 406 /* Diagnostics.X_0_modifier_cannot_appear_on_a_using_declaration */, 'default');
565
+ if (blockScopeKind === 6 /* NodeFlags.AwaitUsing */)
566
+ return grammarErrorOnNode(g, modifier, 410 /* Diagnostics.X_0_modifier_cannot_appear_on_an_await_using_declaration */, 'default');
567
+ if ((flags & 32 /* ModifierFlags.Export */) === 0 && !reparsed)
568
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'export', 'default');
569
+ if (sawExportBeforeDecorators)
570
+ return grammarErrorOnNode(g, firstDecorator, 160 /* Diagnostics.Decorators_are_not_valid_here */);
571
+ flags |= 2048 /* ModifierFlags.Default */;
572
+ break;
573
+ }
574
+ case 137 /* SyntaxKind.DeclareKeyword */:
575
+ if ((flags & 128 /* ModifierFlags.Ambient */) !== 0)
576
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'declare');
577
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0)
578
+ return grammarErrorOnNode(g, modifier, 30 /* Diagnostics.X_0_modifier_cannot_be_used_in_an_ambient_context */, 'async');
579
+ if ((flags & 16 /* ModifierFlags.Override */) !== 0)
580
+ return grammarErrorOnNode(g, modifier, 30 /* Diagnostics.X_0_modifier_cannot_be_used_in_an_ambient_context */, 'override');
581
+ if (isClassLike(parent) && node.kind !== 173 /* SyntaxKind.PropertyDeclaration */)
582
+ return grammarErrorOnNode(g, modifier, 24 /* Diagnostics.X_0_modifier_cannot_appear_on_class_elements_of_this_kind */, 'declare');
583
+ if (node.kind === 170 /* SyntaxKind.Parameter */)
584
+ return grammarErrorOnNode(g, modifier, 59 /* Diagnostics.X_0_modifier_cannot_appear_on_a_parameter */, 'declare');
585
+ if (blockScopeKind === 4 /* NodeFlags.Using */)
586
+ return grammarErrorOnNode(g, modifier, 406 /* Diagnostics.X_0_modifier_cannot_appear_on_a_using_declaration */, 'declare');
587
+ if (blockScopeKind === 6 /* NodeFlags.AwaitUsing */)
588
+ return grammarErrorOnNode(g, modifier, 410 /* Diagnostics.X_0_modifier_cannot_appear_on_an_await_using_declaration */, 'declare');
589
+ if ((parent.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && parent.kind === 269 /* SyntaxKind.ModuleBlock */)
590
+ return grammarErrorOnNode(g, modifier, 28 /* Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context */);
591
+ if (isPrivateIdentifierClassElementDeclaration(node))
592
+ return grammarErrorOnNode(g, modifier, 1841 /* Diagnostics.X_0_modifier_cannot_be_used_with_a_private_identifier */, 'declare');
593
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0)
594
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'declare', 'accessor');
595
+ flags |= 128 /* ModifierFlags.Ambient */;
596
+ lastDeclare = modifier;
597
+ break;
598
+ case 127 /* SyntaxKind.AbstractKeyword */: {
599
+ if ((flags & 64 /* ModifierFlags.Abstract */) !== 0)
600
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'abstract');
601
+ if (node.kind !== 264 /* SyntaxKind.ClassDeclaration */ && node.kind !== 186 /* SyntaxKind.ConstructorType */) {
602
+ if (node.kind !== 175 /* SyntaxKind.MethodDeclaration */ &&
603
+ node.kind !== 173 /* SyntaxKind.PropertyDeclaration */ &&
604
+ node.kind !== 178 /* SyntaxKind.GetAccessor */ &&
605
+ node.kind !== 179 /* SyntaxKind.SetAccessor */)
606
+ return grammarErrorOnNode(g, modifier, 192 /* Diagnostics.X_abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration */);
607
+ if (!(parent.kind === 264 /* SyntaxKind.ClassDeclaration */ && hasSyntacticModifier(parent, 64 /* ModifierFlags.Abstract */)))
608
+ return grammarErrorOnNode(g, modifier, node.kind === 173 /* SyntaxKind.PropertyDeclaration */
609
+ ? 203 /* Diagnostics.Abstract_properties_can_only_appear_within_an_abstract_class */
610
+ : 194 /* Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class */);
611
+ if ((flags & 256 /* ModifierFlags.Static */) !== 0)
612
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'static', 'abstract');
613
+ if ((flags & 2 /* ModifierFlags.Private */) !== 0)
614
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'private', 'abstract');
615
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0 && lastAsync !== undefined)
616
+ return grammarErrorOnNode(g, lastAsync, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'async', 'abstract');
617
+ if ((flags & 16 /* ModifierFlags.Override */) !== 0 && !reparsed)
618
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'abstract', 'override');
619
+ if ((flags & 512 /* ModifierFlags.Accessor */) !== 0 && !reparsed)
620
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'abstract', 'accessor');
621
+ }
622
+ const name = getName(node);
623
+ if (name !== undefined && name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
624
+ return grammarErrorOnNode(g, modifier, 1841 /* Diagnostics.X_0_modifier_cannot_be_used_with_a_private_identifier */, 'abstract');
625
+ flags |= 64 /* ModifierFlags.Abstract */;
626
+ break;
627
+ }
628
+ case 133 /* SyntaxKind.AsyncKeyword */:
629
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0)
630
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, 'async');
631
+ if ((flags & 128 /* ModifierFlags.Ambient */) !== 0 || (parent.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
632
+ return grammarErrorOnNode(g, modifier, 30 /* Diagnostics.X_0_modifier_cannot_be_used_in_an_ambient_context */, 'async');
633
+ if (node.kind === 170 /* SyntaxKind.Parameter */)
634
+ return grammarErrorOnNode(g, modifier, 59 /* Diagnostics.X_0_modifier_cannot_appear_on_a_parameter */, 'async');
635
+ if ((flags & 64 /* ModifierFlags.Abstract */) !== 0)
636
+ return grammarErrorOnNode(g, modifier, 193 /* Diagnostics.X_0_modifier_cannot_be_used_with_1_modifier */, 'async', 'abstract');
637
+ flags |= 1024 /* ModifierFlags.Async */;
638
+ lastAsync = modifier;
639
+ break;
640
+ case 102 /* SyntaxKind.InKeyword */:
641
+ case 147 /* SyntaxKind.OutKeyword */: {
642
+ const inOutFlag = kind === 102 /* SyntaxKind.InKeyword */ ? 8192 /* ModifierFlags.In */ : 16384 /* ModifierFlags.Out */;
643
+ const inOutText = kind === 102 /* SyntaxKind.InKeyword */ ? 'in' : 'out';
644
+ if (node.kind !== 169 /* SyntaxKind.TypeParameter */ ||
645
+ !(parent.kind === 265 /* SyntaxKind.InterfaceDeclaration */ ||
646
+ isClassLike(parent) ||
647
+ parent.kind === 266 /* SyntaxKind.TypeAliasDeclaration */ ||
648
+ parent.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */))
649
+ return grammarErrorOnNode(g, modifier, 223 /* Diagnostics.X_0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias */, inOutText);
650
+ if ((flags & inOutFlag) !== 0)
651
+ return grammarErrorOnNode(g, modifier, 23 /* Diagnostics.X_0_modifier_already_seen */, inOutText);
652
+ if ((inOutFlag & 8192 /* ModifierFlags.In */) !== 0 && (flags & 16384 /* ModifierFlags.Out */) !== 0)
653
+ return grammarErrorOnNode(g, modifier, 22 /* Diagnostics.X_0_modifier_must_precede_1_modifier */, 'in', 'out');
654
+ flags |= inOutFlag;
655
+ break;
656
+ }
657
+ }
658
+ }
659
+ if (node.kind === 177 /* SyntaxKind.Constructor */) {
660
+ if ((flags & 256 /* ModifierFlags.Static */) !== 0)
661
+ return grammarErrorOnNode(g, lastStatic, 58 /* Diagnostics.X_0_modifier_cannot_appear_on_a_constructor_declaration */, 'static');
662
+ if ((flags & 16 /* ModifierFlags.Override */) !== 0)
663
+ return grammarErrorOnNode(g, lastOverride, 58 /* Diagnostics.X_0_modifier_cannot_appear_on_a_constructor_declaration */, 'override');
664
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0)
665
+ return grammarErrorOnNode(g, lastAsync, 58 /* Diagnostics.X_0_modifier_cannot_appear_on_a_constructor_declaration */, 'async');
666
+ return false;
667
+ }
668
+ if ((node.kind === 273 /* SyntaxKind.ImportDeclaration */ ||
669
+ node.kind === 346 /* SyntaxKind.JSImportDeclaration */ ||
670
+ node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */) &&
671
+ (flags & 128 /* ModifierFlags.Ambient */) !== 0)
672
+ return grammarErrorOnNode(g, lastDeclare, 56 /* Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration */, 'declare');
673
+ if (node.kind === 170 /* SyntaxKind.Parameter */ && (flags & 31 /* ModifierFlags.ParameterPropertyModifier */) !== 0) {
674
+ const parameter = node;
675
+ if (isBindingPattern(parameter.name))
676
+ return grammarErrorOnNode(g, node, 143 /* Diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern */);
677
+ if (parameter.dotDotDotToken !== undefined)
678
+ return grammarErrorOnNode(g, node, 253 /* Diagnostics.A_parameter_property_cannot_be_declared_using_a_rest_parameter */);
679
+ }
680
+ if ((flags & 1024 /* ModifierFlags.Async */) !== 0)
681
+ return checkGrammarAsyncModifier(g, node, lastAsync);
682
+ return false;
683
+ }
684
+ function isConstTypeParameterContainer(parent) {
685
+ switch (parent.kind) {
686
+ case 185 /* SyntaxKind.FunctionType */:
687
+ case 186 /* SyntaxKind.ConstructorType */:
688
+ case 180 /* SyntaxKind.CallSignature */:
689
+ case 181 /* SyntaxKind.ConstructSignature */:
690
+ case 174 /* SyntaxKind.MethodSignature */:
691
+ return true;
692
+ }
693
+ return isFunctionLikeDeclarationKind(parent.kind) || isClassLike(parent);
694
+ }
695
+ function reportObviousModifierErrors(g, node, modifiers) {
696
+ const modifier = findFirstIllegalModifier(node, modifiers);
697
+ return modifier !== undefined && grammarErrorOnFirstToken(g, modifier, 140 /* Diagnostics.Modifiers_cannot_appear_here */);
698
+ }
699
+ function findFirstModifier(modifiers) {
700
+ for (const modifier of modifiers.nodes)
701
+ if (isModifierKind(modifier.kind))
702
+ return modifier;
703
+ return undefined;
704
+ }
705
+ function findFirstModifierExcept(modifiers, allowedModifier) {
706
+ const modifier = findFirstModifier(modifiers);
707
+ return modifier !== undefined && modifier.kind !== allowedModifier ? modifier : undefined;
708
+ }
709
+ function findFirstIllegalModifier(node, modifiers) {
710
+ switch (node.kind) {
711
+ case 178 /* SyntaxKind.GetAccessor */:
712
+ case 179 /* SyntaxKind.SetAccessor */:
713
+ case 177 /* SyntaxKind.Constructor */:
714
+ case 173 /* SyntaxKind.PropertyDeclaration */:
715
+ case 172 /* SyntaxKind.PropertySignature */:
716
+ case 175 /* SyntaxKind.MethodDeclaration */:
717
+ case 174 /* SyntaxKind.MethodSignature */:
718
+ case 182 /* SyntaxKind.IndexSignature */:
719
+ case 268 /* SyntaxKind.ModuleDeclaration */:
720
+ case 273 /* SyntaxKind.ImportDeclaration */:
721
+ case 346 /* SyntaxKind.JSImportDeclaration */:
722
+ case 272 /* SyntaxKind.ImportEqualsDeclaration */:
723
+ case 279 /* SyntaxKind.ExportDeclaration */:
724
+ case 278 /* SyntaxKind.ExportAssignment */:
725
+ case 219 /* SyntaxKind.FunctionExpression */:
726
+ case 220 /* SyntaxKind.ArrowFunction */:
727
+ case 170 /* SyntaxKind.Parameter */:
728
+ case 169 /* SyntaxKind.TypeParameter */:
729
+ case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
730
+ return undefined;
731
+ case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
732
+ case 303 /* SyntaxKind.PropertyAssignment */:
733
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
734
+ case 271 /* SyntaxKind.NamespaceExportDeclaration */:
735
+ case 283 /* SyntaxKind.MissingDeclaration */:
736
+ return findFirstModifier(modifiers);
737
+ }
738
+ const parent = node.parent;
739
+ if (parent.kind === 269 /* SyntaxKind.ModuleBlock */ || parent.kind === 307 /* SyntaxKind.SourceFile */)
740
+ return undefined;
741
+ switch (node.kind) {
742
+ case 263 /* SyntaxKind.FunctionDeclaration */:
743
+ return findFirstModifierExcept(modifiers, 133 /* SyntaxKind.AsyncKeyword */);
744
+ case 264 /* SyntaxKind.ClassDeclaration */:
745
+ case 186 /* SyntaxKind.ConstructorType */:
746
+ return findFirstModifierExcept(modifiers, 127 /* SyntaxKind.AbstractKeyword */);
747
+ case 244 /* SyntaxKind.VariableStatement */:
748
+ if ((node.declarationList.flags & 4 /* NodeFlags.Using */) !== 0)
749
+ return findFirstModifierExcept(modifiers, 134 /* SyntaxKind.AwaitKeyword */);
750
+ return findFirstModifier(modifiers);
751
+ case 267 /* SyntaxKind.EnumDeclaration */:
752
+ return findFirstModifierExcept(modifiers, 86 /* SyntaxKind.ConstKeyword */);
753
+ }
754
+ // Class expressions, interfaces and type aliases.
755
+ return findFirstModifier(modifiers);
756
+ }
757
+ function reportObviousDecoratorErrors(g, node, modifiers) {
758
+ if (!canHaveIllegalDecorators(node))
759
+ return false;
760
+ for (const modifier of modifiers.nodes)
761
+ if (modifier.kind === 171 /* SyntaxKind.Decorator */)
762
+ return grammarErrorOnFirstToken(g, modifier, 160 /* Diagnostics.Decorators_are_not_valid_here */);
763
+ return false;
764
+ }
765
+ function checkGrammarAsyncModifier(g, node, asyncModifier) {
766
+ switch (node.kind) {
767
+ case 175 /* SyntaxKind.MethodDeclaration */:
768
+ case 263 /* SyntaxKind.FunctionDeclaration */:
769
+ case 219 /* SyntaxKind.FunctionExpression */:
770
+ case 220 /* SyntaxKind.ArrowFunction */:
771
+ return false;
772
+ }
773
+ return grammarErrorOnNode(g, asyncModifier, 31 /* Diagnostics.X_0_modifier_cannot_be_used_here */, 'async');
774
+ }
775
+ function hasDecorators(node) {
776
+ const modifiers = getModifiers(node);
777
+ if (modifiers === undefined)
778
+ return false;
779
+ for (const modifier of modifiers.nodes)
780
+ if (modifier.kind === 171 /* SyntaxKind.Decorator */)
781
+ return true;
782
+ return false;
783
+ }
784
+ /** Whether `node` is a valid decorator target. */
785
+ function nodeCanBeDecorated(legacy, node, parent, grandparent) {
786
+ const name = getName(node);
787
+ // Legacy decorators don't support private names.
788
+ if (legacy && name !== undefined && name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
789
+ return false;
790
+ switch (node.kind) {
791
+ case 264 /* SyntaxKind.ClassDeclaration */:
792
+ return true;
793
+ case 232 /* SyntaxKind.ClassExpression */:
794
+ return !legacy;
795
+ case 173 /* SyntaxKind.PropertyDeclaration */:
796
+ return (parent !== undefined &&
797
+ (legacy
798
+ ? parent.kind === 264 /* SyntaxKind.ClassDeclaration */
799
+ : isClassLike(parent) && !hasSyntacticModifier(node, 64 /* ModifierFlags.Abstract */ | 128 /* ModifierFlags.Ambient */)));
800
+ case 178 /* SyntaxKind.GetAccessor */:
801
+ case 179 /* SyntaxKind.SetAccessor */:
802
+ case 175 /* SyntaxKind.MethodDeclaration */:
803
+ return (parent !== undefined &&
804
+ getBody(node) !== undefined &&
805
+ (legacy ? parent.kind === 264 /* SyntaxKind.ClassDeclaration */ : isClassLike(parent)));
806
+ case 170 /* SyntaxKind.Parameter */:
807
+ if (!legacy || parent === undefined || getBody(parent) === undefined)
808
+ return false;
809
+ return ((parent.kind === 177 /* SyntaxKind.Constructor */ ||
810
+ parent.kind === 175 /* SyntaxKind.MethodDeclaration */ ||
811
+ parent.kind === 179 /* SyntaxKind.SetAccessor */) &&
812
+ getThisParameter(parent) !== node &&
813
+ grandparent !== undefined &&
814
+ grandparent.kind === 264 /* SyntaxKind.ClassDeclaration */);
815
+ }
816
+ return false;
817
+ }
818
+ /** The first of the get/set accessor pair `node` belongs to. */
819
+ function getFirstAccessorOfPair(c, node) {
820
+ const symbol = getSymbolOfDeclaration(c, node);
821
+ if (symbol === undefined)
822
+ return node;
823
+ const otherKind = node.kind === 178 /* SyntaxKind.GetAccessor */ ? 179 /* SyntaxKind.SetAccessor */ : 178 /* SyntaxKind.GetAccessor */;
824
+ for (const declaration of symbol.declarations)
825
+ if (declaration.kind === otherKind && declaration.pos < node.pos)
826
+ return declaration;
827
+ return node;
828
+ }
829
+ /** The decorator checks of `checkDecorators`. */
830
+ function checkGrammarDecorators(g, node) {
831
+ if (!canHaveDecorators(node) || !hasDecorators(node))
832
+ return;
833
+ if (!nodeCanBeDecorated(g.legacyDecorators, node, node.parent, node.parent.parent))
834
+ return;
835
+ for (const modifier of getModifiers(node).nodes)
836
+ if (modifier.kind === 171 /* SyntaxKind.Decorator */)
837
+ checkGrammarDecorator(g, modifier);
838
+ }
839
+ function checkGrammarDecorator(g, decorator) {
840
+ if (g.hasParseErrors)
841
+ return false;
842
+ let node = decorator.expression;
843
+ // `@(expression)`
844
+ if (node.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
845
+ return false;
846
+ let canHaveCallExpression = true;
847
+ let errorNode;
848
+ for (;;) {
849
+ // Non-null assertions and instantiation expressions are allowed.
850
+ if (node.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */ || node.kind === 236 /* SyntaxKind.NonNullExpression */) {
851
+ node = getExpression(node);
852
+ continue;
853
+ }
854
+ // `@member.expression(arguments)`
855
+ if (node.kind === 214 /* SyntaxKind.CallExpression */) {
856
+ const call = node;
857
+ if (!canHaveCallExpression)
858
+ errorNode = node;
859
+ // A `?.` token comes first, so it wins over an earlier error node.
860
+ if (call.questionDotToken !== undefined)
861
+ errorNode = call.questionDotToken;
862
+ node = call.expression;
863
+ canHaveCallExpression = false;
864
+ continue;
865
+ }
866
+ // `@identifier`, `@member.name` and `@member.#name`
867
+ if (node.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
868
+ const access = node;
869
+ if (access.questionDotToken !== undefined)
870
+ errorNode = access.questionDotToken;
871
+ node = access.expression;
872
+ canHaveCallExpression = false;
873
+ continue;
874
+ }
875
+ if (node.kind !== 79 /* SyntaxKind.Identifier */)
876
+ errorNode = node;
877
+ break;
878
+ }
879
+ if (errorNode === undefined)
880
+ return false;
881
+ const diagnostic = g.c.error(decorator.expression, 412 /* Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator */);
882
+ addRelated(diagnostic, errorNode, 413 /* Diagnostics.Invalid_syntax_in_decorator */);
883
+ return true;
884
+ }
885
+ // ---- Functions and parameters
886
+ function checkGrammarFunctionLikeDeclaration(g, node) {
887
+ // Short-circuits to prevent cascading errors.
888
+ return (checkGrammarModifiers(g, node) ||
889
+ checkGrammarTypeParameterList(g, getTypeParameters(node)) ||
890
+ checkGrammarParameterList(g, getParameters(node)) ||
891
+ checkGrammarArrowFunction(g, node) ||
892
+ (isFunctionLikeDeclarationKind(node.kind) && checkGrammarForUseStrictSimpleParameterList(g, node)));
893
+ }
894
+ function checkGrammarForDisallowedTrailingComma(g, list, message) {
895
+ return list !== undefined && list.hasTrailingComma() && grammarErrorAtPos(g, list.end - 1, 1, message);
896
+ }
897
+ function checkGrammarTypeParameterList(g, typeParameters) {
898
+ if (typeParameters === undefined || typeParameters.nodes.length !== 0)
899
+ return false;
900
+ const start = typeParameters.pos - 1;
901
+ const end = skipTrivia(g.file.text, typeParameters.end) + 1;
902
+ return grammarErrorAtPos(g, start, end - start, 67 /* Diagnostics.Type_parameter_list_cannot_be_empty */);
903
+ }
904
+ function checkGrammarParameterList(g, parameters) {
905
+ let seenOptionalParameter = false;
906
+ const count = parameters.nodes.length;
907
+ for (let i = 0; i < count; i++) {
908
+ const parameter = parameters.nodes[i];
909
+ if (parameter.dotDotDotToken !== undefined) {
910
+ if (i !== count - 1)
911
+ return grammarErrorOnNode(g, parameter.dotDotDotToken, 10 /* Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list */);
912
+ if ((parameter.flags & 8388608 /* NodeFlags.Ambient */) === 0)
913
+ checkGrammarForDisallowedTrailingComma(g, parameters, 9 /* Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma */);
914
+ if (parameter.questionToken !== undefined)
915
+ return grammarErrorOnNode(g, parameter.questionToken, 34 /* Diagnostics.A_rest_parameter_cannot_be_optional */);
916
+ if (parameter.initializer !== undefined)
917
+ return grammarErrorOnNode(g, parameter.name, 35 /* Diagnostics.A_rest_parameter_cannot_have_an_initializer */);
918
+ }
919
+ else if (parameter.questionToken !== undefined) {
920
+ seenOptionalParameter = true;
921
+ // A reparsed `?` comes from a bracketed `@param` name.
922
+ if ((parameter.questionToken.flags & 8 /* NodeFlags.Reparsed */) === 0 && parameter.initializer !== undefined)
923
+ return grammarErrorOnNode(g, parameter.name, 11 /* Diagnostics.Parameter_cannot_have_question_mark_and_initializer */);
924
+ }
925
+ else if (seenOptionalParameter && parameter.initializer === undefined) {
926
+ return grammarErrorOnNode(g, parameter.name, 12 /* Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter */);
927
+ }
928
+ }
929
+ return false;
930
+ }
931
+ function checkGrammarForUseStrictSimpleParameterList(g, node) {
932
+ if (g.c.languageVersion < ScriptTarget.ES2016)
933
+ return false;
934
+ const body = getBody(node);
935
+ if (body === undefined || body.kind !== 242 /* SyntaxKind.Block */)
936
+ return false;
937
+ const useStrictDirective = findUseStrictPrologue(g.file, getStatements(body).nodes);
938
+ if (useStrictDirective === undefined)
939
+ return false;
940
+ const nonSimpleParameters = [];
941
+ for (const parameter of getParameters(node).nodes) {
942
+ const p = parameter;
943
+ if (p.initializer !== undefined || isBindingPattern(p.name) || p.dotDotDotToken !== undefined)
944
+ nonSimpleParameters.push(parameter);
945
+ }
946
+ if (nonSimpleParameters.length === 0)
947
+ return false;
948
+ for (const parameter of nonSimpleParameters) {
949
+ const diagnostic = g.c.error(parameter, 280 /* Diagnostics.This_parameter_is_not_allowed_with_use_strict_directive */);
950
+ addRelated(diagnostic, useStrictDirective, 283 /* Diagnostics.X_use_strict_directive_used_here */);
951
+ }
952
+ const diagnostic = g.c.error(useStrictDirective, 281 /* Diagnostics.X_use_strict_directive_cannot_be_used_with_non_simple_parameter_list */);
953
+ for (let i = 0; i < nonSimpleParameters.length; i++)
954
+ addRelated(diagnostic, nonSimpleParameters[i], i === 0 ? 282 /* Diagnostics.Non_simple_parameter_declared_here */ : 1357 /* Diagnostics.X_and_here */);
955
+ return true;
956
+ }
957
+ function checkGrammarArrowFunction(g, node) {
958
+ if (node.kind !== 220 /* SyntaxKind.ArrowFunction */)
959
+ return false;
960
+ const arrow = node;
961
+ const typeParameters = arrow.typeParameters;
962
+ if (typeParameters !== undefined) {
963
+ const nodes = typeParameters.nodes;
964
+ const hasConstraint = nodes.length > 0 && nodes[0].constraint !== undefined;
965
+ if (!(nodes.length > 1 || typeParameters.hasTrailingComma() || hasConstraint) &&
966
+ fileExtensionIsOneOf(g.file.fileName, ['.mts', '.cts']))
967
+ grammarErrorOnNode(g, nodes[0], 1731 /* Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Add_a_trailing_comma_or_explicit_constraint */);
968
+ }
969
+ const arrowToken = arrow.equalsGreaterThanToken;
970
+ if (arrowToken === undefined)
971
+ return false;
972
+ const lineStarts = g.file.lineStarts();
973
+ return (computeLineOfPosition(lineStarts, arrowToken.pos) !== computeLineOfPosition(lineStarts, arrowToken.end) &&
974
+ grammarErrorOnNode(g, arrowToken, 156 /* Diagnostics.Line_terminator_not_permitted_before_arrow */));
975
+ }
976
+ function checkGrammarForGenerator(g, node) {
977
+ const asteriskToken = getAsteriskToken(node);
978
+ if (asteriskToken === undefined)
979
+ return false;
980
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
981
+ return grammarErrorOnNode(g, asteriskToken, 171 /* Diagnostics.Generators_are_not_allowed_in_an_ambient_context */);
982
+ if (getBody(node) === undefined)
983
+ return grammarErrorOnNode(g, asteriskToken, 172 /* Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator */);
984
+ return false;
985
+ }
986
+ function isThisParameter(node) {
987
+ if (node.kind !== 170 /* SyntaxKind.Parameter */)
988
+ return false;
989
+ const name = node.name;
990
+ return name instanceof Identifier && name.text === 'this';
991
+ }
992
+ function getThisParameter(signature) {
993
+ const parameters = getParameters(signature);
994
+ if (parameters === undefined || parameters.nodes.length === 0)
995
+ return undefined;
996
+ const first = parameters.nodes[0];
997
+ return isThisParameter(first) ? first : undefined;
998
+ }
999
+ function isBindingPattern(node) {
1000
+ return (node !== undefined &&
1001
+ (node.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || node.kind === 208 /* SyntaxKind.ArrayBindingPattern */));
1002
+ }
1003
+ // ---- Signatures and members
1004
+ function checkGrammarIndexSignatureParameters(g, node) {
1005
+ const parameters = node.parameters.nodes;
1006
+ if (parameters.length === 0)
1007
+ return grammarErrorOnNode(g, node, 65 /* Diagnostics.An_index_signature_must_have_exactly_one_parameter */);
1008
+ const parameter = parameters[0];
1009
+ if (parameters.length !== 1)
1010
+ return grammarErrorOnNode(g, parameter.name, 65 /* Diagnostics.An_index_signature_must_have_exactly_one_parameter */);
1011
+ checkGrammarForDisallowedTrailingComma(g, node.parameters, 20 /* Diagnostics.An_index_signature_cannot_have_a_trailing_comma */);
1012
+ if (parameter.dotDotDotToken !== undefined)
1013
+ return grammarErrorOnNode(g, parameter.dotDotDotToken, 13 /* Diagnostics.An_index_signature_cannot_have_a_rest_parameter */);
1014
+ if (parameter.modifiers !== undefined)
1015
+ return grammarErrorOnNode(g, parameter.name, 14 /* Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier */);
1016
+ if (parameter.questionToken !== undefined)
1017
+ return grammarErrorOnNode(g, parameter.questionToken, 15 /* Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark */);
1018
+ if (parameter.initializer !== undefined)
1019
+ return grammarErrorOnNode(g, parameter.name, 16 /* Diagnostics.An_index_signature_parameter_cannot_have_an_initializer */);
1020
+ if (parameter.type === undefined)
1021
+ return grammarErrorOnNode(g, parameter.name, 18 /* Diagnostics.An_index_signature_parameter_must_have_a_type_annotation */);
1022
+ const t = getTypeFromTypeNode(g.c, parameter.type);
1023
+ if (someTypeHasFlags(t, 19456 /* TypeFlags.StringOrNumberLiteralOrUnique */) || isGenericType(g.c, t))
1024
+ return grammarErrorOnNode(g, parameter.name, 272 /* Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead */);
1025
+ if (!everyTypeIsValidIndexKey(g.c, t))
1026
+ return grammarErrorOnNode(g, parameter.name, 217 /* Diagnostics.An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type */);
1027
+ if (node.type === undefined)
1028
+ return grammarErrorOnNode(g, node, 17 /* Diagnostics.An_index_signature_must_have_a_type_annotation */);
1029
+ return false;
1030
+ }
1031
+ function someTypeHasFlags(t, flags) {
1032
+ if ((t.flags & 134217728 /* TypeFlags.Union */) === 0)
1033
+ return (t.flags & flags) !== 0;
1034
+ for (const member of t.types)
1035
+ if ((member.flags & flags) !== 0)
1036
+ return true;
1037
+ return false;
1038
+ }
1039
+ function everyTypeIsValidIndexKey(c, t) {
1040
+ if ((t.flags & 134217728 /* TypeFlags.Union */) === 0)
1041
+ return isValidIndexKeyType(c, t);
1042
+ for (const member of t.types)
1043
+ if (!isValidIndexKeyType(c, member))
1044
+ return false;
1045
+ return true;
1046
+ }
1047
+ function checkGrammarTypeArguments(g, typeArguments) {
1048
+ if (checkGrammarForDisallowedTrailingComma(g, typeArguments, 5 /* Diagnostics.Trailing_comma_not_allowed */))
1049
+ return true;
1050
+ if (typeArguments === undefined || typeArguments.nodes.length !== 0)
1051
+ return false;
1052
+ const start = typeArguments.pos - 1;
1053
+ const end = skipTrivia(g.file.text, typeArguments.end) + 1;
1054
+ return grammarErrorAtPos(g, start, end - start, 68 /* Diagnostics.Type_argument_list_cannot_be_empty */);
1055
+ }
1056
+ function checkGrammarExpressionWithTypeArguments(g, node) {
1057
+ const typeArguments = getTypeArguments(node);
1058
+ if (node.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */ &&
1059
+ node.expression.kind === 101 /* SyntaxKind.ImportKeyword */ &&
1060
+ typeArguments !== undefined)
1061
+ return grammarErrorOnNode(g, node, 262 /* Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments */);
1062
+ return checkGrammarTypeArguments(g, typeArguments);
1063
+ }
1064
+ function checkGrammarHeritageClause(g, clause) {
1065
+ const types = clause.types;
1066
+ if (checkGrammarForDisallowedTrailingComma(g, types, 5 /* Diagnostics.Trailing_comma_not_allowed */))
1067
+ return true;
1068
+ if (types.nodes.length === 0)
1069
+ return grammarErrorAtPos(g, types.pos, 0, 66 /* Diagnostics.X_0_list_cannot_be_empty */, tokenToString(clause.token));
1070
+ for (const type of types.nodes)
1071
+ if (checkGrammarExpressionWithTypeArguments(g, type))
1072
+ return true;
1073
+ return false;
1074
+ }
1075
+ function checkGrammarClassDeclaration(g, node) {
1076
+ const modifiers = getModifiers(node);
1077
+ if (g.legacyDecorators && modifiers !== undefined) {
1078
+ let firstDecorator;
1079
+ for (const modifier of modifiers.nodes)
1080
+ if (modifier.kind === 171 /* SyntaxKind.Decorator */) {
1081
+ firstDecorator = modifier;
1082
+ break;
1083
+ }
1084
+ if (firstDecorator !== undefined)
1085
+ for (const member of getMembers(node).nodes)
1086
+ if (hasSyntacticModifier(member, 256 /* ModifierFlags.Static */) && isPrivateIdentifierClassElementDeclaration(member)) {
1087
+ grammarErrorOnNode(g, firstDecorator, 1853 /* Diagnostics.Class_decorators_can_t_be_used_with_static_private_identifier_Consider_removing_the_experimental_decorator */);
1088
+ break;
1089
+ }
1090
+ }
1091
+ if (getName(node) === undefined && !hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */))
1092
+ grammarErrorOnFirstToken(g, node, 164 /* Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name */);
1093
+ checkGrammarClassLikeDeclaration(g, node);
1094
+ }
1095
+ function checkGrammarClassLikeDeclaration(g, node) {
1096
+ if (!checkGrammarClassDeclarationHeritageClauses(g, node))
1097
+ checkGrammarTypeParameterList(g, getTypeParameters(node));
1098
+ checkGrammarDecorators(g, node);
1099
+ // `implements` clause elements are checked again as type references.
1100
+ const clauses = getHeritageClauses(node);
1101
+ if (clauses !== undefined)
1102
+ for (const clause of clauses.nodes)
1103
+ if (clause.token === 118 /* SyntaxKind.ImplementsKeyword */)
1104
+ for (const type of clause.types.nodes)
1105
+ checkGrammarTypeArguments(g, getTypeArguments(type));
1106
+ }
1107
+ function checkGrammarClassDeclarationHeritageClauses(g, node) {
1108
+ let seenExtendsClause = false;
1109
+ let seenImplementsClause = false;
1110
+ const clauses = getHeritageClauses(node);
1111
+ if (checkGrammarModifiers(g, node) || clauses === undefined)
1112
+ return false;
1113
+ for (const clauseNode of clauses.nodes) {
1114
+ const clause = clauseNode;
1115
+ if (clause.token === 95 /* SyntaxKind.ExtendsKeyword */) {
1116
+ if (seenExtendsClause)
1117
+ return grammarErrorOnFirstToken(g, clause, 128 /* Diagnostics.X_extends_clause_already_seen */);
1118
+ if (seenImplementsClause)
1119
+ return grammarErrorOnFirstToken(g, clause, 129 /* Diagnostics.X_extends_clause_must_precede_implements_clause */);
1120
+ if (clause.types.nodes.length > 1)
1121
+ return grammarErrorOnFirstToken(g, clause.types.nodes[1], 130 /* Diagnostics.Classes_can_only_extend_a_single_class */);
1122
+ if (clause.types.nodes.length > 0) {
1123
+ const mismatch = findMismatchedAugmentsTag(node, clause.types.nodes[0]);
1124
+ if (mismatch !== undefined)
1125
+ return grammarErrorOnNode(g, mismatch.name, 1752 /* Diagnostics.JSDoc_0_1_does_not_match_the_extends_2_clause */, mismatch.tagName, mismatch.className, mismatch.extendsName);
1126
+ }
1127
+ seenExtendsClause = true;
1128
+ }
1129
+ else {
1130
+ if (seenImplementsClause)
1131
+ return grammarErrorOnFirstToken(g, clause, 131 /* Diagnostics.X_implements_clause_already_seen */);
1132
+ seenImplementsClause = true;
1133
+ }
1134
+ checkGrammarHeritageClause(g, clause);
1135
+ }
1136
+ return false;
1137
+ }
1138
+ function checkGrammarInterfaceDeclaration(g, node) {
1139
+ const clauses = getHeritageClauses(node);
1140
+ if (!checkGrammarModifiers(g, node) && clauses !== undefined) {
1141
+ let seenExtendsClause = false;
1142
+ for (const clauseNode of clauses.nodes) {
1143
+ const clause = clauseNode;
1144
+ if (clause.token === 95 /* SyntaxKind.ExtendsKeyword */) {
1145
+ if (seenExtendsClause) {
1146
+ grammarErrorOnFirstToken(g, clause, 128 /* Diagnostics.X_extends_clause_already_seen */);
1147
+ break;
1148
+ }
1149
+ seenExtendsClause = true;
1150
+ }
1151
+ else {
1152
+ grammarErrorOnFirstToken(g, clause, 132 /* Diagnostics.Interface_declaration_cannot_have_implements_clause */);
1153
+ break;
1154
+ }
1155
+ checkGrammarHeritageClause(g, clause);
1156
+ }
1157
+ }
1158
+ if (!containerAllowsBlockScopedVariable(node.parent))
1159
+ grammarErrorOnNode(g, node, 116 /* Diagnostics.X_0_declarations_can_only_be_declared_inside_a_block */, 'interface');
1160
+ // `extends` clause elements are checked again as type references.
1161
+ if (clauses !== undefined)
1162
+ for (const clause of clauses.nodes)
1163
+ if (clause.token === 95 /* SyntaxKind.ExtendsKeyword */)
1164
+ for (const type of clause.types.nodes)
1165
+ checkGrammarTypeArguments(g, getTypeArguments(type));
1166
+ }
1167
+ function checkGrammarComputedPropertyName(g, node) {
1168
+ if (node.kind !== 168 /* SyntaxKind.ComputedPropertyName */)
1169
+ return false;
1170
+ const expression = node.expression;
1171
+ return (expression.kind === 227 /* SyntaxKind.BinaryExpression */ &&
1172
+ expression.operatorToken.kind === 27 /* SyntaxKind.CommaToken */ &&
1173
+ grammarErrorOnNode(g, expression, 127 /* Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name */));
1174
+ }
1175
+ function checkGrammarForInvalidQuestionMark(g, postfixToken, message) {
1176
+ return (postfixToken !== undefined &&
1177
+ postfixToken.kind === 57 /* SyntaxKind.QuestionToken */ &&
1178
+ grammarErrorOnNode(g, postfixToken, message));
1179
+ }
1180
+ function checkGrammarForInvalidExclamationToken(g, postfixToken, message) {
1181
+ return (postfixToken !== undefined &&
1182
+ postfixToken.kind === 53 /* SyntaxKind.ExclamationToken */ &&
1183
+ grammarErrorOnNode(g, postfixToken, message));
1184
+ }
1185
+ /** Whether a name is dynamic and can't be late bound: its type isn't a literal or unique symbol. */
1186
+ function isNonBindableDynamicName(c, node) {
1187
+ if (!isDynamicName(node))
1188
+ return false;
1189
+ let expression;
1190
+ if (node.kind === 168 /* SyntaxKind.ComputedPropertyName */)
1191
+ expression = getExpression(node);
1192
+ else if (node instanceof ElementAccessExpression)
1193
+ expression = node.argumentExpression;
1194
+ if (expression === undefined || !isEntityNameExpression(expression, false))
1195
+ return true;
1196
+ const t = node.kind === 168 /* SyntaxKind.ComputedPropertyName */
1197
+ ? checkComputedPropertyName(c, node)
1198
+ : checkExpressionCached(c, expression);
1199
+ return !isTypeUsableAsPropertyName(t);
1200
+ }
1201
+ function checkGrammarForInvalidDynamicName(g, node, message) {
1202
+ if (!isNonBindableDynamicName(g.c, node))
1203
+ return false;
1204
+ const expression = node instanceof ElementAccessExpression ? skipParentheses(node.argumentExpression) : getExpression(node);
1205
+ return !isEntityNameExpression(expression, false) && grammarErrorOnNode(g, node, message);
1206
+ }
1207
+ function checkGrammarMethodDeclaration(g, node) {
1208
+ if (node.parent.kind === 211 /* SyntaxKind.ObjectLiteralExpression */) {
1209
+ // `checkObjectLiteralMethod` checks the method, then checks it again as a function expression.
1210
+ checkGrammarMethod(g, node);
1211
+ checkGrammarFunctionLikeDeclaration(g, node);
1212
+ return;
1213
+ }
1214
+ const name = getName(node);
1215
+ if (!checkGrammarMethod(g, node)) {
1216
+ checkGrammarComputedPropertyName(g, name);
1217
+ if (getAsteriskToken(node) !== undefined && name instanceof Identifier && name.text === 'constructor')
1218
+ g.c.error(name, 302 /* Diagnostics.Class_constructor_may_not_be_a_generator */);
1219
+ }
1220
+ checkGrammarDecorators(g, node);
1221
+ if (name.kind === 80 /* SyntaxKind.PrivateIdentifier */ && getContainingClass(node) === undefined)
1222
+ g.c.error(node, 1838 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
1223
+ }
1224
+ function checkGrammarMethod(g, node) {
1225
+ if (checkGrammarFunctionLikeDeclaration(g, node))
1226
+ return true;
1227
+ const parent = node.parent;
1228
+ if (node.kind === 175 /* SyntaxKind.MethodDeclaration */) {
1229
+ if (parent.kind === 211 /* SyntaxKind.ObjectLiteralExpression */) {
1230
+ // Only `async` is allowed on object literal methods.
1231
+ const modifiers = getModifiers(node);
1232
+ if (modifiers !== undefined &&
1233
+ !(modifiers.nodes.length === 1 && modifiers.nodes[0].kind === 133 /* SyntaxKind.AsyncKeyword */))
1234
+ return grammarErrorOnFirstToken(g, node, 140 /* Diagnostics.Modifiers_cannot_appear_here */);
1235
+ const postfixToken = getPostfixToken(node);
1236
+ if (checkGrammarForInvalidQuestionMark(g, postfixToken, 119 /* Diagnostics.An_object_member_cannot_be_declared_optional */))
1237
+ return true;
1238
+ if (checkGrammarForInvalidExclamationToken(g, postfixToken, 205 /* Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context */))
1239
+ return true;
1240
+ if (getBody(node) === undefined)
1241
+ return grammarErrorAtPos(g, node.end - 1, 1, 2 /* Diagnostics.X_0_expected */, '{');
1242
+ }
1243
+ if (checkGrammarForGenerator(g, node))
1244
+ return true;
1245
+ }
1246
+ const name = getName(node);
1247
+ if (isClassLike(parent)) {
1248
+ // Computed names are disallowed in ambient contexts for properties and accessors too, but
1249
+ // those report other errors first.
1250
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
1251
+ return checkGrammarForInvalidDynamicName(g, name, 122 /* Diagnostics.A_computed_property_name_in_an_ambient_context_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type */);
1252
+ if (node.kind === 175 /* SyntaxKind.MethodDeclaration */ && getBody(node) === undefined)
1253
+ return checkGrammarForInvalidDynamicName(g, name, 124 /* Diagnostics.A_computed_property_name_in_a_method_overload_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type */);
1254
+ }
1255
+ else if (parent.kind === 265 /* SyntaxKind.InterfaceDeclaration */) {
1256
+ return checkGrammarForInvalidDynamicName(g, name, 125 /* Diagnostics.A_computed_property_name_in_an_interface_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type */);
1257
+ }
1258
+ else if (parent.kind === 188 /* SyntaxKind.TypeLiteral */) {
1259
+ return checkGrammarForInvalidDynamicName(g, name, 126 /* Diagnostics.A_computed_property_name_in_a_type_literal_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type */);
1260
+ }
1261
+ return false;
1262
+ }
1263
+ function checkGrammarConstructorTypeParameters(g, node) {
1264
+ const range = node.typeParameters;
1265
+ if (range === undefined)
1266
+ return false;
1267
+ const pos = range.pos === range.end ? range.pos : skipTrivia(g.file.text, range.pos);
1268
+ return grammarErrorAtPos(g, pos, range.end - pos, 61 /* Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration */);
1269
+ }
1270
+ function checkGrammarAccessorDeclaration(g, node) {
1271
+ const name = getName(node);
1272
+ if (!checkGrammarFunctionLikeDeclaration(g, node) && !checkGrammarAccessor(g, node))
1273
+ checkGrammarComputedPropertyName(g, name);
1274
+ checkGrammarDecorators(g, node);
1275
+ }
1276
+ function checkGrammarAccessor(g, accessor) {
1277
+ const body = getBody(accessor);
1278
+ const parent = accessor.parent;
1279
+ const inTypeMember = parent.kind === 188 /* SyntaxKind.TypeLiteral */ || parent.kind === 265 /* SyntaxKind.InterfaceDeclaration */;
1280
+ const isAbstract = hasSyntacticModifier(accessor, 64 /* ModifierFlags.Abstract */);
1281
+ if ((accessor.flags & 8388608 /* NodeFlags.Ambient */) === 0 && !inTypeMember && body === undefined && !isAbstract)
1282
+ return grammarErrorAtPos(g, accessor.end - 1, 1, 2 /* Diagnostics.X_0_expected */, '{');
1283
+ if (body !== undefined) {
1284
+ if (isAbstract)
1285
+ return grammarErrorOnNode(g, accessor, 254 /* Diagnostics.An_abstract_accessor_cannot_have_an_implementation */);
1286
+ if (inTypeMember)
1287
+ return grammarErrorOnNode(g, body, 139 /* Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts */);
1288
+ }
1289
+ const name = getName(accessor);
1290
+ if (getTypeParameters(accessor) !== undefined)
1291
+ return grammarErrorOnNode(g, name, 63 /* Diagnostics.An_accessor_cannot_have_type_parameters */);
1292
+ const parameters = getParameters(accessor).nodes;
1293
+ const isGetter = accessor.kind === 178 /* SyntaxKind.GetAccessor */;
1294
+ // A `this` parameter only counts with the right number of other parameters.
1295
+ const hasThisParameter = parameters.length === (isGetter ? 1 : 2) && isThisParameter(parameters[0]);
1296
+ if (!hasThisParameter && parameters.length !== (isGetter ? 0 : 1))
1297
+ return grammarErrorOnNode(g, name, isGetter
1298
+ ? 40 /* Diagnostics.A_get_accessor_cannot_have_parameters */
1299
+ : 36 /* Diagnostics.A_set_accessor_must_have_exactly_one_parameter */);
1300
+ if (!isGetter) {
1301
+ if (getType(accessor) !== undefined)
1302
+ return grammarErrorOnNode(g, name, 64 /* Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation */);
1303
+ const parameter = parameters[hasThisParameter ? 1 : 0];
1304
+ if (parameter.dotDotDotToken !== undefined)
1305
+ return grammarErrorOnNode(g, parameter.dotDotDotToken, 39 /* Diagnostics.A_set_accessor_cannot_have_rest_parameter */);
1306
+ if (parameter.questionToken !== undefined)
1307
+ return grammarErrorOnNode(g, parameter.questionToken, 37 /* Diagnostics.A_set_accessor_cannot_have_an_optional_parameter */);
1308
+ if (parameter.initializer !== undefined)
1309
+ return grammarErrorOnNode(g, name, 38 /* Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer */);
1310
+ }
1311
+ return false;
1312
+ }
1313
+ function checkGrammarPropertyDeclaration(g, node) {
1314
+ if (!checkGrammarModifiers(g, node) && !checkGrammarProperty(g, node))
1315
+ checkGrammarComputedPropertyName(g, getName(node));
1316
+ }
1317
+ function checkGrammarProperty(g, node) {
1318
+ const name = getName(node);
1319
+ const parent = node.parent;
1320
+ if (name.kind === 168 /* SyntaxKind.ComputedPropertyName */) {
1321
+ const expression = name.expression;
1322
+ if (expression.kind === 227 /* SyntaxKind.BinaryExpression */ &&
1323
+ expression.operatorToken.kind === 102 /* SyntaxKind.InKeyword */)
1324
+ return grammarErrorOnNode(g, getMembers(parent).nodes[0], 1732 /* Diagnostics.A_mapped_type_may_not_declare_properties_or_methods */);
1325
+ }
1326
+ if (isClassLike(parent)) {
1327
+ if (name instanceof StringLiteral && name.text === 'constructor')
1328
+ return grammarErrorOnNode(g, name, 1829 /* Diagnostics.Classes_may_not_have_a_field_named_constructor */);
1329
+ if (checkGrammarForInvalidDynamicName(g, name, 123 /* Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_have_a_simple_literal_type_or_a_unique_symbol_type */))
1330
+ return true;
1331
+ if (isAutoAccessorPropertyDeclaration(node) &&
1332
+ checkGrammarForInvalidQuestionMark(g, getPostfixToken(node), 225 /* Diagnostics.An_accessor_property_cannot_be_declared_optional */))
1333
+ return true;
1334
+ }
1335
+ else if (parent.kind === 265 /* SyntaxKind.InterfaceDeclaration */) {
1336
+ if (checkGrammarForInvalidDynamicName(g, name, 125 /* Diagnostics.A_computed_property_name_in_an_interface_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type */))
1337
+ return true;
1338
+ const initializer = getInitializer(node);
1339
+ if (initializer !== undefined)
1340
+ return grammarErrorOnNode(g, initializer, 196 /* Diagnostics.An_interface_property_cannot_have_an_initializer */);
1341
+ }
1342
+ else if (parent.kind === 188 /* SyntaxKind.TypeLiteral */) {
1343
+ if (checkGrammarForInvalidDynamicName(g, name, 126 /* Diagnostics.A_computed_property_name_in_a_type_literal_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type */))
1344
+ return true;
1345
+ const initializer = getInitializer(node);
1346
+ if (initializer !== undefined)
1347
+ return grammarErrorOnNode(g, initializer, 197 /* Diagnostics.A_type_literal_property_cannot_have_an_initializer */);
1348
+ }
1349
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
1350
+ checkAmbientInitializer(g, node);
1351
+ if (node.kind === 173 /* SyntaxKind.PropertyDeclaration */) {
1352
+ const property = node;
1353
+ const postfixToken = property.postfixToken;
1354
+ if (postfixToken !== undefined && postfixToken.kind === 53 /* SyntaxKind.ExclamationToken */) {
1355
+ if (property.initializer !== undefined)
1356
+ return grammarErrorOnNode(g, postfixToken, 212 /* Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions */);
1357
+ if (property.type === undefined)
1358
+ return grammarErrorOnNode(g, postfixToken, 213 /* Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations */);
1359
+ if (!isClassLike(parent) ||
1360
+ (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0 ||
1361
+ isStatic(node) ||
1362
+ hasSyntacticModifier(node, 64 /* ModifierFlags.Abstract */))
1363
+ return grammarErrorOnNode(g, postfixToken, 205 /* Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context */);
1364
+ }
1365
+ }
1366
+ return false;
1367
+ }
1368
+ function checkAmbientInitializer(g, node) {
1369
+ const initializer = getInitializer(node);
1370
+ if (initializer === undefined)
1371
+ return false;
1372
+ const isInvalidInitializer = !(isInitializerStringOrNumberLiteralExpression(initializer) ||
1373
+ isInitializerSimpleLiteralEnumReference(g.c, initializer) ||
1374
+ initializer.kind === 111 /* SyntaxKind.TrueKeyword */ ||
1375
+ initializer.kind === 96 /* SyntaxKind.FalseKeyword */ ||
1376
+ isInitializerBigIntLiteralExpression(initializer));
1377
+ const isConstOrReadonly = isDeclarationReadonly(node) || (node.kind === 261 /* SyntaxKind.VariableDeclaration */ && isVarConstLike(node));
1378
+ if (!isConstOrReadonly || getType(node) !== undefined)
1379
+ return grammarErrorOnNode(g, initializer, 29 /* Diagnostics.Initializers_are_not_allowed_in_ambient_contexts */);
1380
+ if (isInvalidInitializer)
1381
+ return grammarErrorOnNode(g, initializer, 204 /* Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal_or_literal_enum_reference */);
1382
+ return false;
1383
+ }
1384
+ function isDeclarationReadonly(node) {
1385
+ return ((getCombinedModifierFlags(node) & 8 /* ModifierFlags.Readonly */) !== 0 &&
1386
+ !(node.kind === 170 /* SyntaxKind.Parameter */ && node.parent.kind === 177 /* SyntaxKind.Constructor */));
1387
+ }
1388
+ function isVarConstLike(node) {
1389
+ const blockScopeKind = getCombinedNodeFlags(node) & 7 /* NodeFlags.BlockScoped */;
1390
+ return (blockScopeKind === 2 /* NodeFlags.Const */ || blockScopeKind === 4 /* NodeFlags.Using */ || blockScopeKind === 6 /* NodeFlags.AwaitUsing */);
1391
+ }
1392
+ function isInitializerStringOrNumberLiteralExpression(expression) {
1393
+ switch (expression.kind) {
1394
+ case 10 /* SyntaxKind.StringLiteral */:
1395
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
1396
+ case 8 /* SyntaxKind.NumericLiteral */:
1397
+ return true;
1398
+ case 225 /* SyntaxKind.PrefixUnaryExpression */: {
1399
+ const unary = expression;
1400
+ return unary.operator === 40 /* SyntaxKind.MinusToken */ && unary.operand.kind === 8 /* SyntaxKind.NumericLiteral */;
1401
+ }
1402
+ }
1403
+ return false;
1404
+ }
1405
+ function isInitializerBigIntLiteralExpression(expression) {
1406
+ if (expression.kind === 9 /* SyntaxKind.BigIntLiteral */)
1407
+ return true;
1408
+ if (expression.kind !== 225 /* SyntaxKind.PrefixUnaryExpression */)
1409
+ return false;
1410
+ const unary = expression;
1411
+ return unary.operator === 40 /* SyntaxKind.MinusToken */ && unary.operand.kind === 9 /* SyntaxKind.BigIntLiteral */;
1412
+ }
1413
+ function isInitializerSimpleLiteralEnumReference(c, expression) {
1414
+ if (expression.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
1415
+ return (checkExpressionCached(c, expression).flags & 98304 /* TypeFlags.EnumLike */) !== 0;
1416
+ if (expression instanceof ElementAccessExpression)
1417
+ return (isInitializerStringOrNumberLiteralExpression(expression.argumentExpression) &&
1418
+ isEntityNameExpression(expression.expression, false) &&
1419
+ (checkExpressionCached(c, expression).flags & 98304 /* TypeFlags.EnumLike */) !== 0);
1420
+ return false;
1421
+ }
1422
+ // ---- Statements
1423
+ function checkGrammarStatementInAmbientContext(g, node) {
1424
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
1425
+ return false;
1426
+ const parent = node.parent;
1427
+ const id = getNodeId(node);
1428
+ if (!g.reportedAmbientStatements.has(id) && (isFunctionLike(parent) || isAccessor(parent))) {
1429
+ const reported = grammarErrorOnFirstToken(g, node, 139 /* Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts */);
1430
+ if (reported)
1431
+ g.reportedAmbientStatements.add(id);
1432
+ return reported;
1433
+ }
1434
+ // Report once per block; statements nested in other statements are covered by their parent.
1435
+ if (parent.kind === 242 /* SyntaxKind.Block */ ||
1436
+ parent.kind === 269 /* SyntaxKind.ModuleBlock */ ||
1437
+ parent.kind === 307 /* SyntaxKind.SourceFile */) {
1438
+ const parentId = getNodeId(parent);
1439
+ if (!g.reportedAmbientStatements.has(parentId)) {
1440
+ const reported = grammarErrorOnFirstToken(g, node, 27 /* Diagnostics.Statements_are_not_allowed_in_ambient_contexts */);
1441
+ if (reported)
1442
+ g.reportedAmbientStatements.add(parentId);
1443
+ return reported;
1444
+ }
1445
+ }
1446
+ return false;
1447
+ }
1448
+ function isAccessor(node) {
1449
+ return node.kind === 178 /* SyntaxKind.GetAccessor */ || node.kind === 179 /* SyntaxKind.SetAccessor */;
1450
+ }
1451
+ function checkGrammarVariableStatement(g, node) {
1452
+ if (!checkGrammarModifiers(g, node) && !checkGrammarVariableDeclarationList(g, node.declarationList))
1453
+ checkGrammarForDisallowedBlockScopedVariableStatement(g, node);
1454
+ }
1455
+ function checkGrammarForDisallowedBlockScopedVariableStatement(g, node) {
1456
+ if (containerAllowsBlockScopedVariable(node.parent))
1457
+ return;
1458
+ const blockScopeKind = getCombinedNodeFlags(node.declarationList) & 7 /* NodeFlags.BlockScoped */;
1459
+ if (blockScopeKind === 0)
1460
+ return;
1461
+ let keyword;
1462
+ if (blockScopeKind === 1 /* NodeFlags.Let */)
1463
+ keyword = 'let';
1464
+ else if (blockScopeKind === 2 /* NodeFlags.Const */)
1465
+ keyword = 'const';
1466
+ else if (blockScopeKind === 4 /* NodeFlags.Using */)
1467
+ keyword = 'using';
1468
+ else
1469
+ keyword = 'await using';
1470
+ g.c.error(node, 116 /* Diagnostics.X_0_declarations_can_only_be_declared_inside_a_block */, keyword);
1471
+ }
1472
+ function containerAllowsBlockScopedVariable(parent) {
1473
+ switch (parent.kind) {
1474
+ case 246 /* SyntaxKind.IfStatement */:
1475
+ case 247 /* SyntaxKind.DoStatement */:
1476
+ case 248 /* SyntaxKind.WhileStatement */:
1477
+ case 255 /* SyntaxKind.WithStatement */:
1478
+ case 249 /* SyntaxKind.ForStatement */:
1479
+ case 250 /* SyntaxKind.ForInStatement */:
1480
+ case 251 /* SyntaxKind.ForOfStatement */:
1481
+ return false;
1482
+ case 257 /* SyntaxKind.LabeledStatement */:
1483
+ return containerAllowsBlockScopedVariable(parent.parent);
1484
+ }
1485
+ return true;
1486
+ }
1487
+ function checkGrammarVariableDeclarationList(g, list) {
1488
+ const declarations = list.declarations;
1489
+ if (checkGrammarForDisallowedTrailingComma(g, declarations, 5 /* Diagnostics.Trailing_comma_not_allowed */))
1490
+ return true;
1491
+ if (declarations.nodes.length === 0)
1492
+ return grammarErrorAtPos(g, declarations.pos, declarations.end - declarations.pos, 90 /* Diagnostics.Variable_declaration_list_cannot_be_empty */);
1493
+ const blockScopeFlags = list.flags & 7 /* NodeFlags.BlockScoped */;
1494
+ const parent = list.parent;
1495
+ if (blockScopeFlags === 4 /* NodeFlags.Using */ || blockScopeFlags === 6 /* NodeFlags.AwaitUsing */) {
1496
+ const isUsing = blockScopeFlags === 4 /* NodeFlags.Using */;
1497
+ if (parent.kind === 250 /* SyntaxKind.ForInStatement */)
1498
+ return grammarErrorOnNode(g, list, isUsing
1499
+ ? 408 /* Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_using_declaration */
1500
+ : 409 /* Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_an_await_using_declaration */);
1501
+ if ((list.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
1502
+ return grammarErrorOnNode(g, list, isUsing
1503
+ ? 460 /* Diagnostics.X_using_declarations_are_not_allowed_in_ambient_contexts */
1504
+ : 461 /* Diagnostics.X_await_using_declarations_are_not_allowed_in_ambient_contexts */);
1505
+ if (parent.kind === 244 /* SyntaxKind.VariableStatement */ &&
1506
+ (parent.parent.kind === 297 /* SyntaxKind.CaseClause */ || parent.parent.kind === 298 /* SyntaxKind.DefaultClause */))
1507
+ return grammarErrorOnNode(g, list, isUsing
1508
+ ? 462 /* Diagnostics.X_using_declarations_are_not_allowed_in_case_or_default_clauses_unless_contained_within_a_block */
1509
+ : 463 /* Diagnostics.X_await_using_declarations_are_not_allowed_in_case_or_default_clauses_unless_contained_within_a_block */);
1510
+ }
1511
+ if (blockScopeFlags === 6 /* NodeFlags.AwaitUsing */)
1512
+ return checkGrammarAwaitOrAwaitUsing(g, list);
1513
+ return false;
1514
+ }
1515
+ function checkGrammarVariableDeclaration(g, node) {
1516
+ const nodeFlags = getCombinedNodeFlags(node);
1517
+ const blockScopeKind = nodeFlags & 7 /* NodeFlags.BlockScoped */;
1518
+ const name = node.name;
1519
+ if (isBindingPattern(name)) {
1520
+ if (blockScopeKind === 6 /* NodeFlags.AwaitUsing */)
1521
+ return grammarErrorOnNode(g, node, 407 /* Diagnostics.X_0_declarations_may_not_have_binding_patterns */, 'await using');
1522
+ if (blockScopeKind === 4 /* NodeFlags.Using */)
1523
+ return grammarErrorOnNode(g, node, 407 /* Diagnostics.X_0_declarations_may_not_have_binding_patterns */, 'using');
1524
+ }
1525
+ const statement = node.parent.parent;
1526
+ if (statement.kind !== 250 /* SyntaxKind.ForInStatement */ && statement.kind !== 251 /* SyntaxKind.ForOfStatement */) {
1527
+ if ((nodeFlags & 8388608 /* NodeFlags.Ambient */) !== 0)
1528
+ checkAmbientInitializer(g, node);
1529
+ else if (node.initializer === undefined) {
1530
+ if (isBindingPattern(name) && !isBindingPattern(node.parent))
1531
+ return grammarErrorOnNode(g, node, 138 /* Diagnostics.A_destructuring_declaration_must_have_an_initializer */);
1532
+ if (blockScopeKind === 6 /* NodeFlags.AwaitUsing */)
1533
+ return grammarErrorOnNode(g, node, 115 /* Diagnostics.X_0_declarations_must_be_initialized */, 'await using');
1534
+ if (blockScopeKind === 4 /* NodeFlags.Using */)
1535
+ return grammarErrorOnNode(g, node, 115 /* Diagnostics.X_0_declarations_must_be_initialized */, 'using');
1536
+ if (blockScopeKind === 2 /* NodeFlags.Const */)
1537
+ return grammarErrorOnNode(g, node, 115 /* Diagnostics.X_0_declarations_must_be_initialized */, 'const');
1538
+ }
1539
+ }
1540
+ const exclamationToken = node.exclamationToken;
1541
+ if (exclamationToken !== undefined &&
1542
+ (statement.kind !== 244 /* SyntaxKind.VariableStatement */ ||
1543
+ node.type === undefined ||
1544
+ node.initializer !== undefined ||
1545
+ (nodeFlags & 8388608 /* NodeFlags.Ambient */) !== 0)) {
1546
+ const message = node.initializer !== undefined
1547
+ ? 212 /* Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions */
1548
+ : node.type === undefined
1549
+ ? 213 /* Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations */
1550
+ : 205 /* Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context */;
1551
+ return grammarErrorOnNode(g, exclamationToken, message);
1552
+ }
1553
+ if (getEmitModuleFormat(g) < ModuleKind.System &&
1554
+ (statement.flags & 8388608 /* NodeFlags.Ambient */) === 0 &&
1555
+ hasSyntacticModifier(statement, 32 /* ModifierFlags.Export */))
1556
+ checkGrammarForEsModuleMarkerInBindingName(g, name);
1557
+ // `let` can't be a name in `let` or `const` declarations.
1558
+ return blockScopeKind !== 0 && checkGrammarNameInLetOrConstDeclarations(g, name);
1559
+ }
1560
+ function checkGrammarForEsModuleMarkerInBindingName(g, name) {
1561
+ if (name instanceof Identifier)
1562
+ return (name.text === '__esModule' &&
1563
+ grammarErrorOnNode(g, name, 169 /* Diagnostics.Identifier_expected_esModule_is_reserved_as_an_exported_marker_when_transforming_ECMAScript_modules */));
1564
+ for (const element of getElements(name).nodes) {
1565
+ const elementName = getName(element);
1566
+ if (elementName !== undefined)
1567
+ return checkGrammarForEsModuleMarkerInBindingName(g, elementName);
1568
+ }
1569
+ return false;
1570
+ }
1571
+ function checkGrammarNameInLetOrConstDeclarations(g, name) {
1572
+ if (name instanceof Identifier) {
1573
+ const identifier = name;
1574
+ if (identifier.text === 'let')
1575
+ return grammarErrorOnNode(g, name, 643 /* Diagnostics.X_let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations */);
1576
+ return false;
1577
+ }
1578
+ for (const element of getElements(name).nodes) {
1579
+ const elementName = getName(element);
1580
+ if (elementName !== undefined)
1581
+ checkGrammarNameInLetOrConstDeclarations(g, elementName);
1582
+ }
1583
+ return false;
1584
+ }
1585
+ function checkGrammarBindingElement(g, node) {
1586
+ if (node.dotDotDotToken !== undefined) {
1587
+ const elements = getElements(node.parent);
1588
+ if (node !== elements.nodes[elements.nodes.length - 1])
1589
+ return grammarErrorOnNode(g, node, 628 /* Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern */);
1590
+ checkGrammarForDisallowedTrailingComma(g, elements, 9 /* Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma */);
1591
+ if (node.propertyName !== undefined)
1592
+ return grammarErrorOnNode(g, node.name, 720 /* Diagnostics.A_rest_element_cannot_have_a_property_name */);
1593
+ // Report on the `=` before the initializer.
1594
+ if (node.initializer !== undefined)
1595
+ return grammarErrorAtPos(g, node.initializer.pos - 1, 1, 142 /* Diagnostics.A_rest_element_cannot_have_an_initializer */);
1596
+ }
1597
+ return false;
1598
+ }
1599
+ function checkGrammarForInOrForOfStatement(g, node) {
1600
+ checkGrammarForInOrForOfStatementWorker(g, node);
1601
+ // `checkForOfStatement` reports `for await` in static blocks after the statement's grammar.
1602
+ const awaitModifier = node.awaitModifier;
1603
+ if (node.kind === 251 /* SyntaxKind.ForOfStatement */ && awaitModifier !== undefined) {
1604
+ const container = getContainingFunctionOrClassStaticBlock(node);
1605
+ if (container !== undefined && container.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */)
1606
+ grammarErrorOnNode(g, awaitModifier, 1855 /* Diagnostics.X_for_await_loops_cannot_be_used_inside_a_class_static_block */);
1607
+ }
1608
+ return false;
1609
+ }
1610
+ function checkGrammarForInOrForOfStatementWorker(g, node) {
1611
+ if (checkGrammarStatementInAmbientContext(g, node))
1612
+ return true;
1613
+ const awaitModifier = node.awaitModifier;
1614
+ if (node.kind === 251 /* SyntaxKind.ForOfStatement */ &&
1615
+ awaitModifier !== undefined &&
1616
+ (node.flags & 8192 /* NodeFlags.AwaitContext */) === 0) {
1617
+ if (isInTopLevelContext(node)) {
1618
+ if (!g.hasParseErrors) {
1619
+ if (!isEffectiveExternalModule(g))
1620
+ g.c.addDiagnostic(createDiagnosticForNode(awaitModifier, 357 /* Diagnostics.X_for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */, []));
1621
+ const kind = checkTopLevelAwaitModule(g);
1622
+ if (kind === 1 /* TopLevelAwaitSupport.CommonJS */)
1623
+ g.c.addDiagnostic(createDiagnosticForNode(awaitModifier, 247 /* Diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level */, []));
1624
+ else if (kind === 2 /* TopLevelAwaitSupport.Unsupported */)
1625
+ g.c.addDiagnostic(createDiagnosticForNode(awaitModifier, 358 /* Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */, []));
1626
+ }
1627
+ }
1628
+ else if (!g.hasParseErrors) {
1629
+ // `for await` in a function that isn't async.
1630
+ const diagnostic = createDiagnosticForNode(awaitModifier, 72 /* Diagnostics.X_for_await_loops_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules */, []);
1631
+ const containingFunction = getContainingFunction(node);
1632
+ if (containingFunction !== undefined && containingFunction.kind !== 177 /* SyntaxKind.Constructor */)
1633
+ addRelated(diagnostic, containingFunction, 290 /* Diagnostics.Did_you_mean_to_mark_this_function_as_async */);
1634
+ g.c.addDiagnostic(diagnostic);
1635
+ return true;
1636
+ }
1637
+ }
1638
+ const initializer = node.initializer;
1639
+ if (node.kind === 251 /* SyntaxKind.ForOfStatement */ &&
1640
+ (node.flags & 8192 /* NodeFlags.AwaitContext */) === 0 &&
1641
+ initializer instanceof Identifier &&
1642
+ initializer.text === 'async') {
1643
+ grammarErrorOnNode(g, initializer, 75 /* Diagnostics.The_left_hand_side_of_a_for_of_statement_may_not_be_async */);
1644
+ return false;
1645
+ }
1646
+ if (initializer.kind !== 262 /* SyntaxKind.VariableDeclarationList */)
1647
+ return false;
1648
+ const list = initializer;
1649
+ if (checkGrammarVariableDeclarationList(g, list))
1650
+ return false;
1651
+ // Declarations can be empty after a parse error, as in `for (let of x)`.
1652
+ const declarations = list.declarations.nodes;
1653
+ if (declarations.length === 0)
1654
+ return false;
1655
+ const isForIn = node.kind === 250 /* SyntaxKind.ForInStatement */;
1656
+ if (declarations.length > 1)
1657
+ return grammarErrorOnFirstToken(g, declarations[1], isForIn
1658
+ ? 60 /* Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement */
1659
+ : 144 /* Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement */);
1660
+ const first = declarations[0];
1661
+ if (first.initializer !== undefined)
1662
+ return grammarErrorOnNode(g, first.name, isForIn
1663
+ ? 145 /* Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer */
1664
+ : 146 /* Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer */);
1665
+ if (first.type !== undefined)
1666
+ return grammarErrorOnNode(g, first, isForIn
1667
+ ? 575 /* Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation */
1668
+ : 645 /* Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation */);
1669
+ return false;
1670
+ }
1671
+ /** Whether the module and target options allow top-level `await`. */
1672
+ function checkTopLevelAwaitModule(g) {
1673
+ const moduleKind = g.moduleKind;
1674
+ if (moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext) {
1675
+ if (g.metadata.impliedNodeFormat === ModuleKind.CommonJS)
1676
+ return 1 /* TopLevelAwaitSupport.CommonJS */;
1677
+ }
1678
+ else if (moduleKind !== ModuleKind.ES2022 &&
1679
+ moduleKind !== ModuleKind.ESNext &&
1680
+ moduleKind !== ModuleKind.Preserve &&
1681
+ moduleKind !== ModuleKind.System)
1682
+ return 2 /* TopLevelAwaitSupport.Unsupported */;
1683
+ return g.c.languageVersion >= ScriptTarget.ES2017 ? 0 /* TopLevelAwaitSupport.Supported */ : 2 /* TopLevelAwaitSupport.Unsupported */;
1684
+ }
1685
+ function checkGrammarBreakOrContinueStatement(g, node) {
1686
+ const targetLabel = getLabel(node);
1687
+ const isBreak = node.kind === 253 /* SyntaxKind.BreakStatement */;
1688
+ for (let current = node; current !== undefined; current = current.parent) {
1689
+ if (isFunctionLike(current) || current.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */)
1690
+ return grammarErrorOnNode(g, node, 76 /* Diagnostics.Jump_target_cannot_cross_function_boundary */);
1691
+ if (current.kind === 257 /* SyntaxKind.LabeledStatement */) {
1692
+ const labeled = current;
1693
+ if (targetLabel !== undefined && labeled.label.text === getText(targetLabel)) {
1694
+ // `continue` can only target labels of iteration statements.
1695
+ if (!isBreak && !isIterationStatement(labeled.statement, true))
1696
+ return grammarErrorOnNode(g, node, 83 /* Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement */);
1697
+ return false;
1698
+ }
1699
+ }
1700
+ else if (current.kind === 256 /* SyntaxKind.SwitchStatement */) {
1701
+ if (isBreak && targetLabel === undefined)
1702
+ return false;
1703
+ }
1704
+ else if (isIterationStatement(current, false) && targetLabel === undefined) {
1705
+ return false;
1706
+ }
1707
+ }
1708
+ if (targetLabel !== undefined)
1709
+ return grammarErrorOnNode(g, node, isBreak
1710
+ ? 84 /* Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement */
1711
+ : 83 /* Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement */);
1712
+ return grammarErrorOnNode(g, node, isBreak
1713
+ ? 74 /* Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement */
1714
+ : 73 /* Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement */);
1715
+ }
1716
+ function isIterationStatement(node, lookInLabeledStatements) {
1717
+ switch (node.kind) {
1718
+ case 249 /* SyntaxKind.ForStatement */:
1719
+ case 250 /* SyntaxKind.ForInStatement */:
1720
+ case 251 /* SyntaxKind.ForOfStatement */:
1721
+ case 247 /* SyntaxKind.DoStatement */:
1722
+ case 248 /* SyntaxKind.WhileStatement */:
1723
+ return true;
1724
+ case 257 /* SyntaxKind.LabeledStatement */:
1725
+ return lookInLabeledStatements && isIterationStatement(node.statement, true);
1726
+ }
1727
+ return false;
1728
+ }
1729
+ /** Returns whether the statement's expression is checked. */
1730
+ function checkGrammarReturnStatement(g, node) {
1731
+ if (checkGrammarStatementInAmbientContext(g, node))
1732
+ return false;
1733
+ const container = getContainingFunctionOrClassStaticBlock(node);
1734
+ if (container !== undefined && container.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */) {
1735
+ grammarErrorOnFirstToken(g, node, 1857 /* Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block */);
1736
+ return false;
1737
+ }
1738
+ if (container === undefined) {
1739
+ grammarErrorOnFirstToken(g, node, 77 /* Diagnostics.A_return_statement_can_only_be_used_within_a_function_body */);
1740
+ return false;
1741
+ }
1742
+ return true;
1743
+ }
1744
+ function checkGrammarWithStatement(g, node) {
1745
+ if (!checkGrammarStatementInAmbientContext(g, node) && (node.flags & 8192 /* NodeFlags.AwaitContext */) !== 0)
1746
+ grammarErrorOnFirstToken(g, node, 245 /* Diagnostics.X_with_statements_are_not_allowed_in_an_async_function_block */);
1747
+ // The body of a `with` statement isn't checked.
1748
+ g.visitNode(node.expression);
1749
+ const start = skipTrivia(g.file.text, node.pos);
1750
+ grammarErrorAtPos(g, start, node.statement.pos - start, 581 /* Diagnostics.The_with_statement_is_not_supported_All_symbols_in_a_with_block_will_have_type_any */);
1751
+ }
1752
+ function checkGrammarSwitchStatement(g, node) {
1753
+ checkGrammarStatementInAmbientContext(g, node);
1754
+ let seenDefaultClause = false;
1755
+ for (const clause of node.caseBlock.clauses.nodes) {
1756
+ if (clause.kind !== 298 /* SyntaxKind.DefaultClause */)
1757
+ continue;
1758
+ if (!seenDefaultClause)
1759
+ seenDefaultClause = true;
1760
+ else {
1761
+ grammarErrorOnNode(g, clause, 81 /* Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement */);
1762
+ return;
1763
+ }
1764
+ }
1765
+ }
1766
+ function checkGrammarLabeledStatement(g, node) {
1767
+ if (checkGrammarStatementInAmbientContext(g, node))
1768
+ return;
1769
+ const label = node.label;
1770
+ for (let current = node.parent; current !== undefined && !isFunctionLike(current); current = current.parent)
1771
+ if (current.kind === 257 /* SyntaxKind.LabeledStatement */ && current.label.text === label.text) {
1772
+ grammarErrorOnNode(g, label, 82 /* Diagnostics.Duplicate_label_0 */, label.text);
1773
+ return;
1774
+ }
1775
+ }
1776
+ function checkGrammarCatchClause(g, node) {
1777
+ const declaration = node.variableDeclaration;
1778
+ if (declaration === undefined)
1779
+ return;
1780
+ const typeNode = declaration.type;
1781
+ if (typeNode !== undefined) {
1782
+ const t = getTypeFromTypeNode(g.c, typeNode);
1783
+ if ((t.flags & 3 /* TypeFlags.AnyOrUnknown */) === 0)
1784
+ grammarErrorOnFirstToken(g, typeNode, 152 /* Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified */);
1785
+ }
1786
+ else if (declaration.initializer !== undefined) {
1787
+ grammarErrorOnFirstToken(g, declaration.initializer, 153 /* Diagnostics.Catch_clause_variable_cannot_have_an_initializer */);
1788
+ }
1789
+ else {
1790
+ const blockLocals = getLocals(node.block);
1791
+ const locals = getLocals(node);
1792
+ if (blockLocals === undefined || locals === undefined)
1793
+ return;
1794
+ for (const caughtName of locals.keys()) {
1795
+ const blockLocal = blockLocals.get(caughtName);
1796
+ if (blockLocal !== undefined &&
1797
+ blockLocal.valueDeclaration !== undefined &&
1798
+ (blockLocal.flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0)
1799
+ grammarErrorOnNode(g, blockLocal.valueDeclaration, 652 /* Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause */, caughtName);
1800
+ }
1801
+ }
1802
+ }
1803
+ function getContainingFunction(node) {
1804
+ let current = node.parent;
1805
+ while (current !== undefined && !isFunctionLike(current))
1806
+ current = current.parent;
1807
+ return current;
1808
+ }
1809
+ export function getContainingFunctionOrClassStaticBlock(node) {
1810
+ let current = node.parent;
1811
+ while (current !== undefined && !isFunctionLike(current) && current.kind !== 176 /* SyntaxKind.ClassStaticBlockDeclaration */)
1812
+ current = current.parent;
1813
+ return current;
1814
+ }
1815
+ // ---- Modules, imports and exports
1816
+ function checkGrammarTopLevelElementsForRequiredDeclareModifier(g, file) {
1817
+ for (const statement of file.statements.nodes) {
1818
+ if (!isDeclarationNode(statement) && statement.kind !== 244 /* SyntaxKind.VariableStatement */)
1819
+ continue;
1820
+ // Everything but interfaces, type aliases, imports and exports needs `declare` or `export`.
1821
+ switch (statement.kind) {
1822
+ case 265 /* SyntaxKind.InterfaceDeclaration */:
1823
+ case 266 /* SyntaxKind.TypeAliasDeclaration */:
1824
+ case 273 /* SyntaxKind.ImportDeclaration */:
1825
+ case 346 /* SyntaxKind.JSImportDeclaration */:
1826
+ case 272 /* SyntaxKind.ImportEqualsDeclaration */:
1827
+ case 279 /* SyntaxKind.ExportDeclaration */:
1828
+ case 278 /* SyntaxKind.ExportAssignment */:
1829
+ case 271 /* SyntaxKind.NamespaceExportDeclaration */:
1830
+ continue;
1831
+ }
1832
+ if (hasSyntacticModifier(statement, 128 /* ModifierFlags.Ambient */ | 32 /* ModifierFlags.Export */ | 2048 /* ModifierFlags.Default */))
1833
+ continue;
1834
+ if (grammarErrorOnFirstToken(g, statement, 33 /* Diagnostics.Top_level_declarations_in_d_ts_files_must_start_with_either_a_declare_or_export_modifier */))
1835
+ return true;
1836
+ }
1837
+ return false;
1838
+ }
1839
+ function checkGrammarModuleElementContext(g, node, message) {
1840
+ const parent = node.parent;
1841
+ const isInAppropriateContext = parent.kind === 307 /* SyntaxKind.SourceFile */ ||
1842
+ parent.kind === 269 /* SyntaxKind.ModuleBlock */ ||
1843
+ parent.kind === 268 /* SyntaxKind.ModuleDeclaration */;
1844
+ if (!isInAppropriateContext)
1845
+ grammarErrorOnFirstToken(g, node, message);
1846
+ return !isInAppropriateContext;
1847
+ }
1848
+ function checkGrammarModuleDeclaration(g, node) {
1849
+ // The declaration check reports an illegal context and skips the rest.
1850
+ const parent = node.parent.kind;
1851
+ if (parent !== 307 /* SyntaxKind.SourceFile */ && parent !== 269 /* SyntaxKind.ModuleBlock */ && parent !== 268 /* SyntaxKind.ModuleDeclaration */)
1852
+ return true;
1853
+ if (!checkGrammarModifiers(g, node) &&
1854
+ (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 &&
1855
+ node.name.kind === 10 /* SyntaxKind.StringLiteral */)
1856
+ grammarErrorOnNode(g, node.name, 26 /* Diagnostics.Only_ambient_modules_can_use_quoted_names */);
1857
+ return true;
1858
+ }
1859
+ /** Checks an import or export with a module specifier; reports and returns `false` if it is invalid. */
1860
+ function checkExternalImportOrExportDeclaration(g, node) {
1861
+ const moduleName = getExternalModuleName(node);
1862
+ // A missing name is a parse error.
1863
+ if (moduleName === undefined || moduleName.pos === moduleName.end)
1864
+ return false;
1865
+ if (moduleName.kind !== 10 /* SyntaxKind.StringLiteral */) {
1866
+ g.c.error(moduleName, 107 /* Diagnostics.String_literal_expected */);
1867
+ return false;
1868
+ }
1869
+ const parent = node.parent;
1870
+ const inAmbientExternalModule = parent.kind === 269 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
1871
+ if (parent.kind !== 307 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule) {
1872
+ g.c.error(moduleName, node.kind === 279 /* SyntaxKind.ExportDeclaration */
1873
+ ? 150 /* Diagnostics.Export_declarations_are_not_permitted_in_a_namespace */
1874
+ : 112 /* Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module */);
1875
+ return false;
1876
+ }
1877
+ if (inAmbientExternalModule &&
1878
+ isExternalModuleNameRelative(moduleName.text) &&
1879
+ !isModuleAugmentationExternal(parent.parent)) {
1880
+ // Module augmentations report relative names when checking the augmentation.
1881
+ g.c.error(node, 607 /* Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name */);
1882
+ return false;
1883
+ }
1884
+ if (node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */)
1885
+ return true;
1886
+ const attributes = getImportAttributes(node);
1887
+ if (attributes === undefined)
1888
+ return true;
1889
+ let hasError = false;
1890
+ for (const attribute of attributes.attributes.nodes) {
1891
+ const value = attribute.value;
1892
+ if (value.kind !== 10 /* SyntaxKind.StringLiteral */) {
1893
+ hasError = true;
1894
+ g.c.error(value, 978 /* Diagnostics.Import_attribute_values_must_be_string_literal_expressions */);
1895
+ }
1896
+ }
1897
+ return !hasError;
1898
+ }
1899
+ function getImportAttributes(node) {
1900
+ if (node.kind === 273 /* SyntaxKind.ImportDeclaration */ || node.kind === 346 /* SyntaxKind.JSImportDeclaration */)
1901
+ return node.attributes;
1902
+ if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
1903
+ return node.attributes;
1904
+ return undefined;
1905
+ }
1906
+ function checkGrammarImportDeclaration(g, node) {
1907
+ if (checkGrammarModuleElementContext(g, node, isInJSFile(node)
1908
+ ? 388 /* Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module */
1909
+ : 182 /* Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module */))
1910
+ return;
1911
+ if (!checkGrammarModifiers(g, node) && node.modifiers !== undefined)
1912
+ grammarErrorOnFirstToken(g, node, 147 /* Diagnostics.An_import_declaration_cannot_have_modifiers */);
1913
+ const clause = node.importClause;
1914
+ if (checkExternalImportOrExportDeclaration(g, node) && clause !== undefined)
1915
+ checkGrammarImportClause(g, clause);
1916
+ checkGrammarImportAttributes(g, node);
1917
+ }
1918
+ function checkGrammarImportClause(g, node) {
1919
+ const namedBindings = node.namedBindings;
1920
+ if (node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */) {
1921
+ if ((node.flags & 4194304 /* NodeFlags.JSDoc */) === 0 && node.name !== undefined && namedBindings !== undefined)
1922
+ return grammarErrorOnNode(g, node, 297 /* Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both */);
1923
+ if (namedBindings !== undefined && namedBindings.kind === 276 /* SyntaxKind.NamedImports */)
1924
+ return checkGrammarTypeOnlyNamedImportsOrExports(g, namedBindings);
1925
+ }
1926
+ else if (node.phaseModifier === 166 /* SyntaxKind.DeferKeyword */) {
1927
+ if (node.name !== undefined)
1928
+ return grammarErrorOnNode(g, node, 1873 /* Diagnostics.Default_imports_are_not_allowed_in_a_deferred_import */);
1929
+ if (namedBindings !== undefined && namedBindings.kind === 276 /* SyntaxKind.NamedImports */)
1930
+ return grammarErrorOnNode(g, node, 1874 /* Diagnostics.Named_imports_are_not_allowed_in_a_deferred_import */);
1931
+ if (g.moduleKind !== ModuleKind.ESNext && g.moduleKind !== ModuleKind.Preserve)
1932
+ return grammarErrorOnNode(g, node, 1875 /* Diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_or_preserve */);
1933
+ }
1934
+ return false;
1935
+ }
1936
+ function checkGrammarTypeOnlyNamedImportsOrExports(g, namedBindings) {
1937
+ const isImport = namedBindings.kind === 276 /* SyntaxKind.NamedImports */;
1938
+ for (const specifier of getElements(namedBindings).nodes)
1939
+ if (getIsTypeOnly(specifier))
1940
+ return grammarErrorOnFirstToken(g, specifier, isImport
1941
+ ? 471 /* Diagnostics.The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement */
1942
+ : 472 /* Diagnostics.The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement */);
1943
+ return false;
1944
+ }
1945
+ function checkGrammarImportEqualsDeclaration(g, node) {
1946
+ if (checkGrammarModuleElementContext(g, node, isInJSFile(node)
1947
+ ? 388 /* Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module */
1948
+ : 182 /* Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module */))
1949
+ return;
1950
+ checkGrammarModifiers(g, node);
1951
+ const isExternal = node.moduleReference.kind === 284 /* SyntaxKind.ExternalModuleReference */;
1952
+ if (!isExternal) {
1953
+ if (node.isTypeOnly) {
1954
+ const symbol = getSymbolOfDeclaration(g.c, node);
1955
+ if (symbol !== undefined && resolveAlias(g.c, symbol) !== g.c.unknownSymbol)
1956
+ grammarErrorOnNode(g, node, 318 /* Diagnostics.An_import_alias_cannot_use_import_type */);
1957
+ }
1958
+ return;
1959
+ }
1960
+ if (checkExternalImportOrExportDeclaration(g, node) &&
1961
+ g.moduleKind >= ModuleKind.ES2015 &&
1962
+ g.moduleKind <= ModuleKind.ESNext &&
1963
+ !node.isTypeOnly &&
1964
+ (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
1965
+ // Import assignments can't be emitted as ECMAScript modules.
1966
+ grammarErrorOnNode(g, node, 157 /* Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead */);
1967
+ }
1968
+ function checkGrammarExportDeclaration(g, node) {
1969
+ if (checkGrammarModuleElementContext(g, node, 183 /* Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module */))
1970
+ return;
1971
+ if (!checkGrammarModifiers(g, node) && node.modifiers !== undefined)
1972
+ grammarErrorOnFirstToken(g, node, 149 /* Diagnostics.An_export_declaration_cannot_have_modifiers */);
1973
+ const clause = node.exportClause;
1974
+ if (node.isTypeOnly && clause !== undefined && clause.kind === 280 /* SyntaxKind.NamedExports */)
1975
+ checkGrammarTypeOnlyNamedImportsOrExports(g, clause);
1976
+ const hasModuleSpecifier = node.moduleSpecifier !== undefined;
1977
+ if ((!hasModuleSpecifier || checkExternalImportOrExportDeclaration(g, node)) &&
1978
+ clause !== undefined &&
1979
+ clause.kind === 280 /* SyntaxKind.NamedExports */) {
1980
+ for (const specifier of getElements(clause).nodes) {
1981
+ checkGrammarModuleExportName(g, specifier.propertyName, hasModuleSpecifier);
1982
+ checkGrammarModuleExportName(g, specifier.name, true);
1983
+ }
1984
+ const parent = node.parent;
1985
+ const inAmbientExternalModule = parent.kind === 269 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
1986
+ const inAmbientNamespaceDeclaration = !inAmbientExternalModule &&
1987
+ parent.kind === 269 /* SyntaxKind.ModuleBlock */ &&
1988
+ !hasModuleSpecifier &&
1989
+ (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
1990
+ if (parent.kind !== 307 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule && !inAmbientNamespaceDeclaration)
1991
+ g.c.error(node, 150 /* Diagnostics.Export_declarations_are_not_permitted_in_a_namespace */);
1992
+ }
1993
+ checkGrammarImportAttributes(g, node);
1994
+ }
1995
+ function checkGrammarModuleExportName(g, name, allowStringLiteral) {
1996
+ if (name === undefined || name.kind !== 10 /* SyntaxKind.StringLiteral */)
1997
+ return;
1998
+ if (!allowStringLiteral)
1999
+ grammarErrorOnNode(g, name, 1 /* Diagnostics.Identifier_expected */);
2000
+ else if ((g.moduleKind === ModuleKind.ES2015 || g.moduleKind === ModuleKind.ES2020) && !g.file.isDeclarationFile)
2001
+ grammarErrorOnNode(g, name, 1872 /* Diagnostics.String_literal_import_and_export_names_are_not_supported_when_the_module_flag_is_set_to_es2015_or_es2020 */);
2002
+ }
2003
+ /** Returns whether the export's expression is checked. */
2004
+ function checkGrammarExportAssignment(g, node) {
2005
+ const isExportEquals = node.isExportEquals;
2006
+ if (checkGrammarModuleElementContext(g, node, isExportEquals
2007
+ ? 181 /* Diagnostics.An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration */
2008
+ : 207 /* Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration */))
2009
+ return false;
2010
+ const parent = node.parent;
2011
+ const container = parent.kind === 307 /* SyntaxKind.SourceFile */ ? parent : parent.parent;
2012
+ if (container.kind === 268 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container)) {
2013
+ g.c.error(node, isExportEquals
2014
+ ? 48 /* Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace */
2015
+ : 255 /* Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module */);
2016
+ return false;
2017
+ }
2018
+ if (!checkGrammarModifiers(g, node) && node.modifiers !== undefined)
2019
+ grammarErrorOnFirstToken(g, node, 88 /* Diagnostics.An_export_assignment_cannot_have_modifiers */);
2020
+ const isAmbient = (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
2021
+ if (isAmbient && !isEntityNameExpression(node.expression, false))
2022
+ grammarErrorOnNode(g, node.expression, 846 /* Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context */);
2023
+ if (isExportEquals) {
2024
+ const impliedFormat = getImpliedNodeFormatForEmit(g.file.fileName, g.moduleKind, g.metadata);
2025
+ // Export assignments aren't supported in ECMAScript modules.
2026
+ if (g.moduleKind >= ModuleKind.ES2015 &&
2027
+ g.moduleKind !== ModuleKind.Preserve &&
2028
+ (isAmbient ? impliedFormat === ModuleKind.ESNext : impliedFormat !== ModuleKind.CommonJS))
2029
+ grammarErrorOnNode(g, node, 158 /* Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead */);
2030
+ else if (g.moduleKind === ModuleKind.System && !isAmbient)
2031
+ grammarErrorOnNode(g, node, 170 /* Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system */);
2032
+ }
2033
+ return true;
2034
+ }
2035
+ function getEmitModuleFormat(g) {
2036
+ return getEmitModuleFormatOfFile(g.file.fileName, g.c.compilerOptions, g.metadata);
2037
+ }
2038
+ function isEffectiveExternalModule(g) {
2039
+ if (isExternalModule(g.file))
2040
+ return true;
2041
+ const moduleKind = g.moduleKind;
2042
+ const commonJSContaining = moduleKind === ModuleKind.CommonJS || (moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext);
2043
+ return commonJSContaining && g.file.commonJSModuleIndicator !== undefined;
2044
+ }
2045
+ // ---- Type nodes
2046
+ function checkGrammarTypeReference(g, node) {
2047
+ checkGrammarTypeArguments(g, node.typeArguments);
2048
+ const typeArguments = node.typeArguments;
2049
+ if ((node.flags & 4194304 /* NodeFlags.JSDoc */) !== 0 || typeArguments === undefined || node.typeName.end === typeArguments.pos)
2050
+ return;
2051
+ // `Foo.<T>` is JSDoc syntax. A token starting with `<`, as in `Foo<T>`, is not a dot, which
2052
+ // saves creating a scanner over the file.
2053
+ if (g.file.text.charCodeAt(node.typeName.end) === 60 /* CharacterCodes.lessThan */)
2054
+ return;
2055
+ const scanner = g.getScanner();
2056
+ scanner.resetTokenState(node.typeName.end);
2057
+ if (scanner.scan() === 24 /* SyntaxKind.DotToken */)
2058
+ grammarErrorAtPos(g, skipTrivia(g.file.text, node.typeName.end), 1, 1749 /* Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments */);
2059
+ }
2060
+ function checkGrammarTypeOperatorNode(g, node) {
2061
+ const innerType = node.type;
2062
+ if (node.operator === 158 /* SyntaxKind.UniqueKeyword */) {
2063
+ if (innerType.kind !== 155 /* SyntaxKind.SymbolKeyword */)
2064
+ return grammarErrorOnNode(g, innerType, 2 /* Diagnostics.X_0_expected */, tokenToString(155 /* SyntaxKind.SymbolKeyword */));
2065
+ let parent = node.parent;
2066
+ while (parent.kind === 197 /* SyntaxKind.ParenthesizedType */)
2067
+ parent = parent.parent;
2068
+ switch (parent.kind) {
2069
+ case 261 /* SyntaxKind.VariableDeclaration */: {
2070
+ const declaration = parent;
2071
+ if (declaration.name.kind !== 79 /* SyntaxKind.Identifier */)
2072
+ return grammarErrorOnNode(g, node, 269 /* Diagnostics.X_unique_symbol_types_may_not_be_used_on_a_variable_declaration_with_a_binding_name */);
2073
+ if (!(declaration.parent.kind === 262 /* SyntaxKind.VariableDeclarationList */ &&
2074
+ declaration.parent.parent.kind === 244 /* SyntaxKind.VariableStatement */))
2075
+ return grammarErrorOnNode(g, node, 270 /* Diagnostics.X_unique_symbol_types_are_only_allowed_on_variables_in_a_variable_statement */);
2076
+ if ((declaration.parent.flags & 2 /* NodeFlags.Const */) === 0)
2077
+ return grammarErrorOnNode(g, declaration.name, 268 /* Diagnostics.A_variable_whose_type_is_a_unique_symbol_type_must_be_const */);
2078
+ return false;
2079
+ }
2080
+ case 173 /* SyntaxKind.PropertyDeclaration */:
2081
+ if (!isStatic(parent) || !hasSyntacticModifier(parent, 8 /* ModifierFlags.Readonly */))
2082
+ return grammarErrorOnNode(g, getName(parent), 267 /* Diagnostics.A_property_of_a_class_whose_type_is_a_unique_symbol_type_must_be_both_static_and_readonly */);
2083
+ return false;
2084
+ case 172 /* SyntaxKind.PropertySignature */:
2085
+ if (!hasSyntacticModifier(parent, 8 /* ModifierFlags.Readonly */))
2086
+ return grammarErrorOnNode(g, getName(parent), 266 /* Diagnostics.A_property_of_an_interface_or_type_literal_whose_type_is_a_unique_symbol_type_must_be_readonly */);
2087
+ return false;
2088
+ }
2089
+ return grammarErrorOnNode(g, node, 271 /* Diagnostics.X_unique_symbol_types_are_not_allowed_here */);
2090
+ }
2091
+ if (node.operator === 148 /* SyntaxKind.ReadonlyKeyword */ &&
2092
+ innerType.kind !== 189 /* SyntaxKind.ArrayType */ &&
2093
+ innerType.kind !== 190 /* SyntaxKind.TupleType */)
2094
+ return grammarErrorOnFirstToken(g, node, 288 /* Diagnostics.X_readonly_type_modifier_is_only_permitted_on_array_and_tuple_literal_types */, tokenToString(155 /* SyntaxKind.SymbolKeyword */));
2095
+ return false;
2096
+ }
2097
+ function checkGrammarInferType(g, node) {
2098
+ for (let current = node; current !== undefined; current = current.parent) {
2099
+ const parent = current.parent;
2100
+ if (parent !== undefined &&
2101
+ parent.kind === 195 /* SyntaxKind.ConditionalType */ &&
2102
+ parent.extendsType === current)
2103
+ return;
2104
+ }
2105
+ grammarErrorOnNode(g, node, 273 /* Diagnostics.X_infer_declarations_are_only_permitted_in_the_extends_clause_of_a_conditional_type */);
2106
+ }
2107
+ function checkGrammarTupleType(g, node) {
2108
+ let seenOptionalElement = false;
2109
+ let seenRestElement = false;
2110
+ for (const element of node.elements.nodes) {
2111
+ let flags = getTupleElementFlags(g.c, element);
2112
+ if ((flags & 8 /* ElementFlags.Variadic */) !== 0) {
2113
+ const t = getTypeFromTypeNode(g.c, getType(element));
2114
+ // `checkTupleType` reports non-array rest types and stops.
2115
+ if (!isArrayLikeType(g.c, t))
2116
+ break;
2117
+ if (isArrayType(g.c, t) || (isTupleType(t) && (tupleTargetOf(t).combinedFlags & 4 /* ElementFlags.Rest */) !== 0))
2118
+ flags |= 4 /* ElementFlags.Rest */;
2119
+ }
2120
+ if ((flags & 4 /* ElementFlags.Rest */) !== 0) {
2121
+ if (seenRestElement) {
2122
+ grammarErrorOnNode(g, element, 214 /* Diagnostics.A_rest_element_cannot_follow_another_rest_element */);
2123
+ break;
2124
+ }
2125
+ seenRestElement = true;
2126
+ }
2127
+ else if ((flags & 2 /* ElementFlags.Optional */) !== 0) {
2128
+ if (seenRestElement) {
2129
+ grammarErrorOnNode(g, element, 215 /* Diagnostics.An_optional_element_cannot_follow_a_rest_element */);
2130
+ break;
2131
+ }
2132
+ seenOptionalElement = true;
2133
+ }
2134
+ else if ((flags & 1 /* ElementFlags.Required */) !== 0 && seenOptionalElement) {
2135
+ grammarErrorOnNode(g, element, 206 /* Diagnostics.A_required_element_cannot_follow_an_optional_element */);
2136
+ break;
2137
+ }
2138
+ }
2139
+ }
2140
+ function checkGrammarNamedTupleMember(g, node) {
2141
+ if (node.dotDotDotToken !== undefined && node.questionToken !== undefined)
2142
+ grammarErrorOnNode(g, node, 1159 /* Diagnostics.A_tuple_member_cannot_be_both_optional_and_rest */);
2143
+ if (node.type.kind === 191 /* SyntaxKind.OptionalType */)
2144
+ grammarErrorOnNode(g, node.type, 1160 /* Diagnostics.A_labeled_tuple_element_is_declared_as_optional_with_a_question_mark_after_the_name_and_before_the_colon_rather_than_after_the_type */);
2145
+ if (node.type.kind === 192 /* SyntaxKind.RestType */)
2146
+ grammarErrorOnNode(g, node.type, 1161 /* Diagnostics.A_labeled_tuple_element_is_declared_as_rest_with_a_before_the_name_rather_than_before_the_type */);
2147
+ }
2148
+ /** JSDoc-only type syntax in TypeScript code. */
2149
+ function checkGrammarJSDocTypeInTypeScript(g, node) {
2150
+ if ((node.flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0)
2151
+ return;
2152
+ if (node.kind !== 312 /* SyntaxKind.JSDocNonNullableType */ && node.kind !== 311 /* SyntaxKind.JSDocNullableType */) {
2153
+ grammarErrorOnNode(g, node, 1749 /* Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments */);
2154
+ return;
2155
+ }
2156
+ const isNullable = node.kind === 311 /* SyntaxKind.JSDocNullableType */;
2157
+ const typeNode = getType(node);
2158
+ const postfix = node.pos === typeNode.pos;
2159
+ let t = getTypeFromTypeNode(g.c, typeNode);
2160
+ if (isNullable && t !== g.c.neverType && t !== g.c.voidType)
2161
+ t = getNullableType(g.c, t, postfix ? 4 /* TypeFlags.Undefined */ : 12 /* TypeFlags.Nullable */);
2162
+ grammarErrorOnNode(g, node, postfix
2163
+ ? 1822 /* Diagnostics.X_0_at_the_end_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1 */
2164
+ : 1823 /* Diagnostics.X_0_at_the_start_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1 */, isNullable ? '?' : '!', typeToString(g.c, t));
2165
+ }
2166
+ /** The `resolution-mode` of import type attributes, as tsgo's `getResolutionModeOverride`. */
2167
+ function getResolutionModeOverride(g, node, reportErrors) {
2168
+ const attributes = node.attributes.nodes;
2169
+ if (attributes.length !== 1) {
2170
+ if (reportErrors)
2171
+ grammarErrorOnNode(g, node, 384 /* Diagnostics.Type_import_attributes_should_have_exactly_one_key_resolution_mode_with_value_import_or_require */);
2172
+ return ModuleKind.None;
2173
+ }
2174
+ const attribute = attributes[0];
2175
+ const name = attribute.name;
2176
+ if (name === undefined || !isStringLiteralLike(name))
2177
+ return ModuleKind.None;
2178
+ if (getText(name) !== 'resolution-mode') {
2179
+ if (reportErrors)
2180
+ grammarErrorOnNode(g, name, 383 /* Diagnostics.X_resolution_mode_is_the_only_valid_key_for_type_import_attributes */);
2181
+ return ModuleKind.None;
2182
+ }
2183
+ const value = attribute.value;
2184
+ if (!isStringLiteralLike(value))
2185
+ return ModuleKind.None;
2186
+ const text = getText(value);
2187
+ if (text === 'import')
2188
+ return ModuleKind.ESNext;
2189
+ if (text === 'require')
2190
+ return ModuleKind.CommonJS;
2191
+ if (reportErrors)
2192
+ grammarErrorOnNode(g, value, 374 /* Diagnostics.X_resolution_mode_should_be_either_require_or_import */);
2193
+ return ModuleKind.None;
2194
+ }
2195
+ /** The grammar of `checkImportAttributes` for import and export declarations. */
2196
+ function checkGrammarImportAttributes(g, declaration) {
2197
+ const node = getImportAttributes(declaration);
2198
+ if (node === undefined)
2199
+ return;
2200
+ const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(declaration);
2201
+ const override = getResolutionModeOverride(g, node, isTypeOnly);
2202
+ // Other checks don't apply to type-only imports with a resolution mode.
2203
+ if (isTypeOnly && override !== ModuleKind.None)
2204
+ return;
2205
+ const moduleKind = g.moduleKind;
2206
+ if (!((moduleKind >= ModuleKind.Node18 && moduleKind <= ModuleKind.NodeNext) ||
2207
+ moduleKind === ModuleKind.Preserve ||
2208
+ moduleKind === ModuleKind.ESNext)) {
2209
+ grammarErrorOnNode(g, node, 954 /* Diagnostics.Import_attributes_are_only_supported_when_the_module_option_is_set_to_esnext_node18_node20_nodenext_or_preserve */);
2210
+ return;
2211
+ }
2212
+ const moduleSpecifier = getExternalModuleName(declaration);
2213
+ if (moduleSpecifier !== undefined &&
2214
+ isStringLiteralLike(moduleSpecifier) &&
2215
+ getEmitSyntaxOfImportOrExport(g) === ModuleKind.CommonJS) {
2216
+ grammarErrorOnNode(g, node, 976 /* Diagnostics.Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls */);
2217
+ return;
2218
+ }
2219
+ if (isTypeOnly) {
2220
+ grammarErrorOnNode(g, node, 977 /* Diagnostics.Import_attributes_cannot_be_used_with_type_only_imports_or_exports */);
2221
+ return;
2222
+ }
2223
+ if (override !== ModuleKind.None)
2224
+ grammarErrorOnNode(g, node, 375 /* Diagnostics.X_resolution_mode_can_only_be_set_for_type_only_imports */);
2225
+ }
2226
+ function isExclusivelyTypeOnlyImportOrExport(node) {
2227
+ if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
2228
+ return node.isTypeOnly;
2229
+ if (node.kind !== 273 /* SyntaxKind.ImportDeclaration */ && node.kind !== 346 /* SyntaxKind.JSImportDeclaration */)
2230
+ return false;
2231
+ const clause = node.importClause;
2232
+ return clause !== undefined && clause.phaseModifier === 156 /* SyntaxKind.TypeKeyword */;
2233
+ }
2234
+ /** The module syntax an import or export declaration is emitted as. */
2235
+ function getEmitSyntaxOfImportOrExport(g) {
2236
+ const format = getEmitModuleFormat(g);
2237
+ if (format === ModuleKind.CommonJS)
2238
+ return ModuleKind.CommonJS;
2239
+ if ((format >= ModuleKind.ES2015 && format <= ModuleKind.ESNext) || format === ModuleKind.Preserve)
2240
+ return ModuleKind.ESNext;
2241
+ return ModuleKind.None;
2242
+ }
2243
+ function checkGrammarObjectLiteralExpression(g, node, inDestructuring) {
2244
+ const seen = new Map();
2245
+ for (const property of node.properties.nodes) {
2246
+ if (property.kind === 305 /* SyntaxKind.SpreadAssignment */) {
2247
+ if (inDestructuring) {
2248
+ // A rest property can't be destructured further.
2249
+ const expression = skipParentheses(getExpression(property));
2250
+ if (expression.kind === 210 /* SyntaxKind.ArrayLiteralExpression */ ||
2251
+ expression.kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
2252
+ return grammarErrorOnNode(g, getExpression(property), 661 /* Diagnostics.A_rest_element_cannot_contain_a_binding_pattern */);
2253
+ }
2254
+ continue;
2255
+ }
2256
+ const name = getName(property);
2257
+ if (name.kind === 168 /* SyntaxKind.ComputedPropertyName */)
2258
+ checkGrammarComputedPropertyName(g, name);
2259
+ if (property.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */ && !inDestructuring) {
2260
+ // An initializer is only valid in a destructuring pattern; report on the `=`.
2261
+ const shorthand = property;
2262
+ const equalsToken = shorthand.equalsToken;
2263
+ if (shorthand.objectAssignmentInitializer !== undefined)
2264
+ grammarErrorOnFirstToken(g, equalsToken !== undefined ? equalsToken : shorthand.name, 248 /* Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern */);
2265
+ }
2266
+ if (name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
2267
+ grammarErrorOnNode(g, name, 1838 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
2268
+ // Only `async` is allowed, and only on methods.
2269
+ const modifiers = getModifiers(property);
2270
+ if (modifiers !== undefined)
2271
+ for (const modifier of modifiers.nodes)
2272
+ if (isModifierKind(modifier.kind) &&
2273
+ (modifier.kind !== 133 /* SyntaxKind.AsyncKeyword */ || property.kind !== 175 /* SyntaxKind.MethodDeclaration */))
2274
+ grammarErrorOnNode(g, modifier, 31 /* Diagnostics.X_0_modifier_cannot_be_used_here */, getTextOfNodeFromSourceText(g.file.text, modifier));
2275
+ // Duplicate data properties are errors in strict mode only, but accessors and data
2276
+ // properties never mix, and get/set accessors can't repeat (ECMA-262 11.1.5).
2277
+ let currentKind;
2278
+ switch (property.kind) {
2279
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
2280
+ case 303 /* SyntaxKind.PropertyAssignment */: {
2281
+ const postfixToken = getPostfixToken(property);
2282
+ checkGrammarForInvalidExclamationToken(g, postfixToken, 205 /* Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context */);
2283
+ checkGrammarForInvalidQuestionMark(g, postfixToken, 119 /* Diagnostics.An_object_member_cannot_be_declared_optional */);
2284
+ if (name.kind === 9 /* SyntaxKind.BigIntLiteral */)
2285
+ g.c.addDiagnostic(createDiagnosticForNode(name, 454 /* Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name */, []));
2286
+ currentKind = 4 /* DeclarationMeaning.PropertyAssignment */;
2287
+ break;
2288
+ }
2289
+ case 175 /* SyntaxKind.MethodDeclaration */:
2290
+ currentKind = 8 /* DeclarationMeaning.Method */;
2291
+ break;
2292
+ case 178 /* SyntaxKind.GetAccessor */:
2293
+ currentKind = 1 /* DeclarationMeaning.GetAccessor */;
2294
+ break;
2295
+ default:
2296
+ currentKind = 2 /* DeclarationMeaning.SetAccessor */;
2297
+ break;
2298
+ }
2299
+ if (inDestructuring)
2300
+ continue;
2301
+ const effectiveName = getEffectivePropertyNameForPropertyNameNode(g.c, name);
2302
+ if (effectiveName === undefined)
2303
+ continue;
2304
+ const existingKind = seen.get(effectiveName);
2305
+ if (existingKind === undefined) {
2306
+ seen.set(effectiveName, currentKind);
2307
+ continue;
2308
+ }
2309
+ if ((currentKind & 8 /* DeclarationMeaning.Method */) !== 0 && (existingKind & 8 /* DeclarationMeaning.Method */) !== 0)
2310
+ grammarErrorOnNode(g, name, 478 /* Diagnostics.Duplicate_identifier_0 */, getTextOfNodeFromSourceText(g.file.text, name));
2311
+ else if ((currentKind & 4 /* DeclarationMeaning.PropertyAssignment */) !== 0 &&
2312
+ (existingKind & 4 /* DeclarationMeaning.PropertyAssignment */) !== 0)
2313
+ grammarErrorOnNode(g, name, 85 /* Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name */, getTextOfNodeFromSourceText(g.file.text, name));
2314
+ else if ((currentKind & 3 /* DeclarationMeaning.GetOrSetAccessor */) !== 0 &&
2315
+ (existingKind & 3 /* DeclarationMeaning.GetOrSetAccessor */) !== 0) {
2316
+ if (existingKind !== 3 /* DeclarationMeaning.GetOrSetAccessor */ && currentKind !== existingKind)
2317
+ seen.set(effectiveName, currentKind | existingKind);
2318
+ else
2319
+ return grammarErrorOnNode(g, name, 86 /* Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name */);
2320
+ }
2321
+ else {
2322
+ return grammarErrorOnNode(g, name, 87 /* Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name */);
2323
+ }
2324
+ }
2325
+ return false;
2326
+ }
2327
+ /** The property name a literal or computed name denotes, if known. */
2328
+ function getEffectivePropertyNameForPropertyNameNode(c, name) {
2329
+ switch (name.kind) {
2330
+ case 79 /* SyntaxKind.Identifier */:
2331
+ case 80 /* SyntaxKind.PrivateIdentifier */:
2332
+ case 10 /* SyntaxKind.StringLiteral */:
2333
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
2334
+ case 8 /* SyntaxKind.NumericLiteral */:
2335
+ case 9 /* SyntaxKind.BigIntLiteral */:
2336
+ return getText(name);
2337
+ case 168 /* SyntaxKind.ComputedPropertyName */: {
2338
+ const expression = name.expression;
2339
+ switch (expression.kind) {
2340
+ case 10 /* SyntaxKind.StringLiteral */:
2341
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
2342
+ case 8 /* SyntaxKind.NumericLiteral */:
2343
+ return getText(expression);
2344
+ case 225 /* SyntaxKind.PrefixUnaryExpression */: {
2345
+ const unary = expression;
2346
+ if (unary.operand.kind === 8 /* SyntaxKind.NumericLiteral */ &&
2347
+ (unary.operator === 40 /* SyntaxKind.MinusToken */ || unary.operator === 39 /* SyntaxKind.PlusToken */))
2348
+ return unary.operator === 40 /* SyntaxKind.MinusToken */ ? '-' + getText(unary.operand) : getText(unary.operand);
2349
+ break;
2350
+ }
2351
+ }
2352
+ const t = getTypeOfExpression(c, expression);
2353
+ return (t.flags & (16384 /* TypeFlags.UniqueESSymbol */ | 1024 /* TypeFlags.StringLiteral */ | 2048 /* TypeFlags.NumberLiteral */)) !== 0
2354
+ ? getPropertyNameFromType(t)
2355
+ : undefined;
2356
+ }
2357
+ }
2358
+ return undefined;
2359
+ }
2360
+ function checkGrammarCallExpression(g, node) {
2361
+ const callee = node.expression;
2362
+ const isImportCall = callee.kind === 101 /* SyntaxKind.ImportKeyword */ ||
2363
+ (callee.kind === 237 /* SyntaxKind.MetaProperty */ &&
2364
+ callee.keywordToken === 101 /* SyntaxKind.ImportKeyword */ &&
2365
+ callee.name.text === 'defer');
2366
+ if (isImportCall)
2367
+ checkGrammarImportCallExpression(g, node);
2368
+ else
2369
+ checkGrammarTypeArguments(g, node.typeArguments);
2370
+ }
2371
+ function checkGrammarImportCallExpression(g, node) {
2372
+ const moduleKind = g.moduleKind;
2373
+ if (g.c.compilerOptions.verbatimModuleSyntax === true && moduleKind === ModuleKind.CommonJS)
2374
+ return grammarErrorOnNode(g, node, fileExtensionIsOneOf(g.file.fileName, ['.cts', '.cjs'])
2375
+ ? 235 /* Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax */
2376
+ : 244 /* Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax_Adjust_the_type_field_in_the_nearest_package_json_to_make_this_file_an_ECMAScript_module_or_adjust_your_verbatimModuleSyntax_module_and_moduleResolution_settings_in_TypeScript */);
2377
+ if (node.expression.kind === 237 /* SyntaxKind.MetaProperty */) {
2378
+ if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.Preserve)
2379
+ return grammarErrorOnNode(g, node, 1875 /* Diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_or_preserve */);
2380
+ }
2381
+ else if (moduleKind === ModuleKind.ES2015)
2382
+ return grammarErrorOnNode(g, node, 259 /* Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node16_node18_node20_or_nodenext */);
2383
+ if (node.typeArguments !== undefined)
2384
+ return grammarErrorOnNode(g, node, 262 /* Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments */);
2385
+ const args = node.arguments;
2386
+ const argumentNodes = args.nodes;
2387
+ if (!(moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext) &&
2388
+ moduleKind !== ModuleKind.ESNext &&
2389
+ moduleKind !== ModuleKind.Preserve) {
2390
+ // Import attributes allow a trailing comma.
2391
+ checkGrammarForDisallowedTrailingComma(g, args, 5 /* Diagnostics.Trailing_comma_not_allowed */);
2392
+ if (argumentNodes.length > 1)
2393
+ return grammarErrorOnNode(g, argumentNodes[1], 260 /* Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_node16_node18_node20_nodenext_or_preserve */);
2394
+ }
2395
+ if (argumentNodes.length === 0 || argumentNodes.length > 2)
2396
+ return grammarErrorOnNode(g, node, 372 /* Diagnostics.Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_set_of_attributes_as_arguments */);
2397
+ // Arguments are parsed like array elements, which allows spreads.
2398
+ for (const argument of argumentNodes)
2399
+ if (argument.kind === 231 /* SyntaxKind.SpreadElement */)
2400
+ return grammarErrorOnNode(g, argument, 261 /* Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element */);
2401
+ return false;
2402
+ }
2403
+ function checkGrammarTaggedTemplateChain(g, node) {
2404
+ if (node.questionDotToken === undefined && (node.flags & 32 /* NodeFlags.OptionalChain */) === 0)
2405
+ return false;
2406
+ return grammarErrorOnNode(g, node.template, 292 /* Diagnostics.Tagged_template_expressions_are_not_permitted_in_an_optional_chain */);
2407
+ }
2408
+ function checkGrammarMetaProperty(g, node) {
2409
+ const name = node.name;
2410
+ const nameText = name.text;
2411
+ if (node.keywordToken === 104 /* SyntaxKind.NewKeyword */) {
2412
+ if (nameText !== 'target')
2413
+ return grammarErrorOnNode(g, name, 1815 /* Diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2 */, nameText, tokenToString(node.keywordToken), 'target');
2414
+ }
2415
+ else if (node.keywordToken === 101 /* SyntaxKind.ImportKeyword */ && nameText !== 'meta') {
2416
+ const parent = node.parent;
2417
+ const isCallee = parent.kind === 214 /* SyntaxKind.CallExpression */ && parent.expression === node;
2418
+ if (nameText === 'defer') {
2419
+ if (!isCallee)
2420
+ return grammarErrorAtPos(g, node.end, 0, 2 /* Diagnostics.X_0_expected */, '(');
2421
+ }
2422
+ else {
2423
+ if (isCallee)
2424
+ return grammarErrorOnNode(g, name, 1876 /* Diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_or_defer */, nameText);
2425
+ return grammarErrorOnNode(g, name, 1815 /* Diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2 */, nameText, tokenToString(node.keywordToken), 'meta');
2426
+ }
2427
+ }
2428
+ return false;
2429
+ }
2430
+ function checkGrammarAwaitOrAwaitUsing(g, node) {
2431
+ const isAwaitExpression = node.kind === 224 /* SyntaxKind.AwaitExpression */;
2432
+ let hasError = false;
2433
+ const container = getContainingFunctionOrClassStaticBlock(node);
2434
+ if (container !== undefined && container.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */) {
2435
+ // Reported even with parse errors.
2436
+ g.c.error(node, isAwaitExpression
2437
+ ? 1854 /* Diagnostics.X_await_expression_cannot_be_used_inside_a_class_static_block */
2438
+ : 1869 /* Diagnostics.X_await_using_statements_cannot_be_used_inside_a_class_static_block */);
2439
+ hasError = true;
2440
+ }
2441
+ else if ((node.flags & 8192 /* NodeFlags.AwaitContext */) === 0) {
2442
+ if (isInTopLevelContext(node)) {
2443
+ if (!g.hasParseErrors) {
2444
+ if (!isEffectiveExternalModule(g)) {
2445
+ g.c.addDiagnostic(diagnosticAtFirstToken(g, node, isAwaitExpression
2446
+ ? 304 /* Diagnostics.X_await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */
2447
+ : 973 /* Diagnostics.X_await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */));
2448
+ hasError = true;
2449
+ }
2450
+ const support = checkTopLevelAwaitModule(g);
2451
+ if (support === 1 /* TopLevelAwaitSupport.CommonJS */) {
2452
+ g.c.addDiagnostic(diagnosticAtFirstToken(g, node, 247 /* Diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level */));
2453
+ hasError = true;
2454
+ }
2455
+ else if (support === 2 /* TopLevelAwaitSupport.Unsupported */) {
2456
+ g.c.addDiagnostic(diagnosticAtFirstToken(g, node, isAwaitExpression
2457
+ ? 307 /* Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */
2458
+ : 974 /* Diagnostics.Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */));
2459
+ hasError = true;
2460
+ }
2461
+ }
2462
+ }
2463
+ else if (!g.hasParseErrors) {
2464
+ // `await` in a function that isn't async.
2465
+ const diagnostic = diagnosticAtFirstToken(g, node, isAwaitExpression
2466
+ ? 246 /* Diagnostics.X_await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules */
2467
+ : 972 /* Diagnostics.X_await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules */);
2468
+ if (container !== undefined &&
2469
+ container.kind !== 177 /* SyntaxKind.Constructor */ &&
2470
+ !hasSyntacticModifier(container, 1024 /* ModifierFlags.Async */))
2471
+ addRelated(diagnostic, container, 290 /* Diagnostics.Did_you_mean_to_mark_this_function_as_async */);
2472
+ g.c.addDiagnostic(diagnostic);
2473
+ hasError = true;
2474
+ }
2475
+ }
2476
+ if (isAwaitExpression && isInParameterInitializerBeforeContainingFunction(node)) {
2477
+ // Reported even with parse errors.
2478
+ g.c.error(node, 683 /* Diagnostics.X_await_expressions_cannot_be_used_in_a_parameter_initializer */);
2479
+ hasError = true;
2480
+ }
2481
+ return hasError;
2482
+ }
2483
+ function checkGrammarYieldExpression(g, node) {
2484
+ let hasError = false;
2485
+ if ((node.flags & 2048 /* NodeFlags.YieldContext */) === 0) {
2486
+ grammarErrorOnFirstToken(g, node, 120 /* Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body */);
2487
+ hasError = true;
2488
+ }
2489
+ if (isInParameterInitializerBeforeContainingFunction(node)) {
2490
+ g.c.error(node, 682 /* Diagnostics.X_yield_expressions_cannot_be_used_in_a_parameter_initializer */);
2491
+ hasError = true;
2492
+ }
2493
+ return hasError;
2494
+ }
2495
+ function isInParameterInitializerBeforeContainingFunction(node) {
2496
+ let inBindingInitializer = false;
2497
+ let current = node;
2498
+ while (current.parent !== undefined && !isFunctionLike(current.parent)) {
2499
+ const parent = current.parent;
2500
+ if (parent.kind === 170 /* SyntaxKind.Parameter */ && (inBindingInitializer || getInitializer(parent) === current))
2501
+ return true;
2502
+ if (parent.kind === 209 /* SyntaxKind.BindingElement */ && getInitializer(parent) === current)
2503
+ inBindingInitializer = true;
2504
+ current = parent;
2505
+ }
2506
+ return false;
2507
+ }
2508
+ /** A private name in an expression, which is only valid as `#x in obj`. */
2509
+ function checkGrammarPrivateIdentifierExpression(g, node) {
2510
+ const parent = node.parent;
2511
+ // Names of members and property accesses aren't expressions.
2512
+ if (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || getName(parent) === node)
2513
+ return false;
2514
+ const isForIn = parent.kind === 250 /* SyntaxKind.ForInStatement */;
2515
+ if (getContainingClass(node) === undefined)
2516
+ return grammarErrorOnNode(g, node, 1838 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
2517
+ if (isForIn)
2518
+ return false;
2519
+ const isLeftOfIn = parent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
2520
+ parent.left === node &&
2521
+ parent.operatorToken.kind === 102 /* SyntaxKind.InKeyword */;
2522
+ if (!isLeftOfIn)
2523
+ return grammarErrorOnNode(g, node, 373 /* Diagnostics.Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression */);
2524
+ return false;
2525
+ }
2526
+ function checkGrammarBigIntLiteral(g, node) {
2527
+ const parent = node.parent;
2528
+ // Like tsgo, only BigInt literals checked as expressions are reported, not property or member names.
2529
+ if (getName(parent) === node)
2530
+ return false;
2531
+ const isLiteralType = parent.kind === 202 /* SyntaxKind.LiteralType */ ||
2532
+ (parent.kind === 225 /* SyntaxKind.PrefixUnaryExpression */ && parent.parent.kind === 202 /* SyntaxKind.LiteralType */);
2533
+ // BigInt literals are fine in types and ambient contexts.
2534
+ return (!isLiteralType &&
2535
+ (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 &&
2536
+ g.c.languageVersion < ScriptTarget.ES2020 &&
2537
+ grammarErrorOnNode(g, node, 869 /* Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020 */));
2538
+ }
2539
+ /** Reports the errors of rescanning a regular expression; spelling suggestions become related information. */
2540
+ class RegularExpressionErrorReporter extends ScannerErrorReporter {
2541
+ g;
2542
+ lastError = undefined;
2543
+ constructor(g) {
2544
+ super();
2545
+ this.g = g;
2546
+ }
2547
+ onError(message, start, length, args) {
2548
+ const lastError = this.lastError;
2549
+ if (messageCategory(message) === 3 /* DiagnosticCategory.Message */ &&
2550
+ lastError !== undefined &&
2551
+ start === lastError.pos &&
2552
+ length === lastError.end - lastError.pos) {
2553
+ lastError.relatedInformation.push(new Diagnostic(undefined, start, start + length, message, args));
2554
+ }
2555
+ else if (lastError === undefined || start !== lastError.pos) {
2556
+ const diagnostic = new Diagnostic(this.g.file.diagnosticFile(), start, start + length, message, args);
2557
+ this.lastError = diagnostic;
2558
+ this.g.c.addDiagnostic(diagnostic);
2559
+ }
2560
+ }
2561
+ }
2562
+ function checkGrammarRegularExpressionLiteral(g, node) {
2563
+ if (g.hasParseErrors)
2564
+ return false;
2565
+ const scanner = g.getScanner();
2566
+ const reporter = new RegularExpressionErrorReporter(g);
2567
+ scanner.setOnError(reporter);
2568
+ scanner.resetTokenState(node.pos);
2569
+ scanner.scan();
2570
+ scanner.reScanSlashToken(true);
2571
+ scanner.setOnError(undefined);
2572
+ return reporter.lastError !== undefined;
2573
+ }