@harmoniclabs/pebble 0.1.0-dev0

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 (769) hide show
  1. package/dist/IR/IRHash.d.ts +8 -0
  2. package/dist/IR/IRHash.js +78 -0
  3. package/dist/IR/IRNodeKind.d.ts +17 -0
  4. package/dist/IR/IRNodeKind.js +19 -0
  5. package/dist/IR/IRNodes/BaseIRMetadata.d.ts +3 -0
  6. package/dist/IR/IRNodes/BaseIRMetadata.js +1 -0
  7. package/dist/IR/IRNodes/IRApp.d.ts +36 -0
  8. package/dist/IR/IRNodes/IRApp.js +91 -0
  9. package/dist/IR/IRNodes/IRCase.d.ts +32 -0
  10. package/dist/IR/IRNodes/IRCase.js +91 -0
  11. package/dist/IR/IRNodes/IRConst.d.ts +49 -0
  12. package/dist/IR/IRNodes/IRConst.js +273 -0
  13. package/dist/IR/IRNodes/IRConstr.d.ts +30 -0
  14. package/dist/IR/IRNodes/IRConstr.js +87 -0
  15. package/dist/IR/IRNodes/IRDelayed.d.ts +31 -0
  16. package/dist/IR/IRNodes/IRDelayed.js +68 -0
  17. package/dist/IR/IRNodes/IRError.d.ts +32 -0
  18. package/dist/IR/IRNodes/IRError.js +44 -0
  19. package/dist/IR/IRNodes/IRForced.d.ts +31 -0
  20. package/dist/IR/IRNodes/IRForced.js +69 -0
  21. package/dist/IR/IRNodes/IRFunc.d.ts +33 -0
  22. package/dist/IR/IRNodes/IRFunc.js +91 -0
  23. package/dist/IR/IRNodes/IRHoisted.d.ts +55 -0
  24. package/dist/IR/IRNodes/IRHoisted.js +212 -0
  25. package/dist/IR/IRNodes/IRLetted.d.ts +108 -0
  26. package/dist/IR/IRNodes/IRLetted.js +444 -0
  27. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +138 -0
  28. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +204 -0
  29. package/dist/IR/IRNodes/IRNative/index.d.ts +165 -0
  30. package/dist/IR/IRNodes/IRNative/index.js +240 -0
  31. package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +3 -0
  32. package/dist/IR/IRNodes/IRNative/isForcedNative.js +18 -0
  33. package/dist/IR/IRNodes/IRRecursive.d.ts +29 -0
  34. package/dist/IR/IRNodes/IRRecursive.js +90 -0
  35. package/dist/IR/IRNodes/IRSelfCall.d.ts +46 -0
  36. package/dist/IR/IRNodes/IRSelfCall.js +127 -0
  37. package/dist/IR/IRNodes/IRVar.d.ts +41 -0
  38. package/dist/IR/IRNodes/IRVar.js +93 -0
  39. package/dist/IR/IRNodes/index.d.ts +12 -0
  40. package/dist/IR/IRNodes/index.js +12 -0
  41. package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +5 -0
  42. package/dist/IR/IRNodes/utils/dependsByDbns.js +29 -0
  43. package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +2 -0
  44. package/dist/IR/IRNodes/utils/isClosedAtDbn.js +22 -0
  45. package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +1 -0
  46. package/dist/IR/IRNodes/utils/makeArrayLikeProxy.js +34 -0
  47. package/dist/IR/IRNodes/utils/mapArrayLike.d.ts +1 -0
  48. package/dist/IR/IRNodes/utils/mapArrayLike.js +8 -0
  49. package/dist/IR/IRTerm.d.ts +15 -0
  50. package/dist/IR/IRTerm.js +1 -0
  51. package/dist/IR/index.d.ts +5 -0
  52. package/dist/IR/index.js +5 -0
  53. package/dist/IR/interfaces/IHash.d.ts +6 -0
  54. package/dist/IR/interfaces/IHash.js +1 -0
  55. package/dist/IR/interfaces/IIRParent.d.ts +4 -0
  56. package/dist/IR/interfaces/IIRParent.js +1 -0
  57. package/dist/IR/interfaces/IRMetadata.d.ts +3 -0
  58. package/dist/IR/interfaces/IRMetadata.js +2 -0
  59. package/dist/IR/interfaces/ToIR.d.ts +5 -0
  60. package/dist/IR/interfaces/ToIR.js +1 -0
  61. package/dist/IR/interfaces/index.d.ts +4 -0
  62. package/dist/IR/interfaces/index.js +4 -0
  63. package/dist/IR/toUPLC/CompilerOptions.d.ts +80 -0
  64. package/dist/IR/toUPLC/CompilerOptions.js +98 -0
  65. package/dist/IR/toUPLC/_internal/_addDepth.d.ts +2 -0
  66. package/dist/IR/toUPLC/_internal/_addDepth.js +58 -0
  67. package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +9 -0
  68. package/dist/IR/toUPLC/_internal/_irToUplc.js +156 -0
  69. package/dist/IR/toUPLC/_internal/_makeAllNegativeNativesHoisted.d.ts +2 -0
  70. package/dist/IR/toUPLC/_internal/_makeAllNegativeNativesHoisted.js +12 -0
  71. package/dist/IR/toUPLC/_internal/_modifyChildFromTo.d.ts +10 -0
  72. package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +141 -0
  73. package/dist/IR/toUPLC/_internal/depth.d.ts +5 -0
  74. package/dist/IR/toUPLC/_internal/depth.js +8 -0
  75. package/dist/IR/toUPLC/_internal/findAll.d.ts +3 -0
  76. package/dist/IR/toUPLC/_internal/findAll.js +99 -0
  77. package/dist/IR/toUPLC/_internal/getDebruijnInTerm.d.ts +2 -0
  78. package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +51 -0
  79. package/dist/IR/toUPLC/_internal/getDiffDbn.d.ts +2 -0
  80. package/dist/IR/toUPLC/_internal/getDiffDbn.js +55 -0
  81. package/dist/IR/toUPLC/_internal/includesLettedTerms.d.ts +2 -0
  82. package/dist/IR/toUPLC/_internal/includesLettedTerms.js +50 -0
  83. package/dist/IR/toUPLC/_internal/includesNode.d.ts +2 -0
  84. package/dist/IR/toUPLC/_internal/includesNode.js +54 -0
  85. package/dist/IR/toUPLC/_internal/iterTree.d.ts +2 -0
  86. package/dist/IR/toUPLC/_internal/iterTree.js +93 -0
  87. package/dist/IR/toUPLC/_internal/lowestCommonAncestor.d.ts +3 -0
  88. package/dist/IR/toUPLC/_internal/lowestCommonAncestor.js +41 -0
  89. package/dist/IR/toUPLC/compileIRToUPLC.d.ts +4 -0
  90. package/dist/IR/toUPLC/compileIRToUPLC.js +118 -0
  91. package/dist/IR/toUPLC/index.d.ts +1 -0
  92. package/dist/IR/toUPLC/index.js +1 -0
  93. package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.d.ts +2 -0
  94. package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +161 -0
  95. package/dist/IR/toUPLC/subRoutines/handleLetted/findHighestRecursiveParent.d.ts +5 -0
  96. package/dist/IR/toUPLC/subRoutines/handleLetted/findHighestRecursiveParent.js +14 -0
  97. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +20 -0
  98. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +107 -0
  99. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +9 -0
  100. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +73 -0
  101. package/dist/IR/toUPLC/subRoutines/handleLetted/index.d.ts +2 -0
  102. package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +304 -0
  103. package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.d.ts +3 -0
  104. package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +32 -0
  105. package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.d.ts +2 -0
  106. package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +58 -0
  107. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +1 -0
  108. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +12 -0
  109. package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.d.ts +2 -0
  110. package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +82 -0
  111. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +4 -0
  112. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +68 -0
  113. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.d.ts +5 -0
  114. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +227 -0
  115. package/dist/IR/toUPLC/subRoutines/replaceClosedLettedWithHoisted.d.ts +2 -0
  116. package/dist/IR/toUPLC/subRoutines/replaceClosedLettedWithHoisted.js +13 -0
  117. package/dist/IR/toUPLC/subRoutines/replaceForcedNativesWithHoisted.d.ts +2 -0
  118. package/dist/IR/toUPLC/subRoutines/replaceForcedNativesWithHoisted.js +11 -0
  119. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.d.ts +2 -0
  120. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +16 -0
  121. package/dist/IR/toUPLC/subRoutines/replaceNatives/index.d.ts +2 -0
  122. package/dist/IR/toUPLC/subRoutines/replaceNatives/index.js +16 -0
  123. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +3 -0
  124. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +520 -0
  125. package/dist/IR/toUPLC/subRoutines/sanifyTree.d.ts +5 -0
  126. package/dist/IR/toUPLC/subRoutines/sanifyTree.js +84 -0
  127. package/dist/IR/tree_utils/_ir_apps.d.ts +3 -0
  128. package/dist/IR/tree_utils/_ir_apps.js +8 -0
  129. package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +3 -0
  130. package/dist/IR/tree_utils/_ir_lazyChooseList.js +5 -0
  131. package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +3 -0
  132. package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +5 -0
  133. package/dist/IR/tree_utils/_ir_let.d.ts +3 -0
  134. package/dist/IR/tree_utils/_ir_let.js +4 -0
  135. package/dist/IR/tree_utils/getChildren.d.ts +2 -0
  136. package/dist/IR/tree_utils/getChildren.js +33 -0
  137. package/dist/IR/tree_utils/getRoot.d.ts +2 -0
  138. package/dist/IR/tree_utils/getRoot.js +6 -0
  139. package/dist/IR/utils/MutArrayLike.d.ts +5 -0
  140. package/dist/IR/utils/MutArrayLike.js +1 -0
  141. package/dist/IR/utils/concatUint8Arr.d.ts +1 -0
  142. package/dist/IR/utils/concatUint8Arr.js +11 -0
  143. package/dist/IR/utils/equalIRTerm.d.ts +12 -0
  144. package/dist/IR/utils/equalIRTerm.js +19 -0
  145. package/dist/IR/utils/index.d.ts +3 -0
  146. package/dist/IR/utils/index.js +3 -0
  147. package/dist/IR/utils/isClosedIRTerm.d.ts +2 -0
  148. package/dist/IR/utils/isClosedIRTerm.js +58 -0
  149. package/dist/IR/utils/isIRParentTerm.d.ts +12 -0
  150. package/dist/IR/utils/isIRParentTerm.js +26 -0
  151. package/dist/IR/utils/isIRTerm.d.ts +2 -0
  152. package/dist/IR/utils/isIRTerm.js +30 -0
  153. package/dist/IR/utils/positiveIntAsBytes.d.ts +5 -0
  154. package/dist/IR/utils/positiveIntAsBytes.js +27 -0
  155. package/dist/IR/utils/showIR.d.ts +43 -0
  156. package/dist/IR/utils/showIR.js +372 -0
  157. package/dist/ast/PebbleAst.d.ts +8 -0
  158. package/dist/ast/PebbleAst.js +15 -0
  159. package/dist/ast/Source/Source.d.ts +47 -0
  160. package/dist/ast/Source/Source.js +89 -0
  161. package/dist/ast/Source/SourceRange.d.ts +16 -0
  162. package/dist/ast/Source/SourceRange.js +49 -0
  163. package/dist/ast/nodes/HasSourceRange.d.ts +5 -0
  164. package/dist/ast/nodes/HasSourceRange.js +6 -0
  165. package/dist/ast/nodes/common/Identifier.d.ts +13 -0
  166. package/dist/ast/nodes/common/Identifier.js +20 -0
  167. package/dist/ast/nodes/expr/CaseExpr.d.ts +22 -0
  168. package/dist/ast/nodes/expr/CaseExpr.js +30 -0
  169. package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +12 -0
  170. package/dist/ast/nodes/expr/ElemAccessExpr.js +13 -0
  171. package/dist/ast/nodes/expr/IsExpr.d.ts +1 -0
  172. package/dist/ast/nodes/expr/IsExpr.js +14 -0
  173. package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +8 -0
  174. package/dist/ast/nodes/expr/ParentesizedExpr.js +8 -0
  175. package/dist/ast/nodes/expr/PebbleExpr.d.ts +18 -0
  176. package/dist/ast/nodes/expr/PebbleExpr.js +31 -0
  177. package/dist/ast/nodes/expr/PropAccessExpr.d.ts +28 -0
  178. package/dist/ast/nodes/expr/PropAccessExpr.js +46 -0
  179. package/dist/ast/nodes/expr/TernaryExpr.d.ts +10 -0
  180. package/dist/ast/nodes/expr/TernaryExpr.js +12 -0
  181. package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +10 -0
  182. package/dist/ast/nodes/expr/TypeConversionExpr.js +11 -0
  183. package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +133 -0
  184. package/dist/ast/nodes/expr/binary/BinaryExpr.js +253 -0
  185. package/dist/ast/nodes/expr/functions/ArrowKind.d.ts +9 -0
  186. package/dist/ast/nodes/expr/functions/ArrowKind.js +11 -0
  187. package/dist/ast/nodes/expr/functions/CallExpr.d.ts +17 -0
  188. package/dist/ast/nodes/expr/functions/CallExpr.js +16 -0
  189. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +21 -0
  190. package/dist/ast/nodes/expr/functions/FuncExpr.js +21 -0
  191. package/dist/ast/nodes/expr/litteral/LitArrExpr.d.ts +8 -0
  192. package/dist/ast/nodes/expr/litteral/LitArrExpr.js +8 -0
  193. package/dist/ast/nodes/expr/litteral/LitFalseExpr.d.ts +6 -0
  194. package/dist/ast/nodes/expr/litteral/LitFalseExpr.js +6 -0
  195. package/dist/ast/nodes/expr/litteral/LitHexBytesExpr.d.ts +7 -0
  196. package/dist/ast/nodes/expr/litteral/LitHexBytesExpr.js +8 -0
  197. package/dist/ast/nodes/expr/litteral/LitIntExpr.d.ts +7 -0
  198. package/dist/ast/nodes/expr/litteral/LitIntExpr.js +8 -0
  199. package/dist/ast/nodes/expr/litteral/LitNamedObjExpr.d.ts +12 -0
  200. package/dist/ast/nodes/expr/litteral/LitNamedObjExpr.js +12 -0
  201. package/dist/ast/nodes/expr/litteral/LitObjExpr.d.ts +14 -0
  202. package/dist/ast/nodes/expr/litteral/LitObjExpr.js +10 -0
  203. package/dist/ast/nodes/expr/litteral/LitStrExpr.d.ts +7 -0
  204. package/dist/ast/nodes/expr/litteral/LitStrExpr.js +8 -0
  205. package/dist/ast/nodes/expr/litteral/LitThisExpr.d.ts +6 -0
  206. package/dist/ast/nodes/expr/litteral/LitThisExpr.js +6 -0
  207. package/dist/ast/nodes/expr/litteral/LitTrueExpr.d.ts +6 -0
  208. package/dist/ast/nodes/expr/litteral/LitTrueExpr.js +6 -0
  209. package/dist/ast/nodes/expr/litteral/LitUndefExpr.d.ts +6 -0
  210. package/dist/ast/nodes/expr/litteral/LitUndefExpr.js +6 -0
  211. package/dist/ast/nodes/expr/litteral/LitVoidExpr.d.ts +6 -0
  212. package/dist/ast/nodes/expr/litteral/LitVoidExpr.js +6 -0
  213. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +13 -0
  214. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +24 -0
  215. package/dist/ast/nodes/expr/unary/IUnaryExpression.d.ts +4 -0
  216. package/dist/ast/nodes/expr/unary/IUnaryExpression.js +1 -0
  217. package/dist/ast/nodes/expr/unary/NonNullExpr.d.ts +8 -0
  218. package/dist/ast/nodes/expr/unary/NonNullExpr.js +8 -0
  219. package/dist/ast/nodes/expr/unary/UnaryExclamation.d.ts +9 -0
  220. package/dist/ast/nodes/expr/unary/UnaryExclamation.js +8 -0
  221. package/dist/ast/nodes/expr/unary/UnaryMinus.d.ts +9 -0
  222. package/dist/ast/nodes/expr/unary/UnaryMinus.js +8 -0
  223. package/dist/ast/nodes/expr/unary/UnaryPlus.d.ts +9 -0
  224. package/dist/ast/nodes/expr/unary/UnaryPlus.js +8 -0
  225. package/dist/ast/nodes/expr/unary/UnaryPrefixExpr.d.ts +14 -0
  226. package/dist/ast/nodes/expr/unary/UnaryPrefixExpr.js +27 -0
  227. package/dist/ast/nodes/expr/unary/UnaryTilde.d.ts +9 -0
  228. package/dist/ast/nodes/expr/unary/UnaryTilde.js +8 -0
  229. package/dist/ast/nodes/statements/AssertStmt.d.ts +15 -0
  230. package/dist/ast/nodes/statements/AssertStmt.js +14 -0
  231. package/dist/ast/nodes/statements/AssignmentStmt.d.ts +105 -0
  232. package/dist/ast/nodes/statements/AssignmentStmt.js +211 -0
  233. package/dist/ast/nodes/statements/BlockStmt.d.ts +8 -0
  234. package/dist/ast/nodes/statements/BlockStmt.js +8 -0
  235. package/dist/ast/nodes/statements/BreakStmt.d.ts +6 -0
  236. package/dist/ast/nodes/statements/BreakStmt.js +6 -0
  237. package/dist/ast/nodes/statements/ContinueStmt.d.ts +6 -0
  238. package/dist/ast/nodes/statements/ContinueStmt.js +6 -0
  239. package/dist/ast/nodes/statements/DecrStmt.d.ts +11 -0
  240. package/dist/ast/nodes/statements/DecrStmt.js +11 -0
  241. package/dist/ast/nodes/statements/DoWhileStmt.d.ts +10 -0
  242. package/dist/ast/nodes/statements/DoWhileStmt.js +10 -0
  243. package/dist/ast/nodes/statements/EmptyStmt.d.ts +6 -0
  244. package/dist/ast/nodes/statements/EmptyStmt.js +6 -0
  245. package/dist/ast/nodes/statements/ExportImportStmt.d.ts +15 -0
  246. package/dist/ast/nodes/statements/ExportImportStmt.js +15 -0
  247. package/dist/ast/nodes/statements/ExportStarStmt.d.ts +8 -0
  248. package/dist/ast/nodes/statements/ExportStarStmt.js +8 -0
  249. package/dist/ast/nodes/statements/ExportStmt.d.ts +13 -0
  250. package/dist/ast/nodes/statements/ExportStmt.js +13 -0
  251. package/dist/ast/nodes/statements/ExprStmt.d.ts +8 -0
  252. package/dist/ast/nodes/statements/ExprStmt.js +18 -0
  253. package/dist/ast/nodes/statements/FailStmt.d.ts +11 -0
  254. package/dist/ast/nodes/statements/FailStmt.js +10 -0
  255. package/dist/ast/nodes/statements/ForOfStmt.d.ts +16 -0
  256. package/dist/ast/nodes/statements/ForOfStmt.js +15 -0
  257. package/dist/ast/nodes/statements/ForStmt.d.ts +19 -0
  258. package/dist/ast/nodes/statements/ForStmt.js +19 -0
  259. package/dist/ast/nodes/statements/IfStmt.d.ts +11 -0
  260. package/dist/ast/nodes/statements/IfStmt.js +12 -0
  261. package/dist/ast/nodes/statements/ImportStarStmt.d.ts +15 -0
  262. package/dist/ast/nodes/statements/ImportStarStmt.js +15 -0
  263. package/dist/ast/nodes/statements/ImportStmt.d.ts +21 -0
  264. package/dist/ast/nodes/statements/ImportStmt.js +25 -0
  265. package/dist/ast/nodes/statements/IncrStmt.d.ts +8 -0
  266. package/dist/ast/nodes/statements/IncrStmt.js +8 -0
  267. package/dist/ast/nodes/statements/MatchStmt.d.ts +17 -0
  268. package/dist/ast/nodes/statements/MatchStmt.js +20 -0
  269. package/dist/ast/nodes/statements/PebbleStmt.d.ts +29 -0
  270. package/dist/ast/nodes/statements/PebbleStmt.js +62 -0
  271. package/dist/ast/nodes/statements/ReturnStmt.d.ts +8 -0
  272. package/dist/ast/nodes/statements/ReturnStmt.js +8 -0
  273. package/dist/ast/nodes/statements/TestStmt.d.ts +10 -0
  274. package/dist/ast/nodes/statements/TestStmt.js +10 -0
  275. package/dist/ast/nodes/statements/TypeImplementsStmt.d.ts +21 -0
  276. package/dist/ast/nodes/statements/TypeImplementsStmt.js +26 -0
  277. package/dist/ast/nodes/statements/UsingStmt.d.ts +16 -0
  278. package/dist/ast/nodes/statements/UsingStmt.js +20 -0
  279. package/dist/ast/nodes/statements/VarStmt.d.ts +10 -0
  280. package/dist/ast/nodes/statements/VarStmt.js +11 -0
  281. package/dist/ast/nodes/statements/WhileStmt.d.ts +10 -0
  282. package/dist/ast/nodes/statements/WhileStmt.js +10 -0
  283. package/dist/ast/nodes/statements/declarations/EnumDecl.d.ts +18 -0
  284. package/dist/ast/nodes/statements/declarations/EnumDecl.js +22 -0
  285. package/dist/ast/nodes/statements/declarations/FuncDecl.d.ts +8 -0
  286. package/dist/ast/nodes/statements/declarations/FuncDecl.js +9 -0
  287. package/dist/ast/nodes/statements/declarations/InterfaceDecl.d.ts +19 -0
  288. package/dist/ast/nodes/statements/declarations/InterfaceDecl.js +26 -0
  289. package/dist/ast/nodes/statements/declarations/PebbleTypeDecl.d.ts +5 -0
  290. package/dist/ast/nodes/statements/declarations/PebbleTypeDecl.js +8 -0
  291. package/dist/ast/nodes/statements/declarations/StructDecl.d.ts +25 -0
  292. package/dist/ast/nodes/statements/declarations/StructDecl.js +36 -0
  293. package/dist/ast/nodes/statements/declarations/TypeAliasDecl.d.ts +11 -0
  294. package/dist/ast/nodes/statements/declarations/TypeAliasDecl.js +12 -0
  295. package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +19 -0
  296. package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.js +19 -0
  297. package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +5 -0
  298. package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.js +7 -0
  299. package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +24 -0
  300. package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.js +30 -0
  301. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +17 -0
  302. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +21 -0
  303. package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +24 -0
  304. package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.js +20 -0
  305. package/dist/ast/nodes/statements/declarations/VarDecl/VarDecl.d.ts +8 -0
  306. package/dist/ast/nodes/statements/declarations/VarDecl/VarDecl.js +13 -0
  307. package/dist/ast/nodes/types/AstNamedTypeExpr.d.ts +14 -0
  308. package/dist/ast/nodes/types/AstNamedTypeExpr.js +14 -0
  309. package/dist/ast/nodes/types/AstNativeTypeExpr.d.ts +52 -0
  310. package/dist/ast/nodes/types/AstNativeTypeExpr.js +82 -0
  311. package/dist/ast/nodes/types/AstTypeExpr.d.ts +4 -0
  312. package/dist/ast/nodes/types/AstTypeExpr.js +7 -0
  313. package/dist/common.d.ts +194 -0
  314. package/dist/common.js +224 -0
  315. package/dist/compiler/AstCompiler/AstCompilationCtx.d.ts +35 -0
  316. package/dist/compiler/AstCompiler/AstCompilationCtx.js +43 -0
  317. package/dist/compiler/AstCompiler/AstCompiler.d.ts +73 -0
  318. package/dist/compiler/AstCompiler/AstCompiler.js +532 -0
  319. package/dist/compiler/AstCompiler/compileAst.d.ts +0 -0
  320. package/dist/compiler/AstCompiler/compileAst.js +0 -0
  321. package/dist/compiler/AstCompiler/index.d.ts +1 -0
  322. package/dist/compiler/AstCompiler/index.js +1 -0
  323. package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.d.ts +5 -0
  324. package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +66 -0
  325. package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.d.ts +5 -0
  326. package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +36 -0
  327. package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.d.ts +6 -0
  328. package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.js +47 -0
  329. package/dist/compiler/AstCompiler/internal/exprs/_compileElemAccessExpr.d.ts +5 -0
  330. package/dist/compiler/AstCompiler/internal/exprs/_compileElemAccessExpr.js +23 -0
  331. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.d.ts +22 -0
  332. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +77 -0
  333. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.d.ts +26 -0
  334. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +163 -0
  335. package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.d.ts +1 -0
  336. package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.js +43 -0
  337. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.d.ts +19 -0
  338. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +202 -0
  339. package/dist/compiler/AstCompiler/internal/exprs/_compileNonNullExpr.d.ts +5 -0
  340. package/dist/compiler/AstCompiler/internal/exprs/_compileNonNullExpr.js +43 -0
  341. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.d.ts +9 -0
  342. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +102 -0
  343. package/dist/compiler/AstCompiler/internal/exprs/_compileTernaryExpr.d.ts +5 -0
  344. package/dist/compiler/AstCompiler/internal/exprs/_compileTernaryExpr.js +22 -0
  345. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.d.ts +5 -0
  346. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +25 -0
  347. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.d.ts +5 -0
  348. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +54 -0
  349. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.d.ts +5 -0
  350. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +9 -0
  351. package/dist/compiler/AstCompiler/internal/exprs/_hasDuplicateTypeParams.d.ts +3 -0
  352. package/dist/compiler/AstCompiler/internal/exprs/_hasDuplicateTypeParams.js +13 -0
  353. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileAddExpr.d.ts +5 -0
  354. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileAddExpr.js +20 -0
  355. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileBitwiseAndExpr.d.ts +5 -0
  356. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileBitwiseAndExpr.js +20 -0
  357. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileBitwiseOrExpr.d.ts +5 -0
  358. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileBitwiseOrExpr.js +20 -0
  359. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileBitwiseXorExpr.d.ts +5 -0
  360. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileBitwiseXorExpr.js +20 -0
  361. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileDivExpr.d.ts +5 -0
  362. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileDivExpr.js +20 -0
  363. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileEqualExpr.d.ts +5 -0
  364. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileEqualExpr.js +18 -0
  365. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileExponentiationExpr.d.ts +5 -0
  366. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileExponentiationExpr.js +20 -0
  367. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanEqualExpr.d.ts +5 -0
  368. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanEqualExpr.js +27 -0
  369. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanExpr.d.ts +5 -0
  370. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanExpr.js +26 -0
  371. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanEqualExpr.d.ts +5 -0
  372. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanEqualExpr.js +25 -0
  373. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanExpr.d.ts +5 -0
  374. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanExpr.js +26 -0
  375. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLogicalAndExpr.d.ts +5 -0
  376. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLogicalAndExpr.js +22 -0
  377. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLogicalOrExpr.d.ts +5 -0
  378. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLogicalOrExpr.js +22 -0
  379. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileModuloExpr.d.ts +5 -0
  380. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileModuloExpr.js +20 -0
  381. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileMultExpr.d.ts +5 -0
  382. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileMultExpr.js +20 -0
  383. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileNotEqualExpr.d.ts +5 -0
  384. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileNotEqualExpr.js +18 -0
  385. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileOptionalDefaultExpr.d.ts +5 -0
  386. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileOptionalDefaultExpr.js +60 -0
  387. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileShiftLeftExpr.d.ts +5 -0
  388. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileShiftLeftExpr.js +21 -0
  389. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileShiftRightExpr.d.ts +5 -0
  390. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileShiftRightExpr.js +21 -0
  391. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileSubExpr.d.ts +5 -0
  392. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileSubExpr.js +20 -0
  393. package/dist/compiler/AstCompiler/internal/statements/_compileAssertStmt.d.ts +4 -0
  394. package/dist/compiler/AstCompiler/internal/statements/_compileAssertStmt.js +30 -0
  395. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.d.ts +8 -0
  396. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +154 -0
  397. package/dist/compiler/AstCompiler/internal/statements/_compileBlockStmt.d.ts +4 -0
  398. package/dist/compiler/AstCompiler/internal/statements/_compileBlockStmt.js +14 -0
  399. package/dist/compiler/AstCompiler/internal/statements/_compileBreakStmt.d.ts +4 -0
  400. package/dist/compiler/AstCompiler/internal/statements/_compileBreakStmt.js +7 -0
  401. package/dist/compiler/AstCompiler/internal/statements/_compileContinueStmt.d.ts +4 -0
  402. package/dist/compiler/AstCompiler/internal/statements/_compileContinueStmt.js +7 -0
  403. package/dist/compiler/AstCompiler/internal/statements/_compileExprStmt.d.ts +1 -0
  404. package/dist/compiler/AstCompiler/internal/statements/_compileExprStmt.js +12 -0
  405. package/dist/compiler/AstCompiler/internal/statements/_compileFailStmt.d.ts +4 -0
  406. package/dist/compiler/AstCompiler/internal/statements/_compileFailStmt.js +18 -0
  407. package/dist/compiler/AstCompiler/internal/statements/_compileForOfStmt.d.ts +4 -0
  408. package/dist/compiler/AstCompiler/internal/statements/_compileForOfStmt.js +30 -0
  409. package/dist/compiler/AstCompiler/internal/statements/_compileForStmt.d.ts +7 -0
  410. package/dist/compiler/AstCompiler/internal/statements/_compileForStmt.js +46 -0
  411. package/dist/compiler/AstCompiler/internal/statements/_compileIfStmt.d.ts +4 -0
  412. package/dist/compiler/AstCompiler/internal/statements/_compileIfStmt.js +27 -0
  413. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +6 -0
  414. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +182 -0
  415. package/dist/compiler/AstCompiler/internal/statements/_compileReturnStmt.d.ts +4 -0
  416. package/dist/compiler/AstCompiler/internal/statements/_compileReturnStmt.js +17 -0
  417. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.d.ts +11 -0
  418. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +73 -0
  419. package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.d.ts +1 -0
  420. package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.js +32 -0
  421. package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.d.ts +11 -0
  422. package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.js +41 -0
  423. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +34 -0
  424. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +207 -0
  425. package/dist/compiler/AstCompiler/internal/statements/_compileWhileStmt.d.ts +4 -0
  426. package/dist/compiler/AstCompiler/internal/statements/_compileWhileStmt.js +19 -0
  427. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.d.ts +4 -0
  428. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +61 -0
  429. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.d.ts +4 -0
  430. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +59 -0
  431. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +102 -0
  432. package/dist/compiler/AstCompiler/scope/AstScope.js +195 -0
  433. package/dist/compiler/AstCompiler/utils/deps/ResolveStackNode.d.ts +14 -0
  434. package/dist/compiler/AstCompiler/utils/deps/ResolveStackNode.js +36 -0
  435. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.d.ts +4 -0
  436. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +121 -0
  437. package/dist/compiler/AstCompiler/utils/getTirFuncSigTree/TirFuncSigTree.d.ts +39 -0
  438. package/dist/compiler/AstCompiler/utils/getTirFuncSigTree/TirFuncSigTree.js +129 -0
  439. package/dist/compiler/AstCompiler/utils/getTirFuncSigTree/getTirFuncSigTree.d.ts +4 -0
  440. package/dist/compiler/AstCompiler/utils/getTirFuncSigTree/getTirFuncSigTree.js +49 -0
  441. package/dist/compiler/AstCompiler/utils/wrapManyStatementsOrReturnSame.d.ts +3 -0
  442. package/dist/compiler/AstCompiler/utils/wrapManyStatementsOrReturnSame.js +12 -0
  443. package/dist/compiler/Compiler.d.ts +10 -0
  444. package/dist/compiler/Compiler.js +39 -0
  445. package/dist/compiler/TirCompiler/TirCompilerCtx.d.ts +7 -0
  446. package/dist/compiler/TirCompiler/TirCompilerCtx.js +8 -0
  447. package/dist/compiler/TirCompiler/compileTirProgram.d.ts +9 -0
  448. package/dist/compiler/TirCompiler/compileTirProgram.js +18 -0
  449. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +72 -0
  450. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +282 -0
  451. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.d.ts +27 -0
  452. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +248 -0
  453. package/dist/compiler/TirCompiler/expressify/expressify.d.ts +15 -0
  454. package/dist/compiler/TirCompiler/expressify/expressify.js +403 -0
  455. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +8 -0
  456. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +115 -0
  457. package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.d.ts +6 -0
  458. package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +105 -0
  459. package/dist/compiler/TirCompiler/expressify/expressifyTerminatingIfStmt.d.ts +5 -0
  460. package/dist/compiler/TirCompiler/expressify/expressifyTerminatingIfStmt.js +15 -0
  461. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +4 -0
  462. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +20 -0
  463. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.d.ts +3 -0
  464. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +34 -0
  465. package/dist/compiler/TirCompiler/expressify/expressifyVars.d.ts +10 -0
  466. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +320 -0
  467. package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.d.ts +9 -0
  468. package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +59 -0
  469. package/dist/compiler/TirCompiler/expressify/isSingleConstrStruct.d.ts +3 -0
  470. package/dist/compiler/TirCompiler/expressify/isSingleConstrStruct.js +9 -0
  471. package/dist/compiler/TirCompiler/expressify/toNamedDeconstructVarDecl.d.ts +3 -0
  472. package/dist/compiler/TirCompiler/expressify/toNamedDeconstructVarDecl.js +15 -0
  473. package/dist/compiler/TirCompiler/index.d.ts +2 -0
  474. package/dist/compiler/TirCompiler/index.js +2 -0
  475. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +5 -0
  476. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +37 -0
  477. package/dist/compiler/TirCompiler/internal/deps/DepsNode.d.ts +13 -0
  478. package/dist/compiler/TirCompiler/internal/deps/DepsNode.js +36 -0
  479. package/dist/compiler/index.d.ts +4 -0
  480. package/dist/compiler/index.js +4 -0
  481. package/dist/compiler/internalVar.d.ts +19 -0
  482. package/dist/compiler/internalVar.js +56 -0
  483. package/dist/compiler/io/CompilerIoApi.d.ts +36 -0
  484. package/dist/compiler/io/CompilerIoApi.js +62 -0
  485. package/dist/compiler/io/IOutputStream.d.ts +28 -0
  486. package/dist/compiler/io/IOutputStream.js +45 -0
  487. package/dist/compiler/io/index.d.ts +2 -0
  488. package/dist/compiler/io/index.js +2 -0
  489. package/dist/compiler/path/getAbsolutePath.d.ts +12 -0
  490. package/dist/compiler/path/getAbsolutePath.js +114 -0
  491. package/dist/compiler/path/path.d.ts +5 -0
  492. package/dist/compiler/path/path.js +160 -0
  493. package/dist/compiler/tir/expressions/ITirExpr.d.ts +11 -0
  494. package/dist/compiler/tir/expressions/ITirExpr.js +1 -0
  495. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +19 -0
  496. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +41 -0
  497. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +17 -0
  498. package/dist/compiler/tir/expressions/TirCallExpr.js +28 -0
  499. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +36 -0
  500. package/dist/compiler/tir/expressions/TirCaseExpr.js +257 -0
  501. package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +20 -0
  502. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +43 -0
  503. package/dist/compiler/tir/expressions/TirExpr.d.ts +23 -0
  504. package/dist/compiler/tir/expressions/TirExpr.js +46 -0
  505. package/dist/compiler/tir/expressions/TirFailExpr.d.ts +19 -0
  506. package/dist/compiler/tir/expressions/TirFailExpr.js +28 -0
  507. package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +22 -0
  508. package/dist/compiler/tir/expressions/TirFromDataExpr.js +196 -0
  509. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +37 -0
  510. package/dist/compiler/tir/expressions/TirFuncExpr.js +92 -0
  511. package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +18 -0
  512. package/dist/compiler/tir/expressions/TirHoistedExpr.js +28 -0
  513. package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +16 -0
  514. package/dist/compiler/tir/expressions/TirInlineClosedIR.js +25 -0
  515. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +18 -0
  516. package/dist/compiler/tir/expressions/TirLettedExpr.js +28 -0
  517. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +104 -0
  518. package/dist/compiler/tir/expressions/TirNativeFunc.js +805 -0
  519. package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +17 -0
  520. package/dist/compiler/tir/expressions/TirParentesizedExpr.js +20 -0
  521. package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +18 -0
  522. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +29 -0
  523. package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +18 -0
  524. package/dist/compiler/tir/expressions/TirTernaryExpr.js +36 -0
  525. package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +28 -0
  526. package/dist/compiler/tir/expressions/TirToDataExpr.js +172 -0
  527. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +23 -0
  528. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +32 -0
  529. package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +16 -0
  530. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +66 -0
  531. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +18 -0
  532. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +30 -0
  533. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +29 -0
  534. package/dist/compiler/tir/expressions/ToIRTermCtx.js +77 -0
  535. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +221 -0
  536. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +532 -0
  537. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +16 -0
  538. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +60 -0
  539. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +14 -0
  540. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +17 -0
  541. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +15 -0
  542. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +19 -0
  543. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +15 -0
  544. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +19 -0
  545. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +22 -0
  546. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +105 -0
  547. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +22 -0
  548. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +102 -0
  549. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +15 -0
  550. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +20 -0
  551. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +14 -0
  552. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +20 -0
  553. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +14 -0
  554. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +17 -0
  555. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +18 -0
  556. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +23 -0
  557. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +14 -0
  558. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +17 -0
  559. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +13 -0
  560. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +24 -0
  561. package/dist/compiler/tir/expressions/unary/ITirUnaryExpression.d.ts +4 -0
  562. package/dist/compiler/tir/expressions/unary/ITirUnaryExpression.js +1 -0
  563. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +17 -0
  564. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +23 -0
  565. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +17 -0
  566. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +22 -0
  567. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +15 -0
  568. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +20 -0
  569. package/dist/compiler/tir/expressions/unary/TirUnaryPrefixExpr.d.ts +6 -0
  570. package/dist/compiler/tir/expressions/unary/TirUnaryPrefixExpr.js +10 -0
  571. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +17 -0
  572. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +22 -0
  573. package/dist/compiler/tir/expressions/utils/NamedExpr.d.ts +5 -0
  574. package/dist/compiler/tir/expressions/utils/NamedExpr.js +1 -0
  575. package/dist/compiler/tir/program/TypedProgram.d.ts +44 -0
  576. package/dist/compiler/tir/program/TypedProgram.js +126 -0
  577. package/dist/compiler/tir/program/stdScope/StdTypes.d.ts +34 -0
  578. package/dist/compiler/tir/program/stdScope/StdTypes.js +40 -0
  579. package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.d.ts +0 -0
  580. package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.js +288 -0
  581. package/dist/compiler/tir/program/stdScope/stdScope.d.ts +15 -0
  582. package/dist/compiler/tir/program/stdScope/stdScope.js +730 -0
  583. package/dist/compiler/tir/statements/TirAssertStmt.d.ts +18 -0
  584. package/dist/compiler/tir/statements/TirAssertStmt.js +29 -0
  585. package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +12 -0
  586. package/dist/compiler/tir/statements/TirAssignmentStmt.js +14 -0
  587. package/dist/compiler/tir/statements/TirBlockStmt.d.ts +9 -0
  588. package/dist/compiler/tir/statements/TirBlockStmt.js +25 -0
  589. package/dist/compiler/tir/statements/TirBreakStmt.d.ts +8 -0
  590. package/dist/compiler/tir/statements/TirBreakStmt.js +11 -0
  591. package/dist/compiler/tir/statements/TirContinueStmt.d.ts +8 -0
  592. package/dist/compiler/tir/statements/TirContinueStmt.js +13 -0
  593. package/dist/compiler/tir/statements/TirFailStmt.d.ts +13 -0
  594. package/dist/compiler/tir/statements/TirFailStmt.js +14 -0
  595. package/dist/compiler/tir/statements/TirForOfStmt.d.ts +16 -0
  596. package/dist/compiler/tir/statements/TirForOfStmt.js +25 -0
  597. package/dist/compiler/tir/statements/TirForStmt.d.ts +19 -0
  598. package/dist/compiler/tir/statements/TirForStmt.js +39 -0
  599. package/dist/compiler/tir/statements/TirIfStmt.d.ts +12 -0
  600. package/dist/compiler/tir/statements/TirIfStmt.js +23 -0
  601. package/dist/compiler/tir/statements/TirMatchStmt.d.ts +27 -0
  602. package/dist/compiler/tir/statements/TirMatchStmt.js +51 -0
  603. package/dist/compiler/tir/statements/TirReturnStmt.d.ts +10 -0
  604. package/dist/compiler/tir/statements/TirReturnStmt.js +12 -0
  605. package/dist/compiler/tir/statements/TirStmt.d.ts +32 -0
  606. package/dist/compiler/tir/statements/TirStmt.js +40 -0
  607. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +17 -0
  608. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
  609. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +21 -0
  610. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +34 -0
  611. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +17 -0
  612. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +22 -0
  613. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +17 -0
  614. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +30 -0
  615. package/dist/compiler/tir/statements/TirVarDecl/TirVarDecl.d.ts +10 -0
  616. package/dist/compiler/tir/statements/TirVarDecl/TirVarDecl.js +11 -0
  617. package/dist/compiler/tir/statements/TirWhileStmt.d.ts +11 -0
  618. package/dist/compiler/tir/statements/TirWhileStmt.js +19 -0
  619. package/dist/compiler/tir/statements/utils/definitelyFails.d.ts +3 -0
  620. package/dist/compiler/tir/statements/utils/definitelyFails.js +52 -0
  621. package/dist/compiler/tir/types/TirAliasType.d.ts +32 -0
  622. package/dist/compiler/tir/types/TirAliasType.js +49 -0
  623. package/dist/compiler/tir/types/TirInterfaceImpl.d.ts +44 -0
  624. package/dist/compiler/tir/types/TirInterfaceImpl.js +32 -0
  625. package/dist/compiler/tir/types/TirInterfaceType.d.ts +28 -0
  626. package/dist/compiler/tir/types/TirInterfaceType.js +36 -0
  627. package/dist/compiler/tir/types/TirNativeType/TirNativeType.d.ts +41 -0
  628. package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +86 -0
  629. package/dist/compiler/tir/types/TirNativeType/index.d.ts +2 -0
  630. package/dist/compiler/tir/types/TirNativeType/index.js +2 -0
  631. package/dist/compiler/tir/types/TirNativeType/native/Optional/data.d.ts +17 -0
  632. package/dist/compiler/tir/types/TirNativeType/native/Optional/data.js +47 -0
  633. package/dist/compiler/tir/types/TirNativeType/native/Optional/index.d.ts +3 -0
  634. package/dist/compiler/tir/types/TirNativeType/native/Optional/index.js +3 -0
  635. package/dist/compiler/tir/types/TirNativeType/native/Optional/isTirOptType.d.ts +4 -0
  636. package/dist/compiler/tir/types/TirNativeType/native/Optional/isTirOptType.js +6 -0
  637. package/dist/compiler/tir/types/TirNativeType/native/Optional/sop.d.ts +17 -0
  638. package/dist/compiler/tir/types/TirNativeType/native/Optional/sop.js +48 -0
  639. package/dist/compiler/tir/types/TirNativeType/native/bool.d.ts +13 -0
  640. package/dist/compiler/tir/types/TirNativeType/native/bool.js +12 -0
  641. package/dist/compiler/tir/types/TirNativeType/native/bytes.d.ts +13 -0
  642. package/dist/compiler/tir/types/TirNativeType/native/bytes.js +12 -0
  643. package/dist/compiler/tir/types/TirNativeType/native/data.d.ts +13 -0
  644. package/dist/compiler/tir/types/TirNativeType/native/data.js +12 -0
  645. package/dist/compiler/tir/types/TirNativeType/native/function.d.ts +16 -0
  646. package/dist/compiler/tir/types/TirNativeType/native/function.js +38 -0
  647. package/dist/compiler/tir/types/TirNativeType/native/index.d.ts +10 -0
  648. package/dist/compiler/tir/types/TirNativeType/native/index.js +10 -0
  649. package/dist/compiler/tir/types/TirNativeType/native/int.d.ts +13 -0
  650. package/dist/compiler/tir/types/TirNativeType/native/int.js +12 -0
  651. package/dist/compiler/tir/types/TirNativeType/native/linearMap.d.ts +17 -0
  652. package/dist/compiler/tir/types/TirNativeType/native/linearMap.js +44 -0
  653. package/dist/compiler/tir/types/TirNativeType/native/list.d.ts +16 -0
  654. package/dist/compiler/tir/types/TirNativeType/native/list.js +38 -0
  655. package/dist/compiler/tir/types/TirNativeType/native/string.d.ts +13 -0
  656. package/dist/compiler/tir/types/TirNativeType/native/string.js +12 -0
  657. package/dist/compiler/tir/types/TirNativeType/native/void.d.ts +13 -0
  658. package/dist/compiler/tir/types/TirNativeType/native/void.js +12 -0
  659. package/dist/compiler/tir/types/TirStructType.d.ts +68 -0
  660. package/dist/compiler/tir/types/TirStructType.js +128 -0
  661. package/dist/compiler/tir/types/TirType.d.ts +34 -0
  662. package/dist/compiler/tir/types/TirType.js +16 -0
  663. package/dist/compiler/tir/types/TirTypeParam.d.ts +18 -0
  664. package/dist/compiler/tir/types/TirTypeParam.js +39 -0
  665. package/dist/compiler/tir/types/utils/canAssignTo.d.ts +24 -0
  666. package/dist/compiler/tir/types/utils/canAssignTo.js +337 -0
  667. package/dist/compiler/tir/types/utils/canCastTo.d.ts +9 -0
  668. package/dist/compiler/tir/types/utils/canCastTo.js +155 -0
  669. package/dist/compiler/tir/types/utils/getDeconstructableType.d.ts +9 -0
  670. package/dist/compiler/tir/types/utils/getDeconstructableType.js +20 -0
  671. package/dist/compiler/tir/types/utils/getListTypeArg.d.ts +2 -0
  672. package/dist/compiler/tir/types/utils/getListTypeArg.js +9 -0
  673. package/dist/compiler/tir/types/utils/getOptTypeArg.d.ts +2 -0
  674. package/dist/compiler/tir/types/utils/getOptTypeArg.js +14 -0
  675. package/dist/compiler/tir/types/utils/getUnaliased.d.ts +3 -0
  676. package/dist/compiler/tir/types/utils/getUnaliased.js +9 -0
  677. package/dist/diagnostics/DiagnosticCategory.d.ts +16 -0
  678. package/dist/diagnostics/DiagnosticCategory.js +39 -0
  679. package/dist/diagnostics/DiagnosticEmitter.d.ts +32 -0
  680. package/dist/diagnostics/DiagnosticEmitter.js +95 -0
  681. package/dist/diagnostics/DiagnosticMessage.d.ts +37 -0
  682. package/dist/diagnostics/DiagnosticMessage.js +229 -0
  683. package/dist/diagnostics/diagnosticMessages.generated.d.ts +275 -0
  684. package/dist/diagnostics/diagnosticMessages.generated.js +551 -0
  685. package/dist/diagnostics/utils/types.d.ts +5 -0
  686. package/dist/diagnostics/utils/types.js +1 -0
  687. package/dist/index.d.ts +12 -0
  688. package/dist/index.js +13 -0
  689. package/dist/parser/Parser.d.ts +150 -0
  690. package/dist/parser/Parser.js +2416 -0
  691. package/dist/parser/Precedence.d.ts +38 -0
  692. package/dist/parser/Precedence.js +98 -0
  693. package/dist/parser/hoistStatementsInplace.d.ts +14 -0
  694. package/dist/parser/hoistStatementsInplace.js +94 -0
  695. package/dist/parser/index.d.ts +1 -0
  696. package/dist/parser/index.js +1 -0
  697. package/dist/parser/parseFile.d.ts +3 -0
  698. package/dist/parser/parseFile.js +8 -0
  699. package/dist/tokenizer/IdentifierHandling.d.ts +5 -0
  700. package/dist/tokenizer/IdentifierHandling.js +6 -0
  701. package/dist/tokenizer/OnNewLine.d.ts +6 -0
  702. package/dist/tokenizer/OnNewLine.js +8 -0
  703. package/dist/tokenizer/Token.d.ts +160 -0
  704. package/dist/tokenizer/Token.js +213 -0
  705. package/dist/tokenizer/Tokenizer.d.ts +129 -0
  706. package/dist/tokenizer/Tokenizer.js +1323 -0
  707. package/dist/tokenizer/TokenizerState.d.ts +17 -0
  708. package/dist/tokenizer/TokenizerState.js +17 -0
  709. package/dist/tokenizer/index.d.ts +2 -0
  710. package/dist/tokenizer/index.js +2 -0
  711. package/dist/tokenizer/utils/isIllegalVariableIdentifier.d.ts +1 -0
  712. package/dist/tokenizer/utils/isIllegalVariableIdentifier.js +12 -0
  713. package/dist/tokenizer/utils/operatorTokenToString.d.ts +2 -0
  714. package/dist/tokenizer/utils/operatorTokenToString.js +57 -0
  715. package/dist/tokenizer/utils/tokenFromKeyword.d.ts +2 -0
  716. package/dist/tokenizer/utils/tokenFromKeyword.js +222 -0
  717. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.d.ts +2 -0
  718. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +24 -0
  719. package/dist/utils/BasePlutsError.d.ts +2 -0
  720. package/dist/utils/BasePlutsError.js +2 -0
  721. package/dist/utils/BitUtils/index.d.ts +30 -0
  722. package/dist/utils/BitUtils/index.js +60 -0
  723. package/dist/utils/CharCode.d.ts +125 -0
  724. package/dist/utils/CharCode.js +1 -0
  725. package/dist/utils/Cloneable.d.ts +6 -0
  726. package/dist/utils/Cloneable.js +4 -0
  727. package/dist/utils/InvalidCborFormatError.d.ts +3 -0
  728. package/dist/utils/InvalidCborFormatError.js +5 -0
  729. package/dist/utils/IsSingleKey.d.ts +7 -0
  730. package/dist/utils/IsSingleKey.js +1 -0
  731. package/dist/utils/MaybePromise.d.ts +2 -0
  732. package/dist/utils/MaybePromise.js +4 -0
  733. package/dist/utils/PlutusScriptType.d.ts +12 -0
  734. package/dist/utils/PlutusScriptType.js +1 -0
  735. package/dist/utils/ToJson.d.ts +4 -0
  736. package/dist/utils/ToJson.js +5 -0
  737. package/dist/utils/UPLCFlatUtils/index.d.ts +46 -0
  738. package/dist/utils/UPLCFlatUtils/index.js +124 -0
  739. package/dist/utils/array/filterSortedStrArrInplace.d.ts +7 -0
  740. package/dist/utils/array/filterSortedStrArrInplace.js +46 -0
  741. package/dist/utils/array/keepSortedArrInplace.d.ts +7 -0
  742. package/dist/utils/array/keepSortedArrInplace.js +49 -0
  743. package/dist/utils/array/mergeSortedStrArrInplace.d.ts +6 -0
  744. package/dist/utils/array/mergeSortedStrArrInplace.js +52 -0
  745. package/dist/utils/assert.d.ts +1 -0
  746. package/dist/utils/assert.js +5 -0
  747. package/dist/utils/capitalize.d.ts +1 -0
  748. package/dist/utils/capitalize.js +5 -0
  749. package/dist/utils/combinators.d.ts +37 -0
  750. package/dist/utils/combinators.js +76 -0
  751. package/dist/utils/getCallStackAt/index.d.ts +43 -0
  752. package/dist/utils/getCallStackAt/index.js +295 -0
  753. package/dist/utils/hex.d.ts +1 -0
  754. package/dist/utils/hex.js +6 -0
  755. package/dist/utils/ints.d.ts +4 -0
  756. package/dist/utils/ints.js +19 -0
  757. package/dist/utils/isNonEmpty.d.ts +1 -0
  758. package/dist/utils/isNonEmpty.js +3 -0
  759. package/dist/utils/maybeData.d.ts +4 -0
  760. package/dist/utils/maybeData.js +10 -0
  761. package/dist/utils/stringify.d.ts +2 -0
  762. package/dist/utils/stringify.js +31 -0
  763. package/dist/utils/terminal.d.ts +28 -0
  764. package/dist/utils/terminal.js +38 -0
  765. package/dist/utils/text.d.ts +172 -0
  766. package/dist/utils/text.js +672 -0
  767. package/dist/utils/types.d.ts +12 -0
  768. package/dist/utils/types.js +1 -0
  769. package/package.json +75 -0
