@shapeshift-labs/frontier-lang-compiler 0.2.150 → 0.2.151

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 (276) hide show
  1. package/README.md +315 -9
  2. package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
  3. package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
  4. package/bench/real-repo-corpus-command-execution.mjs +314 -0
  5. package/bench/real-repo-corpus-evidence.mjs +165 -0
  6. package/bench/real-repo-corpus-suite.mjs +273 -0
  7. package/bench/smoke.mjs +109 -7
  8. package/dist/declarations/import-adapter-core.d.ts +4 -3
  9. package/dist/declarations/import-adapter-options-native.d.ts +21 -0
  10. package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
  11. package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
  12. package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
  13. package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
  14. package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
  15. package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
  16. package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
  17. package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
  18. package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
  19. package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
  20. package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
  21. package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
  22. package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
  23. package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
  24. package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
  25. package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
  26. package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
  27. package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
  28. package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
  29. package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
  30. package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
  31. package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
  32. package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
  33. package/dist/declarations/native-project-css-modules.d.ts +90 -0
  34. package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
  35. package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
  36. package/dist/declarations/native-project-module-declarations.d.ts +52 -0
  37. package/dist/declarations/native-project-module-resolution.d.ts +76 -1
  38. package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
  39. package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
  40. package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
  41. package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
  42. package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
  43. package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
  44. package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
  45. package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
  46. package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
  47. package/dist/declarations/native-project-source-evidence.d.ts +8 -0
  48. package/dist/declarations/native-project.d.ts +40 -39
  49. package/dist/declarations/semantic-edit-script.d.ts +10 -8
  50. package/dist/declarations/semantic-graph-layers.d.ts +79 -0
  51. package/dist/declarations/semantic-sidecar.d.ts +3 -2
  52. package/dist/declarations/semantic-structural-diff.d.ts +94 -0
  53. package/dist/declarations/source-preservation.d.ts +32 -1
  54. package/dist/declarations/target-adapters.d.ts +22 -2
  55. package/dist/index.d.ts +31 -0
  56. package/dist/index.js +5 -0
  57. package/dist/internal/index-impl/compileNativeSource.js +53 -5
  58. package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
  59. package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
  60. package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
  61. package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
  62. package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
  63. package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
  64. package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
  65. package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
  66. package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
  67. package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
  68. package/dist/internal/index-impl/importNativeSource.js +2 -3
  69. package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
  70. package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
  71. package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
  72. package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
  73. package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
  74. package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
  75. package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
  76. package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
  77. package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
  78. package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
  79. package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
  80. package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
  81. package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
  82. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
  83. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
  84. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
  85. package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
  86. package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
  87. package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
  88. package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
  89. package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
  90. package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
  91. package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
  92. package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
  93. package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
  94. package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
  95. package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
  96. package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
  97. package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
  98. package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
  99. package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
  100. package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
  101. package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
  102. package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
  103. package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
  104. package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
  105. package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
  106. package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
  107. package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
  108. package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
  109. package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
  110. package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
  111. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
  112. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
  113. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
  114. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
  115. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
  116. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
  117. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
  118. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
  119. package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
  120. package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
  121. package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
  122. package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
  123. package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
  124. package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
  125. package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
  126. package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
  127. package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
  128. package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
  129. package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
  130. package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
  131. package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
  132. package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
  133. package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
  134. package/dist/internal/index-impl/semanticEditScripts.js +42 -5
  135. package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
  136. package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
  137. package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
  138. package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
  139. package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
  140. package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
  141. package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
  142. package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
  143. package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
  144. package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
  145. package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
  146. package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
  147. package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
  148. package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
  149. package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
  150. package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
  151. package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
  152. package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
  153. package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
  154. package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
  155. package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
  156. package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
  157. package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
  158. package/dist/js-ts-safe-member-class-invariants.js +247 -0
  159. package/dist/js-ts-safe-member-merge-result.js +23 -3
  160. package/dist/js-ts-safe-member-merge.js +28 -4
  161. package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
  162. package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +151 -157
  163. package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
  164. package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
  165. package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
  166. package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
  167. package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
  168. package/dist/js-ts-safe-merge-parse-statements.js +8 -0
  169. package/dist/js-ts-safe-merge-semantic-edit-fallback.js +13 -5
  170. package/dist/js-ts-safe-merge-source-shape-fallbacks.js +3 -1
  171. package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
  172. package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
  173. package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
  174. package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
  175. package/dist/js-ts-safe-merge.js +136 -0
  176. package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
  177. package/dist/js-ts-safe-project-merge-admission.js +161 -0
  178. package/dist/js-ts-safe-project-merge-ambient.js +110 -0
  179. package/dist/js-ts-safe-project-merge-core.js +85 -0
  180. package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
  181. package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
  182. package/dist/js-ts-safe-project-merge-declarations.js +227 -0
  183. package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
  184. package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
  185. package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
  186. package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
  187. package/dist/js-ts-safe-project-merge-files.js +70 -0
  188. package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
  189. package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
  190. package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
  191. package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
  192. package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
  193. package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
  194. package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
  195. package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
  196. package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
  197. package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
  198. package/dist/js-ts-safe-project-merge-graph.js +37 -5
  199. package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
  200. package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
  201. package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
  202. package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
  203. package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
  204. package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
  205. package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
  206. package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
  207. package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
  208. package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
  209. package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
  210. package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
  211. package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
  212. package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
  213. package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
  214. package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
  215. package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
  216. package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
  217. package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
  218. package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
  219. package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
  220. package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
  221. package/dist/js-ts-safe-project-merge-summary.js +320 -0
  222. package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
  223. package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
  224. package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
  225. package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
  226. package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
  227. package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
  228. package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
  229. package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
  230. package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
  231. package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
  232. package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
  233. package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
  234. package/dist/js-ts-safe-project-merge.js +170 -171
  235. package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
  236. package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
  237. package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
  238. package/dist/js-ts-semantic-scope-use-def.js +217 -0
  239. package/dist/lightweight-dependency-effects.js +28 -4
  240. package/dist/lightweight-dependency-relations.js +13 -7
  241. package/dist/lightweight-dependency-top-level.js +63 -0
  242. package/dist/native-import-language-profiles.js +27 -1
  243. package/dist/native-js-ts-importers.js +9 -5
  244. package/dist/native-parser-ast-format-profiles.js +12 -0
  245. package/dist/native-parser-html-css-format-profiles.js +85 -0
  246. package/dist/native-region-scanner-core.js +5 -3
  247. package/dist/native-region-scanner-js-commonjs.js +155 -0
  248. package/dist/native-region-scanner-js-imports.js +51 -13
  249. package/dist/native-region-scanner-js-reexports.js +79 -0
  250. package/dist/native-region-scanner-js-ts-helpers.js +23 -0
  251. package/dist/native-source-ledger-helpers.js +1 -1
  252. package/dist/native-source-ledger.js +24 -10
  253. package/dist/native-source-maps-ecma426.js +316 -0
  254. package/dist/native-source-maps.js +36 -6
  255. package/dist/native-source-preservation-ownership.js +292 -0
  256. package/dist/native-source-preservation-scanner.js +63 -25
  257. package/dist/native-source-preservation-types.d.ts +3 -0
  258. package/dist/semantic-import-effect-occurrences.js +242 -0
  259. package/dist/semantic-import-effect-regions.js +95 -58
  260. package/dist/semantic-import-graph-layers.js +224 -0
  261. package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
  262. package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
  263. package/dist/semantic-import-runtime-exit-evidence.js +32 -0
  264. package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
  265. package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
  266. package/dist/semantic-import-runtime-order-evidence.js +318 -0
  267. package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
  268. package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
  269. package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
  270. package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
  271. package/dist/semantic-import-runtime-switch-evidence.js +304 -0
  272. package/dist/semantic-import-runtime-throw-evidence.js +44 -0
  273. package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
  274. package/dist/semantic-import-sidecar-entry.js +4 -0
  275. package/dist/semantic-import-source-preservation.js +6 -2
  276. package/package.json +1 -1
