@runeditrun/rer 0.2.83 → 0.2.85

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 (269) hide show
  1. package/README.md +21 -24
  2. package/cli/README.md +17 -1
  3. package/cli/authoring.mjs +1 -0
  4. package/cli/bounded.mjs +1 -1
  5. package/cli/business/carry.mjs +149 -0
  6. package/cli/business/command.mjs +6 -1
  7. package/cli/business/connect.mjs +1 -1
  8. package/cli/business/local-commands.mjs +2 -0
  9. package/cli/business/opt-ins.mjs +8 -4
  10. package/cli/business/questions.mjs +4 -1
  11. package/cli/business/state.mjs +1 -1
  12. package/cli/business/supervisor.mjs +7 -1
  13. package/cli/container-transfer.mjs +2 -2
  14. package/cli/contract.mjs +7 -7
  15. package/cli/demo-host.mjs +5 -1
  16. package/cli/demo-native.mjs +2 -1
  17. package/cli/demo.mjs +6 -1
  18. package/cli/deploy-command.mjs +6 -4
  19. package/cli/deploy.mjs +9 -7
  20. package/cli/errors.mjs +1 -1
  21. package/cli/export.mjs +1 -1
  22. package/cli/human-error.mjs +20 -0
  23. package/cli/lifecycle.mjs +23 -5
  24. package/cli/main.mjs +1 -1
  25. package/cli/managed-data-schema.mjs +114 -0
  26. package/cli/managed-data-zip.mjs +116 -0
  27. package/cli/managed-data.mjs +110 -0
  28. package/cli/managed-server.mjs +25 -14
  29. package/cli/native-owner-entry.mjs +86 -0
  30. package/cli/output.mjs +3 -2
  31. package/cli/parse.mjs +3 -3
  32. package/cli/portability-empty.mjs +59 -0
  33. package/cli/portability-migrations.mjs +7 -5
  34. package/cli/portability-policy.mjs +5 -2
  35. package/cli/portability-worker.mjs +15 -6
  36. package/cli/portability.mjs +30 -8
  37. package/cli/ready-summary.mjs +9 -0
  38. package/cli/run-transfers.mjs +37 -0
  39. package/cli/runtime-front-door.mjs +4 -4
  40. package/cli/server-proxy.mjs +4 -3
  41. package/cli/server-registry.mjs +13 -8
  42. package/cli/site.mjs +6 -1
  43. package/cli/transfers.mjs +17 -4
  44. package/edition-authoring/base-copies.mjs +125 -30
  45. package/edition-authoring/copy-checkout.mjs +7 -120
  46. package/edition-authoring/edition-migrations.mjs +41 -0
  47. package/edition-authoring/files.mjs +67 -0
  48. package/edition-authoring/lock.mjs +2 -2
  49. package/edition-authoring/module-closure.mjs +232 -0
  50. package/edition-authoring/module-edges.mjs +100 -0
  51. package/edition-authoring/module-resolution.mjs +66 -0
  52. package/edition-authoring/module-syntax.mjs +57 -0
  53. package/edition-authoring/package-target.mjs +92 -0
  54. package/edition-authoring/runtime-dependencies.mjs +74 -97
  55. package/edition-authoring/vendor/babel-parser/LICENSE +22 -0
  56. package/edition-authoring/vendor/babel-parser/README.md +21 -0
  57. package/edition-authoring/vendor/babel-parser/babel-helper-string-parser/index.mjs +292 -0
  58. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/identifier.mjs +66 -0
  59. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/index.mjs +13 -0
  60. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/keyword.mjs +31 -0
  61. package/edition-authoring/vendor/babel-parser/babel-parser/index.mjs +99 -0
  62. package/edition-authoring/vendor/babel-parser/babel-parser/options.mjs +81 -0
  63. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/bind-operator-errors.mjs +8 -0
  64. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/module-errors.mjs +15 -0
  65. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/parse-expression-errors.mjs +10 -0
  66. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/pipeline-operator-errors.mjs +29 -0
  67. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/standard-errors.mjs +224 -0
  68. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/strict-mode-errors.mjs +17 -0
  69. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/to-node-description.mjs +31 -0
  70. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error.mjs +114 -0
  71. package/edition-authoring/vendor/babel-parser/babel-parser/parser/base.mjs +34 -0
  72. package/edition-authoring/vendor/babel-parser/babel-parser/parser/comments.mjs +199 -0
  73. package/edition-authoring/vendor/babel-parser/babel-parser/parser/expression.mjs +1794 -0
  74. package/edition-authoring/vendor/babel-parser/babel-parser/parser/index.mjs +76 -0
  75. package/edition-authoring/vendor/babel-parser/babel-parser/parser/lval.mjs +439 -0
  76. package/edition-authoring/vendor/babel-parser/babel-parser/parser/node.mjs +111 -0
  77. package/edition-authoring/vendor/babel-parser/babel-parser/parser/statement.mjs +1962 -0
  78. package/edition-authoring/vendor/babel-parser/babel-parser/parser/util.mjs +244 -0
  79. package/edition-authoring/vendor/babel-parser/babel-parser/plugin-utils.mjs +116 -0
  80. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/estree.mjs +417 -0
  81. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/index.mjs +2412 -0
  82. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/scope.mjs +37 -0
  83. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/index.mjs +420 -0
  84. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/xhtml.mjs +261 -0
  85. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/placeholders.mjs +205 -0
  86. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/index.mjs +2889 -0
  87. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/scope.mjs +115 -0
  88. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/v8intrinsic.mjs +26 -0
  89. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/context.mjs +22 -0
  90. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/index.mjs +1037 -0
  91. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/state.mjs +178 -0
  92. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/types.mjs +583 -0
  93. package/edition-authoring/vendor/babel-parser/babel-parser/types.mjs +1 -0
  94. package/edition-authoring/vendor/babel-parser/babel-parser/util/class-scope.mjs +82 -0
  95. package/edition-authoring/vendor/babel-parser/babel-parser/util/expression-scope.mjs +121 -0
  96. package/edition-authoring/vendor/babel-parser/babel-parser/util/identifier.mjs +23 -0
  97. package/edition-authoring/vendor/babel-parser/babel-parser/util/location.mjs +34 -0
  98. package/edition-authoring/vendor/babel-parser/babel-parser/util/production-parameter.mjs +40 -0
  99. package/edition-authoring/vendor/babel-parser/babel-parser/util/scope.mjs +173 -0
  100. package/edition-authoring/vendor/babel-parser/babel-parser/util/scopeflags.mjs +66 -0
  101. package/edition-authoring/vendor/babel-parser/babel-parser/util/whitespace.mjs +61 -0
  102. package/edition-authoring/vendor/yaml/LICENSE +13 -0
  103. package/edition-authoring/vendor/yaml/README.md +11 -0
  104. package/edition-authoring/vendor/yaml/compose/compose-collection.mjs +88 -0
  105. package/edition-authoring/vendor/yaml/compose/compose-doc.mjs +43 -0
  106. package/edition-authoring/vendor/yaml/compose/compose-node.mjs +110 -0
  107. package/edition-authoring/vendor/yaml/compose/compose-scalar.mjs +86 -0
  108. package/edition-authoring/vendor/yaml/compose/composer.mjs +218 -0
  109. package/edition-authoring/vendor/yaml/compose/resolve-block-map.mjs +115 -0
  110. package/edition-authoring/vendor/yaml/compose/resolve-block-scalar.mjs +198 -0
  111. package/edition-authoring/vendor/yaml/compose/resolve-block-seq.mjs +49 -0
  112. package/edition-authoring/vendor/yaml/compose/resolve-end.mjs +37 -0
  113. package/edition-authoring/vendor/yaml/compose/resolve-flow-collection.mjs +207 -0
  114. package/edition-authoring/vendor/yaml/compose/resolve-flow-scalar.mjs +228 -0
  115. package/edition-authoring/vendor/yaml/compose/resolve-props.mjs +148 -0
  116. package/edition-authoring/vendor/yaml/compose/util-contains-newline.mjs +34 -0
  117. package/edition-authoring/vendor/yaml/compose/util-empty-scalar-position.mjs +27 -0
  118. package/edition-authoring/vendor/yaml/compose/util-flow-indent-check.mjs +15 -0
  119. package/edition-authoring/vendor/yaml/compose/util-map-includes.mjs +13 -0
  120. package/edition-authoring/vendor/yaml/doc/Document.mjs +333 -0
  121. package/edition-authoring/vendor/yaml/doc/anchors.mjs +74 -0
  122. package/edition-authoring/vendor/yaml/doc/applyReviver.mjs +54 -0
  123. package/edition-authoring/vendor/yaml/doc/createNode.mjs +88 -0
  124. package/edition-authoring/vendor/yaml/doc/directives.mjs +176 -0
  125. package/edition-authoring/vendor/yaml/errors.mjs +57 -0
  126. package/edition-authoring/vendor/yaml/index.mjs +17 -0
  127. package/edition-authoring/vendor/yaml/log.mjs +11 -0
  128. package/edition-authoring/vendor/yaml/nodes/Alias.mjs +119 -0
  129. package/edition-authoring/vendor/yaml/nodes/Collection.mjs +147 -0
  130. package/edition-authoring/vendor/yaml/nodes/Node.mjs +38 -0
  131. package/edition-authoring/vendor/yaml/nodes/Pair.mjs +36 -0
  132. package/edition-authoring/vendor/yaml/nodes/Scalar.mjs +24 -0
  133. package/edition-authoring/vendor/yaml/nodes/YAMLMap.mjs +144 -0
  134. package/edition-authoring/vendor/yaml/nodes/YAMLSeq.mjs +113 -0
  135. package/edition-authoring/vendor/yaml/nodes/addPairToJSMap.mjs +62 -0
  136. package/edition-authoring/vendor/yaml/nodes/identity.mjs +36 -0
  137. package/edition-authoring/vendor/yaml/nodes/toJS.mjs +35 -0
  138. package/edition-authoring/vendor/yaml/parse/cst-scalar.mjs +214 -0
  139. package/edition-authoring/vendor/yaml/parse/cst-stringify.mjs +61 -0
  140. package/edition-authoring/vendor/yaml/parse/cst-visit.mjs +97 -0
  141. package/edition-authoring/vendor/yaml/parse/cst.mjs +98 -0
  142. package/edition-authoring/vendor/yaml/parse/lexer.mjs +722 -0
  143. package/edition-authoring/vendor/yaml/parse/line-counter.mjs +39 -0
  144. package/edition-authoring/vendor/yaml/parse/parser.mjs +975 -0
  145. package/edition-authoring/vendor/yaml/public-api.mjs +102 -0
  146. package/edition-authoring/vendor/yaml/schema/Schema.mjs +37 -0
  147. package/edition-authoring/vendor/yaml/schema/common/map.mjs +17 -0
  148. package/edition-authoring/vendor/yaml/schema/common/null.mjs +15 -0
  149. package/edition-authoring/vendor/yaml/schema/common/seq.mjs +17 -0
  150. package/edition-authoring/vendor/yaml/schema/common/string.mjs +14 -0
  151. package/edition-authoring/vendor/yaml/schema/core/bool.mjs +19 -0
  152. package/edition-authoring/vendor/yaml/schema/core/float.mjs +43 -0
  153. package/edition-authoring/vendor/yaml/schema/core/int.mjs +38 -0
  154. package/edition-authoring/vendor/yaml/schema/core/schema.mjs +23 -0
  155. package/edition-authoring/vendor/yaml/schema/json/schema.mjs +62 -0
  156. package/edition-authoring/vendor/yaml/schema/tags.mjs +96 -0
  157. package/edition-authoring/vendor/yaml/schema/yaml-1.1/binary.mjs +59 -0
  158. package/edition-authoring/vendor/yaml/schema/yaml-1.1/bool.mjs +26 -0
  159. package/edition-authoring/vendor/yaml/schema/yaml-1.1/float.mjs +46 -0
  160. package/edition-authoring/vendor/yaml/schema/yaml-1.1/int.mjs +71 -0
  161. package/edition-authoring/vendor/yaml/schema/yaml-1.1/merge.mjs +67 -0
  162. package/edition-authoring/vendor/yaml/schema/yaml-1.1/omap.mjs +74 -0
  163. package/edition-authoring/vendor/yaml/schema/yaml-1.1/pairs.mjs +78 -0
  164. package/edition-authoring/vendor/yaml/schema/yaml-1.1/schema.mjs +39 -0
  165. package/edition-authoring/vendor/yaml/schema/yaml-1.1/set.mjs +93 -0
  166. package/edition-authoring/vendor/yaml/schema/yaml-1.1/timestamp.mjs +101 -0
  167. package/edition-authoring/vendor/yaml/stringify/foldFlowLines.mjs +146 -0
  168. package/edition-authoring/vendor/yaml/stringify/stringify.mjs +130 -0
  169. package/edition-authoring/vendor/yaml/stringify/stringifyCollection.mjs +155 -0
  170. package/edition-authoring/vendor/yaml/stringify/stringifyComment.mjs +20 -0
  171. package/edition-authoring/vendor/yaml/stringify/stringifyDocument.mjs +85 -0
  172. package/edition-authoring/vendor/yaml/stringify/stringifyNumber.mjs +25 -0
  173. package/edition-authoring/vendor/yaml/stringify/stringifyPair.mjs +150 -0
  174. package/edition-authoring/vendor/yaml/stringify/stringifyString.mjs +338 -0
  175. package/edition-authoring/vendor/yaml/util.mjs +11 -0
  176. package/edition-authoring/vendor/yaml/visit.mjs +233 -0
  177. package/edition-authoring/workflow-copies.mjs +125 -0
  178. package/edition-authoring/workflow-scripts.mjs +112 -0
  179. package/foundation/runtime/contract-docs.mjs +754 -0
  180. package/foundation/runtime/run-data.d.mts +1 -0
  181. package/foundation/runtime/run-data.mjs +2 -0
  182. package/global/CHANGELOG.md +55 -3
  183. package/global/README.md +21 -24
  184. package/global/cli/command.mjs +8 -2
  185. package/global/cli/install.mjs +4 -5
  186. package/global/cli/path-link.mjs +3 -2
  187. package/global/cli/repo-command.mjs +3 -7
  188. package/global/launch/dev.mjs +12 -2
  189. package/global/launch/facts.mjs +2 -2
  190. package/global/launch/render.mjs +16 -9
  191. package/global/launch/state.mjs +4 -4
  192. package/global/main.mjs +12 -7
  193. package/install.sh +17 -6
  194. package/modules/container/README.md +6 -1
  195. package/modules/container/adapters/d1-limits.mjs +286 -0
  196. package/modules/container/adapters/d1-sqlite.mjs +95 -0
  197. package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
  198. package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
  199. package/modules/container/adapters/d1-workerd.mjs +5 -0
  200. package/modules/container/adapters/sqlite-worker.mjs +5 -3
  201. package/modules/container/build.mjs +1 -0
  202. package/modules/container/image-variables.mjs +8 -3
  203. package/modules/container/transfer.mjs +14 -4
  204. package/modules/container/worker-engine.mjs +3 -3
  205. package/modules/demo/declaration.mjs +1 -4
  206. package/modules/demo/vite.mjs +1 -1
  207. package/modules/demo-host/build.mjs +1 -0
  208. package/modules/demo-host/native/prepare.mjs +2 -1
  209. package/modules/demo-host/native/sql.mjs +7 -2
  210. package/modules/deploy-kit/README.md +23 -3
  211. package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
  212. package/modules/deploy-kit/d1-import.mjs +17 -5
  213. package/modules/deploy-kit/diagnostics.mjs +29 -3
  214. package/modules/deploy-kit/owner-cli.mjs +20 -7
  215. package/modules/deploy-kit/provider-transport.mjs +19 -4
  216. package/modules/deploy-kit/provider.mjs +57 -22
  217. package/modules/deploy-kit/readiness-window.mjs +1 -1
  218. package/modules/deploy-kit/site.mjs +8 -3
  219. package/modules/deploy-kit/templates.mjs +3 -3
  220. package/modules/deploy-kit/worker.mjs +4 -4
  221. package/modules/import-kit/src/d1/README.md +23 -4
  222. package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
  223. package/modules/import-kit/src/d1/budget.ts +15 -7
  224. package/modules/import-kit/src/d1/column-layout.ts +5 -0
  225. package/modules/import-kit/src/d1/creation.ts +15 -8
  226. package/modules/import-kit/src/d1/database.ts +3 -3
  227. package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
  228. package/modules/import-kit/src/d1/erasure.ts +2 -2
  229. package/modules/import-kit/src/d1/jobs.ts +10 -6
  230. package/modules/import-kit/src/d1/plans.ts +14 -8
  231. package/modules/import-kit/src/d1/retirement.ts +2 -2
  232. package/modules/import-kit/src/d1/sets.ts +1 -3
  233. package/modules/import-kit/src/d1/staged-creation.ts +3 -3
  234. package/modules/import-kit/src/door/limits.ts +1 -1
  235. package/modules/import-kit/src/door/refusals.ts +1 -1
  236. package/modules/portability/README.md +112 -4
  237. package/modules/portability/backfills.mjs +9 -8
  238. package/modules/portability/bridge.mjs +12 -5
  239. package/modules/portability/catalogue.mjs +12 -5
  240. package/modules/portability/files.mjs +4 -3
  241. package/modules/portability/http.mjs +3 -3
  242. package/modules/portability/import.mjs +18 -9
  243. package/modules/portability/index.d.mts +4 -3
  244. package/modules/portability/index.mjs +1 -1
  245. package/modules/portability/ledgers.mjs +3 -2
  246. package/modules/portability/legacy-safety.mjs +11 -2
  247. package/modules/portability/migration-history.mjs +2 -2
  248. package/modules/portability/progress.mjs +1 -0
  249. package/modules/portability/restore-empty.mjs +12 -0
  250. package/modules/release/github-verify.mjs +11 -2
  251. package/onboarding/adapter.mjs +35 -6
  252. package/onboarding/app-fetch.mjs +6 -4
  253. package/onboarding/development-runtime.mjs +19 -0
  254. package/onboarding/local/operation.mjs +45 -27
  255. package/onboarding/loopback-fetch.mjs +16 -0
  256. package/onboarding/operator-installer.mjs +4 -6
  257. package/onboarding/process-diagnostics.mjs +6 -2
  258. package/onboarding/production-runtime.mjs +4 -2
  259. package/onboarding/readiness.mjs +1 -0
  260. package/package.json +1 -1
  261. package/scripts/publish-check/README.md +6 -0
  262. package/scripts/publish-check/history_scan.py +5 -3
  263. package/scripts/publish-check/hygiene_config.py +2 -1
  264. package/scripts/publish-check/public_hygiene.py +1 -1
  265. package/scripts/publish-check/report.py +9 -3
  266. package/scripts/publish-check/third-party-notices.json +13 -0
  267. package/scripts/publish-check/third_party_notices.py +38 -0
  268. package/scripts/publish-check/tree_scan.py +6 -0
  269. package/scripts/publish-check.mjs +1 -1