@@ -0,0 +1,2416 @@
1
+ import { Identifier } from "../ast/nodes/common/Identifier.js";
2
+ import { NamedDeconstructVarDecl } from "../ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.js";
3
+ import { SingleDeconstructVarDecl } from "../ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.js";
4
+ import { VarStmt } from "../ast/nodes/statements/VarStmt.js";
5
+ import { SourceKind, Source } from "../ast/Source/Source.js";
6
+ import { CommonFlags, LIBRARY_PREFIX, PATH_DELIMITER } from "../common.js";
7
+ import { DiagnosticEmitter } from "../diagnostics/DiagnosticEmitter.js";
8
+ import { DiagnosticCode } from "../diagnostics/diagnosticMessages.generated.js";
9
+ import { Token } from "../tokenizer/Token.js";
10
+ import { Tokenizer } from "../tokenizer/Tokenizer.js";
11
+ import { isNonEmpty } from "../utils/isNonEmpty.js";
12
+ import { SourceRange } from "../ast/Source/SourceRange.js";
13
+ import { SimpleVarDecl } from "../ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js";
14
+ import { ArrayLikeDeconstr } from "../ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.js";
15
+ import { IdentifierHandling } from "../tokenizer/IdentifierHandling.js";
16
+ import { makeUnaryPrefixExpr } from "../ast/nodes/expr/unary/UnaryPrefixExpr.js";
17
+ import { LitUndefExpr } from "../ast/nodes/expr/litteral/LitUndefExpr.js";
18
+ import { LitVoidExpr } from "../ast/nodes/expr/litteral/LitVoidExpr.js";
19
+ import { LitFalseExpr } from "../ast/nodes/expr/litteral/LitFalseExpr.js";
20
+ import { LitThisExpr } from "../ast/nodes/expr/litteral/LitThisExpr.js";
21
+ import { LitTrueExpr } from "../ast/nodes/expr/litteral/LitTrueExpr.js";
22
+ import { ParentesizedExpr } from "../ast/nodes/expr/ParentesizedExpr.js";
23
+ import { ArrowKind } from "../ast/nodes/expr/functions/ArrowKind.js";
24
+ import { FuncExpr } from "../ast/nodes/expr/functions/FuncExpr.js";
25
+ import { AstBooleanType, AstBytesType, AstListType, AstIntType, AstNativeOptionalType, AstVoidType, AstLinearMapType, AstFuncType } from "../ast/nodes/types/AstNativeTypeExpr.js";
26
+ import { AstNamedTypeExpr } from "../ast/nodes/types/AstNamedTypeExpr.js";
27
+ import { LitArrExpr } from "../ast/nodes/expr/litteral/LitArrExpr.js";
28
+ import { LitNamedObjExpr } from "../ast/nodes/expr/litteral/LitNamedObjExpr.js";
29
+ import { LitObjExpr } from "../ast/nodes/expr/litteral/LitObjExpr.js";
30
+ import { LitStrExpr } from "../ast/nodes/expr/litteral/LitStrExpr.js";
31
+ import { LitIntExpr } from "../ast/nodes/expr/litteral/LitIntExpr.js";
32
+ import { LitHexBytesExpr } from "../ast/nodes/expr/litteral/LitHexBytesExpr.js";
33
+ import { CallExpr } from "../ast/nodes/expr/functions/CallExpr.js";
34
+ import { BlockStmt } from "../ast/nodes/statements/BlockStmt.js";
35
+ import { BreakStmt } from "../ast/nodes/statements/BreakStmt.js";
36
+ import { ContinueStmt } from "../ast/nodes/statements/ContinueStmt.js";
37
+ import { ForStmt } from "../ast/nodes/statements/ForStmt.js";
38
+ import { ForOfStmt } from "../ast/nodes/statements/ForOfStmt.js";
39
+ import { IfStmt } from "../ast/nodes/statements/IfStmt.js";
40
+ import { ReturnStmt } from "../ast/nodes/statements/ReturnStmt.js";
41
+ import { EmptyStmt } from "../ast/nodes/statements/EmptyStmt.js";
42
+ import { FuncDecl } from "../ast/nodes/statements/declarations/FuncDecl.js";
43
+ import { FailStmt } from "../ast/nodes/statements/FailStmt.js";
44
+ import { AssertStmt } from "../ast/nodes/statements/AssertStmt.js";
45
+ import { TestStmt } from "../ast/nodes/statements/TestStmt.js";
46
+ import { MatchStmt, MatchStmtCase } from "../ast/nodes/statements/MatchStmt.js";
47
+ import { WhileStmt } from "../ast/nodes/statements/WhileStmt.js";
48
+ import { CaseExpr, CaseExprMatcher } from "../ast/nodes/expr/CaseExpr.js";
49
+ import { StructConstrDecl, StructDecl, StructDeclAstFlags } from "../ast/nodes/statements/declarations/StructDecl.js";
50
+ import { InterfaceDecl, InterfaceDeclMethod } from "../ast/nodes/statements/declarations/InterfaceDecl.js";
51
+ import { ImportStarStmt } from "../ast/nodes/statements/ImportStarStmt.js";
52
+ import { ImportDecl, ImportStmt } from "../ast/nodes/statements/ImportStmt.js";
53
+ import { ExportImportStmt } from "../ast/nodes/statements/ExportImportStmt.js";
54
+ import { ExportStarStmt } from "../ast/nodes/statements/ExportStarStmt.js";
55
+ import { InterfaceMethodImpl, TypeImplementsStmt } from "../ast/nodes/statements/TypeImplementsStmt.js";
56
+ import { TypeAliasDecl } from "../ast/nodes/statements/declarations/TypeAliasDecl.js";
57
+ import { EnumDecl, EnumValueDecl } from "../ast/nodes/statements/declarations/EnumDecl.js";
58
+ import { TypeConversionExpr } from "../ast/nodes/expr/TypeConversionExpr.js";
59
+ import { NonNullExpr } from "../ast/nodes/expr/unary/NonNullExpr.js";
60
+ import { ElemAccessExpr } from "../ast/nodes/expr/ElemAccessExpr.js";
61
+ import { TernaryExpr } from "../ast/nodes/expr/TernaryExpr.js";
62
+ import { makePropAccessExpr } from "../ast/nodes/expr/PropAccessExpr.js";
63
+ import { makeBinaryExpr } from "../ast/nodes/expr/binary/BinaryExpr.js";
64
+ import { isAssignmentStmt, makeAssignmentStmt } from "../ast/nodes/statements/AssignmentStmt.js";
65
+ import { hoistStatementsInplace } from "./hoistStatementsInplace.js";
66
+ import { UsingStmt, UsingStmtDeclaredConstructor } from "../ast/nodes/statements/UsingStmt.js";
67
+ import { IncrStmt } from "../ast/nodes/statements/IncrStmt.js";
68
+ import { DecrStmt } from "../ast/nodes/statements/DecrStmt.js";
69
+ import { ExportStmt } from "../ast/nodes/statements/ExportStmt.js";
70
+ import { defaultSymbolForge } from "../compiler/internalVar.js";
71
+ import { Precedence, determinePrecedence } from "./Precedence.js";
72
+ export class Parser extends DiagnosticEmitter {
73
+ tn;
74
+ constructor(tokenizer, diagnostics = undefined) {
75
+ super(diagnostics);
76
+ this.tn = tokenizer;
77
+ }
78
+ static parseFile(path, src, getUid = defaultSymbolForge.getUid.bind(defaultSymbolForge), isEntry = false) {
79
+ const internalPath = path; // getInternalPath( path );
80
+ const kind = (isEntry
81
+ ? SourceKind.UserEntry
82
+ : path.startsWith(LIBRARY_PREFIX)
83
+ ? path.indexOf(PATH_DELIMITER, LIBRARY_PREFIX.length) < 0
84
+ ? SourceKind.LibraryEntry
85
+ : SourceKind.Library
86
+ : SourceKind.User);
87
+ const source = new Source(kind, internalPath, getUid(), src);
88
+ return [
89
+ source,
90
+ Parser.parseSource(source)
91
+ ];
92
+ }
93
+ static parseSource(src, diagnostics) {
94
+ return new Parser(new Tokenizer(src), diagnostics).parseSource();
95
+ }
96
+ parseSource() {
97
+ const src = this.tn.source;
98
+ if (src.statements.length > 0)
99
+ return this.diagnostics;
100
+ const tn = this.tn;
101
+ let stmt;
102
+ while (!tn.eof()) {
103
+ stmt = this.parseTopLevelStatement();
104
+ if (stmt)
105
+ src.statements.push(stmt);
106
+ else
107
+ this.skipStatement();
108
+ }
109
+ hoistStatementsInplace(src.statements);
110
+ return this.diagnostics;
111
+ }
112
+ parseTopLevelStatement() {
113
+ const tn = this.tn;
114
+ let flags = CommonFlags.None;
115
+ let startPos = tn.pos;
116
+ // `export` keyword
117
+ // `export default` is NOT supported (`export default` should have never exsisted)
118
+ if (tn.skip(Token.Export)) {
119
+ const exportEnd = tn.pos;
120
+ const stmt = this.parseTopLevelStatement();
121
+ if (!stmt)
122
+ return undefined;
123
+ return new ExportStmt(stmt, tn.range(startPos, exportEnd));
124
+ }
125
+ const initialState = tn.mark();
126
+ let statement = undefined;
127
+ let first = tn.peek();
128
+ if (startPos < 0)
129
+ startPos = tn.nextTokenPos;
130
+ switch (first) {
131
+ case Token.Var:
132
+ case Token.Let:
133
+ case Token.Const: {
134
+ tn.next(); // skip `const` | `let` | `var`
135
+ flags |= first === Token.Const ? CommonFlags.Const : CommonFlags.Let;
136
+ if (tn.skip(Token.Enum)) {
137
+ tn.reset(initialState);
138
+ this.skipStatement();
139
+ return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "const enum");
140
+ }
141
+ statement = this.parseVarStmt(flags, startPos);
142
+ break;
143
+ }
144
+ case Token.Using: {
145
+ statement = this.parseUsingDecl();
146
+ break;
147
+ }
148
+ case Token.Enum: {
149
+ tn.next();
150
+ statement = this.parseEnum(flags, startPos);
151
+ // decorators = undefined;
152
+ break;
153
+ }
154
+ case Token.Function: {
155
+ tn.next();
156
+ statement = this.parseFuncDecl(flags, startPos);
157
+ // decorators = undefined;
158
+ break;
159
+ }
160
+ case Token.Data: {
161
+ // skips `data` keyword
162
+ // positions on (expected) `struct` keyword
163
+ if (tn.next() !== Token.Struct)
164
+ return this.error(DiagnosticCode._0_expected, tn.range(), "struct");
165
+ tn.next(); // skip `struct`
166
+ statement = this.parseStruct(StructDeclAstFlags.onlyDataEncoding, flags, startPos);
167
+ break;
168
+ }
169
+ case Token.Runtime: {
170
+ // skips `runtime` keyword
171
+ // positions on (expected) `struct` keyword
172
+ if (tn.next() !== Token.Struct)
173
+ return this.error(DiagnosticCode._0_expected, tn.range(), "struct");
174
+ tn.next(); // skip `struct`
175
+ statement = this.parseStruct(StructDeclAstFlags.onlySopEncoding, flags, startPos);
176
+ break;
177
+ }
178
+ case Token.Struct: {
179
+ tn.next();
180
+ statement = this.parseStruct(StructDeclAstFlags.none, flags, startPos);
181
+ break;
182
+ }
183
+ case Token.Interface: {
184
+ tn.next();
185
+ statement = this.parseInterface(flags, startPos);
186
+ // decorators = undefined;
187
+ break;
188
+ }
189
+ case Token.Import: {
190
+ tn.next();
191
+ statement = this.parseImport();
192
+ break;
193
+ }
194
+ case Token.Type: { // also identifier // no more
195
+ // let state = tn.mark();
196
+ tn.next();
197
+ // if (tn.peek(IdentifierHandling.Prefer) === Token.Identifier) {
198
+ // tn.discard(state);
199
+ // statement = this.parseTypeDeclaration(flags, startPos);
200
+ // // decorators = undefined;
201
+ // } else {
202
+ // tn.reset(state);
203
+ // statement = this.parseStatement(true);
204
+ // }
205
+ statement = this.parseTypeStmt(flags, startPos);
206
+ break;
207
+ }
208
+ default:
209
+ {
210
+ statement = this.parseStatement({ topLevel: true, isExport: false });
211
+ }
212
+ break;
213
+ }
214
+ tn.skip(Token.Semicolon); // if any
215
+ return statement;
216
+ }
217
+ parseUsingDecl() {
218
+ const tn = this.tn;
219
+ const startPos = tn.tokenPos;
220
+ if (!tn.skip(Token.OpenBrace))
221
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
222
+ const members = new Array();
223
+ while (!tn.skip(Token.CloseBrace)) {
224
+ const thisStartPos = tn.tokenPos;
225
+ if (!tn.skipIdentifier())
226
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
227
+ const identifier = new Identifier(tn.readIdentifier(), tn.range());
228
+ let renamed = undefined;
229
+ if (tn.skip(Token.Colon)) {
230
+ if (!tn.skipIdentifier())
231
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
232
+ renamed = new Identifier(tn.readIdentifier(), tn.range());
233
+ }
234
+ members.push(new UsingStmtDeclaredConstructor(identifier, renamed, tn.range(thisStartPos, tn.pos)));
235
+ if (!tn.skip(Token.Comma)) {
236
+ if (tn.skip(Token.CloseBrace))
237
+ break;
238
+ return this.error(DiagnosticCode._0_expected, tn.range(), "}");
239
+ }
240
+ }
241
+ if (!tn.skip(Token.Equals))
242
+ return this.error(DiagnosticCode._0_expected, tn.range(), "=");
243
+ const structTypeExpr = this.parseTypeExpr();
244
+ if (!structTypeExpr)
245
+ return undefined;
246
+ return new UsingStmt(members, structTypeExpr, tn.range(startPos, tn.pos));
247
+ }
248
+ parseTypeParameters() {
249
+ const tn = this.tn;
250
+ // at '<': TypeParameter (',' TypeParameter)* '>'
251
+ const typeParams = new Array();
252
+ while (!tn.skip(Token.GreaterThan)) {
253
+ if (!tn.skipIdentifier())
254
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
255
+ typeParams.push(new Identifier(tn.readIdentifier(), tn.range()));
256
+ if (tn.skip(Token.Comma))
257
+ continue;
258
+ if (tn.skip(Token.GreaterThan))
259
+ break;
260
+ else
261
+ return this.error(DiagnosticCode._0_expected, tn.range(), ">");
262
+ }
263
+ return typeParams;
264
+ }
265
+ parseTypeArguments() {
266
+ const tn = this.tn;
267
+ // at '<': TypeParameter (',' TypeParameter)* '>'
268
+ const typeArgs = new Array();
269
+ while (!tn.skip(Token.GreaterThan)) {
270
+ const typeArg = this.parseTypeExpr();
271
+ if (!typeArg)
272
+ return undefined;
273
+ typeArgs.push(typeArg);
274
+ if (tn.skip(Token.Comma))
275
+ continue;
276
+ if (tn.skip(Token.GreaterThan))
277
+ break;
278
+ else
279
+ return this.error(DiagnosticCode._0_expected, tn.range(), ">");
280
+ }
281
+ return typeArgs;
282
+ }
283
+ parseExport(startPos) {
284
+ const tn = this.tn;
285
+ startPos = startPos ?? tn.tokenPos;
286
+ // export { ... } from "module";
287
+ if (tn.skip(Token.OpenBrace)) {
288
+ const members = new Array();
289
+ while (!tn.skip(Token.CloseBrace)) {
290
+ const member = this.parseImportDeclaration();
291
+ if (!member)
292
+ return undefined;
293
+ members.push(member);
294
+ if (tn.skip(Token.Comma))
295
+ continue;
296
+ if (tn.skip(Token.CloseBrace))
297
+ break;
298
+ else
299
+ return this.error(DiagnosticCode._0_expected, tn.range(), "}");
300
+ }
301
+ if (!tn.skip(Token.From))
302
+ return this.error(DiagnosticCode._0_expected, tn.range(), "from");
303
+ if (!tn.skip(Token.StringLiteral))
304
+ return this.error(DiagnosticCode.String_literal_expected, tn.range());
305
+ tn.skip(Token.Semicolon); // if any
306
+ return new ExportImportStmt(members, new LitStrExpr(tn.readString(), tn.range()), tn.range(startPos, tn.pos));
307
+ }
308
+ // export * from "module";
309
+ if (!tn.skip(Token.Asterisk))
310
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{ or *");
311
+ if (!tn.skip(Token.From))
312
+ return this.error(DiagnosticCode._0_expected, tn.range(), "from");
313
+ if (!tn.skip(Token.StringLiteral))
314
+ return this.error(DiagnosticCode.String_literal_expected, tn.range());
315
+ tn.skip(Token.Semicolon); // if any
316
+ return new ExportStarStmt(new LitStrExpr(tn.readString(), tn.range()), tn.range(startPos, tn.pos));
317
+ }
318
+ parseTypeStmt(flags = CommonFlags.None, startPos) {
319
+ const tn = this.tn;
320
+ startPos = startPos ?? tn.tokenPos;
321
+ // at 'type': Type
322
+ // (('=' Type ) ';'?) |
323
+ // ('implements' Identifier '{' MethodImpl* '}' ';'?)
324
+ if (!tn.skipIdentifier())
325
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
326
+ const typeName = new Identifier(tn.readIdentifier(), tn.range());
327
+ // if `type Name<...params> = ...` these are parameters
328
+ // if `type Name<...args> implements ...` these are arguments
329
+ // so we parse as arguments
330
+ // and later convert to only identifiers if necessary
331
+ let typeArgs = [];
332
+ if (tn.skip(Token.LessThan)) {
333
+ typeArgs = this.parseTypeArguments();
334
+ if (!Array.isArray(typeArgs) || typeArgs.length <= 0)
335
+ return undefined;
336
+ // flags |= CommonFlags.Generic;
337
+ }
338
+ // type NewType = OriginalType
339
+ // if not `=` then it must be `implements` later
340
+ if (tn.skip(Token.Equals)) {
341
+ const nParams = typeArgs.length;
342
+ const typeParams = new Array(nParams);
343
+ for (let i = 0; i < nParams; ++i) {
344
+ const arg = typeArgs[i];
345
+ if (!(arg instanceof AstNamedTypeExpr))
346
+ return this.error(DiagnosticCode.Type_parameters_must_be_identifiers, arg.range);
347
+ typeParams[i] = arg.name;
348
+ }
349
+ const aliasedType = this.parseTypeExpr();
350
+ if (!aliasedType)
351
+ return undefined;
352
+ tn.skip(Token.Semicolon); // if any
353
+ return new TypeAliasDecl(typeName, typeParams, aliasedType, tn.range(startPos, tn.pos));
354
+ }
355
+ if (!tn.skip(Token.Implements))
356
+ return this.error(DiagnosticCode._0_expected, tn.range(), "implements");
357
+ const typeId = new AstNamedTypeExpr(typeName, typeArgs, tn.range(startPos, tn.pos));
358
+ let interfaceType = undefined;
359
+ if (!tn.skip(Token.OpenBrace)) {
360
+ const state = tn.mark();
361
+ interfaceType = this.parseTypeExpr();
362
+ if (!interfaceType ||
363
+ !tn.skip(Token.OpenBrace)) {
364
+ const otherState = tn.mark();
365
+ tn.reset(state);
366
+ this.error(DiagnosticCode._0_expected, tn.range(), "{");
367
+ tn.reset(otherState);
368
+ return undefined;
369
+ }
370
+ }
371
+ const members = new Array();
372
+ while (!tn.skip(Token.CloseBrace)) {
373
+ const startPos = tn.tokenPos;
374
+ const namedSig = this.parseNamedFuncSig(flags, tn.tokenPos);
375
+ if (!namedSig)
376
+ return undefined;
377
+ const [methodName, typeParams, sig] = namedSig;
378
+ if (!tn.skip(Token.OpenBrace))
379
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
380
+ const body = this.parseBlockStmt();
381
+ if (!body)
382
+ return undefined;
383
+ members.push(new InterfaceMethodImpl(methodName, typeParams ?? [], sig, body, tn.range(startPos, tn.pos)));
384
+ }
385
+ tn.skip(Token.Semicolon); // if any
386
+ return new TypeImplementsStmt(typeId, interfaceType, members, tn.range());
387
+ }
388
+ parseImport() {
389
+ const tn = this.tn;
390
+ // at 'import':
391
+ // ('{' (ImportMember (',' ImportMember)* '}') | ('*' 'as' Identifier)?
392
+ // 'from' StringLiteral ';'?
393
+ const startPos = tn.tokenPos;
394
+ if (tn.skip(Token.Asterisk)) // import * as module from "module";
395
+ {
396
+ if (!tn.skip(Token.As))
397
+ return this.error(DiagnosticCode._0_expected, tn.range(), "as");
398
+ if (!tn.skipIdentifier())
399
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
400
+ const identifier = new Identifier(tn.readIdentifier(), tn.range());
401
+ if (!tn.skip(Token.From))
402
+ return this.error(DiagnosticCode._0_expected, tn.range(), "from");
403
+ if (!tn.skip(Token.StringLiteral))
404
+ return this.error(DiagnosticCode.String_literal_expected, tn.range());
405
+ const path = new LitStrExpr(tn.readString(), tn.range());
406
+ tn.skip(Token.Semicolon); // if any
407
+ return new ImportStarStmt(identifier, path, tn.range(startPos, tn.pos));
408
+ }
409
+ if (!tn.skip(Token.OpenBrace)) // import { ... } from "module";
410
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
411
+ const members = new Array();
412
+ while (!tn.skip(Token.CloseBrace)) {
413
+ let member = this.parseImportDeclaration();
414
+ if (!member)
415
+ return undefined;
416
+ members.push(member);
417
+ if (!tn.skip(Token.Comma)) {
418
+ if (tn.skip(Token.CloseBrace))
419
+ break;
420
+ return this.error(DiagnosticCode._0_expected, tn.range(), "}");
421
+ }
422
+ }
423
+ if (!tn.skip(Token.From))
424
+ return this.error(DiagnosticCode._0_expected, tn.range(), "from");
425
+ if (!tn.skip(Token.StringLiteral))
426
+ return this.error(DiagnosticCode.String_literal_expected, tn.range());
427
+ const path = new LitStrExpr(tn.readString(), tn.range());
428
+ tn.skip(Token.Semicolon); // if any
429
+ return new ImportStmt(members, path, tn.range(startPos, tn.pos));
430
+ }
431
+ parseImportDeclaration() {
432
+ const tn = this.tn;
433
+ // before: Identifier ('as' Identifier)?
434
+ if (!tn.skipIdentifier(IdentifierHandling.Always))
435
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
436
+ let identifier = new Identifier(tn.readIdentifier(), tn.range());
437
+ let asIdentifier = undefined;
438
+ if (tn.skip(Token.As)) {
439
+ if (!tn.skipIdentifier())
440
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
441
+ asIdentifier = new Identifier(tn.readIdentifier(), tn.range());
442
+ }
443
+ return new ImportDecl(identifier, asIdentifier, asIdentifier ? SourceRange.join(identifier.range, asIdentifier.range) :
444
+ identifier.range);
445
+ }
446
+ parseInterface(flags, startPos) {
447
+ const tn = this.tn;
448
+ // at 'interface': Identifier
449
+ // ('<' TypeParameters '>')?
450
+ // '{' (FuncDecl | VarDecl)* '}' ';'?
451
+ startPos = startPos ?? tn.tokenPos;
452
+ if (!tn.skipIdentifier())
453
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
454
+ const name = new Identifier(tn.readIdentifier(), tn.range());
455
+ let typeParams = [];
456
+ if (tn.skip(Token.LessThan)) {
457
+ typeParams = this.parseTypeParameters();
458
+ if (!Array.isArray(typeParams)
459
+ || typeParams.length <= 0)
460
+ return undefined; // we had "<" so we expect
461
+ }
462
+ if (!tn.skip(Token.OpenBrace))
463
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
464
+ const members = new Array();
465
+ while (!tn.skip(Token.CloseBrace)) {
466
+ const namedSig = this.parseNamedFuncSig(flags, tn.tokenPos);
467
+ if (!namedSig)
468
+ return undefined;
469
+ const [methodName, typeParams, sig] = namedSig;
470
+ let body = undefined;
471
+ if (tn.skip(Token.OpenBrace)) {
472
+ body = this.parseBlockStmt();
473
+ if (!body)
474
+ return undefined;
475
+ }
476
+ members.push(new InterfaceDeclMethod(methodName,
477
+ // typeParams ?? [],
478
+ sig, body, tn.range(startPos, tn.pos)));
479
+ }
480
+ tn.skip(Token.Semicolon); // if any
481
+ return new InterfaceDecl(name, typeParams ?? [], members, tn.range(startPos, tn.pos));
482
+ }
483
+ parseStruct(structDeclFlags, flags = CommonFlags.Const, startPos) {
484
+ const tn = this.tn;
485
+ startPos = startPos ?? tn.tokenPos;
486
+ if (!tn.skipIdentifier())
487
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
488
+ const name = new Identifier(tn.readIdentifier(), tn.range());
489
+ let typeParams = [];
490
+ if (tn.skip(Token.LessThan)) {
491
+ typeParams = this.parseTypeParameters();
492
+ if (!Array.isArray(typeParams)
493
+ || typeParams.length <= 0)
494
+ return undefined;
495
+ // flags |= CommonFlags.Generic;
496
+ }
497
+ if (!tn.skip(Token.OpenBrace))
498
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
499
+ if (tn.skip(Token.CloseBrace)) // single constr no fields shortcut
500
+ {
501
+ if (typeParams.length > 0) {
502
+ for (const param of typeParams) {
503
+ this.error(DiagnosticCode.Type_parameter_is_unused, param.range); // recoverable
504
+ }
505
+ }
506
+ const range = tn.range(startPos, tn.pos);
507
+ tn.skip(Token.Semicolon); // if any
508
+ return new StructDecl(name, [], // typeParams
509
+ [
510
+ new StructConstrDecl(new Identifier(name.text, name.range), [], // fields
511
+ range)
512
+ ], structDeclFlags & StructDeclAstFlags.untaggedSingleConstructor, range.clone());
513
+ }
514
+ let constrIdentifier = undefined;
515
+ // in case of single constr shortcut
516
+ const preIdState = tn.mark();
517
+ if (!tn.skipIdentifier())
518
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
519
+ constrIdentifier = new Identifier(tn.readIdentifier(), tn.range());
520
+ // no `{` after identifier means single constr shortcut
521
+ if (!tn.skip(Token.OpenBrace)) {
522
+ // reset before identifier, because this is a field name
523
+ tn.reset(preIdState);
524
+ constrIdentifier = undefined;
525
+ const fields = this.parseStructConstrFields(flags);
526
+ if (!fields)
527
+ return undefined;
528
+ // `parseStructConstrFields` already skips the closing brace
529
+ // if( !tn.skip( Token.CloseBrace ) )
530
+ tn.skip(Token.Semicolon); // if any
531
+ return new StructDecl(name, typeParams, [
532
+ new StructConstrDecl(new Identifier(name.text, name.range), fields, tn.range(startPos, tn.pos))
533
+ ], structDeclFlags & StructDeclAstFlags.untaggedSingleConstructor, tn.range(startPos, tn.pos));
534
+ }
535
+ const constrFields = this.parseStructConstrFields(flags);
536
+ if (!Array.isArray(constrFields))
537
+ return undefined;
538
+ const constrs = [
539
+ new StructConstrDecl(constrIdentifier, constrFields, tn.range(startPos, tn.pos))
540
+ ];
541
+ while (!tn.skip(Token.CloseBrace)) {
542
+ if (!tn.skipIdentifier())
543
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
544
+ constrIdentifier = new Identifier(tn.readIdentifier(), tn.range());
545
+ // no `{` only allowed in single constr shortcut
546
+ // this is not the case
547
+ if (!tn.skip(Token.OpenBrace))
548
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
549
+ const constrFields = this.parseStructConstrFields(flags);
550
+ if (!Array.isArray(constrFields))
551
+ return undefined;
552
+ constrs.push(new StructConstrDecl(constrIdentifier, constrFields, tn.range(startPos, tn.pos)));
553
+ }
554
+ tn.skip(Token.Semicolon); // if any
555
+ return new StructDecl(name, typeParams, constrs, structDeclFlags, tn.range(startPos, tn.pos));
556
+ }
557
+ parseStructConstrFields(flags) {
558
+ const tn = this.tn;
559
+ // at '{'
560
+ const fields = new Array();
561
+ while (!tn.skip(Token.CloseBrace)) {
562
+ const field = this._parseVarDecl(flags);
563
+ if (!field)
564
+ return this.warning(DiagnosticCode._0_expected, tn.range(), "var declaration");
565
+ if (!(field instanceof SimpleVarDecl))
566
+ return this.error(DiagnosticCode.Invalid_field_declaration, field.range);
567
+ if (!field.type)
568
+ return this.error(DiagnosticCode.Type_expected, field.range.atEnd());
569
+ if (field.initExpr)
570
+ return this.error(DiagnosticCode.Initialization_expressions_are_not_allowed_in_a_struct_declaration, SourceRange.join(field.type.range.atEnd(), field.initExpr.range));
571
+ fields.push(field);
572
+ if (tn.skip(Token.Comma) ||
573
+ tn.skip(Token.Semicolon) ||
574
+ tn.isNextTokenOnNewLine())
575
+ continue;
576
+ if (tn.skip(Token.CloseBrace))
577
+ break;
578
+ else
579
+ return this.error(DiagnosticCode._0_expected, tn.range(), "}");
580
+ }
581
+ return fields;
582
+ }
583
+ parseNamedFuncSig(flags = CommonFlags.None, startPos) {
584
+ const tn = this.tn;
585
+ startPos = startPos ?? tn.tokenPos;
586
+ if (!tn.skipIdentifier())
587
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
588
+ const name = new Identifier(tn.readIdentifier(), tn.range());
589
+ let sigStart = -1;
590
+ let typeParams = undefined;
591
+ if (tn.skip(Token.LessThan)) {
592
+ sigStart = tn.tokenPos;
593
+ typeParams = this.parseTypeParameters();
594
+ if (!typeParams || typeParams.length === 0)
595
+ return undefined;
596
+ // flags |= CommonFlags.Generic;
597
+ }
598
+ if (!tn.skip(Token.OpenParen))
599
+ return this.error(DiagnosticCode._0_expected, tn.range(), "(");
600
+ sigStart = sigStart < 0 ? tn.tokenPos : sigStart;
601
+ const params = this.parseParameters();
602
+ if (!params)
603
+ return undefined;
604
+ let returnType = undefined;
605
+ if (tn.skip(Token.Colon)) {
606
+ returnType = this.parseTypeExpr();
607
+ if (!returnType)
608
+ return undefined;
609
+ }
610
+ return [
611
+ name,
612
+ typeParams,
613
+ new AstFuncType(params, returnType, tn.range(sigStart, tn.pos))
614
+ ];
615
+ }
616
+ parseFuncDecl(flags, startPos) {
617
+ const tn = this.tn;
618
+ startPos = startPos ?? tn.tokenPos;
619
+ const namedSig = this.parseNamedFuncSig(flags, startPos);
620
+ if (!namedSig)
621
+ return undefined;
622
+ const [name, typeArgs, sig] = namedSig;
623
+ const nParams = typeArgs?.length ?? 0;
624
+ const typeParams = new Array(nParams);
625
+ for (let i = 0; i < nParams; ++i) {
626
+ const arg = typeArgs[i];
627
+ if (!(arg instanceof AstNamedTypeExpr))
628
+ return this.error(DiagnosticCode.Type_parameters_must_be_identifiers, arg.range);
629
+ typeParams[i] = arg.name;
630
+ }
631
+ if (!tn.skip(Token.OpenBrace))
632
+ return this.error(DiagnosticCode.Function_implementation_is_missing_or_not_immediately_following_the_declaration, tn.range());
633
+ const body = this.parseBlockStmt();
634
+ if (!body)
635
+ return undefined;
636
+ const endPos = tn.pos;
637
+ tn.skip(Token.Semicolon); // if any
638
+ const expr = new FuncExpr(name, flags, typeParams ?? [], sig, body, ArrowKind.None, tn.range(startPos, endPos));
639
+ return new FuncDecl(expr);
640
+ }
641
+ parseEnum(flags, startPos) {
642
+ const tn = this.tn;
643
+ // at 'enum': Identifier '{' (EnumValueDecl (',' EnumValueDecl )*)? '}' ';'?
644
+ if (tn.next() !== Token.Identifier)
645
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
646
+ const identifier = new Identifier(tn.readIdentifier(), tn.range());
647
+ if (!tn.skip(Token.OpenBrace))
648
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
649
+ const members = new Array();
650
+ while (!tn.skip(Token.CloseBrace)) {
651
+ const member = this.parseEnumValue(CommonFlags.None);
652
+ if (!member)
653
+ return undefined;
654
+ members.push(member);
655
+ if (tn.skip(Token.Comma))
656
+ continue;
657
+ if (tn.skip(Token.CloseBrace))
658
+ break;
659
+ else
660
+ return this.error(DiagnosticCode._0_expected, tn.range(), "}");
661
+ }
662
+ tn.skip(Token.Semicolon); // if any
663
+ return new EnumDecl(identifier, members, tn.range(startPos, tn.pos));
664
+ }
665
+ parseEnumValue(parentFlags) {
666
+ const tn = this.tn;
667
+ // before: Identifier ('=' Expression)?
668
+ if (!tn.skipIdentifier())
669
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
670
+ const identifier = new Identifier(tn.readIdentifier(), tn.range());
671
+ let value = undefined;
672
+ if (tn.skip(Token.Equals)) {
673
+ value = this.parseExpr(Precedence.Comma + 1);
674
+ if (!value)
675
+ return undefined;
676
+ }
677
+ return new EnumValueDecl(identifier, parentFlags, value, SourceRange.join(identifier.range, tn.range()));
678
+ }
679
+ parseVarStmt(flags, startPos, opts = defaultParseVarOpts) {
680
+ const tn = this.tn;
681
+ // at (`const` | `let` | `var`)
682
+ // varDecl [, ...varDecl] `;`?
683
+ opts = {
684
+ ...defaultParseVarOpts,
685
+ ...opts
686
+ };
687
+ const isFor = opts.isFor;
688
+ const decls = [];
689
+ let decl = undefined;
690
+ do {
691
+ decl = this._parseVarDecl(flags);
692
+ if (!decl)
693
+ return undefined;
694
+ if (!isFor && !decl.initExpr) {
695
+ this.error(DiagnosticCode.Variable_declaration_must_have_an_initializer, decl.range);
696
+ return undefined;
697
+ }
698
+ decls.push(decl);
699
+ } while (tn.skip(Token.Comma)); // keep pushing while there are commas
700
+ if (!isNonEmpty(decls)) {
701
+ this.error(DiagnosticCode.A_variable_statement_must_have_at_least_one_variable_declaration, tn.range(startPos, tn.pos));
702
+ return undefined;
703
+ }
704
+ const result = new VarStmt(decls, tn.range(startPos, tn.pos));
705
+ // if there is no final semicolon (and we are not in a for loop)
706
+ if (!isFor && !tn.skip(Token.Semicolon)) {
707
+ // check for automatic semicolon insertion
708
+ this.emitErrorIfInvalidAutoSemicolon();
709
+ }
710
+ return result;
711
+ }
712
+ // parseVarDecl(
713
+ // flags: CommonFlags = CommonFlags.None,
714
+ // opts: Partial<ParseVarOpts> = defaultParseVarOpts
715
+ // ): VarDecl | undefined
716
+ // {
717
+ // const tn = this.tn;
718
+ // // const startRange = tn.range();
719
+ //
720
+ // opts = {
721
+ // ...defaultParseVarOpts,
722
+ // ...opts
723
+ // };
724
+ //
725
+ // const varDecl = this._parseVarDecl();
726
+ // if( !varDecl ) return undefined;
727
+ //
728
+ // if( !varDecl.initExpr && !opts.isParam )
729
+ // {
730
+ // }
731
+ // }
732
+ /**
733
+ * the parsed variable declaration may or may not have a type and/or an initializer
734
+ *
735
+ * this is so that `_parseVarDecl` can be used both when parsing a variable statement
736
+ * or (recursively) when parsing a deconstructed variable declaration
737
+ *
738
+ * in the case of the variable statement, and a destructured variable,
739
+ * an intializer is REQUIRED, with an optional explicit type
740
+ *
741
+ * on the contrary in case we are parsing a field of a deconstructed variable declaration
742
+ * an initializer MUST NOT be present NOR a type
743
+ */
744
+ _parseVarDecl(flags) {
745
+ const tn = this.tn;
746
+ // ConstrName{ ... } || renamed
747
+ const renamedField = this.parseIdentifier();
748
+ if (tn.skip(Token.OpenBrace)) // ConstrName{ ... } || { ... }
749
+ {
750
+ const unnamed = this.parseSingleDeconstructVarDecl(flags);
751
+ if (!unnamed)
752
+ return undefined;
753
+ return renamedField instanceof Identifier ?
754
+ // ConstrName{ ... }
755
+ NamedDeconstructVarDecl.fromSingleDeconstruct(renamedField, unnamed) :
756
+ // { ... }
757
+ unnamed;
758
+ }
759
+ else if (tn.skip(Token.OpenBracket)) // [ ... ]
760
+ {
761
+ if (renamedField instanceof Identifier) // renamed[ ... ] (what?)
762
+ {
763
+ this.error(DiagnosticCode.Unexpected_token, tn.range());
764
+ return undefined;
765
+ }
766
+ return this.parseArrayLikeDeconstr(flags);
767
+ }
768
+ else if (renamedField instanceof Identifier) // renamed
769
+ {
770
+ const [explicitType, initializer] = this._parseTypeAndInitializer();
771
+ let range = renamedField.range;
772
+ if (initializer)
773
+ range = SourceRange.join(range, initializer.range);
774
+ else if (explicitType)
775
+ range = SourceRange.join(range, explicitType.range);
776
+ return new SimpleVarDecl(renamedField, explicitType, initializer, flags, range);
777
+ }
778
+ else
779
+ return undefined;
780
+ }
781
+ parseSingleDeconstructVarDecl(flags) {
782
+ const tn = this.tn;
783
+ const initRange = tn.range();
784
+ let elements = new Map();
785
+ let fieldName = undefined;
786
+ let element = undefined;
787
+ let rest = undefined;
788
+ let isRest = false;
789
+ let startRange = undefined;
790
+ let explicitType = undefined;
791
+ let initializer = undefined;
792
+ while (!tn.skip(Token.CloseBrace)) {
793
+ if (isRest) {
794
+ this.error(DiagnosticCode.A_rest_element_must_be_last_in_an_object_destructuring_pattern, tn.range());
795
+ return undefined;
796
+ }
797
+ startRange = tn.range();
798
+ if (tn.skip(Token.Dot_Dot_Dot))
799
+ isRest = true;
800
+ // field
801
+ fieldName = this.parseIdentifier(startRange);
802
+ if (isRest) {
803
+ rest = fieldName;
804
+ tn.skip(Token.Comma); // skip comma if present
805
+ continue; // checks for close brace and exits while loop
806
+ }
807
+ if (!fieldName) { // (eg: { , ... }) ??
808
+ this.error(DiagnosticCode.Identifier_expected, tn.range());
809
+ return undefined;
810
+ }
811
+ if (!tn.skip(Token.Colon)) // only field, with no colon (eg: { field, ... })
812
+ {
813
+ element = SimpleVarDecl.onlyIdentifier(fieldName, flags);
814
+ elements.set(fieldName, element);
815
+ if (tn.skip(Token.CloseBrace))
816
+ break; // last field destructured
817
+ if (!tn.skip(Token.Comma)) {
818
+ this.error(DiagnosticCode._0_expected, tn.range(), ",");
819
+ return undefined;
820
+ }
821
+ continue; // early continue to check for close brace or next field
822
+ }
823
+ // else ther is colon (eg: { field: ... })
824
+ element = this._parseVarDecl(flags);
825
+ if (!element) // field: ... what?
826
+ {
827
+ this.error(DiagnosticCode.Unexpected_token, tn.range());
828
+ return undefined;
829
+ }
830
+ if (element.initExpr) {
831
+ this.error(DiagnosticCode.A_field_in_a_deconstructed_declaration_cannot_have_an_initialization, element.range);
832
+ return undefined;
833
+ }
834
+ if (element.type) {
835
+ this.error(DiagnosticCode.A_field_in_a_deconstructed_declaration_cannot_have_an_explicit_type_did_you_mean_to_cast_using_the_as_keyword, element.range);
836
+ return undefined;
837
+ }
838
+ if (tn.skip(Token.As)) {
839
+ const castType = this.parseTypeExpr();
840
+ if (!castType) {
841
+ this.error(DiagnosticCode.Type_expected, tn.range());
842
+ return undefined;
843
+ }
844
+ element.type = castType;
845
+ /// @ts-ignore Cannot assign to 'range' because it is a read-only property.ts(2540)
846
+ element.range =
847
+ SourceRange.join(element.range, castType.range);
848
+ }
849
+ elements.set(fieldName, element);
850
+ tn.skip(Token.Comma); // skip comma if present
851
+ } // while( !tn.skip( Token.CloseBrace ) )
852
+ [explicitType, initializer] = this._parseTypeAndInitializer();
853
+ return new SingleDeconstructVarDecl(elements, rest, explicitType, initializer, flags, SourceRange.join(initRange, tn.range()));
854
+ }
855
+ parseArrayLikeDeconstr(flags) {
856
+ const tn = this.tn;
857
+ // at '[': ( VarDecl ','? )* ']' ( ':' AstTypeExpr )? ( '=' PebbleExpr )?
858
+ const startPos = tn.pos;
859
+ const elems = new Array();
860
+ let rest = undefined;
861
+ while (!tn.skip(Token.CloseBracket)) {
862
+ if (tn.skip(Token.Dot_Dot_Dot)) {
863
+ if (rest)
864
+ return this.error(DiagnosticCode.A_rest_element_must_be_last_in_an_array_destructuring_pattern, tn.range());
865
+ rest = this.parseIdentifier();
866
+ if (!rest)
867
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
868
+ tn.skip(Token.Comma); // skip comma if present
869
+ continue; // checks for close bracket
870
+ }
871
+ if (rest)
872
+ return this.error(DiagnosticCode.A_rest_element_must_be_last_in_an_array_destructuring_pattern, rest.range);
873
+ const elem = this._parseVarDecl(flags);
874
+ if (!elem)
875
+ return undefined;
876
+ if (elem.initExpr || elem.type)
877
+ return this.error(DiagnosticCode.Deconstructed_elements_may_not_have_initializers_or_explicit_types, elem.initExpr ? elem.initExpr.range : elem.type.range);
878
+ if (tn.skip(Token.As)) {
879
+ const castType = this.parseTypeExpr();
880
+ if (!castType) {
881
+ this.error(DiagnosticCode.Type_expected, tn.range());
882
+ return undefined;
883
+ }
884
+ elem.type = castType;
885
+ /// @ts-ignore Cannot assign to 'range' because it is a read-only property.ts(2540)
886
+ elem.range =
887
+ SourceRange.join(elem.range, castType.range);
888
+ }
889
+ elems.push(elem);
890
+ if (tn.skip(Token.Comma))
891
+ continue;
892
+ if (tn.skip(Token.CloseBracket))
893
+ break;
894
+ else {
895
+ this.error(DiagnosticCode._0_expected, tn.range(), "]");
896
+ return undefined;
897
+ }
898
+ }
899
+ const [explicitType, initializer] = this._parseTypeAndInitializer();
900
+ let range = tn.range(startPos, tn.pos);
901
+ if (initializer)
902
+ range = SourceRange.join(range, initializer.range);
903
+ else if (explicitType)
904
+ range = SourceRange.join(range, explicitType.range);
905
+ return new ArrayLikeDeconstr(elems, rest, explicitType, initializer, flags, range);
906
+ }
907
+ parseIdentifier(startRange) {
908
+ const tn = this.tn;
909
+ startRange = startRange ?? tn.range();
910
+ if (tn.skipIdentifier()) {
911
+ return new Identifier(tn.readIdentifier(), SourceRange.join(startRange, tn.range()));
912
+ }
913
+ return undefined;
914
+ }
915
+ /**
916
+ * parses `(: AstTypeExpr)? (= PebbleExpr)?` for parameters and variable declarations
917
+ */
918
+ _parseTypeAndInitializer(startRange = this.tn.range(), isRest = false) {
919
+ const tn = this.tn;
920
+ let type = undefined;
921
+ if (tn.skip(Token.Colon))
922
+ type = this.parseTypeExpr();
923
+ if (!tn.skip(Token.Equals))
924
+ return [type, undefined];
925
+ if (isRest) {
926
+ this.error(DiagnosticCode.A_rest_parameter_cannot_have_an_initializer, SourceRange.join(startRange, tn.range()));
927
+ }
928
+ const init = this.parseExpr(Precedence.Comma + 1);
929
+ return [type, init];
930
+ }
931
+ parseTypeExpr(suppressErrors = false) {
932
+ const tn = this.tn;
933
+ const canError = !suppressErrors;
934
+ const token = tn.next();
935
+ let startPos = tn.tokenPos;
936
+ const currRange = tn.range(startPos, tn.pos);
937
+ switch (token) {
938
+ case Token.Void: return new AstVoidType(currRange);
939
+ // case Token.True:
940
+ // case Token.False:
941
+ case Token.Boolean: return new AstBooleanType(currRange);
942
+ case Token.Int: return new AstIntType(currRange);
943
+ // case Token.Number: return new AstIntType( currRange )
944
+ case Token.Bytes: return new AstBytesType(currRange);
945
+ case Token.Optional: {
946
+ if (!tn.skip(Token.LessThan)) {
947
+ canError && this.error(DiagnosticCode._0_expected, currRange, "Type argument for Optional");
948
+ return undefined;
949
+ }
950
+ const tyArg = this.parseTypeExpr();
951
+ if (!tyArg)
952
+ return undefined;
953
+ if (!tn.skip(Token.GreaterThan)) {
954
+ canError && this.error(DiagnosticCode._0_expected, tn.range(tn.pos), ">");
955
+ return undefined;
956
+ }
957
+ return new AstNativeOptionalType(tyArg, tn.range(startPos, tn.pos));
958
+ }
959
+ case Token.List: {
960
+ if (!tn.skip(Token.LessThan)) {
961
+ canError && this.error(DiagnosticCode._0_expected, currRange, "Type argument for Optional");
962
+ return undefined;
963
+ }
964
+ const tyArg = this.parseTypeExpr();
965
+ if (!tyArg)
966
+ return undefined;
967
+ if (!tn.skip(Token.GreaterThan)) {
968
+ canError && this.error(DiagnosticCode._0_expected, tn.range(tn.pos), ">");
969
+ return undefined;
970
+ }
971
+ new AstListType(tyArg, tn.range(startPos, tn.pos));
972
+ }
973
+ case Token.LinearMap: {
974
+ if (!tn.skip(Token.LessThan)) {
975
+ canError && this.error(DiagnosticCode._0_expected, currRange, "Type argument for Optional");
976
+ return undefined;
977
+ }
978
+ const keyTy = this.parseTypeExpr();
979
+ if (!keyTy)
980
+ return undefined;
981
+ if (!tn.skip(Token.Comma)) {
982
+ canError && this.error(DiagnosticCode._0_expected, currRange, ",");
983
+ return undefined;
984
+ }
985
+ const valTy = this.parseTypeExpr();
986
+ if (!valTy)
987
+ return undefined;
988
+ if (!tn.skip(Token.GreaterThan)) {
989
+ canError && this.error(DiagnosticCode._0_expected, tn.range(tn.pos), ">");
990
+ return undefined;
991
+ }
992
+ new AstLinearMapType(keyTy, valTy, tn.range(startPos, tn.pos));
993
+ }
994
+ case Token.Identifier: {
995
+ const name = new Identifier(tn.readIdentifier(), tn.range());
996
+ const params = new Array();
997
+ if (tn.skip(Token.LessThan)) {
998
+ do {
999
+ const ty = this.parseTypeExpr();
1000
+ if (!ty)
1001
+ return undefined;
1002
+ params.push(ty);
1003
+ } while (tn.skip(Token.Comma));
1004
+ if (!tn.skip(Token.GreaterThan)) {
1005
+ canError && this.error(DiagnosticCode._0_expected, tn.range(), ">");
1006
+ return undefined;
1007
+ }
1008
+ }
1009
+ return new AstNamedTypeExpr(name, params, tn.range(startPos, tn.pos));
1010
+ }
1011
+ default: {
1012
+ canError && this.error(DiagnosticCode.Type_expected, tn.range());
1013
+ return undefined;
1014
+ }
1015
+ }
1016
+ }
1017
+ parseParenthesizedExpr(startPos) {
1018
+ const tn = this.tn;
1019
+ startPos = tn.range(startPos).start;
1020
+ const inner = this.parseExpr();
1021
+ if (!inner)
1022
+ return undefined;
1023
+ if (!tn.skip(Token.CloseParen)) {
1024
+ this.error(DiagnosticCode._0_expected, tn.range(), ")");
1025
+ return undefined;
1026
+ }
1027
+ return new ParentesizedExpr(inner, tn.range(startPos, tn.pos));
1028
+ }
1029
+ parseExpr(precedence = Precedence.Comma) {
1030
+ const tn = this.tn;
1031
+ let expr = this.parseExprStart();
1032
+ if (!expr)
1033
+ return undefined;
1034
+ const startPos = expr.range.start;
1035
+ if (tn.skip(Token.HexBytesLiteral)) {
1036
+ const hexBytes = tn.readHexBytes();
1037
+ if (!hexBytes)
1038
+ return undefined;
1039
+ return new LitHexBytesExpr(hexBytes, tn.range(startPos, tn.pos));
1040
+ }
1041
+ // precedence climbing
1042
+ // see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
1043
+ let nextPrecedence;
1044
+ while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
1045
+ const token = tn.next();
1046
+ switch (token) {
1047
+ case Token.As: {
1048
+ if (tn.skip(Token.Const))
1049
+ return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "as const");
1050
+ const toType = this.parseTypeExpr();
1051
+ if (!toType)
1052
+ return undefined;
1053
+ expr = new TypeConversionExpr(expr, toType, tn.range(startPos, tn.pos));
1054
+ break;
1055
+ }
1056
+ case Token.Exclamation: {
1057
+ expr = new NonNullExpr(expr, tn.range(startPos, tn.pos));
1058
+ expr = this.tryParseCallExprOrReturnSame(expr);
1059
+ break;
1060
+ }
1061
+ /*
1062
+ case Token.Is: {
1063
+ // TODO:
1064
+ // should optionally check for destructuring
1065
+ if(!(tn.skipIdentifier()))
1066
+ {
1067
+ this.error(
1068
+ DiagnosticCode.Identifier_expected,
1069
+ tn.range()
1070
+ );
1071
+ return undefined
1072
+ }
1073
+ const ofType = new Identifier( tn.readIdentifier(), tn.range() );
1074
+ tn.skip( Token.Semicolon); // if any
1075
+ expr = new IsExpr(
1076
+ expr,
1077
+ ofType,
1078
+ tn.range( startPos, tn.pos )
1079
+ );
1080
+ break;
1081
+ }
1082
+ //*/
1083
+ case Token.OpenBracket: { // [ // accessing list element
1084
+ const idxExpr = this.parseExpr();
1085
+ if (!idxExpr)
1086
+ return undefined;
1087
+ if (!tn.skip(Token.CloseBracket))
1088
+ return this.error(DiagnosticCode._0_expected, tn.range(), "]");
1089
+ expr = new ElemAccessExpr(expr, idxExpr, tn.range(startPos, tn.pos));
1090
+ break;
1091
+ }
1092
+ case Token.Plus_Plus:
1093
+ case Token.Minus_Minus: {
1094
+ throw new Error("increments and decrements are assingment statements, not expressions");
1095
+ /*
1096
+ if(!( expr instanceof Identifier ))
1097
+ return this.error(
1098
+ DiagnosticCode.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable,
1099
+ expr.range
1100
+ );
1101
+
1102
+ expr = makeUnaryPostfixExpr(
1103
+ token,
1104
+ expr,
1105
+ tn.range( startPos, tn.pos )
1106
+ );
1107
+ */
1108
+ break;
1109
+ }
1110
+ case Token.Question: {
1111
+ const ifTrue = this.parseExpr();
1112
+ if (!ifTrue)
1113
+ return undefined;
1114
+ if (!tn.skip(Token.Colon))
1115
+ return this.error(DiagnosticCode._0_expected, tn.range(), ":");
1116
+ const ifFalse = this.parseExpr(precedence > Precedence.Comma ? Precedence.Comma + 1 : Precedence.Comma);
1117
+ if (!ifFalse)
1118
+ return undefined;
1119
+ expr = new TernaryExpr(expr, ifTrue, ifFalse, tn.range(startPos, tn.pos));
1120
+ break;
1121
+ }
1122
+ // case Token.Comma: { // comma operator
1123
+ // const commaExprs = [ expr ];
1124
+ // do {
1125
+ // expr = this.parseExpr( Precedence.Comma + 1 )!;
1126
+ // if( !expr ) return undefined;
1127
+ // commaExprs.push( expr );
1128
+ // } while( tn.skip( Token.Comma ) );
1129
+ // expr = new CommaExpr(
1130
+ // commaExprs,
1131
+ // tn.range( startPos, tn.pos )
1132
+ // );
1133
+ // break;
1134
+ // }
1135
+ case Token.Question_Dot:
1136
+ case Token.Exclamation_Dot:
1137
+ case Token.Dot: { // accessing property
1138
+ let prop = undefined;
1139
+ if (tn.skipIdentifier(IdentifierHandling.Always)) {
1140
+ prop = new Identifier(tn.readIdentifier(), tn.range());
1141
+ expr = makePropAccessExpr(token, expr, prop, tn.range(startPos, tn.pos));
1142
+ expr = this.tryParseCallExprOrReturnSame(expr);
1143
+ break;
1144
+ }
1145
+ const state = tn.mark();
1146
+ prop = this.parseExpr(Precedence.Comma + 1);
1147
+ if (prop instanceof CallExpr) {
1148
+ expr = this.joinPropertyCall(startPos, expr, prop);
1149
+ if (!expr)
1150
+ return undefined;
1151
+ break;
1152
+ }
1153
+ else {
1154
+ let errRange;
1155
+ if (prop)
1156
+ errRange = prop.range;
1157
+ else {
1158
+ tn.reset(state);
1159
+ errRange = tn.range();
1160
+ }
1161
+ return this.error(DiagnosticCode.Identifier_expected, errRange);
1162
+ }
1163
+ break;
1164
+ }
1165
+ case Token.Equals:
1166
+ case Token.Plus_Equals:
1167
+ case Token.Minus_Equals:
1168
+ case Token.Asterisk_Asterisk_Equals:
1169
+ case Token.Asterisk_Equals:
1170
+ case Token.Slash_Equals:
1171
+ case Token.Percent_Equals:
1172
+ case Token.LessThan_LessThan_Equals:
1173
+ case Token.GreaterThan_GreaterThan_Equals:
1174
+ case Token.GreaterThan_GreaterThan_GreaterThan_Equals:
1175
+ case Token.Ampersand_Equals:
1176
+ case Token.Caret_Equals:
1177
+ case Token.Ampersand_Ampersand_Equals:
1178
+ case Token.Bar_Bar_Equals:
1179
+ case Token.Question_Question_Equals:
1180
+ case Token.Bar_Equals: {
1181
+ return this.error(DiagnosticCode.Assignments_are_statements_not_expressions, tn.range());
1182
+ }
1183
+ // BinaryExpression (right associative)
1184
+ case Token.Asterisk_Asterisk: {
1185
+ const next = this.parseExpr(nextPrecedence);
1186
+ if (!next)
1187
+ return undefined;
1188
+ expr = makeBinaryExpr(token, expr, next, tn.range(startPos, tn.pos));
1189
+ break;
1190
+ }
1191
+ // BinaryExpression
1192
+ case Token.LessThan:
1193
+ case Token.GreaterThan:
1194
+ case Token.LessThan_Equals:
1195
+ case Token.GreaterThan_Equals:
1196
+ case Token.Equals_Equals:
1197
+ case Token.Equals_Equals_Equals:
1198
+ case Token.Exclamation_Equals_Equals:
1199
+ case Token.Exclamation_Equals:
1200
+ case Token.Plus:
1201
+ case Token.Minus:
1202
+ case Token.Asterisk:
1203
+ case Token.Slash:
1204
+ case Token.Percent:
1205
+ case Token.LessThan_LessThan:
1206
+ case Token.GreaterThan_GreaterThan:
1207
+ case Token.GreaterThan_GreaterThan_GreaterThan:
1208
+ case Token.Ampersand:
1209
+ case Token.Bar:
1210
+ case Token.Caret:
1211
+ case Token.Ampersand_Ampersand:
1212
+ case Token.Question_Question:
1213
+ case Token.Bar_Bar:
1214
+ // case Token.In:
1215
+ {
1216
+ const next = this.parseExpr(nextPrecedence + 1);
1217
+ if (!next)
1218
+ return undefined;
1219
+ expr = makeBinaryExpr(token, expr, next, tn.range(startPos, tn.pos));
1220
+ break;
1221
+ }
1222
+ default: {
1223
+ return this.error(DiagnosticCode.Expression_expected, tn.range());
1224
+ }
1225
+ }
1226
+ }
1227
+ return expr;
1228
+ }
1229
+ parseExprStart() {
1230
+ const tn = this.tn;
1231
+ const token = tn.next(IdentifierHandling.Prefer);
1232
+ const startPos = tn.tokenPos;
1233
+ switch (token) {
1234
+ // TODO: SpreadPebbleExpr, YieldPebbleExpr
1235
+ // case Token.Yield:
1236
+ case Token.Dot_Dot_Dot:
1237
+ {
1238
+ this.error(DiagnosticCode.Not_implemented_0, tn.range(), "SpreadPebbleExpr, YieldPebbleExpr");
1239
+ return undefined;
1240
+ }
1241
+ // UnaryPrefixPebbleExpr
1242
+ case Token.Exclamation:
1243
+ case Token.Tilde:
1244
+ case Token.Plus:
1245
+ case Token.Minus:
1246
+ // case Token.TypeOf:
1247
+ // case Token.Delete:
1248
+ {
1249
+ let operand = this.parseExpr(Precedence.UnaryPrefix);
1250
+ if (!operand)
1251
+ return undefined;
1252
+ return makeUnaryPrefixExpr(token, operand, tn.range(startPos, tn.pos));
1253
+ }
1254
+ case Token.Plus_Plus:
1255
+ case Token.Minus_Minus: {
1256
+ let operand = this.parseExpr(Precedence.UnaryPrefix);
1257
+ if (!operand)
1258
+ return undefined;
1259
+ if (!(operand instanceof Identifier
1260
+ // operand instanceof ElementAccessExpr ||
1261
+ // operand instanceof PropertyAccessExpr
1262
+ )) {
1263
+ this.error(DiagnosticCode.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable, operand.range);
1264
+ }
1265
+ return makeUnaryPrefixExpr(token, operand, tn.range(startPos, tn.pos));
1266
+ }
1267
+ // Special Identifier
1268
+ case Token.Void: return new LitVoidExpr(tn.range());
1269
+ case Token.Undefined: return new LitUndefExpr(tn.range());
1270
+ case Token.True: return new LitTrueExpr(tn.range());
1271
+ case Token.False: return new LitFalseExpr(tn.range());
1272
+ case Token.This: return new LitThisExpr(tn.range());
1273
+ // ParenthesizedPebbleExpr or FunctionPebbleExpr
1274
+ case Token.OpenParen: {
1275
+ // determine whether this is a function expression
1276
+ // close paren immediately follows open (`()`)
1277
+ // must be a function expression
1278
+ // (fast route)
1279
+ if (tn.skip(Token.CloseParen)) {
1280
+ return this.parseCommonFuncExpr(Identifier.anonymous(tn.range(startPos)), [], ArrowKind.Parenthesized);
1281
+ }
1282
+ const isFunc = this.isArrowFuncOrParenExprLookahead();
1283
+ if (isFunc)
1284
+ return this.parseFunctionExpr();
1285
+ else {
1286
+ const inner = this.parseParenthesizedExpr(startPos);
1287
+ if (!inner)
1288
+ return undefined;
1289
+ return this.tryParseCallExprOrReturnSame(inner);
1290
+ }
1291
+ }
1292
+ // ArrayLiteralPebbleExpr
1293
+ case Token.OpenBracket: {
1294
+ const elementPebbleExprs = new Array();
1295
+ while (!tn.skip(Token.CloseBracket)) {
1296
+ let expr;
1297
+ if (tn.peek() === Token.Comma) {
1298
+ this.error(DiagnosticCode.Expression_expected, tn.range());
1299
+ return undefined;
1300
+ }
1301
+ else {
1302
+ expr = this.parseExpr(Precedence.Comma + 1);
1303
+ if (!expr)
1304
+ return undefined;
1305
+ }
1306
+ elementPebbleExprs.push(expr);
1307
+ if (tn.skip(Token.Comma))
1308
+ continue;
1309
+ if (tn.skip(Token.CloseBracket)) {
1310
+ break;
1311
+ }
1312
+ else {
1313
+ this.error(DiagnosticCode._0_expected, tn.range(), "]");
1314
+ return undefined;
1315
+ }
1316
+ }
1317
+ return new LitArrExpr(elementPebbleExprs, tn.range(startPos, tn.pos));
1318
+ }
1319
+ // LitObjExpr
1320
+ case Token.OpenBrace: {
1321
+ let startPos = tn.tokenPos;
1322
+ let names = new Array();
1323
+ let values = new Array();
1324
+ let name;
1325
+ while (!tn.skip(Token.CloseBrace)) {
1326
+ if (!tn.skipIdentifier()) {
1327
+ this.error(DiagnosticCode.Identifier_expected, tn.range());
1328
+ return undefined;
1329
+ }
1330
+ name = new Identifier(tn.readIdentifier(), tn.range());
1331
+ names.push(name);
1332
+ if (tn.skip(Token.Colon)) {
1333
+ let value = this.parseExpr(Precedence.Comma + 1);
1334
+ if (!value)
1335
+ return undefined;
1336
+ values.push(value);
1337
+ }
1338
+ else
1339
+ values.push(name);
1340
+ if (tn.skip(Token.Comma))
1341
+ continue;
1342
+ if (tn.skip(Token.CloseBrace))
1343
+ break;
1344
+ else {
1345
+ this.error(DiagnosticCode._0_expected, tn.range(), "}");
1346
+ return undefined;
1347
+ }
1348
+ }
1349
+ return new LitObjExpr(names, values, tn.range(startPos, tn.pos));
1350
+ }
1351
+ case Token.Identifier: {
1352
+ const identifierText = tn.readIdentifier();
1353
+ if (identifierText === "undefined")
1354
+ return new LitUndefExpr(tn.range()); // special
1355
+ const identifier = new Identifier(identifierText, tn.range(startPos, tn.pos));
1356
+ // LitNamedObjExpr
1357
+ // eg: `Identifier{ a: 1, b: 2 }`
1358
+ if (tn.peek() === Token.OpenBrace) {
1359
+ const endPos = tn.pos;
1360
+ const litObjExpr = this.parseExprStart();
1361
+ if (!(litObjExpr instanceof LitObjExpr)) {
1362
+ this.error(DiagnosticCode.Object_literal_expected, tn.range(identifier.range.end, endPos));
1363
+ return undefined;
1364
+ }
1365
+ return new LitNamedObjExpr(identifier, litObjExpr.fieldNames, litObjExpr.values, SourceRange.join(identifier.range, litObjExpr.range));
1366
+ }
1367
+ // param => ...
1368
+ if (tn.peek() === Token.FatArrow
1369
+ // && !tn.isNextTokenOnNewLine() // original impl had this, not sure why
1370
+ ) {
1371
+ return this.parseCommonFuncExpr(Identifier.anonymous(tn.range(startPos)), [
1372
+ SimpleVarDecl.onlyIdentifier(identifier, CommonFlags.None)
1373
+ ], ArrowKind.Single, startPos);
1374
+ }
1375
+ return this.tryParseCallExprOrReturnSame(identifier, true);
1376
+ }
1377
+ case Token.StringLiteral: {
1378
+ return new LitStrExpr(tn.readString(), tn.range(startPos, tn.pos));
1379
+ }
1380
+ case Token.StringTemplateLiteralQuote: {
1381
+ this.error(DiagnosticCode.Not_implemented_0, tn.range(), "string template literals");
1382
+ return undefined;
1383
+ // return this.parseTemplateLiteral();
1384
+ }
1385
+ case Token.IntegerLiteral: {
1386
+ const value = tn.readInteger();
1387
+ tn.checkForIdentifierStartAfterNumericLiteral();
1388
+ return new LitIntExpr(value, tn.range(startPos, tn.pos));
1389
+ }
1390
+ case Token.HexBytesLiteral:
1391
+ {
1392
+ return new LitHexBytesExpr(tn.readHexBytes(), tn.range(startPos, tn.pos));
1393
+ }
1394
+ ;
1395
+ // RegexpLiteralPebbleExpr
1396
+ // note that this also continues on invalid ones so the surrounding AST remains intact
1397
+ case Token.Slash: {
1398
+ this.error(DiagnosticCode.Not_implemented_0, tn.range(), "RegexpLiteralPebbleExpr");
1399
+ return undefined;
1400
+ // let regexpPattern = tn.readRegexpPattern(); // also reports
1401
+ // if (!tn.skip( Token.Slash)) {
1402
+ // this.error(
1403
+ // DiagnosticCode._0_expected,
1404
+ // tn.range(), "/"
1405
+ // );
1406
+ // return undefined;
1407
+ // }
1408
+ // return new RegexpLiteralPebbleExpr(
1409
+ // regexpPattern,
1410
+ // tn.readRegexpFlags(), // also reports
1411
+ // tn.range(startPos, tn.pos)
1412
+ // );
1413
+ }
1414
+ case Token.Function: {
1415
+ const expr = this.parseFunctionExpr();
1416
+ if (!expr)
1417
+ return undefined;
1418
+ return this.tryParseCallExprOrReturnSame(expr);
1419
+ }
1420
+ case Token.Case: {
1421
+ const expr = this.parseCaseExpr();
1422
+ if (!expr)
1423
+ return undefined;
1424
+ }
1425
+ // case Token.Class: return this.parseClassPebbleExpr();
1426
+ // case Token.Struct: return this.parseStructExpr();
1427
+ default: {
1428
+ if (token === Token.EndOfFile) {
1429
+ this.error(DiagnosticCode.Unexpected_end_of_text, tn.range(startPos));
1430
+ }
1431
+ else {
1432
+ this.error(DiagnosticCode.Expression_expected, tn.range());
1433
+ }
1434
+ return undefined;
1435
+ }
1436
+ }
1437
+ }
1438
+ joinPropertyCall(startPos, expr, call) {
1439
+ const tn = this.tn;
1440
+ let callee = call.funcExpr;
1441
+ switch (true) {
1442
+ case callee instanceof Identifier: return call;
1443
+ case callee instanceof CallExpr: {
1444
+ const inner = this.joinPropertyCall(startPos, expr, callee);
1445
+ if (!inner)
1446
+ return undefined;
1447
+ call = new CallExpr(inner, call.genericTypeArgs, call.args, tn.range(startPos, tn.pos));
1448
+ break;
1449
+ }
1450
+ default: {
1451
+ return this.error(DiagnosticCode.Identifier_expected, call.range);
1452
+ }
1453
+ }
1454
+ return call;
1455
+ }
1456
+ parseCaseExpr() {
1457
+ const tn = this.tn;
1458
+ // at 'case': Expression ('is' VarDecl '=>' Expression)+
1459
+ const startPos = tn.tokenPos;
1460
+ const expr = this.parseExpr();
1461
+ if (!expr)
1462
+ return undefined;
1463
+ let noPatternCaseSeen = false;
1464
+ const cases = new Array();
1465
+ while (tn.skip(Token.Is)) {
1466
+ if (noPatternCaseSeen)
1467
+ return this.error(DiagnosticCode.This_case_will_never_be_evaluated_because_all_patterns_will_be_catched_before, tn.range());
1468
+ const startPos = tn.tokenPos;
1469
+ const matcher = this._parseVarDecl(CommonFlags.Const);
1470
+ if (!matcher)
1471
+ return undefined;
1472
+ if (matcher instanceof SimpleVarDecl)
1473
+ noPatternCaseSeen = true;
1474
+ if (matcher.initExpr || matcher.type)
1475
+ return this.error(DiagnosticCode.Patterns_may_not_have_initializers_or_explicit_types, matcher.initExpr ? matcher.initExpr.range : matcher.type.range);
1476
+ if (!tn.skip(Token.FatArrow))
1477
+ return this.error(DiagnosticCode._0_expected, tn.range(), "=>");
1478
+ const body = this.parseExpr(Precedence.CaseExpr);
1479
+ if (!body)
1480
+ return undefined;
1481
+ cases.push(new CaseExprMatcher(matcher, body, tn.range(startPos, tn.pos)));
1482
+ }
1483
+ const finalRange = tn.range(startPos, tn.pos);
1484
+ if (cases.length < 1)
1485
+ return this.error(DiagnosticCode.A_case_expression_must_have_at_least_one_clause, finalRange);
1486
+ return new CaseExpr(expr, cases, undefined, // wildcard case
1487
+ finalRange);
1488
+ }
1489
+ parseFunctionExpr() {
1490
+ const tn = this.tn;
1491
+ const startPos = tn.tokenPos;
1492
+ let name = undefined;
1493
+ let arrowKind = ArrowKind.None;
1494
+ // either at 'function':
1495
+ // Identifier?
1496
+ // '(' Parameters (':' Type)?
1497
+ // PebbleStmt
1498
+ if (tn.token === Token.Function) {
1499
+ if (tn.skipIdentifier()) {
1500
+ name = new Identifier(tn.readIdentifier(), tn.range());
1501
+ }
1502
+ else { // empty name
1503
+ name = Identifier.anonymous(tn.range(tn.pos));
1504
+ }
1505
+ if (!tn.skip(Token.OpenParen)) {
1506
+ this.error(DiagnosticCode._0_expected, tn.range(tn.pos), "(");
1507
+ return undefined;
1508
+ }
1509
+ // or at '(' of arrow function:
1510
+ // Parameters (':' Type)?
1511
+ // PebbleStmt
1512
+ }
1513
+ else {
1514
+ arrowKind = ArrowKind.Parenthesized;
1515
+ if (tn.token !== Token.OpenParen) {
1516
+ this.error(DiagnosticCode._0_expected, tn.range(), "(");
1517
+ return undefined;
1518
+ }
1519
+ name = Identifier.anonymous(tn.range(tn.tokenPos));
1520
+ }
1521
+ // TODO: type parameters? doesn't seem worth it.
1522
+ let signatureStart = tn.pos;
1523
+ let parameters = this.parseParameters();
1524
+ if (!parameters)
1525
+ return undefined;
1526
+ return this.parseCommonFuncExpr(name, parameters, arrowKind, startPos, signatureStart);
1527
+ }
1528
+ parseParameters() {
1529
+ const tn = this.tn;
1530
+ // at Token.OpenParen
1531
+ // (Parameter (',' Parameter)*)?
1532
+ // Token.CloseParen
1533
+ // at '(': (Parameter (',' Parameter)*)? ')'
1534
+ let parameters = new Array();
1535
+ while (!tn.skip(Token.CloseParen)) {
1536
+ let param = this.parseParameter(tn.skip(Token.Let) ? CommonFlags.Let : CommonFlags.Const);
1537
+ if (!param)
1538
+ return undefined;
1539
+ parameters.push(param);
1540
+ if (!tn.skip(Token.Comma)) {
1541
+ // if not comma, then we expect no more params
1542
+ if (tn.skip(Token.CloseParen))
1543
+ break;
1544
+ this.error(DiagnosticCode._0_expected, tn.range(), ")");
1545
+ return undefined;
1546
+ }
1547
+ }
1548
+ return parameters;
1549
+ }
1550
+ parseParameter(flags) {
1551
+ const tn = this.tn;
1552
+ // before: Identifier '?'? (':' Type)? ('=' PebbleExpr)?
1553
+ if (tn.skip(Token.Dot_Dot_Dot)) {
1554
+ this.error(DiagnosticCode.A_parameter_property_cannot_be_declared_using_a_rest_parameter, tn.range());
1555
+ return undefined;
1556
+ }
1557
+ return this._parseVarDecl(flags);
1558
+ }
1559
+ /**
1560
+ * usually called right after a function expression or access property (method) expression
1561
+ *
1562
+ * example: the function expression parsed the identifier of the function,
1563
+ * and now we look for the "call" part of the expression
1564
+ *
1565
+ * ```ts
1566
+ * function foo() {}
1567
+ *
1568
+ * // `foo` is the function expression
1569
+ * // `()` is the call part of the expression
1570
+ * foo() // <- here
1571
+ * ```
1572
+ */
1573
+ tryParseCallExprOrReturnSame(callerExpr, potentiallyGeneric = false) {
1574
+ const tn = this.tn;
1575
+ let typeArguments = undefined;
1576
+ while (tn.skip(Token.OpenParen) ||
1577
+ potentiallyGeneric &&
1578
+ (typeArguments = this.tryParseTypeArgumentsBeforeArguments())) {
1579
+ let args = this.parseArguments();
1580
+ if (!args)
1581
+ break;
1582
+ callerExpr = new CallExpr(// is again callable
1583
+ callerExpr, typeArguments, args, tn.range(callerExpr.range.start, tn.pos));
1584
+ potentiallyGeneric = false;
1585
+ }
1586
+ return callerExpr;
1587
+ }
1588
+ tryParseTypeArgumentsBeforeArguments() {
1589
+ const tn = this.tn;
1590
+ // at '<': Type (',' Type)* '>' '('
1591
+ const state = tn.mark();
1592
+ if (!tn.skip(Token.LessThan))
1593
+ return undefined;
1594
+ const startPos = tn.tokenPos;
1595
+ let typeArguments = [];
1596
+ do {
1597
+ // closing '>'
1598
+ if (tn.peek() === Token.GreaterThan)
1599
+ break;
1600
+ let type = this.parseTypeExpr(/*suppressError*/ true);
1601
+ if (!type) {
1602
+ tn.reset(state);
1603
+ return undefined;
1604
+ }
1605
+ typeArguments.push(type);
1606
+ } while (tn.skip(Token.Comma));
1607
+ // closing '>'
1608
+ if (!tn.skip(Token.GreaterThan)) {
1609
+ tn.reset(state);
1610
+ return undefined;
1611
+ }
1612
+ let end = tn.pos;
1613
+ // next token must be '('
1614
+ // because this method is called BEFORE parsing arguments
1615
+ if (!tn.skip(Token.OpenParen)) {
1616
+ tn.reset(state);
1617
+ return undefined;
1618
+ }
1619
+ if (typeArguments.length <= 0) {
1620
+ this.error(DiagnosticCode.Type_argument_list_cannot_be_empty, tn.range(startPos, end));
1621
+ return undefined;
1622
+ }
1623
+ return typeArguments;
1624
+ }
1625
+ parseArguments() {
1626
+ const tn = this.tn;
1627
+ // at '(': (PebbleExpr (',' PebbleExpr)*)? ')'
1628
+ let args = new Array();
1629
+ while (!tn.skip(Token.CloseParen)) {
1630
+ const expr = this.parseExpr(Precedence.Comma + 1);
1631
+ if (!expr)
1632
+ return undefined;
1633
+ args.push(expr);
1634
+ if (tn.skip(Token.Comma))
1635
+ continue;
1636
+ if (tn.skip(Token.CloseParen))
1637
+ break;
1638
+ this.error(DiagnosticCode._0_expected, tn.range(), ")");
1639
+ return undefined;
1640
+ }
1641
+ return args;
1642
+ }
1643
+ emitErrorIfInvalidAutoSemicolon() {
1644
+ const tn = this.tn;
1645
+ // see: https://tc39.es/ecma262/#sec-automatic-semicolon-insertion
1646
+ const nextToken = tn.peek();
1647
+ if (nextToken === Token.EndOfFile ||
1648
+ nextToken === Token.CloseBrace || // } => end of block
1649
+ tn.isNextTokenOnNewLine())
1650
+ return undefined; // all good
1651
+ this.error(DiagnosticCode.Unexpected_token, tn.range(tn.nextTokenPos));
1652
+ }
1653
+ /* essentially parses function body */
1654
+ parseCommonFuncExpr(name, parameters, arrowKind, startPos = -1, signatureStart = -1) {
1655
+ const tn = this.tn;
1656
+ if (startPos < 0)
1657
+ startPos = name.range.start;
1658
+ if (signatureStart < 0)
1659
+ signatureStart = startPos;
1660
+ let returnType = undefined;
1661
+ // either `function ( ... )` or `( ... )`
1662
+ // BUT NOT `param =>`
1663
+ // AND there is a `:`
1664
+ // we parse the return type
1665
+ if (arrowKind !== ArrowKind.Single && tn.skip(Token.Colon)) {
1666
+ returnType = this.parseTypeExpr();
1667
+ if (!returnType)
1668
+ return undefined;
1669
+ }
1670
+ // else the return type stays undefined (to infer)
1671
+ else
1672
+ returnType = undefined;
1673
+ const expectArrow = arrowKind !== ArrowKind.None;
1674
+ if (expectArrow && // if we expect an arrow
1675
+ !tn.skip(Token.FatArrow) // but there is none; then error
1676
+ )
1677
+ return this.error(DiagnosticCode._0_expected, tn.range(tn.pos), "=>");
1678
+ let signature = new AstFuncType(parameters, returnType, tn.range(signatureStart, tn.pos));
1679
+ let body = undefined;
1680
+ if (expectArrow) {
1681
+ // if `{` then block statement `() => {}`
1682
+ // else lambda `() => expr`
1683
+ body = tn.skip(Token.OpenBrace) ?
1684
+ this.parseBlockStmt(false) :
1685
+ this.parseExpr(Precedence.Comma + 1);
1686
+ }
1687
+ else {
1688
+ // function name(...) expects necessarely a block statement as body
1689
+ if (!tn.skip(Token.OpenBrace)) {
1690
+ this.error(DiagnosticCode._0_expected, tn.range(tn.pos), "{");
1691
+ return undefined;
1692
+ }
1693
+ body = this.parseBlockStmt(false);
1694
+ }
1695
+ if (!body)
1696
+ return undefined;
1697
+ return new FuncExpr(name, CommonFlags.None, [], signature, body, arrowKind, tn.range(startPos, tn.pos));
1698
+ }
1699
+ parseStatement({ topLevel, isExport } = {
1700
+ topLevel: false,
1701
+ isExport: false
1702
+ }) {
1703
+ const tn = this.tn;
1704
+ // at previous token
1705
+ const state = tn.mark();
1706
+ const token = tn.next();
1707
+ let statement = undefined;
1708
+ switch (token) {
1709
+ case Token.Break: {
1710
+ statement = this.parseBreak();
1711
+ break;
1712
+ }
1713
+ case Token.Var:
1714
+ case Token.Let:
1715
+ case Token.Const: {
1716
+ statement = this.parseVarStmt(token === Token.Const ? CommonFlags.Const : CommonFlags.Let, tn.tokenPos);
1717
+ break;
1718
+ }
1719
+ case Token.Using: {
1720
+ statement = this.parseUsingDecl();
1721
+ break;
1722
+ }
1723
+ case Token.Continue: {
1724
+ statement = this.parseContinue();
1725
+ break;
1726
+ }
1727
+ // case Token.Do: {
1728
+ // statement = this.parseDoStatement();
1729
+ // break;
1730
+ // }
1731
+ case Token.For: {
1732
+ statement = this.parseForStatement();
1733
+ break;
1734
+ }
1735
+ case Token.If: {
1736
+ statement = this.parseIfStatement();
1737
+ break;
1738
+ }
1739
+ case Token.OpenBrace: {
1740
+ statement = this.parseBlockStmt(topLevel);
1741
+ break;
1742
+ }
1743
+ case Token.Return: {
1744
+ if (topLevel) {
1745
+ this.error(DiagnosticCode.A_return_statement_can_only_be_used_within_a_function_body, tn.range()); // recoverable
1746
+ }
1747
+ statement = this.parseReturn();
1748
+ break;
1749
+ }
1750
+ case Token.Test: {
1751
+ if (!topLevel)
1752
+ return this.error(DiagnosticCode.A_test_can_only_be_specified_at_the_top_level_of_the_file_it_cannot_be_defined_in_functions_etc, tn.range());
1753
+ statement = this.parseTestStatement();
1754
+ break;
1755
+ }
1756
+ case Token.Semicolon: {
1757
+ return new EmptyStmt(tn.range(tn.tokenPos));
1758
+ }
1759
+ // case Token.Switch: {
1760
+ // statement = this.parseSwitchStatement();
1761
+ // break;
1762
+ // }
1763
+ case Token.Match:
1764
+ {
1765
+ statement = this.parseMatchStatement();
1766
+ break;
1767
+ }
1768
+ ;
1769
+ // case Token.Throw: {
1770
+ // statement = this.parseThrowStatement();
1771
+ // break;
1772
+ // }
1773
+ case Token.Fail:
1774
+ {
1775
+ statement = this.parseFailStatement();
1776
+ break;
1777
+ }
1778
+ ;
1779
+ case Token.Assert:
1780
+ {
1781
+ statement = this.parseAssertStatement();
1782
+ break;
1783
+ }
1784
+ ;
1785
+ // case Token.Try: {
1786
+ // statement = this.parseTryStatement();
1787
+ // break;
1788
+ // }
1789
+ case Token.Void: {
1790
+ this.error(DiagnosticCode.Not_implemented_0, tn.range(), "void statements");
1791
+ // statement = this.parseVoidStatement();
1792
+ break;
1793
+ }
1794
+ case Token.While: {
1795
+ statement = this.parseWhileStatement();
1796
+ break;
1797
+ }
1798
+ // case Token.Type: { // also identifier
1799
+ // if (tn.peek(IdentifierHandling.Prefer) === Token.Identifier) {
1800
+ // statement = this.parseTypeDeclaration(CommonFlags.None, tn.tokenPos);
1801
+ // break;
1802
+ // }
1803
+ // // fall-through
1804
+ // }
1805
+ case Token.Equals:
1806
+ case Token.Plus_Equals:
1807
+ case Token.Minus_Equals:
1808
+ case Token.Asterisk_Asterisk_Equals:
1809
+ case Token.Asterisk_Equals:
1810
+ case Token.Slash_Equals:
1811
+ case Token.Percent_Equals:
1812
+ case Token.LessThan_LessThan_Equals:
1813
+ case Token.GreaterThan_GreaterThan_Equals:
1814
+ case Token.GreaterThan_GreaterThan_GreaterThan_Equals:
1815
+ case Token.Ampersand_Equals:
1816
+ case Token.Caret_Equals:
1817
+ case Token.Ampersand_Ampersand_Equals:
1818
+ case Token.Bar_Bar_Equals:
1819
+ case Token.Question_Question_Equals:
1820
+ case Token.Bar_Equals:
1821
+ {
1822
+ this.error(DiagnosticCode.Not_implemented_0, tn.range(), "mutable variables assignmets");
1823
+ break;
1824
+ }
1825
+ case Token.Identifier: {
1826
+ // const preIdState = tn.mark();
1827
+ // tn.readIdentifier();
1828
+ // const nextToken = tn.peek();
1829
+ // tn.reset(preIdState);
1830
+ // if( isAssignmentToken( nextToken ) )
1831
+ // {
1832
+ statement = this.parseAssignmentStatement();
1833
+ break;
1834
+ // }
1835
+ // else fall through to default
1836
+ }
1837
+ default: {
1838
+ // tn.reset(state);
1839
+ // statement = this.parseExprStmt();
1840
+ break;
1841
+ }
1842
+ }
1843
+ if (!statement) { // has been reported
1844
+ tn.reset(state);
1845
+ this.error(DiagnosticCode.Statement_expected, tn.range());
1846
+ this.skipStatement();
1847
+ }
1848
+ else {
1849
+ // tn.discard(state);
1850
+ }
1851
+ return statement;
1852
+ }
1853
+ /*
1854
+ parseExprStmt(): ExprStmt | undefined
1855
+ {
1856
+ const tn = this.tn;
1857
+
1858
+ const startPos = tn.tokenPos;
1859
+ const expr = this.parseExpr();
1860
+ if (!expr) return undefined;
1861
+
1862
+ return new ExprStmt(expr, tn.range(startPos, tn.pos));
1863
+ }
1864
+ //*/
1865
+ parseAssignmentStatement() {
1866
+ const tn = this.tn;
1867
+ const startPos = tn.tokenPos;
1868
+ if (!tn.skipIdentifier())
1869
+ return this.error(DiagnosticCode.Identifier_expected, tn.range());
1870
+ const varIdentifier = new Identifier(tn.readIdentifier(), tn.range());
1871
+ const assignmentToken = tn.next();
1872
+ switch (assignmentToken) {
1873
+ case Token.Equals:
1874
+ case Token.Plus_Equals:
1875
+ case Token.Minus_Equals:
1876
+ case Token.Asterisk_Asterisk_Equals:
1877
+ case Token.Asterisk_Equals:
1878
+ case Token.Slash_Equals:
1879
+ case Token.Percent_Equals:
1880
+ case Token.LessThan_LessThan_Equals:
1881
+ case Token.GreaterThan_GreaterThan_Equals:
1882
+ case Token.GreaterThan_GreaterThan_GreaterThan_Equals:
1883
+ case Token.Ampersand_Equals:
1884
+ case Token.Caret_Equals:
1885
+ case Token.Bar_Equals:
1886
+ case Token.Ampersand_Ampersand_Equals:
1887
+ case Token.Bar_Bar_Equals:
1888
+ // case Token.Question_Question_Equals:
1889
+ {
1890
+ const expr = this.parseExpr();
1891
+ if (!expr)
1892
+ return undefined;
1893
+ return makeAssignmentStmt(varIdentifier, assignmentToken, expr, tn.range(startPos, tn.pos));
1894
+ }
1895
+ case Token.Question_Question_Equals: {
1896
+ return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "??=");
1897
+ }
1898
+ default: {
1899
+ return this.error(DiagnosticCode._0_expected, tn.range(), "=");
1900
+ }
1901
+ }
1902
+ }
1903
+ parseBlockStmt(topLevel = false) {
1904
+ const tn = this.tn;
1905
+ // at '{': PebbleStmt* '}' ';'?
1906
+ const startPos = tn.tokenPos;
1907
+ const statements = new Array();
1908
+ while (!tn.skip(Token.CloseBrace)) {
1909
+ let state = tn.mark();
1910
+ let statement = this.parseStatement({ topLevel, isExport: false });
1911
+ if (!statement) {
1912
+ if (tn.token === Token.EndOfFile)
1913
+ return undefined;
1914
+ tn.reset(state);
1915
+ this.skipStatement();
1916
+ }
1917
+ else {
1918
+ statements.push(statement);
1919
+ }
1920
+ }
1921
+ let ret = new BlockStmt(statements, tn.range(startPos, tn.pos));
1922
+ if (topLevel)
1923
+ tn.skip(Token.Semicolon);
1924
+ return ret;
1925
+ }
1926
+ parseBreak() {
1927
+ const tn = this.tn;
1928
+ // at 'break': Identifier? ';'?
1929
+ // let identifier: Identifier | undefined = undefined;
1930
+ // if (tn.peek() === Token.Identifier && !tn.isNextTokenOnNewLine()) {
1931
+ // tn.next(IdentifierHandling.Prefer);
1932
+ // identifier = new Identifier(tn.readIdentifier(), tn.range());
1933
+ // }
1934
+ const result = new BreakStmt(tn.range());
1935
+ tn.skip(Token.Semicolon); // if any
1936
+ return result;
1937
+ }
1938
+ parseContinue() {
1939
+ const tn = this.tn;
1940
+ // at 'continue': Identifier? ';'?
1941
+ // let identifier: Identifier | undefined = undefined;
1942
+ // if (tn.peek() === Token.Identifier && !tn.isNextTokenOnNewLine()) {
1943
+ // tn.next(IdentifierHandling.Prefer);
1944
+ // identifier = new Identifier(tn.readIdentifier(), tn.range());
1945
+ // }
1946
+ let ret = new ContinueStmt(tn.range());
1947
+ tn.skip(Token.Semicolon); // if any
1948
+ return ret;
1949
+ }
1950
+ /*
1951
+ parseDoStatement(): DoWhileStmt | undefined
1952
+ {
1953
+ const tn = this.tn;
1954
+ // at 'do': Statement 'while' '(' Expression ')' ';'?
1955
+
1956
+ let startPos = tn.tokenPos;
1957
+ let statement = this.parseStatement();
1958
+ if (!statement) return undefined;
1959
+
1960
+ if( !tn.skip( Token.While ) )
1961
+ {
1962
+ this.error(
1963
+ DiagnosticCode._0_expected,
1964
+ tn.range(), "while"
1965
+ );
1966
+ return undefined;
1967
+ }
1968
+ if( !tn.skip( Token.OpenParen ) )
1969
+ {
1970
+ this.error(
1971
+ DiagnosticCode._0_expected,
1972
+ tn.range(), "("
1973
+ );
1974
+ return undefined;
1975
+ }
1976
+
1977
+ let condition = this.parseExpr();
1978
+ if (!condition) return undefined;
1979
+
1980
+ if( !tn.skip( Token.CloseParen ) )
1981
+ {
1982
+ this.error(
1983
+ DiagnosticCode._0_expected,
1984
+ tn.range(), ")"
1985
+ );
1986
+ return undefined;
1987
+ }
1988
+
1989
+ const result = new DoWhileStmt(
1990
+ statement,
1991
+ condition,
1992
+ tn.range(startPos, tn.pos)
1993
+ );
1994
+ tn.skip( Token.Semicolon);
1995
+ return result;
1996
+ }
1997
+ */
1998
+ parseForStatement() {
1999
+ const tn = this.tn;
2000
+ // at 'for': '(' Statement? Expression? ';' Expression? ')' Statement
2001
+ const startPos = tn.tokenPos;
2002
+ if (!tn.skip(Token.OpenParen))
2003
+ return this.error(DiagnosticCode._0_expected, tn.range(), "(");
2004
+ let init = undefined;
2005
+ // this.parseVarStmt
2006
+ const token = tn.peek();
2007
+ switch (token) {
2008
+ case Token.Let:
2009
+ case Token.Var:
2010
+ case Token.Const: {
2011
+ tn.next();
2012
+ init = this.parseVarStmt(token === Token.Const ? CommonFlags.Const : CommonFlags.Let, tn.tokenPos, { isFor: true });
2013
+ break;
2014
+ }
2015
+ }
2016
+ // for...of
2017
+ if (tn.skip(Token.Of)) {
2018
+ if (!(init instanceof VarStmt))
2019
+ return this.error(DiagnosticCode._0_expected, tn.range(startPos), "Variable declaration");
2020
+ const decls = init.declarations;
2021
+ if (decls.length !== 1)
2022
+ return this.error(DiagnosticCode.Only_a_single_variable_is_allowed_in_a_for_of_statement, tn.range());
2023
+ const decl = decls[0];
2024
+ if (decl.initExpr !== undefined ||
2025
+ decl.type !== undefined) {
2026
+ return this.error(DiagnosticCode.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer, tn.range());
2027
+ }
2028
+ const iterable = this.parseExpr();
2029
+ if (!iterable)
2030
+ return undefined;
2031
+ if (!tn.skip(Token.CloseParen))
2032
+ return this.error(DiagnosticCode._0_expected, tn.range(), ")");
2033
+ const body = this.parseStatement();
2034
+ if (!body)
2035
+ return undefined;
2036
+ return new ForOfStmt(init, iterable, body, tn.range(startPos, tn.pos));
2037
+ }
2038
+ // non for...of
2039
+ if (!tn.skip(Token.Semicolon))
2040
+ return this.error(DiagnosticCode._0_expected, tn.range(), ";");
2041
+ let condition = undefined;
2042
+ if (!tn.skip(Token.Semicolon)) {
2043
+ condition = this.parseExpr();
2044
+ if (!condition)
2045
+ return undefined;
2046
+ if (!tn.skip(Token.Semicolon))
2047
+ return this.error(DiagnosticCode._0_expected, tn.range(), ";");
2048
+ }
2049
+ let update = undefined;
2050
+ const updates = [];
2051
+ if (!tn.skip(Token.CloseParen)) {
2052
+ do {
2053
+ update = this.parseStatement();
2054
+ if (!update)
2055
+ return undefined;
2056
+ if (!(update instanceof IncrStmt
2057
+ || update instanceof DecrStmt
2058
+ || isAssignmentStmt(update)))
2059
+ return this.error(DiagnosticCode.Invalid_for_statement_update, update.range);
2060
+ updates.push(update);
2061
+ } while (tn.skip(Token.Comma)); // comma expression (allowed only in for update part)
2062
+ if (!tn.skip(Token.CloseParen))
2063
+ return this.error(DiagnosticCode._0_expected, tn.range(), ")");
2064
+ }
2065
+ const body = this.parseStatement();
2066
+ if (!body)
2067
+ return undefined;
2068
+ return new ForStmt(init, condition, updates, body, tn.range(startPos, tn.pos));
2069
+ }
2070
+ parseIfStatement() {
2071
+ const tn = this.tn;
2072
+ // at 'if': '(' Expression ')' Statement ('else' Statement)?
2073
+ const startPos = tn.tokenPos;
2074
+ if (!tn.skip(Token.OpenParen))
2075
+ return this.error(DiagnosticCode._0_expected, tn.range(), "(");
2076
+ let condition = this.parseExpr();
2077
+ if (!condition)
2078
+ return undefined;
2079
+ if (!tn.skip(Token.CloseParen))
2080
+ return this.error(DiagnosticCode._0_expected, tn.range(), ")");
2081
+ let thenStatement = this.parseStatement();
2082
+ if (!thenStatement)
2083
+ return undefined;
2084
+ let elseStatement = undefined;
2085
+ if (tn.skip(Token.Else)) {
2086
+ elseStatement = this.parseStatement();
2087
+ if (!elseStatement)
2088
+ return undefined;
2089
+ }
2090
+ return new IfStmt(condition, thenStatement, elseStatement, tn.range(startPos, tn.pos));
2091
+ }
2092
+ parseReturn() {
2093
+ const tn = this.tn;
2094
+ // at 'return': Expression? ';'
2095
+ const startPos = tn.tokenPos;
2096
+ let expr = undefined;
2097
+ if (!tn.skip(Token.Semicolon) &&
2098
+ !tn.isNextTokenOnNewLine()) {
2099
+ expr = this.parseExpr();
2100
+ if (!expr)
2101
+ return undefined;
2102
+ tn.skip(Token.Semicolon); // if any
2103
+ }
2104
+ return new ReturnStmt(expr, tn.range(startPos, tn.pos));
2105
+ }
2106
+ parseTestStatement() {
2107
+ const tn = this.tn;
2108
+ // at 'test': string? BlockStmt
2109
+ const startPost = tn.pos;
2110
+ let testName = undefined;
2111
+ if (tn.skip(Token.StringLiteral)) {
2112
+ const value = tn.readString();
2113
+ testName = new LitStrExpr(value, tn.range(startPost, tn.pos));
2114
+ }
2115
+ let body = this.parseBlockStmt(true);
2116
+ if (!body)
2117
+ return this.error(DiagnosticCode.Tests_must_be_specified_in_a_block_statement, tn.range());
2118
+ return new TestStmt(testName, body, tn.range(startPost, tn.pos));
2119
+ }
2120
+ parseMatchStatement() {
2121
+ const tn = this.tn;
2122
+ // at 'match': Expression '{' MatchStmtCase* '}' ';'
2123
+ const startPos = tn.pos;
2124
+ const expr = this.parseExpr();
2125
+ if (!expr)
2126
+ return this.error(DiagnosticCode.Expression_expected, tn.range(startPos - 5, startPos));
2127
+ if (!tn.skip(Token.OpenBrace))
2128
+ return this.error(DiagnosticCode._0_expected, tn.range(), "{");
2129
+ let noPatternCaseSeen = false;
2130
+ const cases = new Array();
2131
+ while (!tn.skip(Token.CloseBrace)) {
2132
+ if (!tn.skip(Token.When))
2133
+ return this.error(DiagnosticCode._0_expected, tn.range(), "when");
2134
+ // const startPos = tn.pos;
2135
+ const pattern = this._parseVarDecl(CommonFlags.Const);
2136
+ if (!pattern)
2137
+ return this.error(DiagnosticCode.Pattern_expected, tn.range());
2138
+ if (noPatternCaseSeen)
2139
+ return this.error(DiagnosticCode.This_case_will_never_be_evaluated_because_all_patterns_will_be_catched_before, pattern.range);
2140
+ if (pattern instanceof SimpleVarDecl)
2141
+ noPatternCaseSeen = true;
2142
+ if (!tn.skip(Token.Colon))
2143
+ return this.error(DiagnosticCode._0_expected, tn.range(), ":");
2144
+ const statePreBody = tn.mark();
2145
+ const body = this.parseStatement({ topLevel: false, isExport: false });
2146
+ if (!body)
2147
+ return this.error(DiagnosticCode._0_expected, tn.range(statePreBody.tokenPos, statePreBody.pos), "{");
2148
+ cases.push(new MatchStmtCase(pattern, body, tn.range()));
2149
+ }
2150
+ if (cases.length < 1)
2151
+ return this.error(DiagnosticCode.A_match_statement_must_have_at_least_one_case, tn.range(startPos, tn.pos));
2152
+ return new MatchStmt(expr, cases, tn.range(startPos, tn.pos));
2153
+ }
2154
+ parseFailStatement() {
2155
+ const tn = this.tn;
2156
+ // at 'fail': Expression? ';'
2157
+ if (tn.skip(Token.Semicolon) ||
2158
+ tn.isNextTokenOnNewLine())
2159
+ return new FailStmt(undefined, tn.range());
2160
+ const expr = this.parseExpr();
2161
+ if (!expr)
2162
+ return undefined;
2163
+ return new FailStmt(expr, tn.range());
2164
+ }
2165
+ parseAssertStatement() {
2166
+ const tn = this.tn;
2167
+ const startPos = tn.tokenPos;
2168
+ // at 'assert': Expression (else Expression)? ';'?
2169
+ const condition = this.parseExpr();
2170
+ if (!condition)
2171
+ return this.error(DiagnosticCode.Expression_expected, tn.range());
2172
+ if (!tn.skip(Token.Else)) {
2173
+ tn.skip(Token.Semicolon);
2174
+ return new AssertStmt(condition, undefined, tn.range());
2175
+ }
2176
+ const message = this.parseExpr();
2177
+ if (!message)
2178
+ return this.error(DiagnosticCode.Expression_expected, tn.range());
2179
+ tn.skip(Token.Semicolon);
2180
+ return new AssertStmt(condition, message, tn.range(startPos, startPos + 6));
2181
+ }
2182
+ parseWhileStatement() {
2183
+ const tn = this.tn;
2184
+ // at 'while': '(' Expression ')' Statement
2185
+ const startPos = tn.tokenPos;
2186
+ if (!tn.skip(Token.OpenParen))
2187
+ return this.error(DiagnosticCode._0_expected, tn.range(), "(");
2188
+ let condition = this.parseExpr();
2189
+ if (!condition)
2190
+ return undefined;
2191
+ if (!tn.skip(Token.CloseParen))
2192
+ return this.error(DiagnosticCode._0_expected, tn.range(), ")");
2193
+ let statement = this.parseStatement();
2194
+ if (!statement)
2195
+ return this.error(DiagnosticCode.Statement_expected, tn.range());
2196
+ return new WhileStmt(condition, statement, tn.range(startPos, tn.pos));
2197
+ }
2198
+ /**
2199
+ * looks ahead to see if the expression
2200
+ * needs to be parsed as an arrow function or a parenthesized expression
2201
+ *
2202
+ * @returns {boolean}
2203
+ * `true` if the expression is an arrow function,
2204
+ * `false` if it is a parenthesized expression
2205
+ */
2206
+ isArrowFuncOrParenExprLookahead() {
2207
+ const tn = this.tn;
2208
+ // `()` makes no sense as parenthesized expression
2209
+ // it must be `() =>` or `(): Type =>`
2210
+ if (tn.skip(Token.CloseParen))
2211
+ return true;
2212
+ // get back to this token before return
2213
+ const tnState = tn.mark();
2214
+ // let again = true;
2215
+ while ( /* again */true) {
2216
+ switch (tn.next(IdentifierHandling.Prefer)) {
2217
+ // function expression rest parameter
2218
+ // ( ...rest ) => ...
2219
+ case Token.Dot_Dot_Dot: {
2220
+ tn.reset(tnState);
2221
+ return true;
2222
+ }
2223
+ // can be both parenthesized expression or function parameter
2224
+ // ( Identifier...
2225
+ case Token.Identifier: {
2226
+ // discard identifier for now, we'll get back later
2227
+ tn.readIdentifier();
2228
+ switch (tn.next()) {
2229
+ // if we got here, check for arrow
2230
+ // ( Identifier ) ...
2231
+ case Token.CloseParen: {
2232
+ // `( Identifier ):Type =>` is function expression
2233
+ if (tn.skip(Token.Colon)) {
2234
+ let type = this.parseTypeExpr(true);
2235
+ // we got `( Identifier ):` but no type
2236
+ // so it must be a parenthesized expression
2237
+ // for example in a `match` statement
2238
+ if (type === undefined) {
2239
+ tn.reset(tnState);
2240
+ return false;
2241
+ }
2242
+ }
2243
+ // no arrow after `( Identifier )`
2244
+ // so it must be a parenthesized expression
2245
+ if (!tn.skip(Token.FatArrow)) {
2246
+ tn.reset(tnState);
2247
+ return false;
2248
+ }
2249
+ // else (we met `=>`)
2250
+ tn.reset(tnState);
2251
+ return true;
2252
+ }
2253
+ // function expression
2254
+ // type annotation
2255
+ // ( Identifier:Type ...
2256
+ case Token.Colon: {
2257
+ tn.reset(tnState);
2258
+ return true;
2259
+ }
2260
+ // optional parameter not supported in pebble
2261
+ // ( Identifier? ... )
2262
+ // likely optional prop access ( Identifier?.prop ... )
2263
+ case Token.Question: {
2264
+ tn.reset(tnState);
2265
+ return false;
2266
+ }
2267
+ case Token.Comma: {
2268
+ // not necessarlily a function expression
2269
+ // ( Identifier, ...
2270
+ // could be the `comma operator` (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_operator)
2271
+ // for example in a for loop
2272
+ // for( ...; ...; (i++, j++) )
2273
+ break; // continue
2274
+ }
2275
+ // case Token.EQUALS: // missing type annotation for simplicity
2276
+ case Token.Equals: {
2277
+ // not necessarlily a function expression
2278
+ // ( Identifier = ...
2279
+ // can still be part of a comma operator (see case Token.Comma)
2280
+ // eg: ( myVar = somehtingElse, doStuff( myVar ) )
2281
+ // parse (and discard) initialization expr
2282
+ // (both comma reassignment or function parameter default value)
2283
+ this.parseExpr(Precedence.Comma + 1);
2284
+ break; // continue
2285
+ }
2286
+ // parenthesized expression
2287
+ default: {
2288
+ tn.reset(tnState);
2289
+ return false;
2290
+ }
2291
+ }
2292
+ break;
2293
+ }
2294
+ // parenthesized expression
2295
+ default: {
2296
+ tn.reset(tnState);
2297
+ return false;
2298
+ }
2299
+ }
2300
+ }
2301
+ // parse parenthesized
2302
+ tn.reset(tnState);
2303
+ return false;
2304
+ }
2305
+ /** Skips over a statement on errors in an attempt to reduce unnecessary diagnostic noise. */
2306
+ skipStatement() {
2307
+ const tn = this.tn;
2308
+ if (tn.isNextTokenOnNewLine())
2309
+ tn.next(); // if reset() to the previous line
2310
+ do {
2311
+ let nextToken = tn.peek();
2312
+ if (nextToken === Token.EndOfFile || // next step should handle this
2313
+ nextToken === Token.Semicolon // end of the statement for sure
2314
+ ) {
2315
+ tn.next();
2316
+ break;
2317
+ }
2318
+ if (tn.isNextTokenOnNewLine())
2319
+ break; // end of the statement maybe
2320
+ switch (tn.next()) {
2321
+ case Token.Identifier: {
2322
+ tn.readIdentifier();
2323
+ break;
2324
+ }
2325
+ case Token.StringLiteral:
2326
+ case Token.StringTemplateLiteralQuote: {
2327
+ tn.readString();
2328
+ break;
2329
+ }
2330
+ case Token.IntegerLiteral: {
2331
+ tn.readInteger();
2332
+ tn.checkForIdentifierStartAfterNumericLiteral();
2333
+ break;
2334
+ }
2335
+ case Token.HexBytesLiteral:
2336
+ {
2337
+ tn.readHexBytes();
2338
+ break;
2339
+ }
2340
+ ;
2341
+ // case Token.FloatLiteral: {
2342
+ // tn.readFloat();
2343
+ // tn.checkForIdentifierStartAfterNumericLiteral();
2344
+ // break;
2345
+ // }
2346
+ case Token.OpenBrace: {
2347
+ this.skipBlock(tn);
2348
+ break;
2349
+ }
2350
+ }
2351
+ } while (true);
2352
+ tn.readingTemplateString = false;
2353
+ }
2354
+ /** Skips over a block on errors in an attempt to reduce unnecessary diagnostic noise. */
2355
+ skipBlock(tn) {
2356
+ // at '{': ... '}'
2357
+ let depth = 1;
2358
+ let again = true;
2359
+ do {
2360
+ switch (tn.next()) {
2361
+ case Token.EndOfFile: {
2362
+ this.error(DiagnosticCode._0_expected, tn.range(), "}");
2363
+ again = false;
2364
+ break;
2365
+ }
2366
+ case Token.OpenBrace: {
2367
+ ++depth;
2368
+ break;
2369
+ }
2370
+ case Token.CloseBrace: {
2371
+ --depth;
2372
+ if (!depth)
2373
+ again = false;
2374
+ break;
2375
+ }
2376
+ case Token.Identifier: {
2377
+ tn.readIdentifier();
2378
+ break;
2379
+ }
2380
+ case Token.StringLiteral: {
2381
+ tn.readString();
2382
+ break;
2383
+ }
2384
+ case Token.StringTemplateLiteralQuote: {
2385
+ tn.readString();
2386
+ while (tn.readingTemplateString) {
2387
+ this.skipBlock(tn);
2388
+ tn.readString(96 /* CharCode.Backtick */);
2389
+ }
2390
+ break;
2391
+ }
2392
+ case Token.IntegerLiteral: {
2393
+ tn.readInteger();
2394
+ tn.checkForIdentifierStartAfterNumericLiteral();
2395
+ break;
2396
+ }
2397
+ case Token.HexBytesLiteral:
2398
+ {
2399
+ tn.readHexBytes();
2400
+ break;
2401
+ }
2402
+ ;
2403
+ // case Token.FloatLiteral: {
2404
+ // tn.readFloat();
2405
+ // tn.checkForIdentifierStartAfterNumericLiteral();
2406
+ // break;
2407
+ // }
2408
+ }
2409
+ } while (again);
2410
+ }
2411
+ }
2412
+ const defaultParseVarOpts = Object.freeze({
2413
+ isFor: false,
2414
+ isForOf: false,
2415
+ isParam: false
2416
+ });