@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,2412 @@
1
+ // Generated from Babel v7.29.8 (MIT); see README.md.
2
+ import { tokenIsIdentifier, tokenIsKeyword, tokenIsKeywordOrIdentifier, tokenIsLiteralPropertyName, tokenLabelName, tt, tokenIsFlowInterfaceOrTypeOrOpaque } from "../../tokenizer/types.mjs";
3
+ import { types as tc } from "../../tokenizer/context.mjs";
4
+ import { isIteratorStart } from "../../util/identifier.mjs";
5
+ import FlowScopeHandler from "./scope.mjs";
6
+ import { BindingFlag, ScopeFlag } from "../../util/scopeflags.mjs";
7
+ import { Errors, ParseErrorEnum } from "../../parse-error.mjs";
8
+ const reservedTypes = /* @__PURE__ */ new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
9
+ const FlowErrors = ParseErrorEnum`flow`({
10
+ AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
11
+ AmbiguousDeclareModuleKind: "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.",
12
+ AssignReservedType: ({
13
+ reservedType
14
+ }) => `Cannot overwrite reserved type ${reservedType}.`,
15
+ DeclareClassElement: "The `declare` modifier can only appear on class fields.",
16
+ DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
17
+ DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
18
+ EnumBooleanMemberNotInitialized: ({
19
+ memberName,
20
+ enumName
21
+ }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
22
+ EnumDuplicateMemberName: ({
23
+ memberName,
24
+ enumName
25
+ }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
26
+ EnumInconsistentMemberValues: ({
27
+ enumName
28
+ }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
29
+ EnumInvalidExplicitType: ({
30
+ invalidEnumType,
31
+ enumName
32
+ }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
33
+ EnumInvalidExplicitTypeUnknownSupplied: ({
34
+ enumName
35
+ }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
36
+ EnumInvalidMemberInitializerPrimaryType: ({
37
+ enumName,
38
+ memberName,
39
+ explicitType
40
+ }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
41
+ EnumInvalidMemberInitializerSymbolType: ({
42
+ enumName,
43
+ memberName
44
+ }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
45
+ EnumInvalidMemberInitializerUnknownType: ({
46
+ enumName,
47
+ memberName
48
+ }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
49
+ EnumInvalidMemberName: ({
50
+ enumName,
51
+ memberName,
52
+ suggestion
53
+ }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
54
+ EnumNumberMemberNotInitialized: ({
55
+ enumName,
56
+ memberName
57
+ }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
58
+ EnumStringMemberInconsistentlyInitialized: ({
59
+ enumName
60
+ }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
61
+ GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
62
+ ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
63
+ ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.",
64
+ InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
65
+ InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
66
+ InexactVariance: "Explicit inexact syntax cannot have variance.",
67
+ InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
68
+ MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
69
+ NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
70
+ NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
71
+ PatternIsOptional: {
72
+ message: "A binding pattern parameter cannot be optional in an implementation signature.",
73
+ ...{
74
+ reasonCode: "OptionalBindingPattern"
75
+ }
76
+ },
77
+ SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
78
+ SpreadVariance: "Spread properties cannot have variance.",
79
+ ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
80
+ ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
81
+ ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
82
+ ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
83
+ ThisParamNoDefault: "The `this` parameter may not have a default value.",
84
+ TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
85
+ TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
86
+ UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
87
+ UnexpectedReservedType: ({
88
+ reservedType
89
+ }) => `Unexpected reserved type ${reservedType}.`,
90
+ UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
91
+ UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
92
+ UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
93
+ UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
94
+ UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
95
+ UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
96
+ UnsupportedDeclareExportKind: ({
97
+ unsupportedExportKind,
98
+ suggestion
99
+ }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
100
+ UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
101
+ UnterminatedFlowComment: "Unterminated flow-comment."
102
+ });
103
+ function isEsModuleType(bodyElement) {
104
+ return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
105
+ }
106
+ function hasTypeImportKind(node) {
107
+ return node.importKind === "type" || node.importKind === "typeof";
108
+ }
109
+ const exportSuggestions = {
110
+ const: "declare export var",
111
+ let: "declare export var",
112
+ type: "export type",
113
+ interface: "export interface"
114
+ };
115
+ function partition(list, test) {
116
+ const list1 = [];
117
+ const list2 = [];
118
+ for (let i = 0; i < list.length; i++) {
119
+ (test(list[i], i, list) ? list1 : list2).push(list[i]);
120
+ }
121
+ return [list1, list2];
122
+ }
123
+ const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
124
+ var stdin_default = (superClass) => class FlowParserMixin extends superClass {
125
+ flowPragma = void 0;
126
+ getScopeHandler() {
127
+ return FlowScopeHandler;
128
+ }
129
+ shouldParseTypes() {
130
+ return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
131
+ }
132
+ finishToken(type, val) {
133
+ if (type !== tt.string && type !== tt.semi && type !== tt.interpreterDirective) {
134
+ if (this.flowPragma === void 0) {
135
+ this.flowPragma = null;
136
+ }
137
+ }
138
+ super.finishToken(type, val);
139
+ }
140
+ addComment(comment) {
141
+ if (this.flowPragma === void 0) {
142
+ const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
143
+ if (!matches) {
144
+ // An unsuccessful grammar probe intentionally leaves no result.
145
+ } else if (matches[1] === "flow") {
146
+ this.flowPragma = "flow";
147
+ } else if (matches[1] === "noflow") {
148
+ this.flowPragma = "noflow";
149
+ } else {
150
+ throw new Error("Unexpected flow pragma");
151
+ }
152
+ }
153
+ super.addComment(comment);
154
+ }
155
+ flowParseTypeInitialiser(tok) {
156
+ const oldInType = this.state.inType;
157
+ this.state.inType = true;
158
+ this.expect(tok || tt.colon);
159
+ const type = this.flowParseType();
160
+ this.state.inType = oldInType;
161
+ return type;
162
+ }
163
+ flowParsePredicate() {
164
+ const node = this.startNode();
165
+ const moduloLoc = this.state.startLoc;
166
+ this.next();
167
+ this.expectContextual(tt._checks);
168
+ if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
169
+ this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
170
+ }
171
+ if (this.eat(tt.parenL)) {
172
+ node.value = super.parseExpression();
173
+ this.expect(tt.parenR);
174
+ return this.finishNode(node, "DeclaredPredicate");
175
+ } else {
176
+ return this.finishNode(node, "InferredPredicate");
177
+ }
178
+ }
179
+ flowParseTypeAndPredicateInitialiser() {
180
+ const oldInType = this.state.inType;
181
+ this.state.inType = true;
182
+ this.expect(tt.colon);
183
+ let type = null;
184
+ let predicate = null;
185
+ if (this.match(tt.modulo)) {
186
+ this.state.inType = oldInType;
187
+ predicate = this.flowParsePredicate();
188
+ } else {
189
+ type = this.flowParseType();
190
+ this.state.inType = oldInType;
191
+ if (this.match(tt.modulo)) {
192
+ predicate = this.flowParsePredicate();
193
+ }
194
+ }
195
+ return [type, predicate];
196
+ }
197
+ flowParseDeclareClass(node) {
198
+ this.next();
199
+ this.flowParseInterfaceish(node, true);
200
+ return this.finishNode(node, "DeclareClass");
201
+ }
202
+ flowParseDeclareFunction(node) {
203
+ this.next();
204
+ const id = node.id = this.parseIdentifier();
205
+ const typeNode = this.startNode();
206
+ const typeContainer = this.startNode();
207
+ if (this.match(tt.lt)) {
208
+ typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
209
+ } else {
210
+ typeNode.typeParameters = null;
211
+ }
212
+ this.expect(tt.parenL);
213
+ const tmp = this.flowParseFunctionTypeParams();
214
+ typeNode.params = tmp.params;
215
+ typeNode.rest = tmp.rest;
216
+ typeNode.this = tmp._this;
217
+ this.expect(tt.parenR);
218
+ [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
219
+ typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
220
+ id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
221
+ this.resetEndLocation(id);
222
+ this.semicolon();
223
+ this.scope.declareName(node.id.name, BindingFlag.TYPE_FLOW_DECLARE_FN, node.id.loc.start);
224
+ return this.finishNode(node, "DeclareFunction");
225
+ }
226
+ flowParseDeclare(node, insideModule) {
227
+ if (this.match(tt._class)) {
228
+ return this.flowParseDeclareClass(node);
229
+ } else if (this.match(tt._function)) {
230
+ return this.flowParseDeclareFunction(node);
231
+ } else if (this.match(tt._var)) {
232
+ return this.flowParseDeclareVariable(node);
233
+ } else if (this.eatContextual(tt._module)) {
234
+ if (this.match(tt.dot)) {
235
+ return this.flowParseDeclareModuleExports(node);
236
+ } else {
237
+ if (insideModule) {
238
+ this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
239
+ }
240
+ return this.flowParseDeclareModule(node);
241
+ }
242
+ } else if (this.isContextual(tt._type)) {
243
+ return this.flowParseDeclareTypeAlias(node);
244
+ } else if (this.isContextual(tt._opaque)) {
245
+ return this.flowParseDeclareOpaqueType(node);
246
+ } else if (this.isContextual(tt._interface)) {
247
+ return this.flowParseDeclareInterface(node);
248
+ } else if (this.match(tt._export)) {
249
+ return this.flowParseDeclareExportDeclaration(node, insideModule);
250
+ }
251
+ throw this.unexpected();
252
+ }
253
+ flowParseDeclareVariable(node) {
254
+ this.next();
255
+ node.id = this.flowParseTypeAnnotatableIdentifier();
256
+ this.scope.declareName(node.id.name, BindingFlag.TYPE_VAR, node.id.loc.start);
257
+ this.semicolon();
258
+ return this.finishNode(node, "DeclareVariable");
259
+ }
260
+ flowParseDeclareModule(node) {
261
+ this.scope.enter(ScopeFlag.OTHER);
262
+ if (this.match(tt.string)) {
263
+ node.id = super.parseExprAtom();
264
+ } else {
265
+ node.id = this.parseIdentifier();
266
+ }
267
+ const bodyNode = node.body = this.startNode();
268
+ const body = bodyNode.body = [];
269
+ this.expect(tt.braceL);
270
+ while (!this.match(tt.braceR)) {
271
+ const bodyNode2 = this.startNode();
272
+ if (this.match(tt._import)) {
273
+ this.next();
274
+ if (!this.isContextual(tt._type) && !this.match(tt._typeof)) {
275
+ this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
276
+ }
277
+ body.push(super.parseImport(bodyNode2));
278
+ } else {
279
+ this.expectContextual(tt._declare, FlowErrors.UnsupportedStatementInDeclareModule);
280
+ body.push(this.flowParseDeclare(bodyNode2, true));
281
+ }
282
+ }
283
+ this.scope.exit();
284
+ this.expect(tt.braceR);
285
+ this.finishNode(bodyNode, "BlockStatement");
286
+ let kind = null;
287
+ let hasModuleExport = false;
288
+ body.forEach((bodyElement) => {
289
+ if (isEsModuleType(bodyElement)) {
290
+ if (kind === "CommonJS") {
291
+ this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
292
+ }
293
+ kind = "ES";
294
+ } else if (bodyElement.type === "DeclareModuleExports") {
295
+ if (hasModuleExport) {
296
+ this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
297
+ }
298
+ if (kind === "ES") {
299
+ this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
300
+ }
301
+ kind = "CommonJS";
302
+ hasModuleExport = true;
303
+ }
304
+ });
305
+ node.kind = kind || "CommonJS";
306
+ return this.finishNode(node, "DeclareModule");
307
+ }
308
+ flowParseDeclareExportDeclaration(node, insideModule) {
309
+ this.expect(tt._export);
310
+ if (this.eat(tt._default)) {
311
+ if (this.match(tt._function) || this.match(tt._class)) {
312
+ node.declaration = this.flowParseDeclare(this.startNode());
313
+ } else {
314
+ node.declaration = this.flowParseType();
315
+ this.semicolon();
316
+ }
317
+ node.default = true;
318
+ return this.finishNode(node, "DeclareExportDeclaration");
319
+ } else {
320
+ if (this.match(tt._const) || this.isLet() || (this.isContextual(tt._type) || this.isContextual(tt._interface)) && !insideModule) {
321
+ const label = this.state.value;
322
+ throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
323
+ unsupportedExportKind: label,
324
+ suggestion: exportSuggestions[label]
325
+ });
326
+ }
327
+ if (this.match(tt._var) || this.match(tt._function) || this.match(tt._class) || this.isContextual(tt._opaque)) {
328
+ node.declaration = this.flowParseDeclare(this.startNode());
329
+ node.default = false;
330
+ return this.finishNode(node, "DeclareExportDeclaration");
331
+ } else if (this.match(tt.star) || this.match(tt.braceL) || this.isContextual(tt._interface) || this.isContextual(tt._type) || this.isContextual(tt._opaque)) {
332
+ node = this.parseExport(node, null);
333
+ if (node.type === "ExportNamedDeclaration") {
334
+ node.default = false;
335
+ delete node.exportKind;
336
+ return this.castNodeTo(node, "DeclareExportDeclaration");
337
+ } else {
338
+ return this.castNodeTo(node, "DeclareExportAllDeclaration");
339
+ }
340
+ }
341
+ }
342
+ throw this.unexpected();
343
+ }
344
+ flowParseDeclareModuleExports(node) {
345
+ this.next();
346
+ this.expectContextual(tt._exports);
347
+ node.typeAnnotation = this.flowParseTypeAnnotation();
348
+ this.semicolon();
349
+ return this.finishNode(node, "DeclareModuleExports");
350
+ }
351
+ flowParseDeclareTypeAlias(node) {
352
+ this.next();
353
+ const finished = this.flowParseTypeAlias(node);
354
+ this.castNodeTo(finished, "DeclareTypeAlias");
355
+ return finished;
356
+ }
357
+ flowParseDeclareOpaqueType(node) {
358
+ this.next();
359
+ const finished = this.flowParseOpaqueType(node, true);
360
+ this.castNodeTo(finished, "DeclareOpaqueType");
361
+ return finished;
362
+ }
363
+ flowParseDeclareInterface(node) {
364
+ this.next();
365
+ this.flowParseInterfaceish(node, false);
366
+ return this.finishNode(node, "DeclareInterface");
367
+ }
368
+ flowParseInterfaceish(node, isClass) {
369
+ node.id = this.flowParseRestrictedIdentifier(!isClass, true);
370
+ this.scope.declareName(node.id.name, isClass ? BindingFlag.TYPE_FUNCTION : BindingFlag.TYPE_LEXICAL, node.id.loc.start);
371
+ if (this.match(tt.lt)) {
372
+ node.typeParameters = this.flowParseTypeParameterDeclaration();
373
+ } else {
374
+ node.typeParameters = null;
375
+ }
376
+ node.extends = [];
377
+ if (this.eat(tt._extends)) {
378
+ do {
379
+ node.extends.push(this.flowParseInterfaceExtends());
380
+ } while (!isClass && this.eat(tt.comma));
381
+ }
382
+ if (isClass) {
383
+ node.implements = [];
384
+ node.mixins = [];
385
+ if (this.eatContextual(tt._mixins)) {
386
+ do {
387
+ node.mixins.push(this.flowParseInterfaceExtends());
388
+ } while (this.eat(tt.comma));
389
+ }
390
+ if (this.eatContextual(tt._implements)) {
391
+ do {
392
+ node.implements.push(this.flowParseInterfaceExtends());
393
+ } while (this.eat(tt.comma));
394
+ }
395
+ }
396
+ node.body = this.flowParseObjectType({
397
+ allowStatic: isClass,
398
+ allowExact: false,
399
+ allowSpread: false,
400
+ allowProto: isClass,
401
+ allowInexact: false
402
+ });
403
+ }
404
+ flowParseInterfaceExtends() {
405
+ const node = this.startNode();
406
+ node.id = this.flowParseQualifiedTypeIdentifier();
407
+ if (this.match(tt.lt)) {
408
+ node.typeParameters = this.flowParseTypeParameterInstantiation();
409
+ } else {
410
+ node.typeParameters = null;
411
+ }
412
+ return this.finishNode(node, "InterfaceExtends");
413
+ }
414
+ flowParseInterface(node) {
415
+ this.flowParseInterfaceish(node, false);
416
+ return this.finishNode(node, "InterfaceDeclaration");
417
+ }
418
+ checkNotUnderscore(word) {
419
+ if (word === "_") {
420
+ this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
421
+ }
422
+ }
423
+ checkReservedType(word, startLoc, declaration) {
424
+ if (!reservedTypes.has(word)) return;
425
+ this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
426
+ reservedType: word
427
+ });
428
+ }
429
+ flowParseRestrictedIdentifierName(liberal, declaration) {
430
+ this.checkReservedType(this.state.value, this.state.startLoc, declaration);
431
+ return this.parseIdentifierName(liberal);
432
+ }
433
+ flowParseRestrictedIdentifier(liberal, declaration) {
434
+ const node = this.startNode();
435
+ const name = this.flowParseRestrictedIdentifierName(liberal, declaration);
436
+ return this.createIdentifier(node, name);
437
+ }
438
+ flowParseTypeAlias(node) {
439
+ node.id = this.flowParseRestrictedIdentifier(false, true);
440
+ this.scope.declareName(node.id.name, BindingFlag.TYPE_LEXICAL, node.id.loc.start);
441
+ if (this.match(tt.lt)) {
442
+ node.typeParameters = this.flowParseTypeParameterDeclaration();
443
+ } else {
444
+ node.typeParameters = null;
445
+ }
446
+ node.right = this.flowParseTypeInitialiser(tt.eq);
447
+ this.semicolon();
448
+ return this.finishNode(node, "TypeAlias");
449
+ }
450
+ flowParseOpaqueType(node, declare) {
451
+ this.expectContextual(tt._type);
452
+ node.id = this.flowParseRestrictedIdentifier(true, true);
453
+ this.scope.declareName(node.id.name, BindingFlag.TYPE_LEXICAL, node.id.loc.start);
454
+ if (this.match(tt.lt)) {
455
+ node.typeParameters = this.flowParseTypeParameterDeclaration();
456
+ } else {
457
+ node.typeParameters = null;
458
+ }
459
+ node.supertype = null;
460
+ if (this.match(tt.colon)) {
461
+ node.supertype = this.flowParseTypeInitialiser(tt.colon);
462
+ }
463
+ node.impltype = null;
464
+ if (!declare) {
465
+ node.impltype = this.flowParseTypeInitialiser(tt.eq);
466
+ }
467
+ this.semicolon();
468
+ return this.finishNode(node, "OpaqueType");
469
+ }
470
+ flowParseTypeParameterBound() {
471
+ if (this.match(tt.colon) || this.isContextual(tt._extends)) {
472
+ const node = this.startNode();
473
+ this.next();
474
+ node.typeAnnotation = this.flowParseType();
475
+ return this.finishNode(node, "TypeAnnotation");
476
+ }
477
+ }
478
+ flowParseTypeParameter(requireDefault = false) {
479
+ const nodeStartLoc = this.state.startLoc;
480
+ const node = this.startNode();
481
+ const variance = this.flowParseVariance();
482
+ node.name = this.flowParseRestrictedIdentifierName();
483
+ node.variance = variance;
484
+ node.bound = this.flowParseTypeParameterBound();
485
+ if (this.match(tt.eq)) {
486
+ this.eat(tt.eq);
487
+ node.default = this.flowParseType();
488
+ } else {
489
+ if (requireDefault) {
490
+ this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
491
+ }
492
+ }
493
+ return this.finishNode(node, "TypeParameter");
494
+ }
495
+ flowParseTypeParameterDeclaration() {
496
+ const oldInType = this.state.inType;
497
+ const node = this.startNode();
498
+ node.params = [];
499
+ this.state.inType = true;
500
+ if (this.match(tt.lt) || this.match(tt.jsxTagStart)) {
501
+ this.next();
502
+ } else {
503
+ this.unexpected();
504
+ }
505
+ let defaultRequired = false;
506
+ do {
507
+ const typeParameter = this.flowParseTypeParameter(defaultRequired);
508
+ node.params.push(typeParameter);
509
+ if (typeParameter.default) {
510
+ defaultRequired = true;
511
+ }
512
+ if (!this.match(tt.gt)) {
513
+ this.expect(tt.comma);
514
+ }
515
+ } while (!this.match(tt.gt));
516
+ this.expect(tt.gt);
517
+ this.state.inType = oldInType;
518
+ return this.finishNode(node, "TypeParameterDeclaration");
519
+ }
520
+ flowInTopLevelContext(cb) {
521
+ if (this.curContext() !== tc.brace) {
522
+ const oldContext = this.state.context;
523
+ this.state.context = [oldContext[0]];
524
+ try {
525
+ return cb();
526
+ } finally {
527
+ this.state.context = oldContext;
528
+ }
529
+ } else {
530
+ return cb();
531
+ }
532
+ }
533
+ flowParseTypeParameterInstantiationInExpression() {
534
+ if (this.reScan_lt() !== tt.lt) return;
535
+ return this.flowParseTypeParameterInstantiation();
536
+ }
537
+ flowParseTypeParameterInstantiation() {
538
+ const node = this.startNode();
539
+ const oldInType = this.state.inType;
540
+ this.state.inType = true;
541
+ node.params = [];
542
+ this.flowInTopLevelContext(() => {
543
+ this.expect(tt.lt);
544
+ const oldNoAnonFunctionType = this.state.noAnonFunctionType;
545
+ this.state.noAnonFunctionType = false;
546
+ while (!this.match(tt.gt)) {
547
+ node.params.push(this.flowParseType());
548
+ if (!this.match(tt.gt)) {
549
+ this.expect(tt.comma);
550
+ }
551
+ }
552
+ this.state.noAnonFunctionType = oldNoAnonFunctionType;
553
+ });
554
+ this.state.inType = oldInType;
555
+ if (!this.state.inType && this.curContext() === tc.brace) {
556
+ this.reScan_lt_gt();
557
+ }
558
+ this.expect(tt.gt);
559
+ return this.finishNode(node, "TypeParameterInstantiation");
560
+ }
561
+ flowParseTypeParameterInstantiationCallOrNew() {
562
+ if (this.reScan_lt() !== tt.lt) return null;
563
+ const node = this.startNode();
564
+ const oldInType = this.state.inType;
565
+ node.params = [];
566
+ this.state.inType = true;
567
+ this.expect(tt.lt);
568
+ while (!this.match(tt.gt)) {
569
+ node.params.push(this.flowParseTypeOrImplicitInstantiation());
570
+ if (!this.match(tt.gt)) {
571
+ this.expect(tt.comma);
572
+ }
573
+ }
574
+ this.expect(tt.gt);
575
+ this.state.inType = oldInType;
576
+ return this.finishNode(node, "TypeParameterInstantiation");
577
+ }
578
+ flowParseInterfaceType() {
579
+ const node = this.startNode();
580
+ this.expectContextual(tt._interface);
581
+ node.extends = [];
582
+ if (this.eat(tt._extends)) {
583
+ do {
584
+ node.extends.push(this.flowParseInterfaceExtends());
585
+ } while (this.eat(tt.comma));
586
+ }
587
+ node.body = this.flowParseObjectType({
588
+ allowStatic: false,
589
+ allowExact: false,
590
+ allowSpread: false,
591
+ allowProto: false,
592
+ allowInexact: false
593
+ });
594
+ return this.finishNode(node, "InterfaceTypeAnnotation");
595
+ }
596
+ flowParseObjectPropertyKey() {
597
+ return this.match(tt.num) || this.match(tt.string) ? super.parseExprAtom() : this.parseIdentifier(true);
598
+ }
599
+ flowParseObjectTypeIndexer(node, isStatic, variance) {
600
+ node.static = isStatic;
601
+ if (this.lookahead().type === tt.colon) {
602
+ node.id = this.flowParseObjectPropertyKey();
603
+ node.key = this.flowParseTypeInitialiser();
604
+ } else {
605
+ node.id = null;
606
+ node.key = this.flowParseType();
607
+ }
608
+ this.expect(tt.bracketR);
609
+ node.value = this.flowParseTypeInitialiser();
610
+ node.variance = variance;
611
+ return this.finishNode(node, "ObjectTypeIndexer");
612
+ }
613
+ flowParseObjectTypeInternalSlot(node, isStatic) {
614
+ node.static = isStatic;
615
+ node.id = this.flowParseObjectPropertyKey();
616
+ this.expect(tt.bracketR);
617
+ this.expect(tt.bracketR);
618
+ if (this.match(tt.lt) || this.match(tt.parenL)) {
619
+ node.method = true;
620
+ node.optional = false;
621
+ node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
622
+ } else {
623
+ node.method = false;
624
+ if (this.eat(tt.question)) {
625
+ node.optional = true;
626
+ }
627
+ node.value = this.flowParseTypeInitialiser();
628
+ }
629
+ return this.finishNode(node, "ObjectTypeInternalSlot");
630
+ }
631
+ flowParseObjectTypeMethodish(node) {
632
+ node.params = [];
633
+ node.rest = null;
634
+ node.typeParameters = null;
635
+ node.this = null;
636
+ if (this.match(tt.lt)) {
637
+ node.typeParameters = this.flowParseTypeParameterDeclaration();
638
+ }
639
+ this.expect(tt.parenL);
640
+ if (this.match(tt._this)) {
641
+ node.this = this.flowParseFunctionTypeParam(true);
642
+ node.this.name = null;
643
+ if (!this.match(tt.parenR)) {
644
+ this.expect(tt.comma);
645
+ }
646
+ }
647
+ while (!this.match(tt.parenR) && !this.match(tt.ellipsis)) {
648
+ node.params.push(this.flowParseFunctionTypeParam(false));
649
+ if (!this.match(tt.parenR)) {
650
+ this.expect(tt.comma);
651
+ }
652
+ }
653
+ if (this.eat(tt.ellipsis)) {
654
+ node.rest = this.flowParseFunctionTypeParam(false);
655
+ }
656
+ this.expect(tt.parenR);
657
+ node.returnType = this.flowParseTypeInitialiser();
658
+ return this.finishNode(node, "FunctionTypeAnnotation");
659
+ }
660
+ flowParseObjectTypeCallProperty(node, isStatic) {
661
+ const valueNode = this.startNode();
662
+ node.static = isStatic;
663
+ node.value = this.flowParseObjectTypeMethodish(valueNode);
664
+ return this.finishNode(node, "ObjectTypeCallProperty");
665
+ }
666
+ flowParseObjectType({
667
+ allowStatic,
668
+ allowExact,
669
+ allowSpread,
670
+ allowProto,
671
+ allowInexact
672
+ }) {
673
+ const oldInType = this.state.inType;
674
+ this.state.inType = true;
675
+ const nodeStart = this.startNode();
676
+ nodeStart.callProperties = [];
677
+ nodeStart.properties = [];
678
+ nodeStart.indexers = [];
679
+ nodeStart.internalSlots = [];
680
+ let endDelim;
681
+ let exact;
682
+ let inexact = false;
683
+ if (allowExact && this.match(tt.braceBarL)) {
684
+ this.expect(tt.braceBarL);
685
+ endDelim = tt.braceBarR;
686
+ exact = true;
687
+ } else {
688
+ this.expect(tt.braceL);
689
+ endDelim = tt.braceR;
690
+ exact = false;
691
+ }
692
+ nodeStart.exact = exact;
693
+ while (!this.match(endDelim)) {
694
+ let isStatic = false;
695
+ let protoStartLoc = null;
696
+ let inexactStartLoc = null;
697
+ const node = this.startNode();
698
+ if (allowProto && this.isContextual(tt._proto)) {
699
+ const lookahead = this.lookahead();
700
+ if (lookahead.type !== tt.colon && lookahead.type !== tt.question) {
701
+ this.next();
702
+ protoStartLoc = this.state.startLoc;
703
+ allowStatic = false;
704
+ }
705
+ }
706
+ if (allowStatic && this.isContextual(tt._static)) {
707
+ const lookahead = this.lookahead();
708
+ if (lookahead.type !== tt.colon && lookahead.type !== tt.question) {
709
+ this.next();
710
+ isStatic = true;
711
+ }
712
+ }
713
+ const variance = this.flowParseVariance();
714
+ if (this.eat(tt.bracketL)) {
715
+ if (protoStartLoc != null) {
716
+ this.unexpected(protoStartLoc);
717
+ }
718
+ if (this.eat(tt.bracketL)) {
719
+ if (variance) {
720
+ this.unexpected(variance.loc.start);
721
+ }
722
+ nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
723
+ } else {
724
+ nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
725
+ }
726
+ } else if (this.match(tt.parenL) || this.match(tt.lt)) {
727
+ if (protoStartLoc != null) {
728
+ this.unexpected(protoStartLoc);
729
+ }
730
+ if (variance) {
731
+ this.unexpected(variance.loc.start);
732
+ }
733
+ nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
734
+ } else {
735
+ let kind = "init";
736
+ if (this.isContextual(tt._get) || this.isContextual(tt._set)) {
737
+ const lookahead = this.lookahead();
738
+ if (tokenIsLiteralPropertyName(lookahead.type)) {
739
+ kind = this.state.value;
740
+ this.next();
741
+ }
742
+ }
743
+ const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact ?? !exact);
744
+ if (propOrInexact === null) {
745
+ inexact = true;
746
+ inexactStartLoc = this.state.lastTokStartLoc;
747
+ } else {
748
+ nodeStart.properties.push(propOrInexact);
749
+ }
750
+ }
751
+ this.flowObjectTypeSemicolon();
752
+ if (inexactStartLoc && !this.match(tt.braceR) && !this.match(tt.braceBarR)) {
753
+ this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
754
+ }
755
+ }
756
+ this.expect(endDelim);
757
+ if (allowSpread) {
758
+ nodeStart.inexact = inexact;
759
+ }
760
+ const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
761
+ this.state.inType = oldInType;
762
+ return out;
763
+ }
764
+ flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
765
+ if (this.eat(tt.ellipsis)) {
766
+ const isInexactToken = this.match(tt.comma) || this.match(tt.semi) || this.match(tt.braceR) || this.match(tt.braceBarR);
767
+ if (isInexactToken) {
768
+ if (!allowSpread) {
769
+ this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
770
+ } else if (!allowInexact) {
771
+ this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
772
+ }
773
+ if (variance) {
774
+ this.raise(FlowErrors.InexactVariance, variance);
775
+ }
776
+ return null;
777
+ }
778
+ if (!allowSpread) {
779
+ this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
780
+ }
781
+ if (protoStartLoc != null) {
782
+ this.unexpected(protoStartLoc);
783
+ }
784
+ if (variance) {
785
+ this.raise(FlowErrors.SpreadVariance, variance);
786
+ }
787
+ node.argument = this.flowParseType();
788
+ return this.finishNode(node, "ObjectTypeSpreadProperty");
789
+ } else {
790
+ node.key = this.flowParseObjectPropertyKey();
791
+ node.static = isStatic;
792
+ node.proto = protoStartLoc != null;
793
+ node.kind = kind;
794
+ let optional = false;
795
+ if (this.match(tt.lt) || this.match(tt.parenL)) {
796
+ node.method = true;
797
+ if (protoStartLoc != null) {
798
+ this.unexpected(protoStartLoc);
799
+ }
800
+ if (variance) {
801
+ this.unexpected(variance.loc.start);
802
+ }
803
+ node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
804
+ if (kind === "get" || kind === "set") {
805
+ this.flowCheckGetterSetterParams(node);
806
+ }
807
+ if (!allowSpread && node.key.name === "constructor" && node.value.this) {
808
+ this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
809
+ }
810
+ } else {
811
+ if (kind !== "init") this.unexpected();
812
+ node.method = false;
813
+ if (this.eat(tt.question)) {
814
+ optional = true;
815
+ }
816
+ node.value = this.flowParseTypeInitialiser();
817
+ node.variance = variance;
818
+ }
819
+ node.optional = optional;
820
+ return this.finishNode(node, "ObjectTypeProperty");
821
+ }
822
+ }
823
+ flowCheckGetterSetterParams(property) {
824
+ const paramCount = property.kind === "get" ? 0 : 1;
825
+ const length = property.value.params.length + (property.value.rest ? 1 : 0);
826
+ if (property.value.this) {
827
+ this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
828
+ }
829
+ if (length !== paramCount) {
830
+ this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
831
+ }
832
+ if (property.kind === "set" && property.value.rest) {
833
+ this.raise(Errors.BadSetterRestParameter, property);
834
+ }
835
+ }
836
+ flowObjectTypeSemicolon() {
837
+ if (!this.eat(tt.semi) && !this.eat(tt.comma) && !this.match(tt.braceR) && !this.match(tt.braceBarR)) {
838
+ this.unexpected();
839
+ }
840
+ }
841
+ flowParseQualifiedTypeIdentifier(startLoc, id) {
842
+ startLoc ??= this.state.startLoc;
843
+ let node = id || this.flowParseRestrictedIdentifier(true);
844
+ while (this.eat(tt.dot)) {
845
+ const node2 = this.startNodeAt(startLoc);
846
+ node2.qualification = node;
847
+ node2.id = this.flowParseRestrictedIdentifier(true);
848
+ node = this.finishNode(node2, "QualifiedTypeIdentifier");
849
+ }
850
+ return node;
851
+ }
852
+ flowParseGenericType(startLoc, id) {
853
+ const node = this.startNodeAt(startLoc);
854
+ node.typeParameters = null;
855
+ node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
856
+ if (this.match(tt.lt)) {
857
+ node.typeParameters = this.flowParseTypeParameterInstantiation();
858
+ }
859
+ return this.finishNode(node, "GenericTypeAnnotation");
860
+ }
861
+ flowParseTypeofType() {
862
+ const node = this.startNode();
863
+ this.expect(tt._typeof);
864
+ node.argument = this.flowParsePrimaryType();
865
+ return this.finishNode(node, "TypeofTypeAnnotation");
866
+ }
867
+ flowParseTupleType() {
868
+ const node = this.startNode();
869
+ node.types = [];
870
+ this.expect(tt.bracketL);
871
+ while (this.state.pos < this.length && !this.match(tt.bracketR)) {
872
+ node.types.push(this.flowParseType());
873
+ if (this.match(tt.bracketR)) break;
874
+ this.expect(tt.comma);
875
+ }
876
+ this.expect(tt.bracketR);
877
+ return this.finishNode(node, "TupleTypeAnnotation");
878
+ }
879
+ flowParseFunctionTypeParam(first) {
880
+ let name = null;
881
+ let optional = false;
882
+ let typeAnnotation = null;
883
+ const node = this.startNode();
884
+ const lh = this.lookahead();
885
+ const isThis = this.state.type === tt._this;
886
+ if (lh.type === tt.colon || lh.type === tt.question) {
887
+ if (isThis && !first) {
888
+ this.raise(FlowErrors.ThisParamMustBeFirst, node);
889
+ }
890
+ name = this.parseIdentifier(isThis);
891
+ if (this.eat(tt.question)) {
892
+ optional = true;
893
+ if (isThis) {
894
+ this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
895
+ }
896
+ }
897
+ typeAnnotation = this.flowParseTypeInitialiser();
898
+ } else {
899
+ typeAnnotation = this.flowParseType();
900
+ }
901
+ node.name = name;
902
+ node.optional = optional;
903
+ node.typeAnnotation = typeAnnotation;
904
+ return this.finishNode(node, "FunctionTypeParam");
905
+ }
906
+ reinterpretTypeAsFunctionTypeParam(type) {
907
+ const node = this.startNodeAt(type.loc.start);
908
+ node.name = null;
909
+ node.optional = false;
910
+ node.typeAnnotation = type;
911
+ return this.finishNode(node, "FunctionTypeParam");
912
+ }
913
+ flowParseFunctionTypeParams(params = []) {
914
+ let rest = null;
915
+ let _this = null;
916
+ if (this.match(tt._this)) {
917
+ _this = this.flowParseFunctionTypeParam(true);
918
+ _this.name = null;
919
+ if (!this.match(tt.parenR)) {
920
+ this.expect(tt.comma);
921
+ }
922
+ }
923
+ while (!this.match(tt.parenR) && !this.match(tt.ellipsis)) {
924
+ params.push(this.flowParseFunctionTypeParam(false));
925
+ if (!this.match(tt.parenR)) {
926
+ this.expect(tt.comma);
927
+ }
928
+ }
929
+ if (this.eat(tt.ellipsis)) {
930
+ rest = this.flowParseFunctionTypeParam(false);
931
+ }
932
+ return {
933
+ params,
934
+ rest,
935
+ _this
936
+ };
937
+ }
938
+ flowIdentToTypeAnnotation(startLoc, node, id) {
939
+ switch (id.name) {
940
+ case "any":
941
+ return this.finishNode(node, "AnyTypeAnnotation");
942
+ case "bool":
943
+ case "boolean":
944
+ return this.finishNode(node, "BooleanTypeAnnotation");
945
+ case "mixed":
946
+ return this.finishNode(node, "MixedTypeAnnotation");
947
+ case "empty":
948
+ return this.finishNode(node, "EmptyTypeAnnotation");
949
+ case "number":
950
+ return this.finishNode(node, "NumberTypeAnnotation");
951
+ case "string":
952
+ return this.finishNode(node, "StringTypeAnnotation");
953
+ case "symbol":
954
+ return this.finishNode(node, "SymbolTypeAnnotation");
955
+ default:
956
+ this.checkNotUnderscore(id.name);
957
+ return this.flowParseGenericType(startLoc, id);
958
+ }
959
+ }
960
+ flowParsePrimaryType() {
961
+ const startLoc = this.state.startLoc;
962
+ const node = this.startNode();
963
+ let tmp;
964
+ let type;
965
+ let isGroupedType = false;
966
+ const oldNoAnonFunctionType = this.state.noAnonFunctionType;
967
+ switch (this.state.type) {
968
+ case tt.braceL:
969
+ return this.flowParseObjectType({
970
+ allowStatic: false,
971
+ allowExact: false,
972
+ allowSpread: true,
973
+ allowProto: false,
974
+ allowInexact: true
975
+ });
976
+ case tt.braceBarL:
977
+ return this.flowParseObjectType({
978
+ allowStatic: false,
979
+ allowExact: true,
980
+ allowSpread: true,
981
+ allowProto: false,
982
+ allowInexact: false
983
+ });
984
+ case tt.bracketL:
985
+ this.state.noAnonFunctionType = false;
986
+ type = this.flowParseTupleType();
987
+ this.state.noAnonFunctionType = oldNoAnonFunctionType;
988
+ return type;
989
+ case tt.lt: {
990
+ const node2 = this.startNode();
991
+ node2.typeParameters = this.flowParseTypeParameterDeclaration();
992
+ this.expect(tt.parenL);
993
+ tmp = this.flowParseFunctionTypeParams();
994
+ node2.params = tmp.params;
995
+ node2.rest = tmp.rest;
996
+ node2.this = tmp._this;
997
+ this.expect(tt.parenR);
998
+ this.expect(tt.arrow);
999
+ node2.returnType = this.flowParseType();
1000
+ return this.finishNode(node2, "FunctionTypeAnnotation");
1001
+ }
1002
+ case tt.parenL: {
1003
+ const node2 = this.startNode();
1004
+ this.next();
1005
+ if (!this.match(tt.parenR) && !this.match(tt.ellipsis)) {
1006
+ if (tokenIsIdentifier(this.state.type) || this.match(tt._this)) {
1007
+ const token = this.lookahead().type;
1008
+ isGroupedType = token !== tt.question && token !== tt.colon;
1009
+ } else {
1010
+ isGroupedType = true;
1011
+ }
1012
+ }
1013
+ if (isGroupedType) {
1014
+ this.state.noAnonFunctionType = false;
1015
+ type = this.flowParseType();
1016
+ this.state.noAnonFunctionType = oldNoAnonFunctionType;
1017
+ if (this.state.noAnonFunctionType || !(this.match(tt.comma) || this.match(tt.parenR) && this.lookahead().type === tt.arrow)) {
1018
+ this.expect(tt.parenR);
1019
+ return type;
1020
+ } else {
1021
+ this.eat(tt.comma);
1022
+ }
1023
+ }
1024
+ if (type) {
1025
+ tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
1026
+ } else {
1027
+ tmp = this.flowParseFunctionTypeParams();
1028
+ }
1029
+ node2.params = tmp.params;
1030
+ node2.rest = tmp.rest;
1031
+ node2.this = tmp._this;
1032
+ this.expect(tt.parenR);
1033
+ this.expect(tt.arrow);
1034
+ node2.returnType = this.flowParseType();
1035
+ node2.typeParameters = null;
1036
+ return this.finishNode(node2, "FunctionTypeAnnotation");
1037
+ }
1038
+ case tt.string:
1039
+ return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
1040
+ case tt._true:
1041
+ case tt._false:
1042
+ node.value = this.match(tt._true);
1043
+ this.next();
1044
+ return this.finishNode(node, "BooleanLiteralTypeAnnotation");
1045
+ case tt.plusMin:
1046
+ if (this.state.value === "-") {
1047
+ this.next();
1048
+ if (this.match(tt.num)) {
1049
+ return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
1050
+ }
1051
+ if (this.match(tt.bigint)) {
1052
+ return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
1053
+ }
1054
+ throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
1055
+ }
1056
+ throw this.unexpected();
1057
+ case tt.num:
1058
+ return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
1059
+ case tt.bigint:
1060
+ return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
1061
+ case tt._void:
1062
+ this.next();
1063
+ return this.finishNode(node, "VoidTypeAnnotation");
1064
+ case tt._null:
1065
+ this.next();
1066
+ return this.finishNode(node, "NullLiteralTypeAnnotation");
1067
+ case tt._this:
1068
+ this.next();
1069
+ return this.finishNode(node, "ThisTypeAnnotation");
1070
+ case tt.star:
1071
+ this.next();
1072
+ return this.finishNode(node, "ExistsTypeAnnotation");
1073
+ case tt._typeof:
1074
+ return this.flowParseTypeofType();
1075
+ default:
1076
+ if (tokenIsKeyword(this.state.type)) {
1077
+ const label = tokenLabelName(this.state.type);
1078
+ this.next();
1079
+ return super.createIdentifier(node, label);
1080
+ } else if (tokenIsIdentifier(this.state.type)) {
1081
+ if (this.isContextual(tt._interface)) {
1082
+ return this.flowParseInterfaceType();
1083
+ }
1084
+ return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
1085
+ }
1086
+ }
1087
+ throw this.unexpected();
1088
+ }
1089
+ flowParsePostfixType() {
1090
+ const startLoc = this.state.startLoc;
1091
+ let type = this.flowParsePrimaryType();
1092
+ let seenOptionalIndexedAccess = false;
1093
+ while ((this.match(tt.bracketL) || this.match(tt.questionDot)) && !this.canInsertSemicolon()) {
1094
+ const node = this.startNodeAt(startLoc);
1095
+ const optional = this.eat(tt.questionDot);
1096
+ seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
1097
+ this.expect(tt.bracketL);
1098
+ if (!optional && this.match(tt.bracketR)) {
1099
+ node.elementType = type;
1100
+ this.next();
1101
+ type = this.finishNode(node, "ArrayTypeAnnotation");
1102
+ } else {
1103
+ node.objectType = type;
1104
+ node.indexType = this.flowParseType();
1105
+ this.expect(tt.bracketR);
1106
+ if (seenOptionalIndexedAccess) {
1107
+ node.optional = optional;
1108
+ type = this.finishNode(node, "OptionalIndexedAccessType");
1109
+ } else {
1110
+ type = this.finishNode(node, "IndexedAccessType");
1111
+ }
1112
+ }
1113
+ }
1114
+ return type;
1115
+ }
1116
+ flowParsePrefixType() {
1117
+ const node = this.startNode();
1118
+ if (this.eat(tt.question)) {
1119
+ node.typeAnnotation = this.flowParsePrefixType();
1120
+ return this.finishNode(node, "NullableTypeAnnotation");
1121
+ } else {
1122
+ return this.flowParsePostfixType();
1123
+ }
1124
+ }
1125
+ flowParseAnonFunctionWithoutParens() {
1126
+ const param = this.flowParsePrefixType();
1127
+ if (!this.state.noAnonFunctionType && this.eat(tt.arrow)) {
1128
+ const node = this.startNodeAt(param.loc.start);
1129
+ node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
1130
+ node.rest = null;
1131
+ node.this = null;
1132
+ node.returnType = this.flowParseType();
1133
+ node.typeParameters = null;
1134
+ return this.finishNode(node, "FunctionTypeAnnotation");
1135
+ }
1136
+ return param;
1137
+ }
1138
+ flowParseIntersectionType() {
1139
+ const node = this.startNode();
1140
+ this.eat(tt.bitwiseAND);
1141
+ const type = this.flowParseAnonFunctionWithoutParens();
1142
+ node.types = [type];
1143
+ while (this.eat(tt.bitwiseAND)) {
1144
+ node.types.push(this.flowParseAnonFunctionWithoutParens());
1145
+ }
1146
+ return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
1147
+ }
1148
+ flowParseUnionType() {
1149
+ const node = this.startNode();
1150
+ this.eat(tt.bitwiseOR);
1151
+ const type = this.flowParseIntersectionType();
1152
+ node.types = [type];
1153
+ while (this.eat(tt.bitwiseOR)) {
1154
+ node.types.push(this.flowParseIntersectionType());
1155
+ }
1156
+ return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
1157
+ }
1158
+ flowParseType() {
1159
+ const oldInType = this.state.inType;
1160
+ this.state.inType = true;
1161
+ const type = this.flowParseUnionType();
1162
+ this.state.inType = oldInType;
1163
+ return type;
1164
+ }
1165
+ flowParseTypeOrImplicitInstantiation() {
1166
+ if (this.state.type === tt.name && this.state.value === "_") {
1167
+ const startLoc = this.state.startLoc;
1168
+ const node = this.parseIdentifier();
1169
+ return this.flowParseGenericType(startLoc, node);
1170
+ } else {
1171
+ return this.flowParseType();
1172
+ }
1173
+ }
1174
+ flowParseTypeAnnotation() {
1175
+ const node = this.startNode();
1176
+ node.typeAnnotation = this.flowParseTypeInitialiser();
1177
+ return this.finishNode(node, "TypeAnnotation");
1178
+ }
1179
+ flowParseTypeAnnotatableIdentifier() {
1180
+ const node = this.startNode();
1181
+ const name = this.parseIdentifierName();
1182
+ if (this.match(tt.colon)) {
1183
+ node.typeAnnotation = this.flowParseTypeAnnotation();
1184
+ }
1185
+ return this.createIdentifier(node, name);
1186
+ }
1187
+ typeCastToParameter(node) {
1188
+ node.expression.typeAnnotation = node.typeAnnotation;
1189
+ this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
1190
+ return node.expression;
1191
+ }
1192
+ flowParseVariance() {
1193
+ let variance = null;
1194
+ if (this.match(tt.plusMin)) {
1195
+ variance = this.startNode();
1196
+ if (this.state.value === "+") {
1197
+ variance.kind = "plus";
1198
+ } else {
1199
+ variance.kind = "minus";
1200
+ }
1201
+ this.next();
1202
+ return this.finishNode(variance, "Variance");
1203
+ }
1204
+ return variance;
1205
+ }
1206
+ parseFunctionBody(node, allowExpressionBody, isMethod = false) {
1207
+ if (allowExpressionBody) {
1208
+ this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
1209
+ return;
1210
+ }
1211
+ super.parseFunctionBody(node, false, isMethod);
1212
+ }
1213
+ parseFunctionBodyAndFinish(node, type, isMethod = false) {
1214
+ if (this.match(tt.colon)) {
1215
+ const typeNode = this.startNode();
1216
+ [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
1217
+ node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
1218
+ }
1219
+ return super.parseFunctionBodyAndFinish(node, type, isMethod);
1220
+ }
1221
+ parseStatementLike(flags) {
1222
+ if (this.state.strict && this.isContextual(tt._interface)) {
1223
+ const lookahead = this.lookahead();
1224
+ if (tokenIsKeywordOrIdentifier(lookahead.type)) {
1225
+ const node = this.startNode();
1226
+ this.next();
1227
+ return this.flowParseInterface(node);
1228
+ }
1229
+ } else if (this.isContextual(tt._enum)) {
1230
+ const node = this.startNode();
1231
+ this.next();
1232
+ return this.flowParseEnumDeclaration(node);
1233
+ }
1234
+ const stmt = super.parseStatementLike(flags);
1235
+ if (this.flowPragma === void 0 && !this.isValidDirective(stmt)) {
1236
+ this.flowPragma = null;
1237
+ }
1238
+ return stmt;
1239
+ }
1240
+ parseExpressionStatement(node, expr, decorators) {
1241
+ if (expr.type === "Identifier") {
1242
+ if (expr.name === "declare") {
1243
+ if (this.match(tt._class) || tokenIsIdentifier(this.state.type) || this.match(tt._function) || this.match(tt._var) || this.match(tt._export)) {
1244
+ return this.flowParseDeclare(node);
1245
+ }
1246
+ } else if (tokenIsIdentifier(this.state.type)) {
1247
+ if (expr.name === "interface") {
1248
+ return this.flowParseInterface(node);
1249
+ } else if (expr.name === "type") {
1250
+ return this.flowParseTypeAlias(node);
1251
+ } else if (expr.name === "opaque") {
1252
+ return this.flowParseOpaqueType(node, false);
1253
+ }
1254
+ }
1255
+ }
1256
+ return super.parseExpressionStatement(node, expr, decorators);
1257
+ }
1258
+ shouldParseExportDeclaration() {
1259
+ const {
1260
+ type
1261
+ } = this.state;
1262
+ if (type === tt._enum || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
1263
+ return !this.state.containsEsc;
1264
+ }
1265
+ return super.shouldParseExportDeclaration();
1266
+ }
1267
+ isExportDefaultSpecifier() {
1268
+ const {
1269
+ type
1270
+ } = this.state;
1271
+ if (type === tt._enum || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
1272
+ return this.state.containsEsc;
1273
+ }
1274
+ return super.isExportDefaultSpecifier();
1275
+ }
1276
+ parseExportDefaultExpression() {
1277
+ if (this.isContextual(tt._enum)) {
1278
+ const node = this.startNode();
1279
+ this.next();
1280
+ return this.flowParseEnumDeclaration(node);
1281
+ }
1282
+ return super.parseExportDefaultExpression();
1283
+ }
1284
+ parseConditional(expr, startLoc, refExpressionErrors) {
1285
+ if (!this.match(tt.question)) return expr;
1286
+ if (this.state.maybeInArrowParameters) {
1287
+ const nextCh = this.lookaheadCharCode();
1288
+ if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
1289
+ this.setOptionalParametersError(refExpressionErrors);
1290
+ return expr;
1291
+ }
1292
+ }
1293
+ this.expect(tt.question);
1294
+ const state = this.state.clone();
1295
+ const originalNoArrowAt = this.state.noArrowAt;
1296
+ const node = this.startNodeAt(startLoc);
1297
+ let {
1298
+ consequent,
1299
+ failed
1300
+ } = this.tryParseConditionalConsequent();
1301
+ let [valid, invalid] = this.getArrowLikeExpressions(consequent);
1302
+ if (failed || invalid.length > 0) {
1303
+ const noArrowAt = [...originalNoArrowAt];
1304
+ if (invalid.length > 0) {
1305
+ this.state = state;
1306
+ this.state.noArrowAt = noArrowAt;
1307
+ for (let i = 0; i < invalid.length; i++) {
1308
+ noArrowAt.push(invalid[i].start);
1309
+ }
1310
+ ({
1311
+ consequent,
1312
+ failed
1313
+ } = this.tryParseConditionalConsequent());
1314
+ [valid, invalid] = this.getArrowLikeExpressions(consequent);
1315
+ }
1316
+ if (failed && valid.length > 1) {
1317
+ this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
1318
+ }
1319
+ if (failed && valid.length === 1) {
1320
+ this.state = state;
1321
+ noArrowAt.push(valid[0].start);
1322
+ this.state.noArrowAt = noArrowAt;
1323
+ ({
1324
+ consequent,
1325
+ failed
1326
+ } = this.tryParseConditionalConsequent());
1327
+ }
1328
+ }
1329
+ this.getArrowLikeExpressions(consequent, true);
1330
+ this.state.noArrowAt = originalNoArrowAt;
1331
+ this.expect(tt.colon);
1332
+ node.test = expr;
1333
+ node.consequent = consequent;
1334
+ node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(void 0, void 0));
1335
+ return this.finishNode(node, "ConditionalExpression");
1336
+ }
1337
+ tryParseConditionalConsequent() {
1338
+ this.state.noArrowParamsConversionAt.push(this.state.start);
1339
+ const consequent = this.parseMaybeAssignAllowIn();
1340
+ const failed = !this.match(tt.colon);
1341
+ this.state.noArrowParamsConversionAt.pop();
1342
+ return {
1343
+ consequent,
1344
+ failed
1345
+ };
1346
+ }
1347
+ getArrowLikeExpressions(node, disallowInvalid) {
1348
+ const stack = [node];
1349
+ const arrows = [];
1350
+ while (stack.length !== 0) {
1351
+ const node2 = stack.pop();
1352
+ if (node2.type === "ArrowFunctionExpression" && node2.body.type !== "BlockStatement") {
1353
+ if (node2.typeParameters || !node2.returnType) {
1354
+ this.finishArrowValidation(node2);
1355
+ } else {
1356
+ arrows.push(node2);
1357
+ }
1358
+ stack.push(node2.body);
1359
+ } else if (node2.type === "ConditionalExpression") {
1360
+ stack.push(node2.consequent);
1361
+ stack.push(node2.alternate);
1362
+ }
1363
+ }
1364
+ if (disallowInvalid) {
1365
+ arrows.forEach((node2) => this.finishArrowValidation(node2));
1366
+ return [arrows, []];
1367
+ }
1368
+ return partition(arrows, (node2) => node2.params.every((param) => this.isAssignable(param, true)));
1369
+ }
1370
+ finishArrowValidation(node) {
1371
+ this.toAssignableList(node.params, node.extra?.trailingCommaLoc, false);
1372
+ this.scope.enter(ScopeFlag.FUNCTION | ScopeFlag.ARROW);
1373
+ super.checkParams(node, false, true);
1374
+ this.scope.exit();
1375
+ }
1376
+ forwardNoArrowParamsConversionAt(node, parse) {
1377
+ let result;
1378
+ if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
1379
+ this.state.noArrowParamsConversionAt.push(this.state.start);
1380
+ result = parse();
1381
+ this.state.noArrowParamsConversionAt.pop();
1382
+ } else {
1383
+ result = parse();
1384
+ }
1385
+ return result;
1386
+ }
1387
+ parseParenItem(node, startLoc) {
1388
+ const newNode = super.parseParenItem(node, startLoc);
1389
+ if (this.eat(tt.question)) {
1390
+ newNode.optional = true;
1391
+ this.resetEndLocation(node);
1392
+ }
1393
+ if (this.match(tt.colon)) {
1394
+ const typeCastNode = this.startNodeAt(startLoc);
1395
+ typeCastNode.expression = newNode;
1396
+ typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
1397
+ return this.finishNode(typeCastNode, "TypeCastExpression");
1398
+ }
1399
+ return newNode;
1400
+ }
1401
+ assertModuleNodeAllowed(node) {
1402
+ if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
1403
+ return;
1404
+ }
1405
+ super.assertModuleNodeAllowed(node);
1406
+ }
1407
+ parseExportDeclaration(node) {
1408
+ if (this.isContextual(tt._type)) {
1409
+ node.exportKind = "type";
1410
+ const declarationNode = this.startNode();
1411
+ this.next();
1412
+ if (this.match(tt.braceL)) {
1413
+ node.specifiers = this.parseExportSpecifiers(true);
1414
+ super.parseExportFrom(node);
1415
+ return null;
1416
+ } else {
1417
+ return this.flowParseTypeAlias(declarationNode);
1418
+ }
1419
+ } else if (this.isContextual(tt._opaque)) {
1420
+ node.exportKind = "type";
1421
+ const declarationNode = this.startNode();
1422
+ this.next();
1423
+ return this.flowParseOpaqueType(declarationNode, false);
1424
+ } else if (this.isContextual(tt._interface)) {
1425
+ node.exportKind = "type";
1426
+ const declarationNode = this.startNode();
1427
+ this.next();
1428
+ return this.flowParseInterface(declarationNode);
1429
+ } else if (this.isContextual(tt._enum)) {
1430
+ node.exportKind = "value";
1431
+ const declarationNode = this.startNode();
1432
+ this.next();
1433
+ return this.flowParseEnumDeclaration(declarationNode);
1434
+ } else {
1435
+ return super.parseExportDeclaration(node);
1436
+ }
1437
+ }
1438
+ eatExportStar(node) {
1439
+ if (super.eatExportStar(node)) return true;
1440
+ if (this.isContextual(tt._type) && this.lookahead().type === tt.star) {
1441
+ node.exportKind = "type";
1442
+ this.next();
1443
+ this.next();
1444
+ return true;
1445
+ }
1446
+ return false;
1447
+ }
1448
+ maybeParseExportNamespaceSpecifier(node) {
1449
+ const {
1450
+ startLoc
1451
+ } = this.state;
1452
+ const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
1453
+ if (hasNamespace && node.exportKind === "type") {
1454
+ this.unexpected(startLoc);
1455
+ }
1456
+ return hasNamespace;
1457
+ }
1458
+ parseClassId(node, isStatement, optionalId) {
1459
+ super.parseClassId(node, isStatement, optionalId);
1460
+ if (this.match(tt.lt)) {
1461
+ node.typeParameters = this.flowParseTypeParameterDeclaration();
1462
+ }
1463
+ }
1464
+ parseClassMember(classBody, member, state) {
1465
+ const {
1466
+ startLoc
1467
+ } = this.state;
1468
+ if (this.isContextual(tt._declare)) {
1469
+ if (super.parseClassMemberFromModifier(classBody, member)) {
1470
+ return;
1471
+ }
1472
+ member.declare = true;
1473
+ }
1474
+ super.parseClassMember(classBody, member, state);
1475
+ if (member.declare) {
1476
+ if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
1477
+ this.raise(FlowErrors.DeclareClassElement, startLoc);
1478
+ } else if (member.value) {
1479
+ this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
1480
+ }
1481
+ }
1482
+ }
1483
+ isIterator(word) {
1484
+ return word === "iterator" || word === "asyncIterator";
1485
+ }
1486
+ readIterator() {
1487
+ const word = super.readWord1();
1488
+ const fullWord = "@@" + word;
1489
+ if (!this.isIterator(word) || !this.state.inType) {
1490
+ this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
1491
+ identifierName: fullWord
1492
+ });
1493
+ }
1494
+ this.finishToken(tt.name, fullWord);
1495
+ }
1496
+ getTokenFromCode(code) {
1497
+ const next = this.input.charCodeAt(this.state.pos + 1);
1498
+ if (code === 123 && next === 124) {
1499
+ this.finishOp(tt.braceBarL, 2);
1500
+ } else if (this.state.inType && (code === 62 || code === 60)) {
1501
+ this.finishOp(code === 62 ? tt.gt : tt.lt, 1);
1502
+ } else if (this.state.inType && code === 63) {
1503
+ if (next === 46) {
1504
+ this.finishOp(tt.questionDot, 2);
1505
+ } else {
1506
+ this.finishOp(tt.question, 1);
1507
+ }
1508
+ } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
1509
+ this.state.pos += 2;
1510
+ this.readIterator();
1511
+ } else {
1512
+ super.getTokenFromCode(code);
1513
+ }
1514
+ }
1515
+ isAssignable(node, isBinding) {
1516
+ if (node.type === "TypeCastExpression") {
1517
+ return this.isAssignable(node.expression, isBinding);
1518
+ } else {
1519
+ return super.isAssignable(node, isBinding);
1520
+ }
1521
+ }
1522
+ toAssignable(node, isLHS = false) {
1523
+ if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
1524
+ node.left = this.typeCastToParameter(node.left);
1525
+ }
1526
+ super.toAssignable(node, isLHS);
1527
+ }
1528
+ toAssignableList(exprList, trailingCommaLoc, isLHS) {
1529
+ for (let i = 0; i < exprList.length; i++) {
1530
+ const expr = exprList[i];
1531
+ if (expr?.type === "TypeCastExpression") {
1532
+ exprList[i] = this.typeCastToParameter(expr);
1533
+ }
1534
+ }
1535
+ super.toAssignableList(exprList, trailingCommaLoc, isLHS);
1536
+ }
1537
+ toReferencedList(exprList, isParenthesizedExpr) {
1538
+ for (let i = 0; i < exprList.length; i++) {
1539
+ const expr = exprList[i];
1540
+ if (expr && expr.type === "TypeCastExpression" && !expr.extra?.parenthesized && (exprList.length > 1 || !isParenthesizedExpr)) {
1541
+ this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
1542
+ }
1543
+ }
1544
+ return exprList;
1545
+ }
1546
+ parseArrayLike(close, isTuple, refExpressionErrors) {
1547
+ const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
1548
+ if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
1549
+ this.toReferencedList(node.elements);
1550
+ }
1551
+ return node;
1552
+ }
1553
+ isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
1554
+ return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
1555
+ }
1556
+ parseClassProperty(node) {
1557
+ if (this.match(tt.colon)) {
1558
+ node.typeAnnotation = this.flowParseTypeAnnotation();
1559
+ }
1560
+ return super.parseClassProperty(node);
1561
+ }
1562
+ parseClassPrivateProperty(node) {
1563
+ if (this.match(tt.colon)) {
1564
+ node.typeAnnotation = this.flowParseTypeAnnotation();
1565
+ }
1566
+ return super.parseClassPrivateProperty(node);
1567
+ }
1568
+ isClassMethod() {
1569
+ return this.match(tt.lt) || super.isClassMethod();
1570
+ }
1571
+ isClassProperty() {
1572
+ return this.match(tt.colon) || super.isClassProperty();
1573
+ }
1574
+ isNonstaticConstructor(method) {
1575
+ return !this.match(tt.colon) && super.isNonstaticConstructor(method);
1576
+ }
1577
+ pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
1578
+ if (method.variance) {
1579
+ this.unexpected(method.variance.loc.start);
1580
+ }
1581
+ delete method.variance;
1582
+ if (this.match(tt.lt)) {
1583
+ method.typeParameters = this.flowParseTypeParameterDeclaration();
1584
+ }
1585
+ super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
1586
+ if (method.params && isConstructor) {
1587
+ const params = method.params;
1588
+ if (params.length > 0 && this.isThisParam(params[0])) {
1589
+ this.raise(FlowErrors.ThisParamBannedInConstructor, method);
1590
+ }
1591
+ } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
1592
+ const params = method.value.params;
1593
+ if (params.length > 0 && this.isThisParam(params[0])) {
1594
+ this.raise(FlowErrors.ThisParamBannedInConstructor, method);
1595
+ }
1596
+ }
1597
+ }
1598
+ pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
1599
+ if (method.variance) {
1600
+ this.unexpected(method.variance.loc.start);
1601
+ }
1602
+ delete method.variance;
1603
+ if (this.match(tt.lt)) {
1604
+ method.typeParameters = this.flowParseTypeParameterDeclaration();
1605
+ }
1606
+ super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
1607
+ }
1608
+ parseClassSuper(node) {
1609
+ super.parseClassSuper(node);
1610
+ if (node.superClass && (this.match(tt.lt) || this.match(tt.bitShiftL))) {
1611
+ {
1612
+ node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
1613
+ }
1614
+ }
1615
+ if (this.isContextual(tt._implements)) {
1616
+ this.next();
1617
+ const implemented = node.implements = [];
1618
+ do {
1619
+ const node2 = this.startNode();
1620
+ node2.id = this.flowParseRestrictedIdentifier(true);
1621
+ if (this.match(tt.lt)) {
1622
+ node2.typeParameters = this.flowParseTypeParameterInstantiation();
1623
+ } else {
1624
+ node2.typeParameters = null;
1625
+ }
1626
+ implemented.push(this.finishNode(node2, "ClassImplements"));
1627
+ } while (this.eat(tt.comma));
1628
+ }
1629
+ }
1630
+ checkGetterSetterParams(method) {
1631
+ super.checkGetterSetterParams(method);
1632
+ const params = this.getObjectOrClassMethodParams(method);
1633
+ if (params.length > 0) {
1634
+ const param = params[0];
1635
+ if (this.isThisParam(param) && method.kind === "get") {
1636
+ this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
1637
+ } else if (this.isThisParam(param)) {
1638
+ this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
1639
+ }
1640
+ }
1641
+ }
1642
+ parsePropertyNamePrefixOperator(node) {
1643
+ node.variance = this.flowParseVariance();
1644
+ }
1645
+ parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
1646
+ if (prop.variance) {
1647
+ this.unexpected(prop.variance.loc.start);
1648
+ }
1649
+ delete prop.variance;
1650
+ let typeParameters;
1651
+ if (this.match(tt.lt) && !isAccessor) {
1652
+ typeParameters = this.flowParseTypeParameterDeclaration();
1653
+ if (!this.match(tt.parenL)) this.unexpected();
1654
+ }
1655
+ const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
1656
+ if (typeParameters) {
1657
+ (result.value || result).typeParameters = typeParameters;
1658
+ }
1659
+ return result;
1660
+ }
1661
+ parseFunctionParamType(param) {
1662
+ if (this.eat(tt.question)) {
1663
+ if (param.type !== "Identifier") {
1664
+ this.raise(FlowErrors.PatternIsOptional, param);
1665
+ }
1666
+ if (this.isThisParam(param)) {
1667
+ this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
1668
+ }
1669
+ param.optional = true;
1670
+ }
1671
+ if (this.match(tt.colon)) {
1672
+ param.typeAnnotation = this.flowParseTypeAnnotation();
1673
+ } else if (this.isThisParam(param)) {
1674
+ this.raise(FlowErrors.ThisParamAnnotationRequired, param);
1675
+ }
1676
+ if (this.match(tt.eq) && this.isThisParam(param)) {
1677
+ this.raise(FlowErrors.ThisParamNoDefault, param);
1678
+ }
1679
+ this.resetEndLocation(param);
1680
+ return param;
1681
+ }
1682
+ parseMaybeDefault(startLoc, left) {
1683
+ const node = super.parseMaybeDefault(startLoc, left);
1684
+ if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
1685
+ this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
1686
+ }
1687
+ return node;
1688
+ }
1689
+ checkImportReflection(node) {
1690
+ super.checkImportReflection(node);
1691
+ if (node.module && node.importKind !== "value") {
1692
+ this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
1693
+ }
1694
+ }
1695
+ parseImportSpecifierLocal(node, specifier, type) {
1696
+ specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
1697
+ node.specifiers.push(this.finishImportSpecifier(specifier, type));
1698
+ }
1699
+ isPotentialImportPhase(isExport) {
1700
+ if (super.isPotentialImportPhase(isExport)) return true;
1701
+ if (this.isContextual(tt._type)) {
1702
+ if (!isExport) return true;
1703
+ const ch = this.lookaheadCharCode();
1704
+ return ch === 123 || ch === 42;
1705
+ }
1706
+ return !isExport && this.isContextual(tt._typeof);
1707
+ }
1708
+ applyImportPhase(node, isExport, phase, loc) {
1709
+ super.applyImportPhase(node, isExport, phase, loc);
1710
+ if (isExport) {
1711
+ if (!phase && this.match(tt._default)) {
1712
+ return;
1713
+ }
1714
+ node.exportKind = phase === "type" ? phase : "value";
1715
+ } else {
1716
+ if (phase === "type" && this.match(tt.star)) this.unexpected();
1717
+ node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
1718
+ }
1719
+ }
1720
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1721
+ parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
1722
+ const firstIdent = specifier.imported;
1723
+ let specifierTypeKind = null;
1724
+ if (firstIdent.type === "Identifier") {
1725
+ if (firstIdent.name === "type") {
1726
+ specifierTypeKind = "type";
1727
+ } else if (firstIdent.name === "typeof") {
1728
+ specifierTypeKind = "typeof";
1729
+ }
1730
+ }
1731
+ let isBinding = false;
1732
+ if (this.isContextual(tt._as) && !this.isLookaheadContextual("as")) {
1733
+ const as_ident = this.parseIdentifier(true);
1734
+ if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
1735
+ specifier.imported = as_ident;
1736
+ specifier.importKind = specifierTypeKind;
1737
+ specifier.local = this.cloneIdentifier(as_ident);
1738
+ } else {
1739
+ specifier.imported = firstIdent;
1740
+ specifier.importKind = null;
1741
+ specifier.local = this.parseIdentifier();
1742
+ }
1743
+ } else {
1744
+ if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
1745
+ specifier.imported = this.parseIdentifier(true);
1746
+ specifier.importKind = specifierTypeKind;
1747
+ } else {
1748
+ if (importedIsString) {
1749
+ throw this.raise(Errors.ImportBindingIsString, specifier, {
1750
+ importName: firstIdent.value
1751
+ });
1752
+ }
1753
+ specifier.imported = firstIdent;
1754
+ specifier.importKind = null;
1755
+ }
1756
+ if (this.eatContextual(tt._as)) {
1757
+ specifier.local = this.parseIdentifier();
1758
+ } else {
1759
+ isBinding = true;
1760
+ specifier.local = this.cloneIdentifier(specifier.imported);
1761
+ }
1762
+ }
1763
+ const specifierIsTypeImport = hasTypeImportKind(specifier);
1764
+ if (isInTypeOnlyImport && specifierIsTypeImport) {
1765
+ this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
1766
+ }
1767
+ if (isInTypeOnlyImport || specifierIsTypeImport) {
1768
+ this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
1769
+ }
1770
+ if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
1771
+ this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
1772
+ }
1773
+ return this.finishImportSpecifier(specifier, "ImportSpecifier");
1774
+ }
1775
+ parseBindingAtom() {
1776
+ switch (this.state.type) {
1777
+ case tt._this:
1778
+ return this.parseIdentifier(true);
1779
+ default:
1780
+ return super.parseBindingAtom();
1781
+ }
1782
+ }
1783
+ parseFunctionParams(node, isConstructor) {
1784
+ const kind = node.kind;
1785
+ if (kind !== "get" && kind !== "set" && this.match(tt.lt)) {
1786
+ node.typeParameters = this.flowParseTypeParameterDeclaration();
1787
+ }
1788
+ super.parseFunctionParams(node, isConstructor);
1789
+ }
1790
+ parseVarId(decl, kind) {
1791
+ super.parseVarId(decl, kind);
1792
+ if (this.match(tt.colon)) {
1793
+ decl.id.typeAnnotation = this.flowParseTypeAnnotation();
1794
+ this.resetEndLocation(decl.id);
1795
+ }
1796
+ }
1797
+ parseAsyncArrowFromCallExpression(node, call) {
1798
+ if (this.match(tt.colon)) {
1799
+ const oldNoAnonFunctionType = this.state.noAnonFunctionType;
1800
+ this.state.noAnonFunctionType = true;
1801
+ node.returnType = this.flowParseTypeAnnotation();
1802
+ this.state.noAnonFunctionType = oldNoAnonFunctionType;
1803
+ }
1804
+ return super.parseAsyncArrowFromCallExpression(node, call);
1805
+ }
1806
+ shouldParseAsyncArrow() {
1807
+ return this.match(tt.colon) || super.shouldParseAsyncArrow();
1808
+ }
1809
+ parseMaybeAssign(refExpressionErrors, afterLeftParse) {
1810
+ let state = null;
1811
+ let jsx;
1812
+ if (this.hasPlugin("jsx") && (this.match(tt.jsxTagStart) || this.match(tt.lt))) {
1813
+ state = this.state.clone();
1814
+ jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
1815
+ if (!jsx.error) return jsx.node;
1816
+ const {
1817
+ context
1818
+ } = this.state;
1819
+ const currentContext = context[context.length - 1];
1820
+ if (currentContext === tc.j_oTag || currentContext === tc.j_expr) {
1821
+ context.pop();
1822
+ }
1823
+ }
1824
+ if (jsx?.error || this.match(tt.lt)) {
1825
+ state = state || this.state.clone();
1826
+ let typeParameters;
1827
+ const arrow = this.tryParse((abort) => {
1828
+ typeParameters = this.flowParseTypeParameterDeclaration();
1829
+ const arrowExpression2 = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
1830
+ const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
1831
+ this.resetStartLocationFromNode(result, typeParameters);
1832
+ return result;
1833
+ });
1834
+ if (arrowExpression2.extra?.parenthesized) abort();
1835
+ const expr = this.maybeUnwrapTypeCastExpression(arrowExpression2);
1836
+ if (expr.type !== "ArrowFunctionExpression") abort();
1837
+ expr.typeParameters = typeParameters;
1838
+ this.resetStartLocationFromNode(expr, typeParameters);
1839
+ return arrowExpression2;
1840
+ }, state);
1841
+ let arrowExpression = null;
1842
+ if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
1843
+ if (!arrow.error && !arrow.aborted) {
1844
+ if (arrow.node.async) {
1845
+ this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
1846
+ }
1847
+ return arrow.node;
1848
+ }
1849
+ arrowExpression = arrow.node;
1850
+ }
1851
+ if (jsx?.node) {
1852
+ this.state = jsx.failState;
1853
+ return jsx.node;
1854
+ }
1855
+ if (arrowExpression) {
1856
+ this.state = arrow.failState;
1857
+ return arrowExpression;
1858
+ }
1859
+ if (jsx?.thrown) throw jsx.error;
1860
+ if (arrow.thrown) throw arrow.error;
1861
+ throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
1862
+ }
1863
+ return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
1864
+ }
1865
+ parseArrow(node) {
1866
+ if (this.match(tt.colon)) {
1867
+ const result = this.tryParse(() => {
1868
+ const oldNoAnonFunctionType = this.state.noAnonFunctionType;
1869
+ this.state.noAnonFunctionType = true;
1870
+ const typeNode = this.startNode();
1871
+ [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
1872
+ this.state.noAnonFunctionType = oldNoAnonFunctionType;
1873
+ if (this.canInsertSemicolon()) this.unexpected();
1874
+ if (!this.match(tt.arrow)) this.unexpected();
1875
+ return typeNode;
1876
+ });
1877
+ if (result.thrown) return null;
1878
+ if (result.error) this.state = result.failState;
1879
+ node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
1880
+ }
1881
+ return super.parseArrow(node);
1882
+ }
1883
+ shouldParseArrow(params) {
1884
+ return this.match(tt.colon) || super.shouldParseArrow(params);
1885
+ }
1886
+ setArrowFunctionParameters(node, params) {
1887
+ if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
1888
+ node.params = params;
1889
+ } else {
1890
+ super.setArrowFunctionParameters(node, params);
1891
+ }
1892
+ }
1893
+ checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
1894
+ if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
1895
+ return;
1896
+ }
1897
+ for (let i = 0; i < node.params.length; i++) {
1898
+ if (this.isThisParam(node.params[i]) && i > 0) {
1899
+ this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
1900
+ }
1901
+ }
1902
+ super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
1903
+ }
1904
+ parseParenAndDistinguishExpression(canBeArrow) {
1905
+ return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
1906
+ }
1907
+ parseSubscripts(base, startLoc, noCalls) {
1908
+ if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
1909
+ this.next();
1910
+ const node = this.startNodeAt(startLoc);
1911
+ node.callee = base;
1912
+ node.arguments = super.parseCallExpressionArguments();
1913
+ base = this.finishNode(node, "CallExpression");
1914
+ } else if (base.type === "Identifier" && base.name === "async" && this.match(tt.lt)) {
1915
+ const state = this.state.clone();
1916
+ const arrow = this.tryParse((abort) => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
1917
+ if (!arrow.error && !arrow.aborted) return arrow.node;
1918
+ const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
1919
+ if (result.node && !result.error) return result.node;
1920
+ if (arrow.node) {
1921
+ this.state = arrow.failState;
1922
+ return arrow.node;
1923
+ }
1924
+ if (result.node) {
1925
+ this.state = result.failState;
1926
+ return result.node;
1927
+ }
1928
+ throw arrow.error || result.error;
1929
+ }
1930
+ return super.parseSubscripts(base, startLoc, noCalls);
1931
+ }
1932
+ parseSubscript(base, startLoc, noCalls, subscriptState) {
1933
+ if (this.match(tt.questionDot) && this.isLookaheadToken_lt()) {
1934
+ subscriptState.optionalChainMember = true;
1935
+ if (noCalls) {
1936
+ subscriptState.stop = true;
1937
+ return base;
1938
+ }
1939
+ this.next();
1940
+ const node = this.startNodeAt(startLoc);
1941
+ node.callee = base;
1942
+ node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
1943
+ this.expect(tt.parenL);
1944
+ node.arguments = this.parseCallExpressionArguments();
1945
+ node.optional = true;
1946
+ return this.finishCallExpression(node, true);
1947
+ } else if (!noCalls && this.shouldParseTypes() && (this.match(tt.lt) || this.match(tt.bitShiftL))) {
1948
+ const node = this.startNodeAt(startLoc);
1949
+ node.callee = base;
1950
+ const result = this.tryParse(() => {
1951
+ node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
1952
+ this.expect(tt.parenL);
1953
+ node.arguments = super.parseCallExpressionArguments();
1954
+ if (subscriptState.optionalChainMember) {
1955
+ node.optional = false;
1956
+ }
1957
+ return this.finishCallExpression(node, subscriptState.optionalChainMember);
1958
+ });
1959
+ if (result.node) {
1960
+ if (result.error) this.state = result.failState;
1961
+ return result.node;
1962
+ }
1963
+ }
1964
+ return super.parseSubscript(base, startLoc, noCalls, subscriptState);
1965
+ }
1966
+ parseNewCallee(node) {
1967
+ super.parseNewCallee(node);
1968
+ let targs = null;
1969
+ if (this.shouldParseTypes() && this.match(tt.lt)) {
1970
+ targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
1971
+ }
1972
+ node.typeArguments = targs;
1973
+ }
1974
+ parseAsyncArrowWithTypeParameters(startLoc) {
1975
+ const node = this.startNodeAt(startLoc);
1976
+ this.parseFunctionParams(node, false);
1977
+ if (!this.parseArrow(node)) return;
1978
+ return super.parseArrowExpression(node, void 0, true);
1979
+ }
1980
+ readToken_mult_modulo(code) {
1981
+ const next = this.input.charCodeAt(this.state.pos + 1);
1982
+ if (code === 42 && next === 47 && this.state.hasFlowComment) {
1983
+ this.state.hasFlowComment = false;
1984
+ this.state.pos += 2;
1985
+ this.nextToken();
1986
+ return;
1987
+ }
1988
+ super.readToken_mult_modulo(code);
1989
+ }
1990
+ readToken_pipe_amp(code) {
1991
+ const next = this.input.charCodeAt(this.state.pos + 1);
1992
+ if (code === 124 && next === 125) {
1993
+ this.finishOp(tt.braceBarR, 2);
1994
+ return;
1995
+ }
1996
+ super.readToken_pipe_amp(code);
1997
+ }
1998
+ parseTopLevel(file, program) {
1999
+ const fileNode = super.parseTopLevel(file, program);
2000
+ if (this.state.hasFlowComment) {
2001
+ this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
2002
+ }
2003
+ return fileNode;
2004
+ }
2005
+ skipBlockComment() {
2006
+ if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
2007
+ if (this.state.hasFlowComment) {
2008
+ throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
2009
+ }
2010
+ this.hasFlowCommentCompletion();
2011
+ const commentSkip = this.skipFlowComment();
2012
+ if (commentSkip) {
2013
+ this.state.pos += commentSkip;
2014
+ this.state.hasFlowComment = true;
2015
+ }
2016
+ return;
2017
+ }
2018
+ return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
2019
+ }
2020
+ skipFlowComment() {
2021
+ const {
2022
+ pos
2023
+ } = this.state;
2024
+ let shiftToFirstNonWhiteSpace = 2;
2025
+ while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
2026
+ shiftToFirstNonWhiteSpace++;
2027
+ }
2028
+ const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
2029
+ const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
2030
+ if (ch2 === 58 && ch3 === 58) {
2031
+ return shiftToFirstNonWhiteSpace + 2;
2032
+ }
2033
+ if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
2034
+ return shiftToFirstNonWhiteSpace + 12;
2035
+ }
2036
+ if (ch2 === 58 && ch3 !== 58) {
2037
+ return shiftToFirstNonWhiteSpace;
2038
+ }
2039
+ return false;
2040
+ }
2041
+ hasFlowCommentCompletion() {
2042
+ const end = this.input.indexOf("*/", this.state.pos);
2043
+ if (end === -1) {
2044
+ throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
2045
+ }
2046
+ }
2047
+ flowEnumErrorBooleanMemberNotInitialized(loc, {
2048
+ enumName,
2049
+ memberName
2050
+ }) {
2051
+ this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
2052
+ memberName,
2053
+ enumName
2054
+ });
2055
+ }
2056
+ flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
2057
+ return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
2058
+ }
2059
+ flowEnumErrorNumberMemberNotInitialized(loc, details) {
2060
+ this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
2061
+ }
2062
+ flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
2063
+ this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
2064
+ }
2065
+ flowEnumMemberInit() {
2066
+ const startLoc = this.state.startLoc;
2067
+ const endOfInit = () => this.match(tt.comma) || this.match(tt.braceR);
2068
+ switch (this.state.type) {
2069
+ case tt.num: {
2070
+ const literal = this.parseNumericLiteral(this.state.value);
2071
+ if (endOfInit()) {
2072
+ return {
2073
+ type: "number",
2074
+ loc: literal.loc.start,
2075
+ value: literal
2076
+ };
2077
+ }
2078
+ return {
2079
+ type: "invalid",
2080
+ loc: startLoc
2081
+ };
2082
+ }
2083
+ case tt.string: {
2084
+ const literal = this.parseStringLiteral(this.state.value);
2085
+ if (endOfInit()) {
2086
+ return {
2087
+ type: "string",
2088
+ loc: literal.loc.start,
2089
+ value: literal
2090
+ };
2091
+ }
2092
+ return {
2093
+ type: "invalid",
2094
+ loc: startLoc
2095
+ };
2096
+ }
2097
+ case tt._true:
2098
+ case tt._false: {
2099
+ const literal = this.parseBooleanLiteral(this.match(tt._true));
2100
+ if (endOfInit()) {
2101
+ return {
2102
+ type: "boolean",
2103
+ loc: literal.loc.start,
2104
+ value: literal
2105
+ };
2106
+ }
2107
+ return {
2108
+ type: "invalid",
2109
+ loc: startLoc
2110
+ };
2111
+ }
2112
+ default:
2113
+ return {
2114
+ type: "invalid",
2115
+ loc: startLoc
2116
+ };
2117
+ }
2118
+ }
2119
+ flowEnumMemberRaw() {
2120
+ const loc = this.state.startLoc;
2121
+ const id = this.parseIdentifier(true);
2122
+ const init = this.eat(tt.eq) ? this.flowEnumMemberInit() : {
2123
+ type: "none",
2124
+ loc
2125
+ };
2126
+ return {
2127
+ id,
2128
+ init
2129
+ };
2130
+ }
2131
+ flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
2132
+ const {
2133
+ explicitType
2134
+ } = context;
2135
+ if (explicitType === null) {
2136
+ return;
2137
+ }
2138
+ if (explicitType !== expectedType) {
2139
+ this.flowEnumErrorInvalidMemberInitializer(loc, context);
2140
+ }
2141
+ }
2142
+ flowEnumMembers({
2143
+ enumName,
2144
+ explicitType
2145
+ }) {
2146
+ const seenNames = /* @__PURE__ */ new Set();
2147
+ const members = {
2148
+ booleanMembers: [],
2149
+ numberMembers: [],
2150
+ stringMembers: [],
2151
+ defaultedMembers: []
2152
+ };
2153
+ let hasUnknownMembers = false;
2154
+ while (!this.match(tt.braceR)) {
2155
+ if (this.eat(tt.ellipsis)) {
2156
+ hasUnknownMembers = true;
2157
+ break;
2158
+ }
2159
+ const memberNode = this.startNode();
2160
+ const {
2161
+ id,
2162
+ init
2163
+ } = this.flowEnumMemberRaw();
2164
+ const memberName = id.name;
2165
+ if (memberName === "") {
2166
+ continue;
2167
+ }
2168
+ if (/^[a-z]/.test(memberName)) {
2169
+ this.raise(FlowErrors.EnumInvalidMemberName, id, {
2170
+ memberName,
2171
+ suggestion: memberName[0].toUpperCase() + memberName.slice(1),
2172
+ enumName
2173
+ });
2174
+ }
2175
+ if (seenNames.has(memberName)) {
2176
+ this.raise(FlowErrors.EnumDuplicateMemberName, id, {
2177
+ memberName,
2178
+ enumName
2179
+ });
2180
+ }
2181
+ seenNames.add(memberName);
2182
+ const context = {
2183
+ enumName,
2184
+ explicitType,
2185
+ memberName
2186
+ };
2187
+ memberNode.id = id;
2188
+ switch (init.type) {
2189
+ case "boolean": {
2190
+ this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
2191
+ memberNode.init = init.value;
2192
+ members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
2193
+ break;
2194
+ }
2195
+ case "number": {
2196
+ this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
2197
+ memberNode.init = init.value;
2198
+ members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
2199
+ break;
2200
+ }
2201
+ case "string": {
2202
+ this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
2203
+ memberNode.init = init.value;
2204
+ members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
2205
+ break;
2206
+ }
2207
+ case "invalid": {
2208
+ throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
2209
+ }
2210
+ case "none": {
2211
+ switch (explicitType) {
2212
+ case "boolean":
2213
+ this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
2214
+ break;
2215
+ case "number":
2216
+ this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
2217
+ break;
2218
+ default:
2219
+ members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
2220
+ }
2221
+ }
2222
+ }
2223
+ if (!this.match(tt.braceR)) {
2224
+ this.expect(tt.comma);
2225
+ }
2226
+ }
2227
+ return {
2228
+ members,
2229
+ hasUnknownMembers
2230
+ };
2231
+ }
2232
+ flowEnumStringMembers(initializedMembers, defaultedMembers, {
2233
+ enumName
2234
+ }) {
2235
+ if (initializedMembers.length === 0) {
2236
+ return defaultedMembers;
2237
+ } else if (defaultedMembers.length === 0) {
2238
+ return initializedMembers;
2239
+ } else if (defaultedMembers.length > initializedMembers.length) {
2240
+ for (const member of initializedMembers) {
2241
+ this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
2242
+ enumName
2243
+ });
2244
+ }
2245
+ return defaultedMembers;
2246
+ } else {
2247
+ for (const member of defaultedMembers) {
2248
+ this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
2249
+ enumName
2250
+ });
2251
+ }
2252
+ return initializedMembers;
2253
+ }
2254
+ }
2255
+ flowEnumParseExplicitType({
2256
+ enumName
2257
+ }) {
2258
+ if (!this.eatContextual(tt._of)) return null;
2259
+ if (!tokenIsIdentifier(this.state.type)) {
2260
+ throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
2261
+ enumName
2262
+ });
2263
+ }
2264
+ const {
2265
+ value
2266
+ } = this.state;
2267
+ this.next();
2268
+ if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
2269
+ this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
2270
+ enumName,
2271
+ invalidEnumType: value
2272
+ });
2273
+ }
2274
+ return value;
2275
+ }
2276
+ flowEnumBody(node, id) {
2277
+ const enumName = id.name;
2278
+ const nameLoc = id.loc.start;
2279
+ const explicitType = this.flowEnumParseExplicitType({
2280
+ enumName
2281
+ });
2282
+ this.expect(tt.braceL);
2283
+ const {
2284
+ members,
2285
+ hasUnknownMembers
2286
+ } = this.flowEnumMembers({
2287
+ enumName,
2288
+ explicitType
2289
+ });
2290
+ node.hasUnknownMembers = hasUnknownMembers;
2291
+ switch (explicitType) {
2292
+ case "boolean":
2293
+ node.explicitType = true;
2294
+ node.members = members.booleanMembers;
2295
+ this.expect(tt.braceR);
2296
+ return this.finishNode(node, "EnumBooleanBody");
2297
+ case "number":
2298
+ node.explicitType = true;
2299
+ node.members = members.numberMembers;
2300
+ this.expect(tt.braceR);
2301
+ return this.finishNode(node, "EnumNumberBody");
2302
+ case "string":
2303
+ node.explicitType = true;
2304
+ node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
2305
+ enumName
2306
+ });
2307
+ this.expect(tt.braceR);
2308
+ return this.finishNode(node, "EnumStringBody");
2309
+ case "symbol":
2310
+ node.members = members.defaultedMembers;
2311
+ this.expect(tt.braceR);
2312
+ return this.finishNode(node, "EnumSymbolBody");
2313
+ default: {
2314
+ const empty = () => {
2315
+ node.members = [];
2316
+ this.expect(tt.braceR);
2317
+ return this.finishNode(node, "EnumStringBody");
2318
+ };
2319
+ node.explicitType = false;
2320
+ const boolsLen = members.booleanMembers.length;
2321
+ const numsLen = members.numberMembers.length;
2322
+ const strsLen = members.stringMembers.length;
2323
+ const defaultedLen = members.defaultedMembers.length;
2324
+ if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
2325
+ return empty();
2326
+ } else if (!boolsLen && !numsLen) {
2327
+ node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
2328
+ enumName
2329
+ });
2330
+ this.expect(tt.braceR);
2331
+ return this.finishNode(node, "EnumStringBody");
2332
+ } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
2333
+ for (const member of members.defaultedMembers) {
2334
+ this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
2335
+ enumName,
2336
+ memberName: member.id.name
2337
+ });
2338
+ }
2339
+ node.members = members.booleanMembers;
2340
+ this.expect(tt.braceR);
2341
+ return this.finishNode(node, "EnumBooleanBody");
2342
+ } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
2343
+ for (const member of members.defaultedMembers) {
2344
+ this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
2345
+ enumName,
2346
+ memberName: member.id.name
2347
+ });
2348
+ }
2349
+ node.members = members.numberMembers;
2350
+ this.expect(tt.braceR);
2351
+ return this.finishNode(node, "EnumNumberBody");
2352
+ } else {
2353
+ this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
2354
+ enumName
2355
+ });
2356
+ return empty();
2357
+ }
2358
+ }
2359
+ }
2360
+ }
2361
+ flowParseEnumDeclaration(node) {
2362
+ const id = this.parseIdentifier();
2363
+ node.id = id;
2364
+ node.body = this.flowEnumBody(this.startNode(), id);
2365
+ return this.finishNode(node, "EnumDeclaration");
2366
+ }
2367
+ jsxParseOpeningElementAfterName(node) {
2368
+ if (this.shouldParseTypes()) {
2369
+ if (this.match(tt.lt) || this.match(tt.bitShiftL)) {
2370
+ node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
2371
+ }
2372
+ }
2373
+ return super.jsxParseOpeningElementAfterName(node);
2374
+ }
2375
+ isLookaheadToken_lt() {
2376
+ const next = this.nextTokenStart();
2377
+ if (this.input.charCodeAt(next) === 60) {
2378
+ const afterNext = this.input.charCodeAt(next + 1);
2379
+ return afterNext !== 60 && afterNext !== 61;
2380
+ }
2381
+ return false;
2382
+ }
2383
+ reScan_lt_gt() {
2384
+ const {
2385
+ type
2386
+ } = this.state;
2387
+ if (type === tt.lt) {
2388
+ this.state.pos -= 1;
2389
+ this.readToken_lt();
2390
+ } else if (type === tt.gt) {
2391
+ this.state.pos -= 1;
2392
+ this.readToken_gt();
2393
+ }
2394
+ }
2395
+ reScan_lt() {
2396
+ const {
2397
+ type
2398
+ } = this.state;
2399
+ if (type === tt.bitShiftL) {
2400
+ this.state.pos -= 2;
2401
+ this.finishOp(tt.lt, 1);
2402
+ return tt.lt;
2403
+ }
2404
+ return type;
2405
+ }
2406
+ maybeUnwrapTypeCastExpression(node) {
2407
+ return node.type === "TypeCastExpression" ? node.expression : node;
2408
+ }
2409
+ };
2410
+ export {
2411
+ stdin_default as default
2412
+ };