@@ -0,0 +1,293 @@
1
+ import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
2
+ import { caseSensitiveIdFragment, idFragment, uniqueRecordsById, uniqueStrings } from './native-import-utils.js';
3
+ import { maskNonCode } from './js-ts-semantic-scope-use-def-scan.js';
4
+
5
+ function resourceManagementRecordsForImport(imported, semanticIndex, options = {}) {
6
+ const declarations = resourceManagementDeclarationsForImport(imported, semanticIndex);
7
+ const records = declarations.map((declaration, index) => resourceManagementRegionRecord(imported, declaration, index, options));
8
+ return {
9
+ symbols: uniqueRecordsById(records.map((record) => record.symbol)),
10
+ ownershipRegions: uniqueRecordsById(records.map((record) => record.region))
11
+ };
12
+ }
13
+
14
+ function resourceManagementRuntimeRegionRecordsForImport(imported, semanticIndex, publicKeys = new Set()) {
15
+ const declarations = resourceManagementDeclarationsForImport(imported, semanticIndex);
16
+ const publicNames = new Set((semanticIndex?.symbols ?? []).filter((symbol) => symbol?.kind === 'export').map((symbol) => symbol.name));
17
+ return declarations.map((declaration, index) => {
18
+ const { region } = resourceManagementRegionRecord(imported, declaration, index);
19
+ const runtimeOrderEvidence = region.metadata.runtimeOrderEvidence;
20
+ const signatureHash = hashSemanticValue({
21
+ kind: 'frontier.lang.projectRuntimeRegionSignature',
22
+ regionKind: region.regionKind,
23
+ runtimeKind: 'resource-management',
24
+ runtimeOrderEvidence,
25
+ declarationText: declaration.declarationText,
26
+ initializerText: declaration.initializerText
27
+ });
28
+ return compactRecord({
29
+ id: `runtime_region_${idFragment(region.id)}_${idFragment(signatureHash)}`,
30
+ key: region.key,
31
+ regionKind: region.regionKind,
32
+ runtimeKind: 'resource-management',
33
+ runtimeKinds: declaration.runtimeKinds,
34
+ sourcePath: region.sourcePath,
35
+ sourceHash: region.sourceHash,
36
+ sourceSpan: region.sourceSpan,
37
+ precision: region.precision,
38
+ spanKind: region.metadata.spanKind,
39
+ symbolId: declaration.ownerId,
40
+ symbolName: declaration.ownerName,
41
+ symbolKind: declaration.ownerKind,
42
+ line: declaration.line,
43
+ ordinal: declaration.ordinal,
44
+ runtimeOrderEvidence,
45
+ signatureHash,
46
+ publicContract: publicKeys.has(runtimePublicKey(region.sourcePath, declaration.ownerName))
47
+ || publicNames.has(declaration.ownerName) || undefined,
48
+ factIds: [],
49
+ evidenceIds: [`resource-management:${declaration.id}`]
50
+ });
51
+ });
52
+ }
53
+
54
+ function resourceManagementDeclarationsForImport(imported, semanticIndex) {
55
+ const sourceText = nativeImportSourceText(imported);
56
+ if (typeof sourceText !== 'string' || !sourceText.includes('using')) return [];
57
+ const sourcePath = imported?.sourcePath ?? imported?.nativeSource?.sourcePath ?? imported?.nativeAst?.sourcePath;
58
+ const language = imported?.language ?? imported?.nativeSource?.language ?? imported?.nativeAst?.language;
59
+ const sourceHash = imported?.nativeSource?.sourceHash ?? imported?.nativeAst?.sourceHash ?? imported?.sourceHash;
60
+ const masked = maskNonCode(sourceText).code;
61
+ const lineStarts = lineStartsFor(sourceText);
62
+ const scopes = braceScopes(masked, lineStarts);
63
+ const rawDeclarations = usingDeclarationMatches(sourceText, masked, lineStarts).map((match) => {
64
+ const scope = innermostScopeFor(scopes, match.start) ?? moduleScope(sourceText, lineStarts);
65
+ const owner = ownerSymbolFor(semanticIndex?.symbols ?? [], sourcePath, match.line);
66
+ return {
67
+ ...match,
68
+ id: `resource_${caseSensitiveIdFragment(`${sourcePath ?? 'memory'}:${match.start}:${match.end}:${match.name}`)}`,
69
+ kind: 'resource-management',
70
+ language,
71
+ sourcePath,
72
+ sourceHash,
73
+ ownerId: owner?.id,
74
+ ownerName: owner?.name ?? '(module)',
75
+ ownerKind: owner?.kind ?? 'module',
76
+ nativeAstNodeId: owner?.nativeAstNodeId,
77
+ scopeId: scope.id,
78
+ scopeStartLine: scope.startLine,
79
+ scopeExitLine: scope.endLine,
80
+ scopeStartColumn: scope.startColumn,
81
+ scopeExitColumn: scope.endColumn,
82
+ runtimeKinds: uniqueStrings(['resource-management', match.awaitUsing ? 'await-using' : 'using'])
83
+ };
84
+ });
85
+ return assignResourceOrder(rawDeclarations);
86
+ }
87
+
88
+ function resourceManagementRegionRecord(imported, declaration, index, options = {}) {
89
+ const key = [options.regionPrefix ?? 'source', declaration.sourcePath ?? 'memory', 'effect', `${declaration.ownerName}:resource-management:${declaration.name}#${declaration.ordinal}`].join('#');
90
+ const runtimeOrderEvidence = resourceManagementRuntimeOrderEvidence(declaration);
91
+ const signatureHash = hashSemanticValue({ kind: 'frontier.lang.resourceManagementRegionSignature', runtimeOrderEvidence });
92
+ const symbolName = `${declaration.ownerName}:effect:resource-management#${declaration.ordinal}`;
93
+ const region = {
94
+ id: `region_${caseSensitiveIdFragment(key)}`,
95
+ key,
96
+ regionKind: 'effect',
97
+ granularity: 'resource-management-declaration',
98
+ language: declaration.language,
99
+ sourcePath: declaration.sourcePath,
100
+ sourceHash: declaration.sourceHash,
101
+ symbolId: `symbol:${declaration.language ?? 'source'}:resource-management:${idFragment(key)}`,
102
+ symbolName,
103
+ symbolKind: 'effect',
104
+ nativeAstNodeId: declaration.nativeAstNodeId,
105
+ sourceSpan: sourceSpanForDeclaration(declaration, imported),
106
+ precision: 'line',
107
+ mergePolicy: 'effect-boundary-review-required',
108
+ metadata: {
109
+ semanticRegionTaxonomy: true,
110
+ factKinds: declaration.runtimeKinds,
111
+ factLine: declaration.line,
112
+ predicate: 'effect',
113
+ spanKind: 'resource-management-declaration',
114
+ runtimeOrderEvidence,
115
+ occurrenceOrdinal: declaration.ordinal,
116
+ subjectId: declaration.ownerId,
117
+ subjectName: declaration.ownerName,
118
+ resourceManagementDeclaration: compactRecord({
119
+ name: declaration.name,
120
+ awaitUsing: declaration.awaitUsing || undefined,
121
+ initializerText: declaration.initializerText,
122
+ declarationText: declaration.declarationText,
123
+ scopeExitLine: declaration.scopeExitLine
124
+ })
125
+ }
126
+ };
127
+ return {
128
+ region,
129
+ symbol: {
130
+ id: region.symbolId,
131
+ name: symbolName,
132
+ kind: 'effect',
133
+ language: declaration.language,
134
+ nativeAstNodeId: declaration.nativeAstNodeId,
135
+ sourceSpan: region.sourceSpan,
136
+ signatureHash,
137
+ ownershipRegionId: region.id,
138
+ ownershipKey: region.key,
139
+ ownershipRegionKind: 'effect',
140
+ readiness: 'needs-review'
141
+ }
142
+ };
143
+ }
144
+
145
+ function resourceManagementRuntimeOrderEvidence(declaration) {
146
+ return {
147
+ schema: 'frontier.lang.runtimeOrderEvidence.v1',
148
+ source: 'lexical-source-scan',
149
+ subjectId: declaration.ownerId,
150
+ regionKind: 'effect',
151
+ runtimeKinds: declaration.runtimeKinds,
152
+ line: declaration.line,
153
+ resourceManagementOrder: declaration.scopeDeclarations.map((item) => compactRecord({
154
+ kind: 'resource-management',
155
+ name: item.name,
156
+ declarationKind: item.awaitUsing ? 'await-using' : 'using',
157
+ awaitUsing: item.awaitUsing || undefined,
158
+ line: item.line,
159
+ column: item.column,
160
+ acquisitionOrderIndex: item.acquisitionOrderIndex,
161
+ disposalOrderIndex: item.disposalOrderIndex,
162
+ disposalOrder: 'reverse-lexical-scope',
163
+ scopeStartLine: item.scopeStartLine,
164
+ scopeExitLine: item.scopeExitLine,
165
+ declarationText: item.declarationText,
166
+ initializerText: item.initializerText,
167
+ focusedDeclaration: item.id === declaration.id || undefined,
168
+ disposalMethodPolicy: item.awaitUsing ? 'Symbol.asyncDispose-or-Symbol.dispose' : 'Symbol.dispose',
169
+ staticResourceManagementEvidence: true,
170
+ runtimeEquivalenceClaim: false,
171
+ disposalEffectEquivalenceClaim: false,
172
+ semanticEquivalenceClaim: false
173
+ }))
174
+ };
175
+ }
176
+
177
+ function usingDeclarationMatches(sourceText, masked, lineStarts) {
178
+ const pattern = /(^|[^\w$])(?:(await)\s+)?using\s+([A-Za-z_$][\w$]*)\s*(?::[^=;\n]+)?=\s*/g;
179
+ const records = [];
180
+ for (const match of masked.matchAll(pattern)) {
181
+ const start = match.index + match[1].length;
182
+ const initializerStart = match.index + match[0].length;
183
+ const end = statementEnd(masked, initializerStart);
184
+ const location = lineColumnAt(lineStarts, start);
185
+ records.push({
186
+ start,
187
+ end,
188
+ line: location.line,
189
+ column: location.column,
190
+ name: match[3],
191
+ awaitUsing: Boolean(match[2]),
192
+ declarationText: normalizeText(sourceText.slice(start, end)),
193
+ initializerText: normalizeText(sourceText.slice(initializerStart, end).replace(/;\s*$/, ''))
194
+ });
195
+ }
196
+ return records;
197
+ }
198
+
199
+ function assignResourceOrder(declarations) {
200
+ const byScope = new Map();
201
+ for (const declaration of declarations) {
202
+ const group = byScope.get(declaration.scopeId) ?? [];
203
+ group.push(declaration);
204
+ byScope.set(declaration.scopeId, group);
205
+ }
206
+ for (const group of byScope.values()) {
207
+ group.sort((left, right) => left.start - right.start);
208
+ group.forEach((declaration, index) => {
209
+ declaration.acquisitionOrderIndex = index + 1;
210
+ declaration.disposalOrderIndex = group.length - index;
211
+ declaration.ordinal = index + 1;
212
+ declaration.scopeDeclarations = group;
213
+ });
214
+ }
215
+ return declarations;
216
+ }
217
+
218
+ function ownerSymbolFor(symbols, sourcePath, line) {
219
+ return symbols
220
+ .filter((symbol) => symbol?.definitionSpan?.path === sourcePath || !sourcePath)
221
+ .filter((symbol) => symbol?.definitionSpan?.startLine <= line && symbol?.definitionSpan?.endLine >= line)
222
+ .filter((symbol) => symbol?.metadata?.ownershipRegionKind === 'body' || /function|method|constructor|class/.test(String(symbol.kind ?? '').toLowerCase()))
223
+ .sort((left, right) => spanSize(left.definitionSpan) - spanSize(right.definitionSpan))[0];
224
+ }
225
+
226
+ function braceScopes(masked, lineStarts) {
227
+ const scopes = [];
228
+ const stack = [];
229
+ for (let index = 0; index < masked.length; index += 1) {
230
+ const char = masked[index];
231
+ if (char === '{') {
232
+ const location = lineColumnAt(lineStarts, index);
233
+ stack.push({ start: index, startLine: location.line, startColumn: location.column });
234
+ } else if (char === '}' && stack.length) {
235
+ const open = stack.pop();
236
+ const location = lineColumnAt(lineStarts, index);
237
+ scopes.push({ ...open, end: index, endLine: location.line, endColumn: location.column, id: `scope:${open.start}:${index}` });
238
+ }
239
+ }
240
+ return scopes;
241
+ }
242
+
243
+ function innermostScopeFor(scopes, offset) {
244
+ return scopes
245
+ .filter((scope) => scope.start < offset && scope.end > offset)
246
+ .sort((left, right) => (left.end - left.start) - (right.end - right.start))[0];
247
+ }
248
+
249
+ function moduleScope(sourceText, lineStarts) {
250
+ return { id: 'scope:module', startLine: 1, startColumn: 1, endLine: lineStarts.length, endColumn: String(sourceText).length - lineStarts[lineStarts.length - 1] + 1 };
251
+ }
252
+
253
+ function sourceSpanForDeclaration(declaration, imported) {
254
+ return {
255
+ sourceId: declaration.sourceHash,
256
+ path: declaration.sourcePath ?? imported?.sourcePath ?? imported?.nativeSource?.sourcePath,
257
+ startLine: declaration.line,
258
+ endLine: declaration.line,
259
+ startColumn: declaration.column,
260
+ endColumn: declaration.column + Math.max(1, declaration.declarationText.length)
261
+ };
262
+ }
263
+
264
+ function lineStartsFor(sourceText) {
265
+ const starts = [0];
266
+ for (let index = 0; index < sourceText.length; index += 1) if (sourceText[index] === '\n') starts.push(index + 1);
267
+ return starts;
268
+ }
269
+
270
+ function lineColumnAt(lineStarts, offset) {
271
+ let lineIndex = 0;
272
+ while (lineIndex + 1 < lineStarts.length && lineStarts[lineIndex + 1] <= offset) lineIndex += 1;
273
+ return { line: lineIndex + 1, column: offset - lineStarts[lineIndex] + 1 };
274
+ }
275
+
276
+ function statementEnd(masked, start) {
277
+ for (let index = start, depth = 0; index < masked.length; index += 1) {
278
+ const char = masked[index];
279
+ if (char === '(' || char === '[' || char === '{') depth += 1;
280
+ else if (char === ')' || char === ']' || char === '}') depth = Math.max(0, depth - 1);
281
+ else if (char === ';' && depth === 0) return index + 1;
282
+ else if ((char === '\n' || char === '\r') && depth === 0) return index;
283
+ }
284
+ return masked.length;
285
+ }
286
+
287
+ function runtimePublicKey(sourcePath, symbolName) { return sourcePath && symbolName ? `${sourcePath}\0${symbolName}` : undefined; }
288
+ function nativeImportSourceText(imported) { return imported?.metadata?.sourcePreservation?.sourceText ?? imported?.nativeSource?.metadata?.sourcePreservation?.sourceText ?? imported?.nativeAst?.metadata?.sourcePreservation?.sourceText ?? imported?.universalAst?.metadata?.sourcePreservation?.sourceText ?? imported?.sourceText; }
289
+ function spanSize(span) { return Math.max(0, Number(span?.endLine ?? 0) - Number(span?.startLine ?? 0)); }
290
+ function normalizeText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
291
+ function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
292
+
293
+ export { resourceManagementRecordsForImport, resourceManagementRuntimeRegionRecordsForImport };
@@ -0,0 +1,304 @@
1
+ function switchDispatchOrderEvidence(lines, lineNumber) {
2
+ if (!Array.isArray(lines) || !Number.isFinite(Number(lineNumber))) return [];
3
+ const stack = [];
4
+ let pendingSwitch;
5
+ let depth = 0;
6
+ for (let index = 0; index < lineNumber; index += 1) {
7
+ const line = String(lines[index] ?? '');
8
+ const leadingClose = leadingCloseBraceCount(line);
9
+ if (leadingClose) {
10
+ depth = Math.max(0, depth - leadingClose);
11
+ while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
12
+ }
13
+ const opens = openBraceCount(line);
14
+ const closes = closeBraceCount(line) - leadingClose;
15
+ const switchHead = switchHeadRecord(line);
16
+ if (switchHead) {
17
+ pendingSwitch = undefined;
18
+ if (opens > 0) stack.push(switchContext(switchHead, index + 1, depth + 1));
19
+ else pendingSwitch = switchContext(switchHead, index + 1, depth + 1);
20
+ } else if (pendingSwitch && opens > 0) {
21
+ stack.push({ ...pendingSwitch, depth: depth + 1 });
22
+ pendingSwitch = undefined;
23
+ }
24
+ const current = stack[stack.length - 1];
25
+ const caseHead = caseHeadRecord(line);
26
+ if (current && caseHead) {
27
+ current.caseOrdinal = (current.caseOrdinal ?? 0) + 1;
28
+ const previous = current.currentCase;
29
+ const previousCompletion = current.currentCaseCompletion;
30
+ current.currentCase = { ...caseHead, line: index + 1, ordinal: current.caseOrdinal, previousCase: previous, previousCaseCompletionKind: previousCompletion, fallthroughFromPrevious: Boolean(previous && !previousCompletion) };
31
+ current.currentCaseCompletion = undefined;
32
+ }
33
+ if (index + 1 === Number(lineNumber)) return switchDispatchRecord(current);
34
+ if (current?.currentCase) current.currentCaseCompletion = current.currentCaseCompletion ?? caseCompletionKind(line);
35
+ depth = Math.max(0, depth + opens - Math.max(0, closes));
36
+ while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
37
+ }
38
+ return [];
39
+ }
40
+
41
+ function loopIterationOrderEvidence(lines, lineNumber) {
42
+ if (!Array.isArray(lines) || !Number.isFinite(Number(lineNumber))) return [];
43
+ const stack = [];
44
+ let pendingLoop;
45
+ let depth = 0;
46
+ for (let index = 0; index < lineNumber; index += 1) {
47
+ const line = String(lines[index] ?? '');
48
+ const leadingClose = leadingCloseBraceCount(line);
49
+ if (leadingClose) {
50
+ depth = Math.max(0, depth - leadingClose);
51
+ while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
52
+ }
53
+ const opens = openBraceCount(line);
54
+ const closes = closeBraceCount(line) - leadingClose;
55
+ const loopHead = loopHeadRecord(line);
56
+ if (loopHead) {
57
+ pendingLoop = undefined;
58
+ if (opens > 0) stack.push(loopContext(loopHead, index + 1, depth + 1));
59
+ else pendingLoop = loopContext(loopHead, index + 1, depth + 1);
60
+ } else if (pendingLoop && opens > 0) {
61
+ stack.push({ ...pendingLoop, depth: depth + 1 });
62
+ pendingLoop = undefined;
63
+ }
64
+ if (index + 1 === Number(lineNumber)) return loopIterationRecord(stack[stack.length - 1]);
65
+ depth = Math.max(0, depth + opens - Math.max(0, closes));
66
+ while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
67
+ }
68
+ return [];
69
+ }
70
+
71
+ function controlTransferOrderEvidence(lines, lineNumber) {
72
+ if (!Array.isArray(lines) || !Number.isFinite(Number(lineNumber))) return [];
73
+ const number = Number(lineNumber);
74
+ const record = controlTransferRecord(String(lines[number - 1] ?? ''), number);
75
+ const target = record?.labelText ? labelTargetEvidence(lines, number, record.labelText) : undefined;
76
+ if (record && target) return [{ ...record, ...target }];
77
+ return record ? [record] : [];
78
+ }
79
+
80
+ function switchContext(head, line, depth) {
81
+ return { line, depth, text: head.text, discriminantText: head.discriminantText, caseOrdinal: 0 };
82
+ }
83
+
84
+ function loopContext(head, line, depth) {
85
+ return { line, depth, ...head };
86
+ }
87
+
88
+ function switchDispatchRecord(current) {
89
+ if (!current) return [];
90
+ return [compactRecord({
91
+ kind: 'switch-dispatch',
92
+ switchLine: current.line,
93
+ switchText: current.text,
94
+ discriminantText: current.discriminantText,
95
+ caseLine: current.currentCase?.line,
96
+ caseText: current.currentCase?.text,
97
+ caseKind: current.currentCase?.kind,
98
+ caseOrdinal: current.currentCase?.ordinal,
99
+ previousCaseLine: current.currentCase?.previousCase?.line,
100
+ previousCaseText: current.currentCase?.previousCase?.text,
101
+ previousCaseKind: current.currentCase?.previousCase?.kind,
102
+ previousCaseOrdinal: current.currentCase?.previousCase?.ordinal,
103
+ previousCaseCompletionKind: current.currentCase?.previousCaseCompletionKind,
104
+ fallthroughFromPrevious: current.currentCase?.fallthroughFromPrevious || undefined
105
+ })];
106
+ }
107
+
108
+ function loopIterationRecord(current) {
109
+ if (!current) return [];
110
+ return [compactRecord({
111
+ kind: 'loop-iteration',
112
+ loopKind: current.loopKind,
113
+ loopLine: current.line,
114
+ loopText: current.text,
115
+ iteratorText: current.iteratorText,
116
+ iterableText: current.iterableText,
117
+ initializerText: current.initializerText,
118
+ conditionText: current.conditionText,
119
+ updateText: current.updateText
120
+ })];
121
+ }
122
+
123
+ function controlTransferRecord(line, lineNumber) {
124
+ const match = /\b(break|continue)\b\s*([A-Za-z_$][\w$]*)?/.exec(String(line ?? ''));
125
+ if (!match) return undefined;
126
+ return compactRecord({
127
+ kind: 'control-transfer',
128
+ transferKind: match[1],
129
+ line: lineNumber,
130
+ labelText: match[2],
131
+ text: normalizeOrderEvidenceText(line.slice(match.index, statementEnd(line, match.index)))
132
+ });
133
+ }
134
+
135
+ function labelTargetEvidence(lines, lineNumber, labelText) {
136
+ const stack = [];
137
+ let depth = 0;
138
+ for (let index = 0; index < lineNumber - 1; index += 1) {
139
+ const line = String(lines[index] ?? '');
140
+ const leadingClose = leadingCloseBraceCount(line);
141
+ if (leadingClose) {
142
+ depth = Math.max(0, depth - leadingClose);
143
+ while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
144
+ }
145
+ const label = labelRecord(lines, index, depth);
146
+ if (label) stack.push(label);
147
+ depth = Math.max(0, depth + openBraceCount(line) - Math.max(0, closeBraceCount(line) - leadingClose));
148
+ while (stack.length && stack[stack.length - 1].depth > depth) stack.pop();
149
+ }
150
+ const current = [...stack].reverse().find((record) => record.labelText === labelText);
151
+ return current ? compactRecord({
152
+ labelLine: current.labelLine,
153
+ labelTargetLine: current.labelTargetLine,
154
+ labelTargetKind: current.labelTargetKind,
155
+ labelTargetText: current.labelTargetText
156
+ }) : undefined;
157
+ }
158
+
159
+ function labelRecord(lines, index, depth) {
160
+ const line = String(lines[index] ?? '');
161
+ const match = /^\s*([A-Za-z_$][\w$]*)\s*:\s*(.*)$/.exec(line);
162
+ if (!match || match[1] === 'case' || match[1] === 'default') return undefined;
163
+ const sameLineTarget = normalizeOrderEvidenceText(match[2]);
164
+ const next = sameLineTarget ? { line: index + 1, text: sameLineTarget } : nextNonEmptyLine(lines, index + 1);
165
+ if (!next?.text) return undefined;
166
+ return compactRecord({
167
+ labelText: match[1],
168
+ labelLine: index + 1,
169
+ labelTargetLine: next.line,
170
+ labelTargetKind: labelTargetKind(next.text),
171
+ labelTargetText: labelTargetText(next.text),
172
+ depth: depth + Math.max(1, openBraceCount(next.text))
173
+ });
174
+ }
175
+
176
+ function nextNonEmptyLine(lines, start) {
177
+ for (let index = start; index < lines.length; index += 1) {
178
+ const text = normalizeOrderEvidenceText(lines[index]);
179
+ if (text) return { line: index + 1, text };
180
+ }
181
+ return undefined;
182
+ }
183
+
184
+ function labelTargetKind(text) {
185
+ if (loopHeadRecord(text)) return 'loop';
186
+ if (switchHeadRecord(text)) return 'switch';
187
+ if (/^\{/.test(String(text ?? ''))) return 'block';
188
+ return 'statement';
189
+ }
190
+
191
+ function labelTargetText(text) {
192
+ return loopHeadRecord(text)?.text ?? switchHeadRecord(text)?.text ?? normalizeOrderEvidenceText(text);
193
+ }
194
+
195
+ function switchHeadRecord(line) {
196
+ for (const match of String(line ?? '').matchAll(/\bswitch\b/g)) {
197
+ const open = line.indexOf('(', match.index);
198
+ const close = matchingParenIndex(line, open);
199
+ if (open >= 0 && close !== undefined) return {
200
+ text: normalizeOrderEvidenceText(line.slice(match.index, close + 1)),
201
+ discriminantText: normalizeOrderEvidenceText(line.slice(open + 1, close))
202
+ };
203
+ }
204
+ return undefined;
205
+ }
206
+
207
+ function loopHeadRecord(line) {
208
+ return parenthesizedLoopHead(line, /\bfor\s+await\b/g, 'for-await')
209
+ ?? parenthesizedLoopHead(line, /\bfor\b/g, 'for')
210
+ ?? parenthesizedLoopHead(line, /\bwhile\b/g, 'while')
211
+ ?? doLoopHead(line);
212
+ }
213
+
214
+ function parenthesizedLoopHead(line, pattern, keywordKind) {
215
+ for (const match of String(line ?? '').matchAll(pattern)) {
216
+ const open = line.indexOf('(', match.index);
217
+ const close = matchingParenIndex(line, open);
218
+ if (open < 0 || close === undefined) continue;
219
+ const headerText = normalizeOrderEvidenceText(line.slice(open + 1, close));
220
+ const text = normalizeOrderEvidenceText(line.slice(match.index, close + 1));
221
+ if (keywordKind === 'while') return { loopKind: 'while', text, conditionText: headerText };
222
+ return forLoopHeaderRecord(keywordKind, text, headerText);
223
+ }
224
+ return undefined;
225
+ }
226
+
227
+ function forLoopHeaderRecord(keywordKind, text, headerText) {
228
+ const ofMatch = headerText.match(/^(.*?)\s+of\s+(.+)$/);
229
+ if (ofMatch) return { loopKind: keywordKind === 'for-await' ? 'for-await-of' : 'for-of', text, iteratorText: normalizeOrderEvidenceText(ofMatch[1]), iterableText: normalizeOrderEvidenceText(ofMatch[2]) };
230
+ const inMatch = headerText.match(/^(.*?)\s+in\s+(.+)$/);
231
+ if (inMatch) return { loopKind: 'for-in', text, iteratorText: normalizeOrderEvidenceText(inMatch[1]), iterableText: normalizeOrderEvidenceText(inMatch[2]) };
232
+ const parts = headerText.split(';').map(normalizeOrderEvidenceText);
233
+ return { loopKind: keywordKind, text, initializerText: parts[0], conditionText: parts[1], updateText: parts[2] };
234
+ }
235
+
236
+ function doLoopHead(line) {
237
+ const match = /\bdo\b/.exec(String(line ?? ''));
238
+ return match ? { loopKind: 'do', text: 'do' } : undefined;
239
+ }
240
+
241
+ function caseHeadRecord(line) {
242
+ const match = /\b(case|default)\b/.exec(String(line ?? ''));
243
+ if (!match) return undefined;
244
+ const colon = line.indexOf(':', match.index);
245
+ return {
246
+ kind: match[1] === 'default' ? 'default' : 'case',
247
+ text: normalizeOrderEvidenceText(line.slice(match.index, colon === -1 ? statementEnd(line, match.index) : colon + 1))
248
+ };
249
+ }
250
+
251
+ function caseCompletionKind(line) {
252
+ const text = String(line ?? '');
253
+ if (/\bbreak\b/.test(text)) return 'break';
254
+ if (/\bcontinue\b/.test(text)) return 'continue';
255
+ if (/\breturn\b/.test(text)) return 'return';
256
+ if (/\bthrow\b/.test(text)) return 'throw';
257
+ return undefined;
258
+ }
259
+
260
+ function leadingCloseBraceCount(line) { const match = String(line ?? '').match(/^\s*}+/); return match ? match[0].replace(/\s/g, '').length : 0; }
261
+ function openBraceCount(line) { return countCharsOutsideStrings(line, '{'); }
262
+ function closeBraceCount(line) { return countCharsOutsideStrings(line, '}'); }
263
+ function normalizeOrderEvidenceText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
264
+ function statementEnd(line, start) { const semicolon = String(line ?? '').indexOf(';', start); return semicolon === -1 ? String(line ?? '').length : semicolon + 1; }
265
+ function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
266
+
267
+ function countCharsOutsideStrings(line, target) {
268
+ let count = 0;
269
+ let quote;
270
+ let escaped = false;
271
+ for (const char of String(line ?? '')) {
272
+ if (quote) {
273
+ if (escaped) escaped = false;
274
+ else if (char === '\\') escaped = true;
275
+ else if (char === quote) quote = undefined;
276
+ continue;
277
+ }
278
+ if (char === '\'' || char === '"' || char === '`') { quote = char; continue; }
279
+ if (char === target) count += 1;
280
+ }
281
+ return count;
282
+ }
283
+
284
+ function matchingParenIndex(line, open) {
285
+ if (open < 0) return undefined;
286
+ let depth = 0;
287
+ let quote;
288
+ let escaped = false;
289
+ for (let index = open; index < line.length; index += 1) {
290
+ const char = line[index];
291
+ if (quote) {
292
+ if (escaped) escaped = false;
293
+ else if (char === '\\') escaped = true;
294
+ else if (char === quote) quote = undefined;
295
+ continue;
296
+ }
297
+ if (char === '\'' || char === '"' || char === '`') { quote = char; continue; }
298
+ if (char === '(') depth += 1;
299
+ else if (char === ')' && --depth === 0) return index;
300
+ }
301
+ return undefined;
302
+ }
303
+
304
+ export { controlTransferOrderEvidence, loopIterationOrderEvidence, switchDispatchOrderEvidence };
@@ -0,0 +1,44 @@
1
+ function throwOrderEvidenceRecords(line, start, end) {
2
+ const text = String(line ?? '');
3
+ const index = throwTokenIndex(text, Math.max(0, Math.min(start, end)));
4
+ if (index < 0) return [];
5
+ const statementEndIndex = statementEnd(text, index);
6
+ const expressionStart = index + 'throw'.length;
7
+ const expressionText = normalizeOrderEvidenceText(text.slice(expressionStart, statementEndIndex).replace(/;$/, ''));
8
+ return [compactRecord({
9
+ kind: 'throw',
10
+ text: normalizeOrderEvidenceText(text.slice(index, statementEndIndex)),
11
+ expressionText,
12
+ throwColumn: index + 1,
13
+ regionWithinThrow: start >= index && start <= statementEndIndex || undefined
14
+ })];
15
+ }
16
+
17
+ function throwTokenIndex(text, beforeIndex) {
18
+ let quote;
19
+ let escaped = false;
20
+ let latest = -1;
21
+ for (let index = 0; index < text.length && index <= beforeIndex; index += 1) {
22
+ const char = text[index];
23
+ if (quote) {
24
+ if (escaped) escaped = false;
25
+ else if (char === '\\') escaped = true;
26
+ else if (char === quote) quote = undefined;
27
+ continue;
28
+ }
29
+ if (char === '\'' || char === '"' || char === '`') { quote = char; continue; }
30
+ if (text.slice(index, index + 5) === 'throw' && !isIdentifierPart(text[index - 1]) && !isIdentifierPart(text[index + 5])) latest = index;
31
+ }
32
+ return latest;
33
+ }
34
+
35
+ function statementEnd(text, start) {
36
+ const semicolon = String(text ?? '').indexOf(';', Math.max(0, start));
37
+ return semicolon === -1 ? String(text ?? '').length : semicolon + 1;
38
+ }
39
+
40
+ function normalizeOrderEvidenceText(value) { return String(value ?? '').replace(/\s+/g, ' ').trim(); }
41
+ function isIdentifierPart(char) { return /[A-Za-z0-9_$]/.test(char ?? ''); }
42
+ function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && value !== '')); }
43
+
44
+ export { throwOrderEvidenceRecords };