@shapeshift-labs/frontier-lang-compiler 0.2.149 → 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.
- package/README.md +315 -9
- package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
- package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
- package/bench/real-repo-corpus-command-execution.mjs +314 -0
- package/bench/real-repo-corpus-evidence.mjs +165 -0
- package/bench/real-repo-corpus-suite.mjs +273 -0
- package/bench/smoke.mjs +109 -7
- package/dist/declarations/import-adapter-core.d.ts +4 -3
- package/dist/declarations/import-adapter-options-native.d.ts +21 -0
- package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
- package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
- package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
- package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
- package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
- package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
- package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
- package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
- package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
- package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
- package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
- package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
- package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
- package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
- package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
- package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
- package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
- package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
- package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
- package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
- package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
- package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
- package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
- package/dist/declarations/native-project-css-modules.d.ts +90 -0
- package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
- package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
- package/dist/declarations/native-project-module-declarations.d.ts +52 -0
- package/dist/declarations/native-project-module-resolution.d.ts +76 -1
- package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
- package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
- package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
- package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
- package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
- package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
- package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
- package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
- package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
- package/dist/declarations/native-project-source-evidence.d.ts +8 -0
- package/dist/declarations/native-project.d.ts +40 -39
- package/dist/declarations/semantic-edit-script.d.ts +10 -8
- package/dist/declarations/semantic-graph-layers.d.ts +79 -0
- package/dist/declarations/semantic-patch-bundle-composition.d.ts +62 -0
- package/dist/declarations/semantic-sidecar.d.ts +3 -2
- package/dist/declarations/semantic-structural-diff.d.ts +94 -0
- package/dist/declarations/source-preservation.d.ts +32 -1
- package/dist/declarations/target-adapters.d.ts +22 -2
- package/dist/index.d.ts +32 -0
- package/dist/index.js +6 -0
- package/dist/internal/index-impl/compileNativeSource.js +53 -5
- package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
- package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
- package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
- package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
- package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
- package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
- package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
- package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
- package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
- package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
- package/dist/internal/index-impl/importNativeSource.js +2 -3
- package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
- package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
- package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
- package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
- package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
- package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
- package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
- package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
- package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
- package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
- package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
- package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
- package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
- package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
- package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
- package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
- package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
- package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
- package/dist/internal/index-impl/semanticEditScripts.js +42 -5
- package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
- package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
- package/dist/internal/index-impl/semanticPatchBundleComposition.js +166 -0
- package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
- package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
- package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
- package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
- package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
- package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
- package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
- package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
- package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
- package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
- package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
- package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
- package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
- package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
- package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
- package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
- package/dist/js-ts-safe-member-class-invariants.js +247 -0
- package/dist/js-ts-safe-member-merge-result.js +23 -3
- package/dist/js-ts-safe-member-merge.js +28 -4
- package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
- package/dist/js-ts-safe-merge-context.js +1 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +314 -0
- package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
- package/dist/js-ts-safe-merge-parse-statements.js +8 -0
- package/dist/js-ts-safe-merge-plan.js +3 -1
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +49 -0
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +5 -1
- package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
- package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
- package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
- package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
- package/dist/js-ts-safe-merge.js +136 -0
- package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
- package/dist/js-ts-safe-project-merge-admission.js +161 -0
- package/dist/js-ts-safe-project-merge-ambient.js +110 -0
- package/dist/js-ts-safe-project-merge-core.js +85 -0
- package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
- package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
- package/dist/js-ts-safe-project-merge-declarations.js +227 -0
- package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
- package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
- package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
- package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
- package/dist/js-ts-safe-project-merge-files.js +70 -0
- package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
- package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
- package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
- package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
- package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
- package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
- package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
- package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
- package/dist/js-ts-safe-project-merge-graph.js +37 -5
- package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
- package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
- package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
- package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
- package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
- package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
- package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
- package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
- package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
- package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
- package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
- package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
- package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
- package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
- package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
- package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
- package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
- package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
- package/dist/js-ts-safe-project-merge-summary.js +320 -0
- package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
- package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
- package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
- package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
- package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
- package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
- package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
- package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
- package/dist/js-ts-safe-project-merge.js +171 -172
- package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
- package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
- package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
- package/dist/js-ts-semantic-scope-use-def.js +217 -0
- package/dist/lightweight-dependency-effects.js +28 -4
- package/dist/lightweight-dependency-relations.js +13 -7
- package/dist/lightweight-dependency-top-level.js +63 -0
- package/dist/native-import-language-profiles.js +27 -1
- package/dist/native-js-ts-importers.js +9 -5
- package/dist/native-parser-ast-format-profiles.js +12 -0
- package/dist/native-parser-html-css-format-profiles.js +85 -0
- package/dist/native-region-scanner-core.js +5 -3
- package/dist/native-region-scanner-js-commonjs.js +155 -0
- package/dist/native-region-scanner-js-imports.js +51 -13
- package/dist/native-region-scanner-js-reexports.js +79 -0
- package/dist/native-region-scanner-js-ts-helpers.js +23 -0
- package/dist/native-source-ledger-helpers.js +1 -1
- package/dist/native-source-ledger.js +24 -10
- package/dist/native-source-maps-ecma426.js +316 -0
- package/dist/native-source-maps.js +36 -6
- package/dist/native-source-preservation-ownership.js +292 -0
- package/dist/native-source-preservation-scanner.js +63 -25
- package/dist/native-source-preservation-types.d.ts +3 -0
- package/dist/semantic-import-effect-occurrences.js +242 -0
- package/dist/semantic-import-effect-regions.js +95 -58
- package/dist/semantic-import-graph-layers.js +224 -0
- package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
- package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
- package/dist/semantic-import-runtime-exit-evidence.js +32 -0
- package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
- package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
- package/dist/semantic-import-runtime-order-evidence.js +318 -0
- package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
- package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
- package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
- package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
- package/dist/semantic-import-runtime-switch-evidence.js +304 -0
- package/dist/semantic-import-runtime-throw-evidence.js +44 -0
- package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
- package/dist/semantic-import-sidecar-entry.js +4 -0
- package/dist/semantic-import-source-preservation.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { uniqueStrings } from '../../native-import-utils.js';
|
|
3
|
+
|
|
4
|
+
const WRAPPER_CALL = /(?<![\w$.])((?:React\s*\.\s*)?(?:memo|forwardRef|observer|lazy))\s*(?:<[^(){};]*>)?\s*\(/g;
|
|
5
|
+
|
|
6
|
+
function jsxComponentWrapperRecords(ownerSourceText, ownerName) {
|
|
7
|
+
const text = String(ownerSourceText ?? '');
|
|
8
|
+
const records = [];
|
|
9
|
+
for (const match of text.matchAll(WRAPPER_CALL)) {
|
|
10
|
+
const callStart = match.index;
|
|
11
|
+
if (braceDepthBefore(text, callStart) > 0) continue;
|
|
12
|
+
const calleeText = normalizedCalleeText(match[1]);
|
|
13
|
+
const wrapperName = calleeText.split('.').pop();
|
|
14
|
+
const afterCall = text.slice(callStart + match[0].length);
|
|
15
|
+
const argumentKind = wrapperArgumentKind(afterCall);
|
|
16
|
+
const innerComponentName = wrapperInnerComponentName(afterCall) ?? ownerName;
|
|
17
|
+
const lazyImportSpecifier = wrapperName === 'lazy' ? lazyImportSpecifierText(afterCall) : undefined;
|
|
18
|
+
const wrapperExpressionText = normalizedText(text.slice(callStart, callExpressionPreviewEnd(text, callStart)));
|
|
19
|
+
records.push(compactRecord({
|
|
20
|
+
ordinal: records.length + 1,
|
|
21
|
+
proofStatus: 'static-component-wrapper-evidence',
|
|
22
|
+
reasonCode: 'jsx-render-component-wrapper-static-evidence',
|
|
23
|
+
wrapperName,
|
|
24
|
+
wrapperCalleeText: calleeText,
|
|
25
|
+
wrapperExpressionText,
|
|
26
|
+
wrapperArgumentKind: argumentKind,
|
|
27
|
+
innerComponentName,
|
|
28
|
+
ownerName,
|
|
29
|
+
lazyImportFactory: Boolean(lazyImportSpecifier) || undefined,
|
|
30
|
+
lazyImportSpecifier,
|
|
31
|
+
lazyLoadEquivalenceClaim: wrapperName === 'lazy' ? false : undefined,
|
|
32
|
+
renderEquivalenceClaim: false,
|
|
33
|
+
runtimeEquivalenceClaim: false,
|
|
34
|
+
wrapperExpressionHash: hashSemanticValue({
|
|
35
|
+
kind: 'frontier.lang.projectJsxComponentWrapperExpression',
|
|
36
|
+
ownerName,
|
|
37
|
+
calleeText,
|
|
38
|
+
wrapperExpressionText
|
|
39
|
+
}),
|
|
40
|
+
signatureHash: hashSemanticValue({
|
|
41
|
+
kind: 'frontier.lang.projectJsxComponentWrapper',
|
|
42
|
+
ownerName,
|
|
43
|
+
ordinal: records.length + 1,
|
|
44
|
+
wrapperName,
|
|
45
|
+
calleeText,
|
|
46
|
+
argumentKind,
|
|
47
|
+
innerComponentName
|
|
48
|
+
})
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
return records;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function jsxComponentWrapperRenderRiskEvidence(owner) {
|
|
55
|
+
const records = Array.isArray(owner?.componentWrapperRecords) ? owner.componentWrapperRecords : [];
|
|
56
|
+
if (!records.length) return {};
|
|
57
|
+
const componentWrapperNames = uniqueStrings(records.map((record) => record.wrapperName));
|
|
58
|
+
const componentWrapperCalleeTexts = uniqueStrings(records.map((record) => record.wrapperCalleeText));
|
|
59
|
+
const lazyBoundaryCount = records.filter((record) => record.wrapperName === 'lazy').length;
|
|
60
|
+
return compactRecord({
|
|
61
|
+
renderRiskKinds: ['component-wrapper-boundary'],
|
|
62
|
+
renderRiskReasonCodes: uniqueStrings(['jsx-render-component-wrapper-static-evidence', 'jsx-render-component-wrapper-render-equivalence-unproved', lazyBoundaryCount ? 'jsx-render-component-wrapper-lazy-boundary-evidence' : undefined, lazyBoundaryCount ? 'jsx-render-component-wrapper-lazy-runtime-equivalence-unproved' : undefined]),
|
|
63
|
+
componentWrapperNames,
|
|
64
|
+
componentWrapperCalleeTexts,
|
|
65
|
+
componentWrapperRecords: records,
|
|
66
|
+
componentWrapperCount: records.length,
|
|
67
|
+
componentWrapperLazyBoundaryCount: lazyBoundaryCount || undefined,
|
|
68
|
+
componentWrapperRenderEquivalenceClaim: false,
|
|
69
|
+
componentWrapperLazyLoadEquivalenceClaim: lazyBoundaryCount ? false : undefined,
|
|
70
|
+
componentWrapperSignatureHash: hashSemanticValue({
|
|
71
|
+
kind: 'frontier.lang.projectJsxComponentWrappers',
|
|
72
|
+
publicOwnerName: owner?.name,
|
|
73
|
+
records
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function mergeJsxRenderRiskEvidence(primary = {}, secondary = {}, context = {}) {
|
|
79
|
+
if (!hasRenderRisk(secondary)) return primary;
|
|
80
|
+
const renderRiskKinds = uniqueStrings([...(primary.renderRiskKinds ?? []), ...(secondary.renderRiskKinds ?? [])]);
|
|
81
|
+
const renderRiskReasonCodes = uniqueStrings([...(primary.renderRiskReasonCodes ?? []), ...(secondary.renderRiskReasonCodes ?? [])]);
|
|
82
|
+
return compactRecord({
|
|
83
|
+
...primary,
|
|
84
|
+
...secondary,
|
|
85
|
+
renderRiskKinds,
|
|
86
|
+
renderRiskReasonCodes,
|
|
87
|
+
renderRiskSignatureHash: hashSemanticValue({
|
|
88
|
+
kind: 'frontier.lang.projectJsxRenderRiskSignature',
|
|
89
|
+
tagName: context.tagName,
|
|
90
|
+
tagKey: context.tagKey,
|
|
91
|
+
publicOwnerName: context.publicOwnerName,
|
|
92
|
+
baseRenderRiskSignatureHash: primary.renderRiskSignatureHash,
|
|
93
|
+
componentWrapperSignatureHash: secondary.componentWrapperSignatureHash,
|
|
94
|
+
renderRiskKinds,
|
|
95
|
+
renderRiskReasonCodes
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function hasRenderRisk(record) { return Array.isArray(record?.renderRiskKinds) && record.renderRiskKinds.length > 0; }
|
|
101
|
+
function normalizedCalleeText(text) { return String(text ?? '').replace(/\s+/g, '').replace('React.', 'React.'); }
|
|
102
|
+
function normalizedText(text) { return String(text ?? '').trim().replace(/\s+/g, ' '); }
|
|
103
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
104
|
+
|
|
105
|
+
function wrapperArgumentKind(text) {
|
|
106
|
+
const value = String(text ?? '').trim();
|
|
107
|
+
if (/^(?:async\s+)?function\b/.test(value)) return 'function-expression';
|
|
108
|
+
if (/^class\b/.test(value)) return 'class-expression';
|
|
109
|
+
if (lazyImportSpecifierText(value)) return 'lazy-import-factory';
|
|
110
|
+
if (/^(?:React\s*\.\s*)?(?:memo|forwardRef|observer|lazy)\s*(?:<[^(){};]*>)?\s*\(/.test(value)) return 'wrapper-call';
|
|
111
|
+
if (/^(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>/.test(value)) return 'arrow-function';
|
|
112
|
+
if (/^[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*/.test(value)) return 'reference';
|
|
113
|
+
return 'unknown';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function wrapperInnerComponentName(text) {
|
|
117
|
+
const preview = String(text ?? '').slice(0, 360);
|
|
118
|
+
return /\bfunction\s+([A-Za-z_$][\w$]*)\b/.exec(preview)?.[1]
|
|
119
|
+
?? /\bclass\s+([A-Za-z_$][\w$]*)\b/.exec(preview)?.[1];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function lazyImportSpecifierText(text) { return /^(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>\s*import\s*\(\s*(['"])([^'"]+)\1\s*\)/.exec(String(text ?? '').trim().slice(0, 260))?.[2]; }
|
|
123
|
+
|
|
124
|
+
function callExpressionPreviewEnd(text, start) {
|
|
125
|
+
const value = String(text ?? '');
|
|
126
|
+
const firstBody = value.indexOf('{', start);
|
|
127
|
+
const firstLine = value.indexOf('\n', start);
|
|
128
|
+
const candidates = [firstBody, firstLine, start + 180].filter((index) => index >= start);
|
|
129
|
+
return Math.min(...candidates, value.length);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function braceDepthBefore(text, offset) {
|
|
133
|
+
const value = String(text ?? '').slice(0, offset);
|
|
134
|
+
let depth = 0;
|
|
135
|
+
let quote;
|
|
136
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
137
|
+
const char = value[index];
|
|
138
|
+
if (quote) {
|
|
139
|
+
if (char === '\\') index += 1;
|
|
140
|
+
else if (char === quote) quote = undefined;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (char === '"' || char === "'" || char === '`') quote = char;
|
|
144
|
+
else if (char === '{') depth += 1;
|
|
145
|
+
else if (char === '}') depth = Math.max(0, depth - 1);
|
|
146
|
+
}
|
|
147
|
+
return depth;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { jsxComponentWrapperRecords, jsxComponentWrapperRenderRiskEvidence, mergeJsxRenderRiskEvidence };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { staticOptionalMemberReference } from './staticOptionalMemberReference.js';
|
|
2
|
+
|
|
3
|
+
function jsxContextTargetClassification(expressionText) {
|
|
4
|
+
const text = normalizedContextTargetText(expressionText);
|
|
5
|
+
if (!text) return undefined;
|
|
6
|
+
const optionalReference = staticOptionalMemberReference(text);
|
|
7
|
+
if (optionalReference) return staticOptionalContextTarget(optionalReference);
|
|
8
|
+
const reference = staticContextTargetReference(text);
|
|
9
|
+
if (reference) return staticContextTarget(reference);
|
|
10
|
+
return dynamicContextTarget(text);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function staticOptionalContextTarget(reference) {
|
|
14
|
+
return {
|
|
15
|
+
proofStatus: 'static-optional-context-target-evidence',
|
|
16
|
+
reasonCode: 'jsx-render-context-consumer-target-static-optional-reference-evidence',
|
|
17
|
+
contextName: reference.text,
|
|
18
|
+
contextTargetKind: 'optional-reference',
|
|
19
|
+
contextTargetReferenceRoot: reference.root,
|
|
20
|
+
contextTargetReferencePath: reference.path,
|
|
21
|
+
contextTargetReferenceMemberPath: reference.memberPath,
|
|
22
|
+
optionalReference: true,
|
|
23
|
+
optionalReferenceSegments: reference.optionalSegments,
|
|
24
|
+
optionalReferenceSegmentIndexes: reference.optionalSegmentIndexes,
|
|
25
|
+
optionalNullishBoundaryCount: reference.optionalSegmentIndexes.length
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function staticContextTarget(reference) {
|
|
30
|
+
return {
|
|
31
|
+
proofStatus: 'static-context-target-evidence',
|
|
32
|
+
reasonCode: 'jsx-render-context-consumer-target-static-evidence',
|
|
33
|
+
contextName: reference.text,
|
|
34
|
+
contextTargetKind: 'reference',
|
|
35
|
+
contextTargetReferenceRoot: reference.root,
|
|
36
|
+
contextTargetReferencePath: reference.path,
|
|
37
|
+
contextTargetReferenceMemberPath: reference.memberPath
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function dynamicContextTarget(text) {
|
|
42
|
+
const dynamicTargetKind = dynamicContextTargetKind(text);
|
|
43
|
+
return {
|
|
44
|
+
proofStatus: 'dynamic-context-target-unsupported',
|
|
45
|
+
reasonCode: 'jsx-render-context-consumer-target-unsupported',
|
|
46
|
+
contextTargetKind: 'dynamic-expression',
|
|
47
|
+
dynamicTarget: true,
|
|
48
|
+
dynamicTargetKind,
|
|
49
|
+
dynamicBlockerReasonCode: `jsx-render-context-consumer-target-${dynamicTargetKind}-unsupported`
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function staticContextTargetReference(text) {
|
|
54
|
+
const value = normalizedContextTargetText(text);
|
|
55
|
+
if (!/^(?:[A-Za-z_$][\w$]*\s*\.\s*)*[A-Za-z_$][\w$]*$/.test(value)) return undefined;
|
|
56
|
+
const normalized = value.replace(/\s+/g, '');
|
|
57
|
+
const path = normalized.split('.');
|
|
58
|
+
return { text: normalized, root: path[0], path, memberPath: path.slice(1) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function dynamicContextTargetKind(text) {
|
|
62
|
+
const value = normalizedContextTargetText(text);
|
|
63
|
+
if (/\[[\s\S]*\]/.test(value)) return 'computed-reference';
|
|
64
|
+
if (/\?\.\s*\(/.test(value) || /\b[A-Za-z_$][\w$]*(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)*\s*\(/.test(value)) return 'call-expression';
|
|
65
|
+
if (/\?\./.test(value)) return 'optional-reference';
|
|
66
|
+
return 'dynamic-expression';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function normalizedContextTargetText(text) { return String(text ?? '').trim().replace(/\s+/g, ' '); }
|
|
70
|
+
|
|
71
|
+
export { jsxContextTargetClassification };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { isJsxSpreadAttribute } from '../../js-ts-safe-merge-jsx-attribute-parser.js';
|
|
3
|
+
import { staticOptionalMemberReference } from './staticOptionalMemberReference.js';
|
|
4
|
+
|
|
5
|
+
function jsxContextProviderValueRecord(attributes = []) {
|
|
6
|
+
const attribute = attributes.find((candidate) => candidate.name === 'value' && !isJsxSpreadAttribute(candidate));
|
|
7
|
+
if (!attribute) return undefined;
|
|
8
|
+
const expressionText = normalizedJsxAttributeValueText(attribute.text);
|
|
9
|
+
const classification = jsxContextValueClassification(expressionText);
|
|
10
|
+
const referenceBindingHash = classification.referenceBinding ? hashSemanticValue({
|
|
11
|
+
kind: 'frontier.lang.projectJsxContextProviderValueReferenceBinding',
|
|
12
|
+
expressionText,
|
|
13
|
+
referenceText: classification.referenceBinding.text,
|
|
14
|
+
root: classification.referenceBinding.root,
|
|
15
|
+
memberPath: classification.referenceBinding.memberPath,
|
|
16
|
+
optionalReference: classification.referenceBinding.optionalReference,
|
|
17
|
+
optionalReferenceSegments: classification.referenceBinding.optionalSegments,
|
|
18
|
+
optionalReferenceSegmentIndexes: classification.referenceBinding.optionalSegmentIndexes
|
|
19
|
+
}) : undefined;
|
|
20
|
+
return compactRecord({
|
|
21
|
+
propName: 'value',
|
|
22
|
+
propKind: propKind(attribute),
|
|
23
|
+
proofStatus: classification.proofStatus,
|
|
24
|
+
reasonCode: classification.reasonCode,
|
|
25
|
+
literalValueKind: classification.literal?.kind,
|
|
26
|
+
literalValueText: classification.literal?.text,
|
|
27
|
+
staticValueKind: classification.staticValueKind,
|
|
28
|
+
staticValueText: classification.staticValueText,
|
|
29
|
+
staticReferenceRoot: classification.referenceBinding?.root,
|
|
30
|
+
staticReferencePath: classification.referenceBinding?.path,
|
|
31
|
+
staticReferenceMemberPath: classification.referenceBinding?.memberPath,
|
|
32
|
+
optionalReference: classification.referenceBinding?.optionalReference,
|
|
33
|
+
optionalReferenceSegments: classification.referenceBinding?.optionalSegments,
|
|
34
|
+
optionalReferenceSegmentIndexes: classification.referenceBinding?.optionalSegmentIndexes,
|
|
35
|
+
optionalNullishBoundaryCount: classification.referenceBinding?.optionalSegmentIndexes?.length,
|
|
36
|
+
referenceBindingStatus: classification.referenceBinding?.status,
|
|
37
|
+
referenceBindingScope: classification.referenceBinding?.scope,
|
|
38
|
+
referenceBindingHash,
|
|
39
|
+
dynamicValueKind: classification.dynamic?.kind,
|
|
40
|
+
dynamicValueText: classification.dynamic?.text,
|
|
41
|
+
dynamicBlockerReasonCode: classification.dynamic?.reasonCode,
|
|
42
|
+
expressionHash: hashSemanticValue({
|
|
43
|
+
kind: 'frontier.lang.projectJsxContextProviderValueExpression',
|
|
44
|
+
expressionText
|
|
45
|
+
}),
|
|
46
|
+
signatureHash: hashSemanticValue({
|
|
47
|
+
kind: 'frontier.lang.projectJsxContextProviderValue',
|
|
48
|
+
expressionText,
|
|
49
|
+
proofStatus: classification.proofStatus,
|
|
50
|
+
staticValueKind: classification.staticValueKind,
|
|
51
|
+
optionalNullishBoundaryCount: classification.referenceBinding?.optionalSegmentIndexes?.length,
|
|
52
|
+
referenceBindingHash,
|
|
53
|
+
dynamicValueKind: classification.dynamic?.kind,
|
|
54
|
+
dynamicBlockerReasonCode: classification.dynamic?.reasonCode
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function jsxContextProviderValueReasonCode(record) {
|
|
60
|
+
if (record.reasonCode) return record.reasonCode;
|
|
61
|
+
if (record.proofStatus === 'literal-context-value-evidence') return 'jsx-render-context-provider-value-literal-evidence';
|
|
62
|
+
if (record.proofStatus === 'static-reference-context-value-evidence') return 'jsx-render-context-provider-value-static-reference-evidence';
|
|
63
|
+
if (record.proofStatus === 'static-optional-reference-context-value-evidence') return 'jsx-render-context-provider-value-static-optional-reference-evidence';
|
|
64
|
+
if (record.proofStatus === 'static-data-context-value-evidence') return 'jsx-render-context-provider-value-static-data-evidence';
|
|
65
|
+
return 'jsx-render-context-provider-value-unsupported';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function jsxContextValueClassification(expressionText) {
|
|
69
|
+
const literal = jsxLiteralContextValue(expressionText);
|
|
70
|
+
if (literal) {
|
|
71
|
+
return {
|
|
72
|
+
proofStatus: 'literal-context-value-evidence',
|
|
73
|
+
reasonCode: 'jsx-render-context-provider-value-literal-evidence',
|
|
74
|
+
literal
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const expression = unwrapJsxExpression(expressionText);
|
|
78
|
+
const referenceBinding = staticReferenceBinding(expression);
|
|
79
|
+
if (referenceBinding) {
|
|
80
|
+
return {
|
|
81
|
+
proofStatus: 'static-reference-context-value-evidence',
|
|
82
|
+
reasonCode: 'jsx-render-context-provider-value-static-reference-evidence',
|
|
83
|
+
staticValueKind: 'reference',
|
|
84
|
+
staticValueText: referenceBinding.text,
|
|
85
|
+
referenceBinding
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const optionalReferenceBinding = staticOptionalReferenceBinding(expression);
|
|
89
|
+
if (optionalReferenceBinding) {
|
|
90
|
+
return {
|
|
91
|
+
proofStatus: 'static-optional-reference-context-value-evidence',
|
|
92
|
+
reasonCode: 'jsx-render-context-provider-value-static-optional-reference-evidence',
|
|
93
|
+
staticValueKind: 'optional-reference',
|
|
94
|
+
staticValueText: optionalReferenceBinding.text,
|
|
95
|
+
referenceBinding: optionalReferenceBinding
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const dataKind = staticDataExpressionKind(expression);
|
|
99
|
+
if (dataKind) {
|
|
100
|
+
return {
|
|
101
|
+
proofStatus: 'static-data-context-value-evidence',
|
|
102
|
+
reasonCode: 'jsx-render-context-provider-value-static-data-evidence',
|
|
103
|
+
staticValueKind: dataKind,
|
|
104
|
+
staticValueText: normalizedText(expression)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
proofStatus: 'dynamic-context-value-unsupported',
|
|
109
|
+
reasonCode: 'jsx-render-context-provider-value-unsupported',
|
|
110
|
+
dynamic: dynamicContextValueBlocker(expression)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function jsxLiteralContextValue(expressionText) {
|
|
115
|
+
const expression = unwrapJsxExpression(expressionText);
|
|
116
|
+
if (/^"(?:[^"\\]|\\.)*"$/.test(expression) || /^'(?:[^'\\]|\\.)*'$/.test(expression)) return { kind: 'string', text: expression };
|
|
117
|
+
if (/^(?:true|false)$/.test(expression)) return { kind: 'boolean', text: expression };
|
|
118
|
+
if (/^(?:null|undefined)$/.test(expression)) return { kind: expression, text: expression };
|
|
119
|
+
if (/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(expression)) return { kind: 'number', text: expression };
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function staticDataExpressionKind(expressionText) {
|
|
124
|
+
const expression = normalizedText(expressionText);
|
|
125
|
+
const kind = expression.startsWith('{') && expression.endsWith('}') ? 'object' : expression.startsWith('[') && expression.endsWith(']') ? 'array' : undefined;
|
|
126
|
+
if (!kind || !balancedDelimiters(expression)) return undefined;
|
|
127
|
+
if (/[();=]|=>|\.\.\.|\b(?:await|yield|new|function|class|import|require)\b/.test(expression)) return undefined;
|
|
128
|
+
if (!/^[\s{}\[\],:."'A-Za-z0-9_$-]+$/.test(expression)) return undefined;
|
|
129
|
+
return kind;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function staticReferenceBinding(expressionText) {
|
|
133
|
+
const expression = normalizedText(expressionText);
|
|
134
|
+
if (!/^(?:this|[A-Za-z_$][\w$]*)(?:\s*\.\s*[A-Za-z_$][\w$]*)*$/.test(expression)) return undefined;
|
|
135
|
+
const text = expression.replace(/\s+/g, '');
|
|
136
|
+
const path = text.split('.');
|
|
137
|
+
const [root, ...memberPath] = path;
|
|
138
|
+
return {
|
|
139
|
+
text,
|
|
140
|
+
root,
|
|
141
|
+
path,
|
|
142
|
+
memberPath,
|
|
143
|
+
status: 'static-reference-binding-evidence',
|
|
144
|
+
scope: 'jsx-context-provider-value-reference'
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function staticOptionalReferenceBinding(expressionText) {
|
|
149
|
+
const reference = staticOptionalMemberReference(expressionText);
|
|
150
|
+
return reference ? {
|
|
151
|
+
...reference,
|
|
152
|
+
optionalReference: true,
|
|
153
|
+
status: 'static-optional-reference-binding-evidence',
|
|
154
|
+
scope: 'jsx-context-provider-value-optional-reference'
|
|
155
|
+
} : undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function dynamicContextValueBlocker(expressionText) {
|
|
159
|
+
const text = normalizedText(expressionText);
|
|
160
|
+
if (!text) return dynamicBlocker('empty-expression', text);
|
|
161
|
+
if (/\.\.\./.test(text)) return dynamicBlocker('spread-data', text);
|
|
162
|
+
if (/\[[\s\S]*\]/.test(text)) return dynamicBlocker('computed-reference', text);
|
|
163
|
+
if (/(?:^|[^\w$])(?:await|yield|new|function|class|import|require)\b/.test(text)) return dynamicBlocker('runtime-expression', text);
|
|
164
|
+
if (/=>/.test(text)) return dynamicBlocker('function-expression', text);
|
|
165
|
+
if (/\?\.\s*\(/.test(text) || /\b[A-Za-z_$][\w$]*(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)*\s*(?:<[^>]+>\s*)?\(/.test(text)) return dynamicBlocker('call-expression', text);
|
|
166
|
+
if (/\?\./.test(text)) return dynamicBlocker('optional-reference', text);
|
|
167
|
+
return dynamicBlocker('dynamic-expression', text);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function dynamicBlocker(kind, text) {
|
|
171
|
+
return {
|
|
172
|
+
kind,
|
|
173
|
+
text,
|
|
174
|
+
reasonCode: `jsx-render-context-provider-value-${kind}-unsupported`
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function balancedDelimiters(text) {
|
|
179
|
+
const stack = [];
|
|
180
|
+
const pairs = { '{': '}', '[': ']' };
|
|
181
|
+
let quote;
|
|
182
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
183
|
+
const char = text[index];
|
|
184
|
+
if (quote) {
|
|
185
|
+
if (char === '\\') index += 1;
|
|
186
|
+
else if (char === quote) quote = undefined;
|
|
187
|
+
} else if (char === '"' || char === "'") {
|
|
188
|
+
quote = char;
|
|
189
|
+
} else if (pairs[char]) {
|
|
190
|
+
stack.push(pairs[char]);
|
|
191
|
+
} else if ((char === '}' || char === ']') && stack.pop() !== char) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return !quote && stack.length === 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function unwrapJsxExpression(text) {
|
|
199
|
+
const normalized = normalizedText(text);
|
|
200
|
+
return normalizedText(/^\{\s*([\s\S]*?)\s*\}$/.exec(normalized)?.[1] ?? normalized);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function normalizedJsxAttributeValueText(text) {
|
|
204
|
+
const match = /^[A-Za-z_$][\w$:-]*\s*=\s*([\s\S]*)$/.exec(String(text ?? '').trim());
|
|
205
|
+
return normalizedText(match?.[1] ?? '');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function normalizedText(text) { return String(text ?? '').trim().replace(/\s+/g, ' '); }
|
|
209
|
+
function propKind(attribute) { return isJsxSpreadAttribute(attribute) ? 'spread' : 'named'; }
|
|
210
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
211
|
+
|
|
212
|
+
export { jsxContextProviderValueReasonCode, jsxContextProviderValueRecord };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { isJsxSpreadAttribute } from '../../js-ts-safe-merge-jsx-attribute-parser.js';
|
|
3
|
+
import { staticOptionalMemberReference } from './staticOptionalMemberReference.js';
|
|
4
|
+
|
|
5
|
+
function jsxOwnerEventHandlerDeclarations(sourceText, ownerName) {
|
|
6
|
+
const records = [
|
|
7
|
+
...functionHandlerDeclarations(sourceText, ownerName),
|
|
8
|
+
...variableHandlerDeclarations(sourceText, ownerName)
|
|
9
|
+
];
|
|
10
|
+
return records.length ? new Map(records.map((record) => [record.name, record])) : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function functionHandlerDeclarations(sourceText, ownerName) {
|
|
14
|
+
return [...String(sourceText ?? '').matchAll(/\bfunction\s+([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*\{/g)]
|
|
15
|
+
.map((match) => handlerDeclarationRecord(sourceText, ownerName, match[1], 'function', match.index, balancedEnd(sourceText, match.index + match[0].lastIndexOf('{'), '{', '}')));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function variableHandlerDeclarations(sourceText, ownerName) {
|
|
19
|
+
return [...String(sourceText ?? '').matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?(?:function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/g)]
|
|
20
|
+
.map((match) => handlerDeclarationRecord(sourceText, ownerName, match[1], match[0].includes('function') ? 'function-expression' : 'arrow-function', match.index, statementEnd(sourceText, match.index)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function handlerDeclarationRecord(sourceText, ownerName, name, declarationKind, start, end) {
|
|
24
|
+
const declarationText = normalizedDeclarationText(String(sourceText ?? '').slice(start, end ?? statementEnd(sourceText, start)));
|
|
25
|
+
return compactRecord({
|
|
26
|
+
name,
|
|
27
|
+
declarationKind,
|
|
28
|
+
ownerName,
|
|
29
|
+
declarationHash: hashSemanticValue({ kind: 'frontier.lang.projectJsxEventHandlerDeclaration', ownerName, name, declarationKind, declarationText })
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function jsxEventHandlerProps(attributes = [], handlerDeclarations) {
|
|
34
|
+
const eventHandlers = attributes.filter(isJsxEventHandlerAttribute);
|
|
35
|
+
return eventHandlers.map((attribute, index) => jsxEventHandlerPropRecord(attribute, index + 1, handlerDeclarations));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function jsxEventHandlerPropRecord(attribute, ordinal, handlerDeclarations) {
|
|
39
|
+
const expressionText = normalizedJsxAttributeValueText(attribute.text);
|
|
40
|
+
const handlerReference = staticEventHandlerReference(expressionText);
|
|
41
|
+
const inlineHandlerText = handlerReference ? undefined : staticJsxInlineHandlerText(expressionText);
|
|
42
|
+
const handlerDeclaration = handlerReference?.plainReference ? handlerDeclarations?.get(handlerReference.text) : undefined;
|
|
43
|
+
const inlineHandlerExpressionHash = inlineHandlerText ? hashSemanticValue({
|
|
44
|
+
kind: 'frontier.lang.projectJsxInlineEventHandlerExpression',
|
|
45
|
+
propName: attribute.name,
|
|
46
|
+
inlineHandlerText
|
|
47
|
+
}) : undefined;
|
|
48
|
+
return compactRecord({
|
|
49
|
+
propName: attribute.name,
|
|
50
|
+
ordinal,
|
|
51
|
+
propKind: propKind(attribute),
|
|
52
|
+
proofStatus: handlerReference?.proofStatus ?? (inlineHandlerText ? 'static-inline-event-handler-evidence' : 'dynamic-event-handler-unsupported'),
|
|
53
|
+
reasonCode: handlerReference?.reasonCode,
|
|
54
|
+
handlerReferenceText: handlerReference?.text,
|
|
55
|
+
handlerReferenceRoot: handlerReference?.root,
|
|
56
|
+
handlerReferencePath: handlerReference?.path,
|
|
57
|
+
optionalReference: handlerReference?.optionalReference,
|
|
58
|
+
optionalReferenceSegments: handlerReference?.optionalSegments,
|
|
59
|
+
optionalReferenceSegmentIndexes: handlerReference?.optionalSegmentIndexes,
|
|
60
|
+
optionalNullishBoundaryCount: handlerReference?.optionalSegmentIndexes?.length,
|
|
61
|
+
handlerDeclarationKind: handlerDeclaration?.declarationKind,
|
|
62
|
+
handlerDeclarationName: handlerDeclaration?.name,
|
|
63
|
+
handlerDeclarationOwnerName: handlerDeclaration?.ownerName,
|
|
64
|
+
handlerDeclarationHash: handlerDeclaration?.declarationHash,
|
|
65
|
+
inlineHandlerText,
|
|
66
|
+
inlineHandlerExpressionHash,
|
|
67
|
+
dynamicExpressionText: handlerReference || inlineHandlerText ? undefined : expressionText,
|
|
68
|
+
dynamicExpressionKind: handlerReference || inlineHandlerText ? undefined : dynamicEventHandlerExpressionKind(expressionText),
|
|
69
|
+
dynamicBlockerReasonCode: handlerReference || inlineHandlerText ? undefined : dynamicEventHandlerBlockerReasonCode(expressionText),
|
|
70
|
+
expressionHash: hashSemanticValue({
|
|
71
|
+
kind: 'frontier.lang.projectJsxEventHandlerExpression',
|
|
72
|
+
propName: attribute.name,
|
|
73
|
+
expressionText
|
|
74
|
+
}),
|
|
75
|
+
signatureHash: hashSemanticValue({
|
|
76
|
+
kind: 'frontier.lang.projectJsxEventHandlerProp',
|
|
77
|
+
propName: attribute.name,
|
|
78
|
+
ordinal,
|
|
79
|
+
expressionText,
|
|
80
|
+
handlerReference,
|
|
81
|
+
handlerDeclarationHash: handlerDeclaration?.declarationHash,
|
|
82
|
+
inlineHandlerText,
|
|
83
|
+
dynamicBlockerReasonCode: handlerReference || inlineHandlerText ? undefined : dynamicEventHandlerBlockerReasonCode(expressionText)
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function jsxEventHandlerReasonCodes(records = []) {
|
|
89
|
+
if (!records.length) return [];
|
|
90
|
+
const hasStaticReference = records.some((record) => record.proofStatus === 'static-event-handler-reference-evidence');
|
|
91
|
+
const hasOptionalReference = records.some((record) => record.proofStatus === 'static-optional-event-handler-reference-evidence');
|
|
92
|
+
const hasInline = records.some((record) => record.proofStatus === 'static-inline-event-handler-evidence');
|
|
93
|
+
const hasDynamic = records.some((record) => record.proofStatus === 'dynamic-event-handler-unsupported');
|
|
94
|
+
return [
|
|
95
|
+
hasStaticReference || hasOptionalReference || hasInline ? 'jsx-render-event-handler-prop-static-evidence' : undefined,
|
|
96
|
+
hasOptionalReference ? 'jsx-render-event-handler-prop-static-optional-reference-evidence' : undefined,
|
|
97
|
+
hasInline ? 'jsx-render-event-handler-prop-static-inline-evidence' : undefined,
|
|
98
|
+
records.some((record) => record.handlerDeclarationHash) ? 'jsx-render-event-handler-local-declaration-evidence' : undefined,
|
|
99
|
+
hasDynamic ? 'jsx-render-event-handler-prop-unsupported' : undefined
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function staticEventHandlerReference(expressionText) {
|
|
104
|
+
const text = normalizedText(expressionText);
|
|
105
|
+
const expression = normalizedText(/^\{\s*([\s\S]*?)\s*\}$/.exec(text)?.[1] ?? text);
|
|
106
|
+
const optionalReference = staticOptionalMemberReference(expression);
|
|
107
|
+
if (optionalReference) return {
|
|
108
|
+
...optionalReference,
|
|
109
|
+
proofStatus: 'static-optional-event-handler-reference-evidence',
|
|
110
|
+
reasonCode: 'jsx-render-event-handler-prop-static-optional-reference-evidence',
|
|
111
|
+
optionalReference: true
|
|
112
|
+
};
|
|
113
|
+
if (!/^(?:this|[A-Za-z_$][\w$]*)(?:\s*\.\s*[A-Za-z_$][\w$]*)*$/.test(expression)) return undefined;
|
|
114
|
+
const normalized = expression.replace(/\s+/g, '');
|
|
115
|
+
const path = normalized.split('.');
|
|
116
|
+
return { text: normalized, root: path[0], path, proofStatus: 'static-event-handler-reference-evidence', plainReference: true };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function staticJsxInlineHandlerText(expressionText) {
|
|
120
|
+
const text = normalizedText(expressionText);
|
|
121
|
+
const expression = normalizedText(/^\{\s*([\s\S]*?)\s*\}$/.exec(text)?.[1] ?? text);
|
|
122
|
+
if (/^(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>[\s\S]+$/.test(expression)) return expression;
|
|
123
|
+
if (/^(?:async\s+)?function(?:\s+[A-Za-z_$][\w$]*)?\s*\([^)]*\)\s*\{[\s\S]*\}$/.test(expression)) return expression;
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function dynamicEventHandlerExpressionKind(expressionText) {
|
|
128
|
+
const expression = normalizedEventHandlerExpression(expressionText);
|
|
129
|
+
if (/\[[\s\S]*\]/.test(expression)) return 'computed-reference';
|
|
130
|
+
if (/\?\.\s*\(/.test(expression) || /\b[A-Za-z_$][\w$]*(?:\s*(?:\.|\?\.)\s*[A-Za-z_$][\w$]*)*\s*\(/.test(expression)) return 'call-expression';
|
|
131
|
+
if (/\?\./.test(expression)) return 'optional-reference';
|
|
132
|
+
return 'dynamic-expression';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function dynamicEventHandlerBlockerReasonCode(expressionText) {
|
|
136
|
+
return `jsx-render-event-handler-prop-${dynamicEventHandlerExpressionKind(expressionText)}-unsupported`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function balancedEnd(text, openIndex, open, close) {
|
|
140
|
+
const value = String(text ?? '');
|
|
141
|
+
if (value[openIndex] !== open) return undefined;
|
|
142
|
+
let depth = 0;
|
|
143
|
+
for (let index = openIndex; index < value.length; index += 1) {
|
|
144
|
+
if (value[index] === open) depth += 1;
|
|
145
|
+
else if (value[index] === close && --depth === 0) return index + 1;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function statementEnd(text, start) {
|
|
151
|
+
const value = String(text ?? '');
|
|
152
|
+
const end = value.indexOf(';', start);
|
|
153
|
+
if (end !== -1) return end + 1;
|
|
154
|
+
const lineEnd = value.indexOf('\n', start);
|
|
155
|
+
return lineEnd === -1 ? value.length : lineEnd;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function normalizedDeclarationText(text) { return String(text ?? '').trim().replace(/\s+/g, ' '); }
|
|
159
|
+
function normalizedJsxAttributeValueText(text) {
|
|
160
|
+
const match = /^[A-Za-z_$][\w$:-]*\s*=\s*([\s\S]*)$/.exec(String(text ?? '').trim());
|
|
161
|
+
return normalizedText(match?.[1] ?? '');
|
|
162
|
+
}
|
|
163
|
+
function normalizedEventHandlerExpression(text) {
|
|
164
|
+
const normalized = normalizedText(text);
|
|
165
|
+
return normalizedText(/^\{\s*([\s\S]*?)\s*\}$/.exec(normalized)?.[1] ?? normalized);
|
|
166
|
+
}
|
|
167
|
+
function normalizedText(text) { return String(text ?? '').trim().replace(/\s+/g, ' '); }
|
|
168
|
+
function propKind(attribute) { return isJsxSpreadAttribute(attribute) ? 'spread' : 'named'; }
|
|
169
|
+
function isJsxEventHandlerAttribute(attribute) { return !isJsxSpreadAttribute(attribute) && /^on[A-Z0-9]/.test(String(attribute?.name ?? '')); }
|
|
170
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
171
|
+
|
|
172
|
+
export { jsxEventHandlerProps, jsxEventHandlerReasonCodes, jsxOwnerEventHandlerDeclarations };
|