@@ -0,0 +1,2889 @@
1
+ // Generated from Babel v7.29.8 (MIT); see README.md.
2
+ import { tokenIsIdentifier, tokenIsTSDeclarationStart, tokenIsTSTypeOperator, tokenOperatorPrecedence, tokenIsKeywordOrIdentifier, tt, tokenIsTemplate, tokenCanStartExpression } from "../../tokenizer/types.mjs";
3
+ import { types as tc } from "../../tokenizer/context.mjs";
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
5
+ import { createPositionWithColumnOffset } from "../../util/location.mjs";
6
+ import { ScopeFlag, BindingFlag } from "../../util/scopeflags.mjs";
7
+ import TypeScriptScopeHandler from "./scope.mjs";
8
+ import { ParamKind } from "../../util/production-parameter.mjs";
9
+ import { Errors, ParseErrorEnum } from "../../parse-error.mjs";
10
+ import { ParseBindingListFlags } from "../../parser/lval.mjs";
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
12
+ import { OptionFlags } from "../../options.mjs";
13
+ import { isIdentifierChar, isIdentifierStart } from "../../util/identifier.mjs";
14
+ const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
15
+ function nonNull(x) {
16
+ if (x == null) {
17
+ throw new Error(`Unexpected ${x} value.`);
18
+ }
19
+ return x;
20
+ }
21
+ function assert(x) {
22
+ if (!x) {
23
+ throw new Error("Assert fail");
24
+ }
25
+ }
26
+ const TSErrors = ParseErrorEnum`typescript`({
27
+ AbstractMethodHasImplementation: ({
28
+ methodName
29
+ }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
30
+ AbstractPropertyHasInitializer: ({
31
+ propertyName
32
+ }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
33
+ AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
34
+ AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
35
+ AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
36
+ ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
37
+ ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
38
+ ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
39
+ ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
40
+ DeclareAccessor: ({
41
+ kind
42
+ }) => `'declare' is not allowed in ${kind}ters.`,
43
+ DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
44
+ DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
45
+ DuplicateAccessibilityModifier: ({
46
+ modifier
47
+ }) => `Accessibility modifier already seen: '${modifier}'.`,
48
+ DuplicateModifier: ({
49
+ modifier
50
+ }) => `Duplicate modifier: '${modifier}'.`,
51
+ EmptyHeritageClauseType: ({
52
+ token
53
+ }) => `'${token}' list cannot be empty.`,
54
+ EmptyTypeArguments: "Type argument list cannot be empty.",
55
+ EmptyTypeParameters: "Type parameter list cannot be empty.",
56
+ ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
57
+ ImportAliasHasImportType: "An import alias can not use 'import type'.",
58
+ ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
59
+ IncompatibleModifiers: ({
60
+ modifiers
61
+ }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
62
+ IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
63
+ IndexSignatureHasAccessibility: ({
64
+ modifier
65
+ }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
66
+ IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
67
+ IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
68
+ IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
69
+ InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
70
+ InvalidHeritageClauseType: ({
71
+ token
72
+ }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
73
+ InvalidModifierOnAwaitUsingDeclaration: (modifier) => `'${modifier}' modifier cannot appear on an await using declaration.`,
74
+ InvalidModifierOnTypeMember: ({
75
+ modifier
76
+ }) => `'${modifier}' modifier cannot appear on a type member.`,
77
+ InvalidModifierOnTypeParameter: ({
78
+ modifier
79
+ }) => `'${modifier}' modifier cannot appear on a type parameter.`,
80
+ InvalidModifierOnTypeParameterPositions: ({
81
+ modifier
82
+ }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
83
+ InvalidModifierOnUsingDeclaration: (modifier) => `'${modifier}' modifier cannot appear on a using declaration.`,
84
+ InvalidModifiersOrder: ({
85
+ orderedModifiers
86
+ }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
87
+ InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
88
+ InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
89
+ MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
90
+ NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
91
+ NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
92
+ OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
93
+ OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
94
+ PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
95
+ PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
96
+ PrivateElementHasAccessibility: ({
97
+ modifier
98
+ }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
99
+ ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
100
+ ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
101
+ ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
102
+ SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
103
+ SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
104
+ SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
105
+ SingleTypeParameterWithoutTrailingComma: ({
106
+ typeParameterName
107
+ }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
108
+ StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
109
+ TupleOptionalAfterType: "A labeled tuple optional element must be declared using a question mark after the name and before the colon (`name?: type`), rather than after the type (`name: type?`).",
110
+ TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
111
+ TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
112
+ TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
113
+ TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
114
+ UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
115
+ UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
116
+ UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
117
+ UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
118
+ UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
119
+ UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
120
+ UnsupportedSignatureParameterKind: ({
121
+ type
122
+ }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
123
+ UsingDeclarationInAmbientContext: (kind) => `'${kind}' declarations are not allowed in ambient contexts.`
124
+ });
125
+ function keywordTypeFromName(value) {
126
+ switch (value) {
127
+ case "any":
128
+ return "TSAnyKeyword";
129
+ case "boolean":
130
+ return "TSBooleanKeyword";
131
+ case "bigint":
132
+ return "TSBigIntKeyword";
133
+ case "never":
134
+ return "TSNeverKeyword";
135
+ case "number":
136
+ return "TSNumberKeyword";
137
+ case "object":
138
+ return "TSObjectKeyword";
139
+ case "string":
140
+ return "TSStringKeyword";
141
+ case "symbol":
142
+ return "TSSymbolKeyword";
143
+ case "undefined":
144
+ return "TSUndefinedKeyword";
145
+ case "unknown":
146
+ return "TSUnknownKeyword";
147
+ default:
148
+ return void 0;
149
+ }
150
+ }
151
+ function tsIsAccessModifier(modifier) {
152
+ return modifier === "private" || modifier === "public" || modifier === "protected";
153
+ }
154
+ function tsIsVarianceAnnotations(modifier) {
155
+ return modifier === "in" || modifier === "out";
156
+ }
157
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
158
+ function tsIsEntityName(node) {
159
+ if (node.extra?.parenthesized) {
160
+ return false;
161
+ }
162
+ switch (node.type) {
163
+ case "Identifier":
164
+ return true;
165
+ case "MemberExpression":
166
+ return !node.computed && tsIsEntityName(node.object);
167
+ case "TSInstantiationExpression":
168
+ return tsIsEntityName(node.expression);
169
+ default:
170
+ return false;
171
+ }
172
+ }
173
+ var tsParseEntityNameFlags = {
174
+ NONE: 0,
175
+ ALLOW_RESERVED_WORDS: 1,
176
+ LEADING_THIS_AS_IDENTIFIER: 2
177
+ };
178
+ var stdin_default = (superClass) => class TypeScriptParserMixin extends superClass {
179
+ getScopeHandler() {
180
+ return TypeScriptScopeHandler;
181
+ }
182
+ tsIsIdentifier() {
183
+ return tokenIsIdentifier(this.state.type);
184
+ }
185
+ tsTokenCanFollowModifier() {
186
+ return this.match(tt.bracketL) || this.match(tt.braceL) || this.match(tt.star) || this.match(tt.ellipsis) || this.match(tt.privateName) || this.isLiteralPropertyName();
187
+ }
188
+ tsNextTokenOnSameLineAndCanFollowModifier() {
189
+ this.next();
190
+ if (this.hasPrecedingLineBreak()) {
191
+ return false;
192
+ }
193
+ return this.tsTokenCanFollowModifier();
194
+ }
195
+ tsNextTokenCanFollowModifier() {
196
+ if (this.match(tt._static)) {
197
+ this.next();
198
+ return this.tsTokenCanFollowModifier();
199
+ }
200
+ return this.tsNextTokenOnSameLineAndCanFollowModifier();
201
+ }
202
+ tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
203
+ if (!tokenIsIdentifier(this.state.type) && this.state.type !== tt._in && this.state.type !== tt._const) {
204
+ return void 0;
205
+ }
206
+ const modifier = this.state.value;
207
+ if (allowedModifiers.includes(modifier)) {
208
+ if (hasSeenStaticModifier && this.match(tt._static)) {
209
+ return void 0;
210
+ }
211
+ if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
212
+ return void 0;
213
+ }
214
+ if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
215
+ return modifier;
216
+ }
217
+ }
218
+ return void 0;
219
+ }
220
+ tsParseModifiers({
221
+ allowedModifiers,
222
+ disallowedModifiers,
223
+ stopOnStartOfClassStaticBlock,
224
+ errorTemplate = TSErrors.InvalidModifierOnTypeMember
225
+ }, modified) {
226
+ const enforceOrder = (loc, modifier, before, after) => {
227
+ if (modifier === before && modified[after]) {
228
+ this.raise(TSErrors.InvalidModifiersOrder, loc, {
229
+ orderedModifiers: [before, after]
230
+ });
231
+ }
232
+ };
233
+ const incompatible = (loc, modifier, mod1, mod2) => {
234
+ if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
235
+ this.raise(TSErrors.IncompatibleModifiers, loc, {
236
+ modifiers: [mod1, mod2]
237
+ });
238
+ }
239
+ };
240
+ for (; ; ) {
241
+ const {
242
+ startLoc
243
+ } = this.state;
244
+ const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers ?? []), stopOnStartOfClassStaticBlock, modified.static);
245
+ if (!modifier) break;
246
+ if (tsIsAccessModifier(modifier)) {
247
+ if (modified.accessibility) {
248
+ this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
249
+ modifier
250
+ });
251
+ } else {
252
+ enforceOrder(startLoc, modifier, modifier, "override");
253
+ enforceOrder(startLoc, modifier, modifier, "static");
254
+ enforceOrder(startLoc, modifier, modifier, "readonly");
255
+ modified.accessibility = modifier;
256
+ }
257
+ } else if (tsIsVarianceAnnotations(modifier)) {
258
+ if (modified[modifier]) {
259
+ this.raise(TSErrors.DuplicateModifier, startLoc, {
260
+ modifier
261
+ });
262
+ }
263
+ modified[modifier] = true;
264
+ enforceOrder(startLoc, modifier, "in", "out");
265
+ } else {
266
+ if (Object.hasOwn(modified, modifier)) {
267
+ this.raise(TSErrors.DuplicateModifier, startLoc, {
268
+ modifier
269
+ });
270
+ } else {
271
+ enforceOrder(startLoc, modifier, "static", "readonly");
272
+ enforceOrder(startLoc, modifier, "static", "override");
273
+ enforceOrder(startLoc, modifier, "override", "readonly");
274
+ enforceOrder(startLoc, modifier, "abstract", "override");
275
+ incompatible(startLoc, modifier, "declare", "override");
276
+ incompatible(startLoc, modifier, "static", "abstract");
277
+ }
278
+ modified[modifier] = true;
279
+ }
280
+ if (disallowedModifiers?.includes(modifier)) {
281
+ this.raise(errorTemplate, startLoc, {
282
+ modifier
283
+ });
284
+ }
285
+ }
286
+ }
287
+ tsIsListTerminator(kind) {
288
+ switch (kind) {
289
+ case "EnumMembers":
290
+ case "TypeMembers":
291
+ return this.match(tt.braceR);
292
+ case "HeritageClauseElement":
293
+ return this.match(tt.braceL);
294
+ case "TupleElementTypes":
295
+ return this.match(tt.bracketR);
296
+ case "TypeParametersOrArguments":
297
+ return this.match(tt.gt);
298
+ }
299
+ }
300
+ tsParseList(kind, parseElement) {
301
+ const result = [];
302
+ while (!this.tsIsListTerminator(kind)) {
303
+ result.push(parseElement());
304
+ }
305
+ return result;
306
+ }
307
+ tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
308
+ return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
309
+ }
310
+ tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
311
+ const result = [];
312
+ let trailingCommaPos = -1;
313
+ for (; ; ) {
314
+ if (this.tsIsListTerminator(kind)) {
315
+ break;
316
+ }
317
+ trailingCommaPos = -1;
318
+ const element = parseElement();
319
+ if (element == null) {
320
+ return void 0;
321
+ }
322
+ result.push(element);
323
+ if (this.eat(tt.comma)) {
324
+ trailingCommaPos = this.state.lastTokStartLoc.index;
325
+ continue;
326
+ }
327
+ if (this.tsIsListTerminator(kind)) {
328
+ break;
329
+ }
330
+ if (expectSuccess) {
331
+ this.expect(tt.comma);
332
+ }
333
+ return void 0;
334
+ }
335
+ if (refTrailingCommaPos) {
336
+ refTrailingCommaPos.value = trailingCommaPos;
337
+ }
338
+ return result;
339
+ }
340
+ tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
341
+ if (!skipFirstToken) {
342
+ if (bracket) {
343
+ this.expect(tt.bracketL);
344
+ } else {
345
+ this.expect(tt.lt);
346
+ }
347
+ }
348
+ const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
349
+ if (bracket) {
350
+ this.expect(tt.bracketR);
351
+ } else {
352
+ this.expect(tt.gt);
353
+ }
354
+ return result;
355
+ }
356
+ tsParseImportType() {
357
+ const node = this.startNode();
358
+ this.expect(tt._import);
359
+ this.expect(tt.parenL);
360
+ if (!this.match(tt.string)) {
361
+ this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
362
+ {
363
+ node.argument = super.parseExprAtom();
364
+ }
365
+ } else {
366
+ {
367
+ node.argument = this.parseStringLiteral(this.state.value);
368
+ }
369
+ }
370
+ if (this.eat(tt.comma)) {
371
+ node.options = this.tsParseImportTypeOptions();
372
+ } else {
373
+ node.options = null;
374
+ }
375
+ this.expect(tt.parenR);
376
+ if (this.eat(tt.dot)) {
377
+ node.qualifier = this.tsParseEntityName(tsParseEntityNameFlags.ALLOW_RESERVED_WORDS | tsParseEntityNameFlags.LEADING_THIS_AS_IDENTIFIER);
378
+ }
379
+ if (this.match(tt.lt)) {
380
+ {
381
+ node.typeParameters = this.tsParseTypeArguments();
382
+ }
383
+ }
384
+ return this.finishNode(node, "TSImportType");
385
+ }
386
+ tsParseImportTypeOptions() {
387
+ const node = this.startNode();
388
+ this.expect(tt.braceL);
389
+ const withProperty = this.startNode();
390
+ if (this.isContextual(tt._with)) {
391
+ withProperty.method = false;
392
+ withProperty.key = this.parseIdentifier(true);
393
+ withProperty.computed = false;
394
+ withProperty.shorthand = false;
395
+ } else {
396
+ this.unexpected(null, tt._with);
397
+ }
398
+ this.expect(tt.colon);
399
+ withProperty.value = this.tsParseImportTypeWithPropertyValue();
400
+ node.properties = [this.finishObjectProperty(withProperty)];
401
+ this.eat(tt.comma);
402
+ this.expect(tt.braceR);
403
+ return this.finishNode(node, "ObjectExpression");
404
+ }
405
+ tsParseImportTypeWithPropertyValue() {
406
+ const node = this.startNode();
407
+ const properties = [];
408
+ this.expect(tt.braceL);
409
+ while (!this.match(tt.braceR)) {
410
+ const type = this.state.type;
411
+ if (tokenIsIdentifier(type) || type === tt.string) {
412
+ properties.push(super.parsePropertyDefinition(null));
413
+ } else {
414
+ this.unexpected();
415
+ }
416
+ this.eat(tt.comma);
417
+ }
418
+ node.properties = properties;
419
+ this.next();
420
+ return this.finishNode(node, "ObjectExpression");
421
+ }
422
+ tsParseEntityName(flags) {
423
+ let entity;
424
+ if (flags & tsParseEntityNameFlags.ALLOW_RESERVED_WORDS && this.match(tt._this)) {
425
+ if (flags & tsParseEntityNameFlags.LEADING_THIS_AS_IDENTIFIER) {
426
+ entity = this.parseIdentifier(true);
427
+ } else {
428
+ const node = this.startNode();
429
+ this.next();
430
+ entity = this.finishNode(node, "ThisExpression");
431
+ }
432
+ } else {
433
+ entity = this.parseIdentifier(!!(flags & tsParseEntityNameFlags.ALLOW_RESERVED_WORDS));
434
+ }
435
+ while (this.eat(tt.dot)) {
436
+ const node = this.startNodeAtNode(entity);
437
+ node.left = entity;
438
+ node.right = this.parseIdentifier(!!(flags & tsParseEntityNameFlags.ALLOW_RESERVED_WORDS));
439
+ entity = this.finishNode(node, "TSQualifiedName");
440
+ }
441
+ return entity;
442
+ }
443
+ tsParseTypeReference() {
444
+ const node = this.startNode();
445
+ node.typeName = this.tsParseEntityName(tsParseEntityNameFlags.ALLOW_RESERVED_WORDS);
446
+ if (!this.hasPrecedingLineBreak() && this.match(tt.lt)) {
447
+ {
448
+ node.typeParameters = this.tsParseTypeArguments();
449
+ }
450
+ }
451
+ return this.finishNode(node, "TSTypeReference");
452
+ }
453
+ tsParseThisTypePredicate(lhs) {
454
+ this.next();
455
+ const node = this.startNodeAtNode(lhs);
456
+ node.parameterName = lhs;
457
+ node.typeAnnotation = this.tsParseTypeAnnotation(false);
458
+ node.asserts = false;
459
+ return this.finishNode(node, "TSTypePredicate");
460
+ }
461
+ tsParseThisTypeNode() {
462
+ const node = this.startNode();
463
+ this.next();
464
+ return this.finishNode(node, "TSThisType");
465
+ }
466
+ tsParseTypeQuery() {
467
+ const node = this.startNode();
468
+ this.expect(tt._typeof);
469
+ if (this.match(tt._import)) {
470
+ node.exprName = this.tsParseImportType();
471
+ } else {
472
+ {
473
+ node.exprName = this.tsParseEntityName(tsParseEntityNameFlags.ALLOW_RESERVED_WORDS | tsParseEntityNameFlags.LEADING_THIS_AS_IDENTIFIER);
474
+ }
475
+ }
476
+ if (!this.hasPrecedingLineBreak() && this.match(tt.lt)) {
477
+ {
478
+ node.typeParameters = this.tsParseTypeArguments();
479
+ }
480
+ }
481
+ return this.finishNode(node, "TSTypeQuery");
482
+ }
483
+ tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
484
+ allowedModifiers: ["in", "out"],
485
+ disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
486
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameter
487
+ });
488
+ tsParseConstModifier = this.tsParseModifiers.bind(this, {
489
+ allowedModifiers: ["const"],
490
+ disallowedModifiers: ["in", "out"],
491
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
492
+ });
493
+ tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
494
+ allowedModifiers: ["in", "out", "const"],
495
+ disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
496
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameter
497
+ });
498
+ tsParseTypeParameter(parseModifiers) {
499
+ const node = this.startNode();
500
+ parseModifiers(node);
501
+ node.name = this.tsParseTypeParameterName();
502
+ node.constraint = this.tsEatThenParseType(tt._extends);
503
+ node.default = this.tsEatThenParseType(tt.eq);
504
+ return this.finishNode(node, "TSTypeParameter");
505
+ }
506
+ tsTryParseTypeParameters(parseModifiers) {
507
+ if (this.match(tt.lt)) {
508
+ return this.tsParseTypeParameters(parseModifiers);
509
+ }
510
+ }
511
+ tsParseTypeParameters(parseModifiers) {
512
+ const node = this.startNode();
513
+ if (this.match(tt.lt) || this.match(tt.jsxTagStart)) {
514
+ this.next();
515
+ } else {
516
+ this.unexpected();
517
+ }
518
+ const refTrailingCommaPos = {
519
+ value: -1
520
+ };
521
+ node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
522
+ if (node.params.length === 0) {
523
+ this.raise(TSErrors.EmptyTypeParameters, node);
524
+ }
525
+ if (refTrailingCommaPos.value !== -1) {
526
+ this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
527
+ }
528
+ return this.finishNode(node, "TSTypeParameterDeclaration");
529
+ }
530
+ tsFillSignature(returnToken, signature) {
531
+ const returnTokenRequired = returnToken === tt.arrow;
532
+ const paramsKey = "parameters";
533
+ const returnTypeKey = "typeAnnotation";
534
+ signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
535
+ this.expect(tt.parenL);
536
+ signature[paramsKey] = this.tsParseBindingListForSignature();
537
+ if (returnTokenRequired) {
538
+ signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
539
+ } else if (this.match(returnToken)) {
540
+ signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
541
+ }
542
+ }
543
+ tsParseBindingListForSignature() {
544
+ const list = super.parseBindingList(tt.parenR, 41, ParseBindingListFlags.IS_FUNCTION_PARAMS);
545
+ for (const pattern of list) {
546
+ const {
547
+ type
548
+ } = pattern;
549
+ if (type === "AssignmentPattern" || type === "TSParameterProperty") {
550
+ this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
551
+ type
552
+ });
553
+ }
554
+ }
555
+ return list;
556
+ }
557
+ tsParseTypeMemberSemicolon() {
558
+ if (!this.eat(tt.comma) && !this.isLineTerminator()) {
559
+ this.expect(tt.semi);
560
+ }
561
+ }
562
+ tsParseSignatureMember(kind, node) {
563
+ this.tsFillSignature(tt.colon, node);
564
+ this.tsParseTypeMemberSemicolon();
565
+ return this.finishNode(node, kind);
566
+ }
567
+ tsIsUnambiguouslyIndexSignature() {
568
+ this.next();
569
+ if (tokenIsIdentifier(this.state.type)) {
570
+ this.next();
571
+ return this.match(tt.colon);
572
+ }
573
+ return false;
574
+ }
575
+ tsTryParseIndexSignature(node) {
576
+ if (!(this.match(tt.bracketL) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
577
+ return;
578
+ }
579
+ this.expect(tt.bracketL);
580
+ const id = this.parseIdentifier();
581
+ id.typeAnnotation = this.tsParseTypeAnnotation();
582
+ this.resetEndLocation(id);
583
+ this.expect(tt.bracketR);
584
+ node.parameters = [id];
585
+ const type = this.tsTryParseTypeAnnotation();
586
+ if (type) node.typeAnnotation = type;
587
+ this.tsParseTypeMemberSemicolon();
588
+ return this.finishNode(node, "TSIndexSignature");
589
+ }
590
+ tsParsePropertyOrMethodSignature(node, readonly) {
591
+ if (this.eat(tt.question)) node.optional = true;
592
+ if (this.match(tt.parenL) || this.match(tt.lt)) {
593
+ if (readonly) {
594
+ this.raise(TSErrors.ReadonlyForMethodSignature, node);
595
+ }
596
+ const method = node;
597
+ if (method.kind && this.match(tt.lt)) {
598
+ this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
599
+ }
600
+ this.tsFillSignature(tt.colon, method);
601
+ this.tsParseTypeMemberSemicolon();
602
+ const paramsKey = "parameters";
603
+ const returnTypeKey = "typeAnnotation";
604
+ if (method.kind === "get") {
605
+ if (method[paramsKey].length > 0) {
606
+ this.raise(Errors.BadGetterArity, this.state.curPosition());
607
+ if (this.isThisParam(method[paramsKey][0])) {
608
+ this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
609
+ }
610
+ }
611
+ } else if (method.kind === "set") {
612
+ if (method[paramsKey].length !== 1) {
613
+ this.raise(Errors.BadSetterArity, this.state.curPosition());
614
+ } else {
615
+ const firstParameter = method[paramsKey][0];
616
+ if (this.isThisParam(firstParameter)) {
617
+ this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
618
+ }
619
+ if (firstParameter.type === "Identifier" && firstParameter.optional) {
620
+ this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
621
+ }
622
+ if (firstParameter.type === "RestElement") {
623
+ this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
624
+ }
625
+ }
626
+ if (method[returnTypeKey]) {
627
+ this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
628
+ }
629
+ } else {
630
+ method.kind = "method";
631
+ }
632
+ return this.finishNode(method, "TSMethodSignature");
633
+ } else {
634
+ const property = node;
635
+ if (readonly) property.readonly = true;
636
+ const type = this.tsTryParseTypeAnnotation();
637
+ if (type) property.typeAnnotation = type;
638
+ this.tsParseTypeMemberSemicolon();
639
+ return this.finishNode(property, "TSPropertySignature");
640
+ }
641
+ }
642
+ tsParseTypeMember() {
643
+ const node = this.startNode();
644
+ if (this.match(tt.parenL) || this.match(tt.lt)) {
645
+ return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
646
+ }
647
+ if (this.match(tt._new)) {
648
+ const id = this.startNode();
649
+ this.next();
650
+ if (this.match(tt.parenL) || this.match(tt.lt)) {
651
+ return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
652
+ } else {
653
+ node.key = this.createIdentifier(id, "new");
654
+ return this.tsParsePropertyOrMethodSignature(node, false);
655
+ }
656
+ }
657
+ this.tsParseModifiers({
658
+ allowedModifiers: ["readonly"],
659
+ disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
660
+ }, node);
661
+ const idx = this.tsTryParseIndexSignature(node);
662
+ if (idx) {
663
+ return idx;
664
+ }
665
+ super.parsePropertyName(node);
666
+ if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
667
+ node.kind = node.key.name;
668
+ super.parsePropertyName(node);
669
+ if (!this.match(tt.parenL) && !this.match(tt.lt)) {
670
+ this.unexpected(null, tt.parenL);
671
+ }
672
+ }
673
+ return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
674
+ }
675
+ tsParseTypeLiteral() {
676
+ const node = this.startNode();
677
+ node.members = this.tsParseObjectTypeMembers();
678
+ return this.finishNode(node, "TSTypeLiteral");
679
+ }
680
+ tsParseObjectTypeMembers() {
681
+ this.expect(tt.braceL);
682
+ const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
683
+ this.expect(tt.braceR);
684
+ return members;
685
+ }
686
+ tsIsStartOfMappedType() {
687
+ this.next();
688
+ if (this.eat(tt.plusMin)) {
689
+ return this.isContextual(tt._readonly);
690
+ }
691
+ if (this.isContextual(tt._readonly)) {
692
+ this.next();
693
+ }
694
+ if (!this.match(tt.bracketL)) {
695
+ return false;
696
+ }
697
+ this.next();
698
+ if (!this.tsIsIdentifier()) {
699
+ return false;
700
+ }
701
+ this.next();
702
+ return this.match(tt._in);
703
+ }
704
+ tsParseMappedType() {
705
+ const node = this.startNode();
706
+ this.expect(tt.braceL);
707
+ if (this.match(tt.plusMin)) {
708
+ node.readonly = this.state.value;
709
+ this.next();
710
+ this.expectContextual(tt._readonly);
711
+ } else if (this.eatContextual(tt._readonly)) {
712
+ node.readonly = true;
713
+ }
714
+ this.expect(tt.bracketL);
715
+ {
716
+ const typeParameter = this.startNode();
717
+ typeParameter.name = this.tsParseTypeParameterName();
718
+ typeParameter.constraint = this.tsExpectThenParseType(tt._in);
719
+ node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
720
+ }
721
+ node.nameType = this.eatContextual(tt._as) ? this.tsParseType() : null;
722
+ this.expect(tt.bracketR);
723
+ if (this.match(tt.plusMin)) {
724
+ node.optional = this.state.value;
725
+ this.next();
726
+ this.expect(tt.question);
727
+ } else if (this.eat(tt.question)) {
728
+ node.optional = true;
729
+ }
730
+ node.typeAnnotation = this.tsTryParseType();
731
+ this.semicolon();
732
+ this.expect(tt.braceR);
733
+ return this.finishNode(node, "TSMappedType");
734
+ }
735
+ tsParseTupleType() {
736
+ const node = this.startNode();
737
+ node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
738
+ let seenOptionalElement = false;
739
+ node.elementTypes.forEach((elementNode) => {
740
+ const {
741
+ type
742
+ } = elementNode;
743
+ if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
744
+ this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
745
+ }
746
+ seenOptionalElement ||= type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType";
747
+ });
748
+ return this.finishNode(node, "TSTupleType");
749
+ }
750
+ tsParseTupleElementType() {
751
+ const restStartLoc = this.state.startLoc;
752
+ const rest = this.eat(tt.ellipsis);
753
+ const {
754
+ startLoc
755
+ } = this.state;
756
+ let labeled;
757
+ let label;
758
+ let optional;
759
+ let type;
760
+ const isWord = tokenIsKeywordOrIdentifier(this.state.type);
761
+ const chAfterWord = isWord ? this.lookaheadCharCode() : null;
762
+ if (chAfterWord === 58) {
763
+ labeled = true;
764
+ optional = false;
765
+ label = this.parseIdentifier(true);
766
+ this.expect(tt.colon);
767
+ type = this.tsParseType();
768
+ } else if (chAfterWord === 63) {
769
+ optional = true;
770
+ const wordName = this.state.value;
771
+ const typeOrLabel = this.tsParseNonArrayType();
772
+ if (this.lookaheadCharCode() === 58) {
773
+ labeled = true;
774
+ label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
775
+ this.expect(tt.question);
776
+ this.expect(tt.colon);
777
+ type = this.tsParseType();
778
+ } else {
779
+ labeled = false;
780
+ type = typeOrLabel;
781
+ this.expect(tt.question);
782
+ }
783
+ } else {
784
+ type = this.tsParseType();
785
+ optional = this.eat(tt.question);
786
+ labeled = this.eat(tt.colon);
787
+ }
788
+ if (labeled) {
789
+ let labeledNode;
790
+ if (label) {
791
+ labeledNode = this.startNodeAt(startLoc);
792
+ labeledNode.optional = optional;
793
+ labeledNode.label = label;
794
+ labeledNode.elementType = type;
795
+ if (this.eat(tt.question)) {
796
+ labeledNode.optional = true;
797
+ this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
798
+ }
799
+ } else {
800
+ labeledNode = this.startNodeAt(startLoc);
801
+ labeledNode.optional = optional;
802
+ this.raise(TSErrors.InvalidTupleMemberLabel, type);
803
+ labeledNode.label = type;
804
+ labeledNode.elementType = this.tsParseType();
805
+ }
806
+ type = this.finishNode(labeledNode, "TSNamedTupleMember");
807
+ } else if (optional) {
808
+ const optionalTypeNode = this.startNodeAt(startLoc);
809
+ optionalTypeNode.typeAnnotation = type;
810
+ type = this.finishNode(optionalTypeNode, "TSOptionalType");
811
+ }
812
+ if (rest) {
813
+ const restNode = this.startNodeAt(restStartLoc);
814
+ restNode.typeAnnotation = type;
815
+ type = this.finishNode(restNode, "TSRestType");
816
+ }
817
+ return type;
818
+ }
819
+ tsParseParenthesizedType() {
820
+ const node = this.startNode();
821
+ this.expect(tt.parenL);
822
+ node.typeAnnotation = this.tsParseType();
823
+ this.expect(tt.parenR);
824
+ return this.finishNode(node, "TSParenthesizedType");
825
+ }
826
+ tsParseFunctionOrConstructorType(type, abstract) {
827
+ const node = this.startNode();
828
+ if (type === "TSConstructorType") {
829
+ node.abstract = !!abstract;
830
+ if (abstract) this.next();
831
+ this.next();
832
+ }
833
+ this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(tt.arrow, node));
834
+ return this.finishNode(node, type);
835
+ }
836
+ tsParseLiteralTypeNode() {
837
+ const node = this.startNode();
838
+ switch (this.state.type) {
839
+ case tt.num:
840
+ case tt.bigint:
841
+ case tt.string:
842
+ case tt._true:
843
+ case tt._false:
844
+ node.literal = super.parseExprAtom();
845
+ break;
846
+ default:
847
+ this.unexpected();
848
+ }
849
+ return this.finishNode(node, "TSLiteralType");
850
+ }
851
+ tsParseTemplateLiteralType() {
852
+ {
853
+ const node = this.startNode();
854
+ node.literal = super.parseTemplate(false);
855
+ return this.finishNode(node, "TSLiteralType");
856
+ }
857
+ }
858
+ parseTemplateSubstitution() {
859
+ if (this.state.inType) return this.tsParseType();
860
+ return super.parseTemplateSubstitution();
861
+ }
862
+ tsParseThisTypeOrThisTypePredicate() {
863
+ const thisKeyword = this.tsParseThisTypeNode();
864
+ if (this.isContextual(tt._is) && !this.hasPrecedingLineBreak()) {
865
+ return this.tsParseThisTypePredicate(thisKeyword);
866
+ } else {
867
+ return thisKeyword;
868
+ }
869
+ }
870
+ tsParseNonArrayType() {
871
+ switch (this.state.type) {
872
+ case tt.string:
873
+ case tt.num:
874
+ case tt.bigint:
875
+ case tt._true:
876
+ case tt._false:
877
+ return this.tsParseLiteralTypeNode();
878
+ case tt.plusMin:
879
+ if (this.state.value === "-") {
880
+ const node = this.startNode();
881
+ const nextToken = this.lookahead();
882
+ if (nextToken.type !== tt.num && nextToken.type !== tt.bigint) {
883
+ this.unexpected();
884
+ }
885
+ node.literal = this.parseMaybeUnary();
886
+ return this.finishNode(node, "TSLiteralType");
887
+ }
888
+ break;
889
+ case tt._this:
890
+ return this.tsParseThisTypeOrThisTypePredicate();
891
+ case tt._typeof:
892
+ return this.tsParseTypeQuery();
893
+ case tt._import:
894
+ return this.tsParseImportType();
895
+ case tt.braceL:
896
+ return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
897
+ case tt.bracketL:
898
+ return this.tsParseTupleType();
899
+ case tt.parenL:
900
+ return this.tsParseParenthesizedType();
901
+ case tt.templateNonTail:
902
+ case tt.templateTail:
903
+ return this.tsParseTemplateLiteralType();
904
+ default: {
905
+ const {
906
+ type
907
+ } = this.state;
908
+ if (tokenIsIdentifier(type) || type === tt._void || type === tt._null) {
909
+ const nodeType = type === tt._void ? "TSVoidKeyword" : type === tt._null ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
910
+ if (nodeType !== void 0 && this.lookaheadCharCode() !== 46) {
911
+ const node = this.startNode();
912
+ this.next();
913
+ return this.finishNode(node, nodeType);
914
+ }
915
+ return this.tsParseTypeReference();
916
+ }
917
+ }
918
+ }
919
+ throw this.unexpected();
920
+ }
921
+ tsParseArrayTypeOrHigher() {
922
+ const {
923
+ startLoc
924
+ } = this.state;
925
+ let type = this.tsParseNonArrayType();
926
+ while (!this.hasPrecedingLineBreak() && this.eat(tt.bracketL)) {
927
+ if (this.match(tt.bracketR)) {
928
+ const node = this.startNodeAt(startLoc);
929
+ node.elementType = type;
930
+ this.expect(tt.bracketR);
931
+ type = this.finishNode(node, "TSArrayType");
932
+ } else {
933
+ const node = this.startNodeAt(startLoc);
934
+ node.objectType = type;
935
+ node.indexType = this.tsParseType();
936
+ this.expect(tt.bracketR);
937
+ type = this.finishNode(node, "TSIndexedAccessType");
938
+ }
939
+ }
940
+ return type;
941
+ }
942
+ tsParseTypeOperator() {
943
+ const node = this.startNode();
944
+ const operator = this.state.value;
945
+ this.next();
946
+ node.operator = operator;
947
+ node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
948
+ if (operator === "readonly") {
949
+ this.tsCheckTypeAnnotationForReadOnly(node);
950
+ }
951
+ return this.finishNode(node, "TSTypeOperator");
952
+ }
953
+ tsCheckTypeAnnotationForReadOnly(node) {
954
+ switch (node.typeAnnotation.type) {
955
+ case "TSTupleType":
956
+ case "TSArrayType":
957
+ return;
958
+ default:
959
+ this.raise(TSErrors.UnexpectedReadonly, node);
960
+ }
961
+ }
962
+ tsParseInferType() {
963
+ const node = this.startNode();
964
+ this.expectContextual(tt._infer);
965
+ const typeParameter = this.startNode();
966
+ typeParameter.name = this.tsParseTypeParameterName();
967
+ typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
968
+ node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
969
+ return this.finishNode(node, "TSInferType");
970
+ }
971
+ tsParseConstraintForInferType() {
972
+ if (this.eat(tt._extends)) {
973
+ const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
974
+ if (this.state.inDisallowConditionalTypesContext || !this.match(tt.question)) {
975
+ return constraint;
976
+ }
977
+ }
978
+ }
979
+ tsParseTypeOperatorOrHigher() {
980
+ const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
981
+ return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(tt._infer) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
982
+ }
983
+ tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
984
+ const node = this.startNode();
985
+ const hasLeadingOperator = this.eat(operator);
986
+ const types = [];
987
+ do {
988
+ types.push(parseConstituentType());
989
+ } while (this.eat(operator));
990
+ if (types.length === 1 && !hasLeadingOperator) {
991
+ return types[0];
992
+ }
993
+ node.types = types;
994
+ return this.finishNode(node, kind);
995
+ }
996
+ tsParseIntersectionTypeOrHigher() {
997
+ return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), tt.bitwiseAND);
998
+ }
999
+ tsParseUnionTypeOrHigher() {
1000
+ return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), tt.bitwiseOR);
1001
+ }
1002
+ tsIsStartOfFunctionType() {
1003
+ if (this.match(tt.lt)) {
1004
+ return true;
1005
+ }
1006
+ return this.match(tt.parenL) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
1007
+ }
1008
+ tsSkipParameterStart() {
1009
+ if (tokenIsIdentifier(this.state.type) || this.match(tt._this)) {
1010
+ this.next();
1011
+ return true;
1012
+ }
1013
+ if (this.match(tt.braceL)) {
1014
+ const {
1015
+ errors
1016
+ } = this.state;
1017
+ const previousErrorCount = errors.length;
1018
+ try {
1019
+ this.parseObjectLike(tt.braceR, true);
1020
+ return errors.length === previousErrorCount;
1021
+ } catch {
1022
+ return false;
1023
+ }
1024
+ }
1025
+ if (this.match(tt.bracketL)) {
1026
+ this.next();
1027
+ const {
1028
+ errors
1029
+ } = this.state;
1030
+ const previousErrorCount = errors.length;
1031
+ try {
1032
+ super.parseBindingList(tt.bracketR, 93, ParseBindingListFlags.ALLOW_EMPTY);
1033
+ return errors.length === previousErrorCount;
1034
+ } catch {
1035
+ return false;
1036
+ }
1037
+ }
1038
+ return false;
1039
+ }
1040
+ tsIsUnambiguouslyStartOfFunctionType() {
1041
+ this.next();
1042
+ if (this.match(tt.parenR) || this.match(tt.ellipsis)) {
1043
+ return true;
1044
+ }
1045
+ if (this.tsSkipParameterStart()) {
1046
+ if (this.match(tt.colon) || this.match(tt.comma) || this.match(tt.question) || this.match(tt.eq)) {
1047
+ return true;
1048
+ }
1049
+ if (this.match(tt.parenR)) {
1050
+ this.next();
1051
+ if (this.match(tt.arrow)) {
1052
+ return true;
1053
+ }
1054
+ }
1055
+ }
1056
+ return false;
1057
+ }
1058
+ tsParseTypeOrTypePredicateAnnotation(returnToken) {
1059
+ return this.tsInType(() => {
1060
+ const t = this.startNode();
1061
+ this.expect(returnToken);
1062
+ const node = this.startNode();
1063
+ const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
1064
+ if (asserts && this.match(tt._this)) {
1065
+ let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
1066
+ if (thisTypePredicate.type === "TSThisType") {
1067
+ node.parameterName = thisTypePredicate;
1068
+ node.asserts = true;
1069
+ node.typeAnnotation = null;
1070
+ thisTypePredicate = this.finishNode(node, "TSTypePredicate");
1071
+ } else {
1072
+ this.resetStartLocationFromNode(thisTypePredicate, node);
1073
+ thisTypePredicate.asserts = true;
1074
+ }
1075
+ t.typeAnnotation = thisTypePredicate;
1076
+ return this.finishNode(t, "TSTypeAnnotation");
1077
+ }
1078
+ const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
1079
+ if (!typePredicateVariable) {
1080
+ if (!asserts) {
1081
+ return this.tsParseTypeAnnotation(false, t);
1082
+ }
1083
+ node.parameterName = this.parseIdentifier();
1084
+ node.asserts = asserts;
1085
+ node.typeAnnotation = null;
1086
+ t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
1087
+ return this.finishNode(t, "TSTypeAnnotation");
1088
+ }
1089
+ const type = this.tsParseTypeAnnotation(false);
1090
+ node.parameterName = typePredicateVariable;
1091
+ node.typeAnnotation = type;
1092
+ node.asserts = asserts;
1093
+ t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
1094
+ return this.finishNode(t, "TSTypeAnnotation");
1095
+ });
1096
+ }
1097
+ tsTryParseTypeOrTypePredicateAnnotation() {
1098
+ if (this.match(tt.colon)) {
1099
+ return this.tsParseTypeOrTypePredicateAnnotation(tt.colon);
1100
+ }
1101
+ }
1102
+ tsTryParseTypeAnnotation() {
1103
+ if (this.match(tt.colon)) {
1104
+ return this.tsParseTypeAnnotation();
1105
+ }
1106
+ }
1107
+ tsTryParseType() {
1108
+ return this.tsEatThenParseType(tt.colon);
1109
+ }
1110
+ tsParseTypePredicatePrefix() {
1111
+ const id = this.parseIdentifier();
1112
+ if (this.isContextual(tt._is) && !this.hasPrecedingLineBreak()) {
1113
+ this.next();
1114
+ return id;
1115
+ }
1116
+ }
1117
+ tsParseTypePredicateAsserts() {
1118
+ if (this.state.type !== tt._asserts) {
1119
+ return false;
1120
+ }
1121
+ const containsEsc = this.state.containsEsc;
1122
+ this.next();
1123
+ if (!tokenIsIdentifier(this.state.type) && !this.match(tt._this)) {
1124
+ return false;
1125
+ }
1126
+ if (containsEsc) {
1127
+ this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
1128
+ reservedWord: "asserts"
1129
+ });
1130
+ }
1131
+ return true;
1132
+ }
1133
+ tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
1134
+ this.tsInType(() => {
1135
+ if (eatColon) this.expect(tt.colon);
1136
+ t.typeAnnotation = this.tsParseType();
1137
+ });
1138
+ return this.finishNode(t, "TSTypeAnnotation");
1139
+ }
1140
+ tsParseType() {
1141
+ assert(this.state.inType);
1142
+ const type = this.tsParseNonConditionalType();
1143
+ if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(tt._extends)) {
1144
+ return type;
1145
+ }
1146
+ const node = this.startNodeAtNode(type);
1147
+ node.checkType = type;
1148
+ node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
1149
+ this.expect(tt.question);
1150
+ node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
1151
+ this.expect(tt.colon);
1152
+ node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
1153
+ return this.finishNode(node, "TSConditionalType");
1154
+ }
1155
+ isAbstractConstructorSignature() {
1156
+ return this.isContextual(tt._abstract) && this.isLookaheadContextual("new");
1157
+ }
1158
+ tsParseNonConditionalType() {
1159
+ if (this.tsIsStartOfFunctionType()) {
1160
+ return this.tsParseFunctionOrConstructorType("TSFunctionType");
1161
+ }
1162
+ if (this.match(tt._new)) {
1163
+ return this.tsParseFunctionOrConstructorType("TSConstructorType");
1164
+ } else if (this.isAbstractConstructorSignature()) {
1165
+ return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
1166
+ }
1167
+ return this.tsParseUnionTypeOrHigher();
1168
+ }
1169
+ tsParseTypeAssertion() {
1170
+ if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
1171
+ this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
1172
+ }
1173
+ const node = this.startNode();
1174
+ node.typeAnnotation = this.tsInType(() => {
1175
+ this.next();
1176
+ return this.match(tt._const) ? this.tsParseTypeReference() : this.tsParseType();
1177
+ });
1178
+ this.expect(tt.gt);
1179
+ node.expression = this.parseMaybeUnary();
1180
+ return this.finishNode(node, "TSTypeAssertion");
1181
+ }
1182
+ tsParseHeritageClause(token) {
1183
+ const originalStartLoc = this.state.startLoc;
1184
+ const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
1185
+ {
1186
+ const node = this.startNode();
1187
+ node.expression = this.tsParseEntityName(tsParseEntityNameFlags.ALLOW_RESERVED_WORDS | tsParseEntityNameFlags.LEADING_THIS_AS_IDENTIFIER);
1188
+ if (this.match(tt.lt)) {
1189
+ node.typeParameters = this.tsParseTypeArguments();
1190
+ }
1191
+ return this.finishNode(node, "TSExpressionWithTypeArguments");
1192
+ }
1193
+ });
1194
+ if (!delimitedList.length) {
1195
+ this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
1196
+ token
1197
+ });
1198
+ }
1199
+ return delimitedList;
1200
+ }
1201
+ tsParseInterfaceDeclaration(node, properties = {}) {
1202
+ if (this.hasFollowingLineBreak()) return null;
1203
+ this.expectContextual(tt._interface);
1204
+ if (properties.declare) node.declare = true;
1205
+ if (tokenIsIdentifier(this.state.type)) {
1206
+ node.id = this.parseIdentifier();
1207
+ this.checkIdentifier(node.id, BindingFlag.TYPE_TS_INTERFACE);
1208
+ } else {
1209
+ node.id = null;
1210
+ this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
1211
+ }
1212
+ node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
1213
+ if (this.eat(tt._extends)) {
1214
+ node.extends = this.tsParseHeritageClause("extends");
1215
+ }
1216
+ const body = this.startNode();
1217
+ body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
1218
+ node.body = this.finishNode(body, "TSInterfaceBody");
1219
+ return this.finishNode(node, "TSInterfaceDeclaration");
1220
+ }
1221
+ tsParseTypeAliasDeclaration(node) {
1222
+ node.id = this.parseIdentifier();
1223
+ this.checkIdentifier(node.id, BindingFlag.TYPE_TS_TYPE);
1224
+ node.typeAnnotation = this.tsInType(() => {
1225
+ node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
1226
+ this.expect(tt.eq);
1227
+ if (this.isContextual(tt._intrinsic) && this.lookaheadCharCode() !== 46) {
1228
+ const node2 = this.startNode();
1229
+ this.next();
1230
+ return this.finishNode(node2, "TSIntrinsicKeyword");
1231
+ }
1232
+ return this.tsParseType();
1233
+ });
1234
+ this.semicolon();
1235
+ return this.finishNode(node, "TSTypeAliasDeclaration");
1236
+ }
1237
+ tsInTopLevelContext(cb) {
1238
+ if (this.curContext() !== tc.brace) {
1239
+ const oldContext = this.state.context;
1240
+ this.state.context = [oldContext[0]];
1241
+ try {
1242
+ return cb();
1243
+ } finally {
1244
+ this.state.context = oldContext;
1245
+ }
1246
+ } else {
1247
+ return cb();
1248
+ }
1249
+ }
1250
+ tsInType(cb) {
1251
+ const oldInType = this.state.inType;
1252
+ this.state.inType = true;
1253
+ try {
1254
+ return cb();
1255
+ } finally {
1256
+ this.state.inType = oldInType;
1257
+ }
1258
+ }
1259
+ tsInDisallowConditionalTypesContext(cb) {
1260
+ const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
1261
+ this.state.inDisallowConditionalTypesContext = true;
1262
+ try {
1263
+ return cb();
1264
+ } finally {
1265
+ this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
1266
+ }
1267
+ }
1268
+ tsInAllowConditionalTypesContext(cb) {
1269
+ const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
1270
+ this.state.inDisallowConditionalTypesContext = false;
1271
+ try {
1272
+ return cb();
1273
+ } finally {
1274
+ this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
1275
+ }
1276
+ }
1277
+ tsEatThenParseType(token) {
1278
+ if (this.match(token)) {
1279
+ return this.tsNextThenParseType();
1280
+ }
1281
+ }
1282
+ tsExpectThenParseType(token) {
1283
+ return this.tsInType(() => {
1284
+ this.expect(token);
1285
+ return this.tsParseType();
1286
+ });
1287
+ }
1288
+ tsNextThenParseType() {
1289
+ return this.tsInType(() => {
1290
+ this.next();
1291
+ return this.tsParseType();
1292
+ });
1293
+ }
1294
+ tsParseEnumMember() {
1295
+ const node = this.startNode();
1296
+ node.id = this.match(tt.string) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
1297
+ if (this.eat(tt.eq)) {
1298
+ node.initializer = super.parseMaybeAssignAllowIn();
1299
+ }
1300
+ return this.finishNode(node, "TSEnumMember");
1301
+ }
1302
+ tsParseEnumDeclaration(node, properties = {}) {
1303
+ if (properties.const) node.const = true;
1304
+ if (properties.declare) node.declare = true;
1305
+ this.expectContextual(tt._enum);
1306
+ node.id = this.parseIdentifier();
1307
+ this.checkIdentifier(node.id, node.const ? BindingFlag.TYPE_TS_CONST_ENUM : BindingFlag.TYPE_TS_ENUM);
1308
+ {
1309
+ this.expect(tt.braceL);
1310
+ node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
1311
+ this.expect(tt.braceR);
1312
+ }
1313
+ return this.finishNode(node, "TSEnumDeclaration");
1314
+ }
1315
+ tsParseEnumBody() {
1316
+ const node = this.startNode();
1317
+ this.expect(tt.braceL);
1318
+ node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
1319
+ this.expect(tt.braceR);
1320
+ return this.finishNode(node, "TSEnumBody");
1321
+ }
1322
+ tsParseModuleBlock() {
1323
+ const node = this.startNode();
1324
+ this.scope.enter(ScopeFlag.OTHER);
1325
+ this.expect(tt.braceL);
1326
+ super.parseBlockOrModuleBlockBody(node.body = [], void 0, true, tt.braceR);
1327
+ this.scope.exit();
1328
+ return this.finishNode(node, "TSModuleBlock");
1329
+ }
1330
+ tsParseModuleOrNamespaceDeclaration(node, nested = false) {
1331
+ node.id = this.parseIdentifier();
1332
+ if (!nested) {
1333
+ this.checkIdentifier(node.id, BindingFlag.TYPE_TS_NAMESPACE);
1334
+ }
1335
+ if (this.eat(tt.dot)) {
1336
+ const inner = this.startNode();
1337
+ this.tsParseModuleOrNamespaceDeclaration(inner, true);
1338
+ node.body = inner;
1339
+ } else {
1340
+ this.scope.enter(ScopeFlag.TS_MODULE);
1341
+ this.prodParam.enter(ParamKind.PARAM);
1342
+ node.body = this.tsParseModuleBlock();
1343
+ this.prodParam.exit();
1344
+ this.scope.exit();
1345
+ }
1346
+ return this.finishNode(node, "TSModuleDeclaration");
1347
+ }
1348
+ tsParseAmbientExternalModuleDeclaration(node) {
1349
+ if (this.isContextual(tt._global)) {
1350
+ node.kind = "global";
1351
+ {
1352
+ node.global = true;
1353
+ }
1354
+ node.id = this.parseIdentifier();
1355
+ } else if (this.match(tt.string)) {
1356
+ node.kind = "module";
1357
+ node.id = super.parseStringLiteral(this.state.value);
1358
+ } else {
1359
+ this.unexpected();
1360
+ }
1361
+ if (this.match(tt.braceL)) {
1362
+ this.scope.enter(ScopeFlag.TS_MODULE);
1363
+ this.prodParam.enter(ParamKind.PARAM);
1364
+ node.body = this.tsParseModuleBlock();
1365
+ this.prodParam.exit();
1366
+ this.scope.exit();
1367
+ } else {
1368
+ this.semicolon();
1369
+ }
1370
+ return this.finishNode(node, "TSModuleDeclaration");
1371
+ }
1372
+ tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
1373
+ {
1374
+ node.isExport = isExport || false;
1375
+ }
1376
+ node.id = maybeDefaultIdentifier || this.parseIdentifier();
1377
+ this.checkIdentifier(node.id, BindingFlag.TYPE_TS_VALUE_IMPORT);
1378
+ this.expect(tt.eq);
1379
+ const moduleReference = this.tsParseModuleReference();
1380
+ if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
1381
+ this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
1382
+ }
1383
+ node.moduleReference = moduleReference;
1384
+ this.semicolon();
1385
+ return this.finishNode(node, "TSImportEqualsDeclaration");
1386
+ }
1387
+ tsIsExternalModuleReference() {
1388
+ return this.isContextual(tt._require) && this.lookaheadCharCode() === 40;
1389
+ }
1390
+ tsParseModuleReference() {
1391
+ return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(tsParseEntityNameFlags.NONE);
1392
+ }
1393
+ tsParseExternalModuleReference() {
1394
+ const node = this.startNode();
1395
+ this.expectContextual(tt._require);
1396
+ this.expect(tt.parenL);
1397
+ if (!this.match(tt.string)) {
1398
+ this.unexpected();
1399
+ }
1400
+ node.expression = super.parseExprAtom();
1401
+ this.expect(tt.parenR);
1402
+ this.sawUnambiguousESM = true;
1403
+ return this.finishNode(node, "TSExternalModuleReference");
1404
+ }
1405
+ tsLookAhead(f) {
1406
+ const state = this.state.clone();
1407
+ const res = f();
1408
+ this.state = state;
1409
+ return res;
1410
+ }
1411
+ tsTryParseAndCatch(f) {
1412
+ const result = this.tryParse((abort) => f() || abort());
1413
+ if (result.aborted || !result.node) return;
1414
+ if (result.error) this.state = result.failState;
1415
+ return result.node;
1416
+ }
1417
+ tsTryParse(f) {
1418
+ const state = this.state.clone();
1419
+ const result = f();
1420
+ if (result !== void 0 && result !== false) {
1421
+ return result;
1422
+ }
1423
+ this.state = state;
1424
+ }
1425
+ tsTryParseDeclare(node) {
1426
+ if (this.isLineTerminator()) {
1427
+ return;
1428
+ }
1429
+ const startType = this.state.type;
1430
+ return this.tsInAmbientContext(() => {
1431
+ switch (startType) {
1432
+ case tt._function:
1433
+ node.declare = true;
1434
+ return super.parseFunctionStatement(node, false, false);
1435
+ case tt._class:
1436
+ node.declare = true;
1437
+ return this.parseClass(node, true, false);
1438
+ case tt._enum:
1439
+ return this.tsParseEnumDeclaration(node, {
1440
+ declare: true
1441
+ });
1442
+ case tt._global:
1443
+ return this.tsParseAmbientExternalModuleDeclaration(node);
1444
+ case tt._let:
1445
+ if (this.state.containsEsc) {
1446
+ return;
1447
+ }
1448
+ // falls through (upstream parser grammar)
1449
+ case tt._const:
1450
+ case tt._var:
1451
+ if (!this.match(tt._const) || !this.isLookaheadContextual("enum")) {
1452
+ node.declare = true;
1453
+ return this.parseVarStatement(node, this.state.value, true);
1454
+ }
1455
+ this.expect(tt._const);
1456
+ return this.tsParseEnumDeclaration(node, {
1457
+ const: true,
1458
+ declare: true
1459
+ });
1460
+ case tt._using:
1461
+ if (this.isUsing()) {
1462
+ this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
1463
+ node.declare = true;
1464
+ return this.parseVarStatement(node, "using", true);
1465
+ }
1466
+ break;
1467
+ case tt._await:
1468
+ if (this.isAwaitUsing()) {
1469
+ this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
1470
+ node.declare = true;
1471
+ this.next();
1472
+ return this.parseVarStatement(node, "await using", true);
1473
+ }
1474
+ break;
1475
+ case tt._interface: {
1476
+ const result = this.tsParseInterfaceDeclaration(node, {
1477
+ declare: true
1478
+ });
1479
+ if (result) return result;
1480
+ }
1481
+ // falls through (upstream parser grammar)
1482
+ default:
1483
+ if (tokenIsIdentifier(startType)) {
1484
+ return this.tsParseDeclaration(node, this.state.type, true, null);
1485
+ }
1486
+ }
1487
+ });
1488
+ }
1489
+ tsTryParseExportDeclaration() {
1490
+ return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
1491
+ }
1492
+ tsParseDeclaration(node, type, next, decorators) {
1493
+ switch (type) {
1494
+ case tt._abstract:
1495
+ if (this.tsCheckLineTerminator(next) && (this.match(tt._class) || tokenIsIdentifier(this.state.type))) {
1496
+ return this.tsParseAbstractDeclaration(node, decorators);
1497
+ }
1498
+ break;
1499
+ case tt._module:
1500
+ if (this.tsCheckLineTerminator(next)) {
1501
+ if (this.match(tt.string)) {
1502
+ return this.tsParseAmbientExternalModuleDeclaration(node);
1503
+ } else if (tokenIsIdentifier(this.state.type)) {
1504
+ node.kind = "module";
1505
+ return this.tsParseModuleOrNamespaceDeclaration(node);
1506
+ }
1507
+ }
1508
+ break;
1509
+ case tt._namespace:
1510
+ if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
1511
+ node.kind = "namespace";
1512
+ return this.tsParseModuleOrNamespaceDeclaration(node);
1513
+ }
1514
+ break;
1515
+ case tt._type:
1516
+ if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
1517
+ return this.tsParseTypeAliasDeclaration(node);
1518
+ }
1519
+ break;
1520
+ }
1521
+ }
1522
+ tsCheckLineTerminator(next) {
1523
+ if (next) {
1524
+ if (this.hasFollowingLineBreak()) return false;
1525
+ this.next();
1526
+ return true;
1527
+ }
1528
+ return !this.isLineTerminator();
1529
+ }
1530
+ tsTryParseGenericAsyncArrowFunction(startLoc) {
1531
+ if (!this.match(tt.lt)) return;
1532
+ const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
1533
+ this.state.maybeInArrowParameters = true;
1534
+ const res = this.tsTryParseAndCatch(() => {
1535
+ const node = this.startNodeAt(startLoc);
1536
+ node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
1537
+ super.parseFunctionParams(node);
1538
+ node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
1539
+ this.expect(tt.arrow);
1540
+ return node;
1541
+ });
1542
+ this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
1543
+ if (!res) return;
1544
+ return super.parseArrowExpression(res, null, true);
1545
+ }
1546
+ tsParseTypeArgumentsInExpression() {
1547
+ if (this.reScan_lt() !== tt.lt) return;
1548
+ return this.tsParseTypeArguments();
1549
+ }
1550
+ tsParseTypeArguments() {
1551
+ const node = this.startNode();
1552
+ node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
1553
+ this.expect(tt.lt);
1554
+ return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
1555
+ }));
1556
+ if (node.params.length === 0) {
1557
+ this.raise(TSErrors.EmptyTypeArguments, node);
1558
+ } else if (!this.state.inType && this.curContext() === tc.brace) {
1559
+ this.reScan_lt_gt();
1560
+ }
1561
+ this.expect(tt.gt);
1562
+ return this.finishNode(node, "TSTypeParameterInstantiation");
1563
+ }
1564
+ tsIsDeclarationStart() {
1565
+ return tokenIsTSDeclarationStart(this.state.type);
1566
+ }
1567
+ isExportDefaultSpecifier() {
1568
+ if (this.tsIsDeclarationStart()) return false;
1569
+ return super.isExportDefaultSpecifier();
1570
+ }
1571
+ parseBindingElement(flags, decorators) {
1572
+ const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
1573
+ const modified = {};
1574
+ this.tsParseModifiers({
1575
+ allowedModifiers: ["public", "private", "protected", "override", "readonly"]
1576
+ }, modified);
1577
+ const accessibility = modified.accessibility;
1578
+ const override = modified.override;
1579
+ const readonly = modified.readonly;
1580
+ if (!(flags & ParseBindingListFlags.IS_CONSTRUCTOR_PARAMS) && (accessibility || readonly || override)) {
1581
+ this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
1582
+ }
1583
+ const left = this.parseMaybeDefault();
1584
+ if (flags & ParseBindingListFlags.IS_FUNCTION_PARAMS) {
1585
+ this.parseFunctionParamType(left);
1586
+ }
1587
+ const elt = this.parseMaybeDefault(left.loc.start, left);
1588
+ if (accessibility || readonly || override) {
1589
+ const pp = this.startNodeAt(startLoc);
1590
+ if (decorators.length) {
1591
+ pp.decorators = decorators;
1592
+ }
1593
+ if (accessibility) pp.accessibility = accessibility;
1594
+ if (readonly) pp.readonly = readonly;
1595
+ if (override) pp.override = override;
1596
+ if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
1597
+ this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
1598
+ }
1599
+ pp.parameter = elt;
1600
+ return this.finishNode(pp, "TSParameterProperty");
1601
+ }
1602
+ if (decorators.length) {
1603
+ left.decorators = decorators;
1604
+ }
1605
+ return elt;
1606
+ }
1607
+ isSimpleParameter(node) {
1608
+ return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
1609
+ }
1610
+ tsDisallowOptionalPattern(node) {
1611
+ for (const param of node.params) {
1612
+ if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
1613
+ this.raise(TSErrors.PatternIsOptional, param);
1614
+ }
1615
+ }
1616
+ }
1617
+ setArrowFunctionParameters(node, params, trailingCommaLoc) {
1618
+ super.setArrowFunctionParameters(node, params, trailingCommaLoc);
1619
+ this.tsDisallowOptionalPattern(node);
1620
+ }
1621
+ parseFunctionBodyAndFinish(node, type, isMethod = false) {
1622
+ if (this.match(tt.colon)) {
1623
+ node.returnType = this.tsParseTypeOrTypePredicateAnnotation(tt.colon);
1624
+ }
1625
+ const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : void 0;
1626
+ if (bodilessType && !this.match(tt.braceL) && this.isLineTerminator()) {
1627
+ return this.finishNode(node, bodilessType);
1628
+ }
1629
+ if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
1630
+ this.raise(TSErrors.DeclareFunctionHasImplementation, node);
1631
+ if (node.declare) {
1632
+ return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
1633
+ }
1634
+ }
1635
+ this.tsDisallowOptionalPattern(node);
1636
+ return super.parseFunctionBodyAndFinish(node, type, isMethod);
1637
+ }
1638
+ registerFunctionStatementId(node) {
1639
+ if (!node.body && node.id) {
1640
+ this.checkIdentifier(node.id, BindingFlag.TYPE_TS_AMBIENT);
1641
+ } else {
1642
+ super.registerFunctionStatementId(node);
1643
+ }
1644
+ }
1645
+ tsCheckForInvalidTypeCasts(items) {
1646
+ items.forEach((node) => {
1647
+ if (node?.type === "TSTypeCastExpression") {
1648
+ this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
1649
+ }
1650
+ });
1651
+ }
1652
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1653
+ toReferencedList(exprList, isInParens) {
1654
+ this.tsCheckForInvalidTypeCasts(exprList);
1655
+ return exprList;
1656
+ }
1657
+ parseArrayLike(close, isTuple, refExpressionErrors) {
1658
+ const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
1659
+ if (node.type === "ArrayExpression") {
1660
+ this.tsCheckForInvalidTypeCasts(node.elements);
1661
+ }
1662
+ return node;
1663
+ }
1664
+ parseSubscript(base, startLoc, noCalls, state) {
1665
+ if (!this.hasPrecedingLineBreak() && this.match(tt.bang)) {
1666
+ this.state.canStartJSXElement = false;
1667
+ this.next();
1668
+ const nonNullExpression = this.startNodeAt(startLoc);
1669
+ nonNullExpression.expression = base;
1670
+ return this.finishNode(nonNullExpression, "TSNonNullExpression");
1671
+ }
1672
+ let isOptionalCall = false;
1673
+ if (this.match(tt.questionDot) && this.lookaheadCharCode() === 60) {
1674
+ if (noCalls) {
1675
+ state.stop = true;
1676
+ return base;
1677
+ }
1678
+ state.optionalChainMember = isOptionalCall = true;
1679
+ this.next();
1680
+ }
1681
+ if (this.match(tt.lt) || this.match(tt.bitShiftL)) {
1682
+ let missingParenErrorLoc;
1683
+ const result = this.tsTryParseAndCatch(() => {
1684
+ if (!noCalls && this.atPossibleAsyncArrow(base)) {
1685
+ const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
1686
+ if (asyncArrowFn) {
1687
+ state.stop = true;
1688
+ return asyncArrowFn;
1689
+ }
1690
+ }
1691
+ const typeArguments = this.tsParseTypeArgumentsInExpression();
1692
+ if (!typeArguments) return;
1693
+ if (isOptionalCall && !this.match(tt.parenL)) {
1694
+ missingParenErrorLoc = this.state.curPosition();
1695
+ return;
1696
+ }
1697
+ if (tokenIsTemplate(this.state.type)) {
1698
+ const result2 = super.parseTaggedTemplateExpression(base, startLoc, state);
1699
+ {
1700
+ result2.typeParameters = typeArguments;
1701
+ }
1702
+ return result2;
1703
+ }
1704
+ if (!noCalls && this.eat(tt.parenL)) {
1705
+ const node2 = this.startNodeAt(startLoc);
1706
+ node2.callee = base;
1707
+ node2.arguments = this.parseCallExpressionArguments();
1708
+ this.tsCheckForInvalidTypeCasts(node2.arguments);
1709
+ {
1710
+ node2.typeParameters = typeArguments;
1711
+ }
1712
+ if (state.optionalChainMember) {
1713
+ node2.optional = isOptionalCall;
1714
+ }
1715
+ return this.finishCallExpression(node2, state.optionalChainMember);
1716
+ }
1717
+ const tokenType = this.state.type;
1718
+ if (tokenType === tt.gt || tokenType === tt.bitShiftR || tokenType !== tt.parenL && tokenType !== tt._as && tokenType !== tt._satisfies && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
1719
+ return;
1720
+ }
1721
+ const node = this.startNodeAt(startLoc);
1722
+ node.expression = base;
1723
+ {
1724
+ node.typeParameters = typeArguments;
1725
+ }
1726
+ return this.finishNode(node, "TSInstantiationExpression");
1727
+ });
1728
+ if (missingParenErrorLoc) {
1729
+ this.unexpected(missingParenErrorLoc, tt.parenL);
1730
+ }
1731
+ if (result) {
1732
+ if (result.type === "TSInstantiationExpression") {
1733
+ if (this.match(tt.dot) || this.match(tt.questionDot) && this.lookaheadCharCode() !== 40) {
1734
+ this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
1735
+ }
1736
+ if (!this.match(tt.dot) && !this.match(tt.questionDot)) {
1737
+ result.expression = super.stopParseSubscript(base, state);
1738
+ }
1739
+ }
1740
+ return result;
1741
+ }
1742
+ }
1743
+ return super.parseSubscript(base, startLoc, noCalls, state);
1744
+ }
1745
+ parseNewCallee(node) {
1746
+ super.parseNewCallee(node);
1747
+ const {
1748
+ callee
1749
+ } = node;
1750
+ if (callee.type === "TSInstantiationExpression" && !callee.extra?.parenthesized) {
1751
+ {
1752
+ node.typeParameters = callee.typeParameters;
1753
+ }
1754
+ node.callee = callee.expression;
1755
+ }
1756
+ }
1757
+ parseExprOp(left, leftStartLoc, minPrec) {
1758
+ let isSatisfies;
1759
+ if (tokenOperatorPrecedence(tt._in) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(tt._as) || (isSatisfies = this.isContextual(tt._satisfies)))) {
1760
+ const node = this.startNodeAt(leftStartLoc);
1761
+ node.expression = left;
1762
+ node.typeAnnotation = this.tsInType(() => {
1763
+ this.next();
1764
+ if (this.match(tt._const)) {
1765
+ if (isSatisfies) {
1766
+ this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
1767
+ keyword: "const"
1768
+ });
1769
+ }
1770
+ return this.tsParseTypeReference();
1771
+ }
1772
+ return this.tsParseType();
1773
+ });
1774
+ this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
1775
+ this.reScan_lt_gt();
1776
+ return this.parseExprOp(node, leftStartLoc, minPrec);
1777
+ }
1778
+ return super.parseExprOp(left, leftStartLoc, minPrec);
1779
+ }
1780
+ checkReservedWord(word, startLoc, checkKeywords, isBinding) {
1781
+ if (!this.state.isAmbientContext) {
1782
+ super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
1783
+ }
1784
+ }
1785
+ checkImportReflection(node) {
1786
+ super.checkImportReflection(node);
1787
+ if (node.module && node.importKind !== "value") {
1788
+ this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
1789
+ }
1790
+ }
1791
+ checkDuplicateExports() {
1792
+ }
1793
+ isPotentialImportPhase(isExport) {
1794
+ if (super.isPotentialImportPhase(isExport)) return true;
1795
+ if (this.isContextual(tt._type)) {
1796
+ const ch = this.lookaheadCharCode();
1797
+ return isExport ? ch === 123 || ch === 42 : ch !== 61;
1798
+ }
1799
+ return !isExport && this.isContextual(tt._typeof);
1800
+ }
1801
+ applyImportPhase(node, isExport, phase, loc) {
1802
+ super.applyImportPhase(node, isExport, phase, loc);
1803
+ if (isExport) {
1804
+ node.exportKind = phase === "type" ? "type" : "value";
1805
+ } else {
1806
+ node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
1807
+ }
1808
+ }
1809
+ parseImport(node) {
1810
+ if (this.match(tt.string)) {
1811
+ node.importKind = "value";
1812
+ return super.parseImport(node);
1813
+ }
1814
+ let importNode;
1815
+ if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
1816
+ node.importKind = "value";
1817
+ return this.tsParseImportEqualsDeclaration(node);
1818
+ } else if (this.isContextual(tt._type)) {
1819
+ const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
1820
+ if (this.lookaheadCharCode() === 61) {
1821
+ return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
1822
+ } else {
1823
+ importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
1824
+ }
1825
+ } else {
1826
+ importNode = super.parseImport(node);
1827
+ }
1828
+ if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
1829
+ this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
1830
+ }
1831
+ return importNode;
1832
+ }
1833
+ parseExport(node, decorators) {
1834
+ if (this.match(tt._import)) {
1835
+ const nodeImportEquals = node;
1836
+ this.next();
1837
+ let maybeDefaultIdentifier = null;
1838
+ if (this.isContextual(tt._type) && this.isPotentialImportPhase(false)) {
1839
+ maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
1840
+ } else {
1841
+ nodeImportEquals.importKind = "value";
1842
+ }
1843
+ const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
1844
+ {
1845
+ return declaration;
1846
+ }
1847
+ } else if (this.eat(tt.eq)) {
1848
+ const assign = node;
1849
+ assign.expression = super.parseExpression();
1850
+ this.semicolon();
1851
+ this.sawUnambiguousESM = true;
1852
+ return this.finishNode(assign, "TSExportAssignment");
1853
+ } else if (this.eatContextual(tt._as)) {
1854
+ const decl = node;
1855
+ this.expectContextual(tt._namespace);
1856
+ decl.id = this.parseIdentifier();
1857
+ this.semicolon();
1858
+ return this.finishNode(decl, "TSNamespaceExportDeclaration");
1859
+ } else {
1860
+ return super.parseExport(node, decorators);
1861
+ }
1862
+ }
1863
+ isAbstractClass() {
1864
+ return this.isContextual(tt._abstract) && this.isLookaheadContextual("class");
1865
+ }
1866
+ parseExportDefaultExpression() {
1867
+ if (this.isAbstractClass()) {
1868
+ const cls = this.startNode();
1869
+ this.next();
1870
+ cls.abstract = true;
1871
+ return this.parseClass(cls, true, true);
1872
+ }
1873
+ if (this.match(tt._interface)) {
1874
+ const result = this.tsParseInterfaceDeclaration(this.startNode());
1875
+ if (result) return result;
1876
+ }
1877
+ return super.parseExportDefaultExpression();
1878
+ }
1879
+ parseVarStatement(node, kind, allowMissingInitializer = false) {
1880
+ const {
1881
+ isAmbientContext
1882
+ } = this.state;
1883
+ const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
1884
+ if (!isAmbientContext) return declaration;
1885
+ if (!node.declare && (kind === "using" || kind === "await using")) {
1886
+ this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
1887
+ return declaration;
1888
+ }
1889
+ for (const {
1890
+ id,
1891
+ init
1892
+ } of declaration.declarations) {
1893
+ if (!init) continue;
1894
+ if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
1895
+ this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
1896
+ } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
1897
+ this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
1898
+ }
1899
+ }
1900
+ return declaration;
1901
+ }
1902
+ parseStatementContent(flags, decorators) {
1903
+ if (!this.state.containsEsc) {
1904
+ switch (this.state.type) {
1905
+ case tt._const: {
1906
+ if (this.isLookaheadContextual("enum")) {
1907
+ const node = this.startNode();
1908
+ this.expect(tt._const);
1909
+ return this.tsParseEnumDeclaration(node, {
1910
+ const: true
1911
+ });
1912
+ }
1913
+ break;
1914
+ }
1915
+ case tt._abstract:
1916
+ case tt._declare: {
1917
+ if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
1918
+ const token = this.state.type;
1919
+ const node = this.startNode();
1920
+ this.next();
1921
+ const declaration = token === tt._declare ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
1922
+ if (declaration) {
1923
+ if (token === tt._declare) {
1924
+ declaration.declare = true;
1925
+ }
1926
+ return declaration;
1927
+ } else {
1928
+ node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === tt._declare ? "declare" : "abstract");
1929
+ this.semicolon(false);
1930
+ return this.finishNode(node, "ExpressionStatement");
1931
+ }
1932
+ }
1933
+ break;
1934
+ }
1935
+ case tt._enum:
1936
+ return this.tsParseEnumDeclaration(this.startNode());
1937
+ case tt._global: {
1938
+ const nextCh = this.lookaheadCharCode();
1939
+ if (nextCh === 123) {
1940
+ const node = this.startNode();
1941
+ return this.tsParseAmbientExternalModuleDeclaration(node);
1942
+ }
1943
+ break;
1944
+ }
1945
+ case tt._interface: {
1946
+ const result = this.tsParseInterfaceDeclaration(this.startNode());
1947
+ if (result) return result;
1948
+ break;
1949
+ }
1950
+ case tt._module: {
1951
+ if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
1952
+ const node = this.startNode();
1953
+ this.next();
1954
+ return this.tsParseDeclaration(node, tt._module, false, decorators);
1955
+ }
1956
+ break;
1957
+ }
1958
+ case tt._namespace: {
1959
+ if (this.nextTokenIsIdentifierOnSameLine()) {
1960
+ const node = this.startNode();
1961
+ this.next();
1962
+ return this.tsParseDeclaration(node, tt._namespace, false, decorators);
1963
+ }
1964
+ break;
1965
+ }
1966
+ case tt._type: {
1967
+ if (this.nextTokenIsIdentifierOnSameLine()) {
1968
+ const node = this.startNode();
1969
+ this.next();
1970
+ return this.tsParseTypeAliasDeclaration(node);
1971
+ }
1972
+ break;
1973
+ }
1974
+ }
1975
+ }
1976
+ return super.parseStatementContent(flags, decorators);
1977
+ }
1978
+ parseAccessModifier() {
1979
+ return this.tsParseModifier(["public", "protected", "private"]);
1980
+ }
1981
+ tsHasSomeModifiers(member, modifiers) {
1982
+ return modifiers.some((modifier) => {
1983
+ if (tsIsAccessModifier(modifier)) {
1984
+ return member.accessibility === modifier;
1985
+ }
1986
+ return !!member[modifier];
1987
+ });
1988
+ }
1989
+ tsIsStartOfStaticBlocks() {
1990
+ return this.isContextual(tt._static) && this.lookaheadCharCode() === 123;
1991
+ }
1992
+ parseClassMember(classBody, member, state) {
1993
+ const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
1994
+ this.tsParseModifiers({
1995
+ allowedModifiers: modifiers,
1996
+ disallowedModifiers: ["in", "out"],
1997
+ stopOnStartOfClassStaticBlock: true,
1998
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
1999
+ }, member);
2000
+ const callParseClassMemberWithIsStatic = () => {
2001
+ if (this.tsIsStartOfStaticBlocks()) {
2002
+ this.next();
2003
+ this.next();
2004
+ if (this.tsHasSomeModifiers(member, modifiers)) {
2005
+ this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
2006
+ }
2007
+ super.parseClassStaticBlock(classBody, member);
2008
+ } else {
2009
+ this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
2010
+ }
2011
+ };
2012
+ if (member.declare) {
2013
+ this.tsInAmbientContext(callParseClassMemberWithIsStatic);
2014
+ } else {
2015
+ callParseClassMemberWithIsStatic();
2016
+ }
2017
+ }
2018
+ parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
2019
+ const idx = this.tsTryParseIndexSignature(member);
2020
+ if (idx) {
2021
+ classBody.body.push(idx);
2022
+ if (member.abstract) {
2023
+ this.raise(TSErrors.IndexSignatureHasAbstract, member);
2024
+ }
2025
+ if (member.accessibility) {
2026
+ this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
2027
+ modifier: member.accessibility
2028
+ });
2029
+ }
2030
+ if (member.declare) {
2031
+ this.raise(TSErrors.IndexSignatureHasDeclare, member);
2032
+ }
2033
+ if (member.override) {
2034
+ this.raise(TSErrors.IndexSignatureHasOverride, member);
2035
+ }
2036
+ return;
2037
+ }
2038
+ if (!this.state.inAbstractClass && member.abstract) {
2039
+ this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
2040
+ }
2041
+ if (member.override) {
2042
+ if (!state.hadSuperClass) {
2043
+ this.raise(TSErrors.OverrideNotInSubClass, member);
2044
+ }
2045
+ }
2046
+ super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
2047
+ }
2048
+ parsePostMemberNameModifiers(methodOrProp) {
2049
+ const optional = this.eat(tt.question);
2050
+ if (optional) methodOrProp.optional = true;
2051
+ if (methodOrProp.readonly && this.match(tt.parenL)) {
2052
+ this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
2053
+ }
2054
+ if (methodOrProp.declare && this.match(tt.parenL)) {
2055
+ this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
2056
+ }
2057
+ }
2058
+ shouldParseExportDeclaration() {
2059
+ if (this.tsIsDeclarationStart()) return true;
2060
+ return super.shouldParseExportDeclaration();
2061
+ }
2062
+ parseConditional(expr, startLoc, refExpressionErrors) {
2063
+ if (!this.match(tt.question)) return expr;
2064
+ if (this.state.maybeInArrowParameters) {
2065
+ const nextCh = this.lookaheadCharCode();
2066
+ if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
2067
+ this.setOptionalParametersError(refExpressionErrors);
2068
+ return expr;
2069
+ }
2070
+ }
2071
+ return super.parseConditional(expr, startLoc, refExpressionErrors);
2072
+ }
2073
+ parseParenItem(node, startLoc) {
2074
+ const newNode = super.parseParenItem(node, startLoc);
2075
+ if (this.eat(tt.question)) {
2076
+ newNode.optional = true;
2077
+ this.resetEndLocation(node);
2078
+ }
2079
+ if (this.match(tt.colon)) {
2080
+ const typeCastNode = this.startNodeAt(startLoc);
2081
+ typeCastNode.expression = node;
2082
+ typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
2083
+ return this.finishNode(typeCastNode, "TSTypeCastExpression");
2084
+ }
2085
+ return node;
2086
+ }
2087
+ parseExportDeclaration(node) {
2088
+ if (!this.state.isAmbientContext && this.isContextual(tt._declare)) {
2089
+ return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
2090
+ }
2091
+ const startLoc = this.state.startLoc;
2092
+ const isDeclare = this.eatContextual(tt._declare);
2093
+ if (isDeclare && (this.isContextual(tt._declare) || !this.shouldParseExportDeclaration())) {
2094
+ throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
2095
+ }
2096
+ const isIdentifier = tokenIsIdentifier(this.state.type);
2097
+ const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
2098
+ if (!declaration) return null;
2099
+ if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
2100
+ node.exportKind = "type";
2101
+ }
2102
+ if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
2103
+ this.resetStartLocation(declaration, startLoc);
2104
+ declaration.declare = true;
2105
+ }
2106
+ return declaration;
2107
+ }
2108
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
2109
+ parseClassId(node, isStatement, optionalId, bindingType) {
2110
+ if ((!isStatement || optionalId) && this.isContextual(tt._implements)) {
2111
+ return;
2112
+ }
2113
+ super.parseClassId(node, isStatement, optionalId, node.declare ? BindingFlag.TYPE_TS_AMBIENT : BindingFlag.TYPE_CLASS);
2114
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
2115
+ if (typeParameters) node.typeParameters = typeParameters;
2116
+ }
2117
+ parseClassPropertyAnnotation(node) {
2118
+ if (!node.optional) {
2119
+ if (this.eat(tt.bang)) {
2120
+ node.definite = true;
2121
+ } else if (this.eat(tt.question)) {
2122
+ node.optional = true;
2123
+ }
2124
+ }
2125
+ const type = this.tsTryParseTypeAnnotation();
2126
+ if (type) node.typeAnnotation = type;
2127
+ }
2128
+ parseClassProperty(node) {
2129
+ this.parseClassPropertyAnnotation(node);
2130
+ if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(tt.eq)) {
2131
+ this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
2132
+ }
2133
+ if (node.abstract && this.match(tt.eq)) {
2134
+ const {
2135
+ key
2136
+ } = node;
2137
+ this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
2138
+ propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
2139
+ });
2140
+ }
2141
+ return super.parseClassProperty(node);
2142
+ }
2143
+ parseClassPrivateProperty(node) {
2144
+ if (node.abstract) {
2145
+ this.raise(TSErrors.PrivateElementHasAbstract, node);
2146
+ }
2147
+ if (node.accessibility) {
2148
+ this.raise(TSErrors.PrivateElementHasAccessibility, node, {
2149
+ modifier: node.accessibility
2150
+ });
2151
+ }
2152
+ this.parseClassPropertyAnnotation(node);
2153
+ return super.parseClassPrivateProperty(node);
2154
+ }
2155
+ parseClassAccessorProperty(node) {
2156
+ this.parseClassPropertyAnnotation(node);
2157
+ if (node.optional) {
2158
+ this.raise(TSErrors.AccessorCannotBeOptional, node);
2159
+ }
2160
+ return super.parseClassAccessorProperty(node);
2161
+ }
2162
+ pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
2163
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
2164
+ if (typeParameters && isConstructor) {
2165
+ this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
2166
+ }
2167
+ const {
2168
+ declare = false,
2169
+ kind
2170
+ } = method;
2171
+ if (declare && (kind === "get" || kind === "set")) {
2172
+ this.raise(TSErrors.DeclareAccessor, method, {
2173
+ kind
2174
+ });
2175
+ }
2176
+ if (typeParameters) method.typeParameters = typeParameters;
2177
+ super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
2178
+ }
2179
+ pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
2180
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
2181
+ if (typeParameters) method.typeParameters = typeParameters;
2182
+ super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
2183
+ }
2184
+ declareClassPrivateMethodInScope(node, kind) {
2185
+ if (node.type === "TSDeclareMethod") return;
2186
+ if (node.type === "MethodDefinition" && node.value.body == null) {
2187
+ return;
2188
+ }
2189
+ super.declareClassPrivateMethodInScope(node, kind);
2190
+ }
2191
+ parseClassSuper(node) {
2192
+ super.parseClassSuper(node);
2193
+ if (node.superClass) {
2194
+ if (node.superClass.type === "TSInstantiationExpression") {
2195
+ const tsInstantiationExpression = node.superClass;
2196
+ const superClass2 = tsInstantiationExpression.expression;
2197
+ this.takeSurroundingComments(superClass2, superClass2.start, superClass2.end);
2198
+ const superTypeArguments = tsInstantiationExpression.typeParameters;
2199
+ this.takeSurroundingComments(superTypeArguments, superTypeArguments.start, superTypeArguments.end);
2200
+ node.superClass = superClass2;
2201
+ node.superTypeParameters = superTypeArguments;
2202
+ } else if (this.match(tt.lt) || this.match(tt.bitShiftL)) {
2203
+ {
2204
+ node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
2205
+ }
2206
+ }
2207
+ }
2208
+ if (this.eatContextual(tt._implements)) {
2209
+ node.implements = this.tsParseHeritageClause("implements");
2210
+ }
2211
+ }
2212
+ parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
2213
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
2214
+ if (typeParameters) prop.typeParameters = typeParameters;
2215
+ return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
2216
+ }
2217
+ parseFunctionParams(node, isConstructor) {
2218
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
2219
+ if (typeParameters) node.typeParameters = typeParameters;
2220
+ super.parseFunctionParams(node, isConstructor);
2221
+ }
2222
+ parseVarId(decl, kind) {
2223
+ super.parseVarId(decl, kind);
2224
+ if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(tt.bang)) {
2225
+ decl.definite = true;
2226
+ }
2227
+ const type = this.tsTryParseTypeAnnotation();
2228
+ if (type) {
2229
+ decl.id.typeAnnotation = type;
2230
+ this.resetEndLocation(decl.id);
2231
+ }
2232
+ }
2233
+ parseAsyncArrowFromCallExpression(node, call) {
2234
+ if (this.match(tt.colon)) {
2235
+ node.returnType = this.tsParseTypeAnnotation();
2236
+ }
2237
+ return super.parseAsyncArrowFromCallExpression(node, call);
2238
+ }
2239
+ parseMaybeAssign(refExpressionErrors, afterLeftParse) {
2240
+ let state;
2241
+ let jsx;
2242
+ let typeCast;
2243
+ if (this.hasPlugin("jsx") && (this.match(tt.jsxTagStart) || this.match(tt.lt))) {
2244
+ state = this.state.clone();
2245
+ jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
2246
+ if (!jsx.error) return jsx.node;
2247
+ const {
2248
+ context
2249
+ } = this.state;
2250
+ const currentContext = context[context.length - 1];
2251
+ if (currentContext === tc.j_oTag || currentContext === tc.j_expr) {
2252
+ context.pop();
2253
+ }
2254
+ }
2255
+ if (!jsx?.error && !this.match(tt.lt)) {
2256
+ return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
2257
+ }
2258
+ if (!state || state === this.state) state = this.state.clone();
2259
+ let typeParameters;
2260
+ const arrow = this.tryParse((abort) => {
2261
+ typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
2262
+ const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
2263
+ if (expr.type !== "ArrowFunctionExpression" || expr.extra?.parenthesized) {
2264
+ abort();
2265
+ }
2266
+ if (typeParameters?.params.length !== 0) {
2267
+ this.resetStartLocationFromNode(expr, typeParameters);
2268
+ }
2269
+ expr.typeParameters = typeParameters;
2270
+ return expr;
2271
+ }, state);
2272
+ if (!arrow.error && !arrow.aborted) {
2273
+ if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
2274
+ return arrow.node;
2275
+ }
2276
+ if (!jsx) {
2277
+ assert(!this.hasPlugin("jsx"));
2278
+ typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
2279
+ if (!typeCast.error) return typeCast.node;
2280
+ }
2281
+ if (jsx?.node) {
2282
+ this.state = jsx.failState;
2283
+ return jsx.node;
2284
+ }
2285
+ if (arrow.node) {
2286
+ this.state = arrow.failState;
2287
+ if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
2288
+ return arrow.node;
2289
+ }
2290
+ if (typeCast?.node) {
2291
+ this.state = typeCast.failState;
2292
+ return typeCast.node;
2293
+ }
2294
+ throw jsx?.error || arrow.error || typeCast?.error;
2295
+ }
2296
+ reportReservedArrowTypeParam(node) {
2297
+ if (node.params.length === 1 && !node.params[0].constraint && !node.extra?.trailingComma && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
2298
+ this.raise(TSErrors.ReservedArrowTypeParam, node);
2299
+ }
2300
+ }
2301
+ parseMaybeUnary(refExpressionErrors, sawUnary) {
2302
+ if (!this.hasPlugin("jsx") && this.match(tt.lt)) {
2303
+ return this.tsParseTypeAssertion();
2304
+ }
2305
+ return super.parseMaybeUnary(refExpressionErrors, sawUnary);
2306
+ }
2307
+ parseArrow(node) {
2308
+ if (this.match(tt.colon)) {
2309
+ const result = this.tryParse((abort) => {
2310
+ const returnType = this.tsParseTypeOrTypePredicateAnnotation(tt.colon);
2311
+ if (this.canInsertSemicolon() || !this.match(tt.arrow)) abort();
2312
+ return returnType;
2313
+ });
2314
+ if (result.aborted) return;
2315
+ if (!result.thrown) {
2316
+ if (result.error) this.state = result.failState;
2317
+ node.returnType = result.node;
2318
+ }
2319
+ }
2320
+ return super.parseArrow(node);
2321
+ }
2322
+ parseFunctionParamType(param) {
2323
+ if (this.eat(tt.question)) {
2324
+ param.optional = true;
2325
+ }
2326
+ const type = this.tsTryParseTypeAnnotation();
2327
+ if (type) param.typeAnnotation = type;
2328
+ this.resetEndLocation(param);
2329
+ return param;
2330
+ }
2331
+ isAssignable(node, isBinding) {
2332
+ switch (node.type) {
2333
+ case "TSTypeCastExpression":
2334
+ return this.isAssignable(node.expression, isBinding);
2335
+ case "TSParameterProperty":
2336
+ return true;
2337
+ default:
2338
+ return super.isAssignable(node, isBinding);
2339
+ }
2340
+ }
2341
+ toAssignable(node, isLHS = false) {
2342
+ switch (node.type) {
2343
+ case "ParenthesizedExpression":
2344
+ this.toAssignableParenthesizedExpression(node, isLHS);
2345
+ break;
2346
+ case "TSAsExpression":
2347
+ case "TSSatisfiesExpression":
2348
+ case "TSNonNullExpression":
2349
+ case "TSTypeAssertion":
2350
+ if (isLHS) {
2351
+ this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
2352
+ } else {
2353
+ this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
2354
+ }
2355
+ this.toAssignable(node.expression, isLHS);
2356
+ break;
2357
+ case "AssignmentExpression":
2358
+ if (!isLHS && node.left.type === "TSTypeCastExpression") {
2359
+ node.left = this.typeCastToParameter(node.left);
2360
+ }
2361
+ // falls through (upstream parser grammar)
2362
+ default:
2363
+ super.toAssignable(node, isLHS);
2364
+ }
2365
+ }
2366
+ toAssignableParenthesizedExpression(node, isLHS) {
2367
+ switch (node.expression.type) {
2368
+ case "TSAsExpression":
2369
+ case "TSSatisfiesExpression":
2370
+ case "TSNonNullExpression":
2371
+ case "TSTypeAssertion":
2372
+ case "ParenthesizedExpression":
2373
+ this.toAssignable(node.expression, isLHS);
2374
+ break;
2375
+ default:
2376
+ super.toAssignable(node, isLHS);
2377
+ }
2378
+ }
2379
+ checkToRestConversion(node, allowPattern) {
2380
+ switch (node.type) {
2381
+ case "TSAsExpression":
2382
+ case "TSSatisfiesExpression":
2383
+ case "TSTypeAssertion":
2384
+ case "TSNonNullExpression":
2385
+ this.checkToRestConversion(node.expression, false);
2386
+ break;
2387
+ default:
2388
+ super.checkToRestConversion(node, allowPattern);
2389
+ }
2390
+ }
2391
+ isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
2392
+ switch (type) {
2393
+ case "TSTypeCastExpression":
2394
+ return true;
2395
+ case "TSParameterProperty":
2396
+ return "parameter";
2397
+ case "TSNonNullExpression":
2398
+ return "expression";
2399
+ case "TSAsExpression":
2400
+ case "TSSatisfiesExpression":
2401
+ case "TSTypeAssertion":
2402
+ return (binding !== BindingFlag.TYPE_NONE || !isUnparenthesizedInAssign) && ["expression", true];
2403
+ default:
2404
+ return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
2405
+ }
2406
+ }
2407
+ parseBindingAtom() {
2408
+ if (this.state.type === tt._this) {
2409
+ return this.parseIdentifier(true);
2410
+ }
2411
+ return super.parseBindingAtom();
2412
+ }
2413
+ parseMaybeDecoratorArguments(expr, startLoc) {
2414
+ if (this.match(tt.lt) || this.match(tt.bitShiftL)) {
2415
+ const typeArguments = this.tsParseTypeArgumentsInExpression();
2416
+ if (this.match(tt.parenL)) {
2417
+ const call = super.parseMaybeDecoratorArguments(expr, startLoc);
2418
+ {
2419
+ call.typeParameters = typeArguments;
2420
+ }
2421
+ return call;
2422
+ }
2423
+ this.unexpected(null, tt.parenL);
2424
+ }
2425
+ return super.parseMaybeDecoratorArguments(expr, startLoc);
2426
+ }
2427
+ checkCommaAfterRest(close) {
2428
+ if (this.state.isAmbientContext && this.match(tt.comma) && this.lookaheadCharCode() === close) {
2429
+ this.next();
2430
+ return false;
2431
+ }
2432
+ return super.checkCommaAfterRest(close);
2433
+ }
2434
+ isClassMethod() {
2435
+ return this.match(tt.lt) || super.isClassMethod();
2436
+ }
2437
+ isClassProperty() {
2438
+ return this.match(tt.bang) || this.match(tt.colon) || super.isClassProperty();
2439
+ }
2440
+ parseMaybeDefault(startLoc, left) {
2441
+ const node = super.parseMaybeDefault(startLoc, left);
2442
+ if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
2443
+ this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
2444
+ }
2445
+ return node;
2446
+ }
2447
+ getTokenFromCode(code) {
2448
+ if (this.state.inType) {
2449
+ if (code === 62) {
2450
+ this.finishOp(tt.gt, 1);
2451
+ return;
2452
+ }
2453
+ if (code === 60) {
2454
+ this.finishOp(tt.lt, 1);
2455
+ return;
2456
+ }
2457
+ }
2458
+ super.getTokenFromCode(code);
2459
+ }
2460
+ reScan_lt_gt() {
2461
+ const {
2462
+ type
2463
+ } = this.state;
2464
+ if (type === tt.lt) {
2465
+ this.state.pos -= 1;
2466
+ this.readToken_lt();
2467
+ } else if (type === tt.gt) {
2468
+ this.state.pos -= 1;
2469
+ this.readToken_gt();
2470
+ }
2471
+ }
2472
+ reScan_lt() {
2473
+ const {
2474
+ type
2475
+ } = this.state;
2476
+ if (type === tt.bitShiftL) {
2477
+ this.state.pos -= 2;
2478
+ this.finishOp(tt.lt, 1);
2479
+ return tt.lt;
2480
+ }
2481
+ return type;
2482
+ }
2483
+ toAssignableListItem(exprList, index, isLHS) {
2484
+ const node = exprList[index];
2485
+ if (node.type === "TSTypeCastExpression") {
2486
+ exprList[index] = this.typeCastToParameter(node);
2487
+ }
2488
+ super.toAssignableListItem(exprList, index, isLHS);
2489
+ }
2490
+ typeCastToParameter(node) {
2491
+ node.expression.typeAnnotation = node.typeAnnotation;
2492
+ this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
2493
+ return node.expression;
2494
+ }
2495
+ shouldParseArrow(params) {
2496
+ if (this.match(tt.colon)) {
2497
+ return params.every((expr) => this.isAssignable(expr, true));
2498
+ }
2499
+ return super.shouldParseArrow(params);
2500
+ }
2501
+ shouldParseAsyncArrow() {
2502
+ return this.match(tt.colon) || super.shouldParseAsyncArrow();
2503
+ }
2504
+ canHaveLeadingDecorator() {
2505
+ return super.canHaveLeadingDecorator() || this.isAbstractClass();
2506
+ }
2507
+ jsxParseOpeningElementAfterName(node) {
2508
+ if (this.match(tt.lt) || this.match(tt.bitShiftL)) {
2509
+ const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
2510
+ if (typeArguments) {
2511
+ {
2512
+ node.typeParameters = typeArguments;
2513
+ }
2514
+ }
2515
+ }
2516
+ return super.jsxParseOpeningElementAfterName(node);
2517
+ }
2518
+ getGetterSetterExpectedParamCount(method) {
2519
+ const baseCount = super.getGetterSetterExpectedParamCount(method);
2520
+ const params = this.getObjectOrClassMethodParams(method);
2521
+ const firstParam = params[0];
2522
+ const hasContextParam = firstParam && this.isThisParam(firstParam);
2523
+ return hasContextParam ? baseCount + 1 : baseCount;
2524
+ }
2525
+ parseCatchClauseParam() {
2526
+ const param = super.parseCatchClauseParam();
2527
+ const type = this.tsTryParseTypeAnnotation();
2528
+ if (type) {
2529
+ param.typeAnnotation = type;
2530
+ this.resetEndLocation(param);
2531
+ }
2532
+ return param;
2533
+ }
2534
+ tsInAmbientContext(cb) {
2535
+ const {
2536
+ isAmbientContext: oldIsAmbientContext,
2537
+ strict: oldStrict
2538
+ } = this.state;
2539
+ this.state.isAmbientContext = true;
2540
+ this.state.strict = false;
2541
+ try {
2542
+ return cb();
2543
+ } finally {
2544
+ this.state.isAmbientContext = oldIsAmbientContext;
2545
+ this.state.strict = oldStrict;
2546
+ }
2547
+ }
2548
+ parseClass(node, isStatement, optionalId) {
2549
+ const oldInAbstractClass = this.state.inAbstractClass;
2550
+ this.state.inAbstractClass = !!node.abstract;
2551
+ try {
2552
+ return super.parseClass(node, isStatement, optionalId);
2553
+ } finally {
2554
+ this.state.inAbstractClass = oldInAbstractClass;
2555
+ }
2556
+ }
2557
+ tsParseAbstractDeclaration(node, decorators) {
2558
+ if (this.match(tt._class)) {
2559
+ node.abstract = true;
2560
+ return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
2561
+ } else if (this.isContextual(tt._interface)) {
2562
+ if (!this.hasFollowingLineBreak()) {
2563
+ node.abstract = true;
2564
+ this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
2565
+ return this.tsParseInterfaceDeclaration(node);
2566
+ } else {
2567
+ return null;
2568
+ }
2569
+ }
2570
+ throw this.unexpected(null, tt._class);
2571
+ }
2572
+ parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
2573
+ const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
2574
+ if (method.abstract || method.type === "TSAbstractMethodDefinition") {
2575
+ const hasEstreePlugin = this.hasPlugin("estree");
2576
+ const methodFn = hasEstreePlugin ? method.value : method;
2577
+ if (methodFn.body) {
2578
+ const {
2579
+ key
2580
+ } = method;
2581
+ this.raise(TSErrors.AbstractMethodHasImplementation, method, {
2582
+ methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
2583
+ });
2584
+ }
2585
+ }
2586
+ return method;
2587
+ }
2588
+ tsParseTypeParameterName() {
2589
+ const typeName = this.parseIdentifier();
2590
+ return typeName.name;
2591
+ }
2592
+ shouldParseAsAmbientContext() {
2593
+ return !!this.getPluginOption("typescript", "dts");
2594
+ }
2595
+ parse() {
2596
+ if (this.shouldParseAsAmbientContext()) {
2597
+ this.state.isAmbientContext = true;
2598
+ }
2599
+ return super.parse();
2600
+ }
2601
+ getExpression() {
2602
+ if (this.shouldParseAsAmbientContext()) {
2603
+ this.state.isAmbientContext = true;
2604
+ }
2605
+ return super.getExpression();
2606
+ }
2607
+ parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
2608
+ if (!isString && isMaybeTypeOnly) {
2609
+ this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
2610
+ return this.finishNode(node, "ExportSpecifier");
2611
+ }
2612
+ node.exportKind = "value";
2613
+ return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
2614
+ }
2615
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
2616
+ parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
2617
+ if (!importedIsString && isMaybeTypeOnly) {
2618
+ this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
2619
+ return this.finishNode(specifier, "ImportSpecifier");
2620
+ }
2621
+ specifier.importKind = "value";
2622
+ return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BindingFlag.TYPE_TS_TYPE_IMPORT : BindingFlag.TYPE_TS_VALUE_IMPORT);
2623
+ }
2624
+ parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
2625
+ const leftOfAsKey = isImport ? "imported" : "local";
2626
+ const rightOfAsKey = isImport ? "local" : "exported";
2627
+ let leftOfAs = node[leftOfAsKey];
2628
+ let rightOfAs;
2629
+ let hasTypeSpecifier = false;
2630
+ let canParseAsKeyword = true;
2631
+ const loc = leftOfAs.loc.start;
2632
+ if (this.isContextual(tt._as)) {
2633
+ const firstAs = this.parseIdentifier();
2634
+ if (this.isContextual(tt._as)) {
2635
+ const secondAs = this.parseIdentifier();
2636
+ if (tokenIsKeywordOrIdentifier(this.state.type)) {
2637
+ hasTypeSpecifier = true;
2638
+ leftOfAs = firstAs;
2639
+ rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
2640
+ canParseAsKeyword = false;
2641
+ } else {
2642
+ rightOfAs = secondAs;
2643
+ canParseAsKeyword = false;
2644
+ }
2645
+ } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
2646
+ canParseAsKeyword = false;
2647
+ rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
2648
+ } else {
2649
+ hasTypeSpecifier = true;
2650
+ leftOfAs = firstAs;
2651
+ }
2652
+ } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
2653
+ hasTypeSpecifier = true;
2654
+ if (isImport) {
2655
+ leftOfAs = this.parseIdentifier(true);
2656
+ if (!this.isContextual(tt._as)) {
2657
+ this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
2658
+ }
2659
+ } else {
2660
+ leftOfAs = this.parseModuleExportName();
2661
+ }
2662
+ }
2663
+ if (hasTypeSpecifier && isInTypeOnlyImportExport) {
2664
+ this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
2665
+ }
2666
+ node[leftOfAsKey] = leftOfAs;
2667
+ node[rightOfAsKey] = rightOfAs;
2668
+ const kindKey = isImport ? "importKind" : "exportKind";
2669
+ node[kindKey] = hasTypeSpecifier ? "type" : "value";
2670
+ if (canParseAsKeyword && this.eatContextual(tt._as)) {
2671
+ node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
2672
+ }
2673
+ if (!node[rightOfAsKey]) {
2674
+ node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
2675
+ }
2676
+ if (isImport) {
2677
+ this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BindingFlag.TYPE_TS_TYPE_IMPORT : BindingFlag.TYPE_TS_VALUE_IMPORT);
2678
+ }
2679
+ }
2680
+ fillOptionalPropertiesForTSESLint(node) {
2681
+ switch (node.type) {
2682
+ case "ExpressionStatement":
2683
+ node.directive ??= void 0;
2684
+ return;
2685
+ case "RestElement":
2686
+ node.value = void 0;
2687
+ // falls through (upstream parser grammar)
2688
+ case "Identifier":
2689
+ case "ArrayPattern":
2690
+ case "AssignmentPattern":
2691
+ case "ObjectPattern":
2692
+ node.decorators ??= [];
2693
+ node.optional ??= false;
2694
+ node.typeAnnotation ??= void 0;
2695
+ return;
2696
+ case "TSParameterProperty":
2697
+ node.accessibility ??= void 0;
2698
+ node.decorators ??= [];
2699
+ node.override ??= false;
2700
+ node.readonly ??= false;
2701
+ node.static ??= false;
2702
+ return;
2703
+ case "TSEmptyBodyFunctionExpression":
2704
+ node.body = null;
2705
+ // falls through (upstream parser grammar)
2706
+ case "TSDeclareFunction":
2707
+ case "FunctionDeclaration":
2708
+ case "FunctionExpression":
2709
+ case "ClassMethod":
2710
+ case "ClassPrivateMethod":
2711
+ node.declare ??= false;
2712
+ node.returnType ??= void 0;
2713
+ node.typeParameters ??= void 0;
2714
+ return;
2715
+ case "Property":
2716
+ node.optional ??= false;
2717
+ return;
2718
+ case "TSMethodSignature":
2719
+ case "TSPropertySignature":
2720
+ node.optional ??= false;
2721
+ // falls through (upstream parser grammar)
2722
+ case "TSIndexSignature":
2723
+ node.accessibility ??= void 0;
2724
+ node.readonly ??= false;
2725
+ node.static ??= false;
2726
+ return;
2727
+ case "TSAbstractPropertyDefinition":
2728
+ case "PropertyDefinition":
2729
+ case "TSAbstractAccessorProperty":
2730
+ case "AccessorProperty":
2731
+ node.declare ??= false;
2732
+ node.definite ??= false;
2733
+ node.readonly ??= false;
2734
+ node.typeAnnotation ??= void 0;
2735
+ // falls through (upstream parser grammar)
2736
+ case "TSAbstractMethodDefinition":
2737
+ case "MethodDefinition":
2738
+ node.accessibility ??= void 0;
2739
+ node.decorators ??= [];
2740
+ node.override ??= false;
2741
+ node.optional ??= false;
2742
+ return;
2743
+ case "ClassExpression":
2744
+ node.id ??= null;
2745
+ // falls through (upstream parser grammar)
2746
+ case "ClassDeclaration":
2747
+ node.abstract ??= false;
2748
+ node.declare ??= false;
2749
+ node.decorators ??= [];
2750
+ node.implements ??= [];
2751
+ node.superTypeArguments ??= void 0;
2752
+ node.typeParameters ??= void 0;
2753
+ return;
2754
+ case "TSTypeAliasDeclaration":
2755
+ case "VariableDeclaration":
2756
+ node.declare ??= false;
2757
+ return;
2758
+ case "VariableDeclarator":
2759
+ node.definite ??= false;
2760
+ return;
2761
+ case "TSEnumDeclaration":
2762
+ node.const ??= false;
2763
+ node.declare ??= false;
2764
+ return;
2765
+ case "TSEnumMember":
2766
+ node.computed ??= false;
2767
+ return;
2768
+ case "TSImportType":
2769
+ node.qualifier ??= null;
2770
+ node.options ??= null;
2771
+ return;
2772
+ case "TSInterfaceDeclaration":
2773
+ node.declare ??= false;
2774
+ node.extends ??= [];
2775
+ return;
2776
+ case "TSMappedType":
2777
+ node.optional ??= false;
2778
+ node.readonly ??= void 0;
2779
+ return;
2780
+ case "TSModuleDeclaration":
2781
+ node.declare ??= false;
2782
+ node.global ??= node.kind === "global";
2783
+ return;
2784
+ case "TSTypeParameter":
2785
+ node.const ??= false;
2786
+ node.in ??= false;
2787
+ node.out ??= false;
2788
+ return;
2789
+ }
2790
+ }
2791
+ chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
2792
+ if (isIdentifierStart(ch)) {
2793
+ keywordAndTSRelationalOperator.lastIndex = pos;
2794
+ if (keywordAndTSRelationalOperator.test(this.input)) {
2795
+ const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
2796
+ if (!isIdentifierChar(endCh) && endCh !== 92) {
2797
+ return false;
2798
+ }
2799
+ }
2800
+ return true;
2801
+ } else if (ch === 92) {
2802
+ return true;
2803
+ } else {
2804
+ return false;
2805
+ }
2806
+ }
2807
+ nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
2808
+ const next = this.nextTokenInLineStart();
2809
+ const nextCh = this.codePointAtPos(next);
2810
+ return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
2811
+ }
2812
+ nextTokenIsIdentifierOrStringLiteralOnSameLine() {
2813
+ const next = this.nextTokenInLineStart();
2814
+ const nextCh = this.codePointAtPos(next);
2815
+ return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
2816
+ }
2817
+ };
2818
+ function isPossiblyLiteralEnum(expression) {
2819
+ if (expression.type !== "MemberExpression") return false;
2820
+ const {
2821
+ computed,
2822
+ property
2823
+ } = expression;
2824
+ if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
2825
+ return false;
2826
+ }
2827
+ return isUncomputedMemberExpressionChain(expression.object);
2828
+ }
2829
+ function isValidAmbientConstInitializer(expression, estree) {
2830
+ const {
2831
+ type
2832
+ } = expression;
2833
+ if (expression.extra?.parenthesized) {
2834
+ return false;
2835
+ }
2836
+ if (estree) {
2837
+ if (type === "Literal") {
2838
+ const {
2839
+ value
2840
+ } = expression;
2841
+ if (typeof value === "string" || typeof value === "boolean") {
2842
+ return true;
2843
+ }
2844
+ }
2845
+ } else {
2846
+ if (type === "StringLiteral" || type === "BooleanLiteral") {
2847
+ return true;
2848
+ }
2849
+ }
2850
+ if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
2851
+ return true;
2852
+ }
2853
+ if (type === "TemplateLiteral" && expression.expressions.length === 0) {
2854
+ return true;
2855
+ }
2856
+ if (isPossiblyLiteralEnum(expression)) {
2857
+ return true;
2858
+ }
2859
+ return false;
2860
+ }
2861
+ function isNumber(expression, estree) {
2862
+ if (estree) {
2863
+ return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
2864
+ }
2865
+ return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
2866
+ }
2867
+ function isNegativeNumber(expression, estree) {
2868
+ if (expression.type === "UnaryExpression") {
2869
+ const {
2870
+ operator,
2871
+ argument
2872
+ } = expression;
2873
+ if (operator === "-" && isNumber(argument, estree)) {
2874
+ return true;
2875
+ }
2876
+ }
2877
+ return false;
2878
+ }
2879
+ function isUncomputedMemberExpressionChain(expression) {
2880
+ if (expression.type === "Identifier") return true;
2881
+ if (expression.type !== "MemberExpression" || expression.computed) {
2882
+ return false;
2883
+ }
2884
+ return isUncomputedMemberExpressionChain(expression.object);
2885
+ }
2886
+ export {
2887
+ stdin_default as default,
2888
+ tsParseEntityNameFlags
2889
+ };