@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,319 @@
|
|
|
1
|
+
import { uniqueStrings } from './js-ts-safe-merge-context.js';
|
|
2
|
+
import { hasConditionalChildExpressionOperator, parseDirectChildren, parseJsxSource } from './js-ts-safe-merge-jsx-child-expression-parser.js';
|
|
3
|
+
|
|
4
|
+
function mergeJsxChildExpressionSources(input) {
|
|
5
|
+
if (![input.baseSourceText, input.workerSourceText, input.headSourceText, input.currentSourceText].every(isString)) {
|
|
6
|
+
return blocked('missing-source-text');
|
|
7
|
+
}
|
|
8
|
+
if (input.currentSourceText !== input.headSourceText) return blocked('jsx-child-expression-current-source-unsupported');
|
|
9
|
+
const parsed = ['base', 'worker', 'head', 'current'].map((side) => parseJsxSource(input[`${side}SourceText`]));
|
|
10
|
+
if (parsed.some((source) => source.reasonCodes.length)) return blocked('jsx-child-expression-parse-blocked');
|
|
11
|
+
const [base, worker, head, current] = parsed;
|
|
12
|
+
const currentEdits = [];
|
|
13
|
+
const workerProofEdits = [];
|
|
14
|
+
const headProofEdits = [];
|
|
15
|
+
let changedElements = 0;
|
|
16
|
+
let childAdditions = 0;
|
|
17
|
+
let keyedChildAdditions = 0;
|
|
18
|
+
let keyedFragmentAdditions = 0;
|
|
19
|
+
for (const baseElement of base.elements) {
|
|
20
|
+
if (baseElement.selfClosing) continue;
|
|
21
|
+
const merged = mergeCandidateElement({
|
|
22
|
+
sourceTexts: input,
|
|
23
|
+
parsed: { base, worker, head, current },
|
|
24
|
+
elements: {
|
|
25
|
+
base: baseElement,
|
|
26
|
+
worker: worker.byKey.get(baseElement.key),
|
|
27
|
+
head: head.byKey.get(baseElement.key),
|
|
28
|
+
current: current.byKey.get(baseElement.key)
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (merged.status === 'blocked') return blocked(...merged.reasonCodes);
|
|
32
|
+
if (merged.status !== 'merged') continue;
|
|
33
|
+
currentEdits.push(...merged.currentEdits);
|
|
34
|
+
workerProofEdits.push(...merged.workerProofEdits);
|
|
35
|
+
headProofEdits.push(...merged.headProofEdits);
|
|
36
|
+
changedElements += 1;
|
|
37
|
+
childAdditions += merged.childAdditions ?? 0;
|
|
38
|
+
keyedChildAdditions += merged.keyedChildAdditions ?? 0;
|
|
39
|
+
keyedFragmentAdditions += merged.keyedFragmentAdditions ?? 0;
|
|
40
|
+
}
|
|
41
|
+
if (!currentEdits.length) return blocked('no-jsx-child-expression-merge-candidate');
|
|
42
|
+
if (applyEdits(input.baseSourceText, workerProofEdits) !== input.workerSourceText) return blocked('jsx-child-expression-worker-diff-unsupported');
|
|
43
|
+
if (applyEdits(input.baseSourceText, headProofEdits) !== input.headSourceText) return blocked('jsx-child-expression-head-diff-unsupported');
|
|
44
|
+
return {
|
|
45
|
+
ok: true,
|
|
46
|
+
sourceText: applyEdits(input.currentSourceText, currentEdits),
|
|
47
|
+
summary: { elements: changedElements, edits: currentEdits.length, childAdditions, keyedChildAdditions, keyedFragmentAdditions }
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function mergeCandidateElement(input) {
|
|
52
|
+
const { base, worker, head, current } = input.elements;
|
|
53
|
+
if (![worker, head, current].every(Boolean)) return { status: 'skipped' };
|
|
54
|
+
if (![worker, head, current].every((element) => element.tagName === base.tagName)) {
|
|
55
|
+
return blockedElement('jsx-child-expression-tag-name-changed');
|
|
56
|
+
}
|
|
57
|
+
if (![worker, head, current].every((element) => element.openText === base.openText && element.closeText === base.closeText)) {
|
|
58
|
+
return { status: 'skipped' };
|
|
59
|
+
}
|
|
60
|
+
const children = childrenBySide(input.sourceTexts, input.parsed, input.elements);
|
|
61
|
+
const childReasonCodes = Object.values(children).flatMap((entry) => entry.reasonCodes);
|
|
62
|
+
if (childReasonCodes.length) return blockedElement(...childReasonCodes);
|
|
63
|
+
const tokens = Object.fromEntries(Object.entries(children).map(([side, entry]) => [side, entry.tokens]));
|
|
64
|
+
if (!sameChildShape(tokens.base, tokens.worker) || !sameChildShape(tokens.base, tokens.head) || !sameChildShape(tokens.base, tokens.current)) {
|
|
65
|
+
return mergeChildAdditions(tokens, input.elements);
|
|
66
|
+
}
|
|
67
|
+
return mergeChildTokens(tokens);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function childrenBySide(sourceTexts, parsed, elements) {
|
|
71
|
+
return Object.fromEntries(['base', 'worker', 'head', 'current'].map((side) => [
|
|
72
|
+
side,
|
|
73
|
+
parseDirectChildren(sourceTexts[`${side}SourceText`], parsed[side], elements[side])
|
|
74
|
+
]));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function mergeChildTokens(tokens) {
|
|
78
|
+
const currentEdits = [];
|
|
79
|
+
const workerProofEdits = [];
|
|
80
|
+
const headProofEdits = [];
|
|
81
|
+
for (let index = 0; index < tokens.base.length; index += 1) {
|
|
82
|
+
const baseChild = tokens.base[index];
|
|
83
|
+
const workerChild = tokens.worker[index];
|
|
84
|
+
const headChild = tokens.head[index];
|
|
85
|
+
const currentChild = tokens.current[index];
|
|
86
|
+
if (baseChild.kind !== 'expression') {
|
|
87
|
+
const identityConflict = childIdentityConflict(baseChild, workerChild, headChild, currentChild);
|
|
88
|
+
if (identityConflict.length) return blockedElement(...identityConflict);
|
|
89
|
+
if (workerChild.text !== baseChild.text || headChild.text !== baseChild.text || currentChild.text !== headChild.text) return { status: 'skipped' };
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const workerChanged = workerChild.text !== baseChild.text;
|
|
93
|
+
const headChanged = headChild.text !== baseChild.text;
|
|
94
|
+
if ((workerChanged || headChanged) && [baseChild, workerChild, headChild, currentChild].some((token) => hasConditionalChildExpressionOperator(token?.text))) {
|
|
95
|
+
return blockedElement('jsx-child-conditional-expression-unsupported');
|
|
96
|
+
}
|
|
97
|
+
if (workerChanged && headChanged && workerChild.text !== headChild.text) return blockedElement('jsx-child-expression-conflict');
|
|
98
|
+
if (currentChild.text !== headChild.text && currentChild.text !== workerChild.text) return blockedElement('jsx-child-expression-current-diverged');
|
|
99
|
+
if (workerChanged && currentChild.text !== workerChild.text) {
|
|
100
|
+
currentEdits.push({ start: currentChild.start, end: currentChild.end, replacement: workerChild.text });
|
|
101
|
+
}
|
|
102
|
+
if (workerChanged) workerProofEdits.push({ start: baseChild.start, end: baseChild.end, replacement: workerChild.text });
|
|
103
|
+
if (headChanged) headProofEdits.push({ start: baseChild.start, end: baseChild.end, replacement: headChild.text });
|
|
104
|
+
}
|
|
105
|
+
return { status: currentEdits.length ? 'merged' : 'skipped', currentEdits, workerProofEdits, headProofEdits };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function mergeChildAdditions(tokens, elements) {
|
|
109
|
+
const worker = analyzeChildAdditions(tokens.base, tokens.worker);
|
|
110
|
+
const head = analyzeChildAdditions(tokens.base, tokens.head);
|
|
111
|
+
const current = analyzeChildAdditions(tokens.base, tokens.current);
|
|
112
|
+
const reasonCodes = uniqueStrings([worker, head, current].flatMap((entry) => entry.reasonCodes ?? []));
|
|
113
|
+
if (reasonCodes.length) return blockedElement(...reasonCodes);
|
|
114
|
+
if (![worker, head, current].every((entry) => entry.ok)) return { status: 'skipped' };
|
|
115
|
+
if (!sameAdditionPlan(head, current)) return blockedElement('jsx-child-current-diverged');
|
|
116
|
+
const sameGapReasonCodes = sameGapChildAdditionReasonCodes(tokens.base, worker.additionsByGap, head.additionsByGap);
|
|
117
|
+
if (sameGapReasonCodes.length) return blockedElement(...sameGapReasonCodes);
|
|
118
|
+
const duplicateOutputKeyReasonCodes = duplicateStableChildKeyReasonCodes(plannedMergedChildTokens(tokens.base, worker.additionsByGap, head.additionsByGap));
|
|
119
|
+
if (duplicateOutputKeyReasonCodes.length) return blockedElement(...duplicateOutputKeyReasonCodes);
|
|
120
|
+
const currentEdits = [];
|
|
121
|
+
const workerProofEdits = [];
|
|
122
|
+
const headProofEdits = [];
|
|
123
|
+
let keyedChildAdditions = 0;
|
|
124
|
+
let keyedFragmentAdditions = 0;
|
|
125
|
+
for (let gap = 0; gap <= tokens.base.length; gap += 1) {
|
|
126
|
+
const workerAdditions = worker.additionsByGap.get(gap);
|
|
127
|
+
const workerText = additionText(workerAdditions);
|
|
128
|
+
const headText = additionText(head.additionsByGap.get(gap));
|
|
129
|
+
if (workerText && !headText) {
|
|
130
|
+
const currentPosition = sideInsertionPosition(tokens.current, current.baseTokenIndexes, elements.current, gap);
|
|
131
|
+
const basePosition = baseInsertionPosition(tokens.base, elements.base, gap);
|
|
132
|
+
currentEdits.push({ start: currentPosition, end: currentPosition, replacement: workerText });
|
|
133
|
+
workerProofEdits.push({ start: basePosition, end: basePosition, replacement: workerText });
|
|
134
|
+
keyedChildAdditions += (workerAdditions ?? []).filter((token) => token.stableKey === true).length;
|
|
135
|
+
keyedFragmentAdditions += (workerAdditions ?? []).filter((token) => isKeyedFragmentToken(token)).length;
|
|
136
|
+
}
|
|
137
|
+
if (headText) {
|
|
138
|
+
const basePosition = baseInsertionPosition(tokens.base, elements.base, gap);
|
|
139
|
+
headProofEdits.push({ start: basePosition, end: basePosition, replacement: headText });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
status: currentEdits.length ? 'merged' : 'skipped',
|
|
144
|
+
currentEdits,
|
|
145
|
+
workerProofEdits,
|
|
146
|
+
headProofEdits,
|
|
147
|
+
childAdditions: currentEdits.length,
|
|
148
|
+
keyedChildAdditions,
|
|
149
|
+
keyedFragmentAdditions
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function analyzeChildAdditions(baseTokens, sideTokens) {
|
|
154
|
+
const duplicateKeyReasonCodes = duplicateStableChildKeyReasonCodes(sideTokens);
|
|
155
|
+
if (duplicateKeyReasonCodes.length) return { ok: false, reasonCodes: duplicateKeyReasonCodes };
|
|
156
|
+
const additionsByGap = new Map();
|
|
157
|
+
const baseTokenIndexes = new Map();
|
|
158
|
+
let baseIndex = 0;
|
|
159
|
+
for (let sideIndex = 0; sideIndex < sideTokens.length; sideIndex += 1) {
|
|
160
|
+
const sideToken = sideTokens[sideIndex];
|
|
161
|
+
const baseToken = baseTokens[baseIndex];
|
|
162
|
+
if (baseToken && sameToken(sideToken, baseToken)) {
|
|
163
|
+
baseTokenIndexes.set(baseIndex, sideIndex);
|
|
164
|
+
baseIndex += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (isReorderedExistingChild(sideToken, baseTokens, baseIndex)) {
|
|
168
|
+
return { ok: false, reasonCodes: ['jsx-child-reorder-unsupported'] };
|
|
169
|
+
}
|
|
170
|
+
const safety = addedChildSafety(sideToken);
|
|
171
|
+
if (!safety.ok) return safety.reasonCodes.length ? { ok: false, reasonCodes: safety.reasonCodes } : { ok: false };
|
|
172
|
+
const gap = baseIndex;
|
|
173
|
+
additionsByGap.set(gap, [...(additionsByGap.get(gap) ?? []), sideToken]);
|
|
174
|
+
}
|
|
175
|
+
return { ok: baseIndex === baseTokens.length, additionsByGap, baseTokenIndexes };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function sameAdditionPlan(left, right) {
|
|
179
|
+
const gaps = new Set([...left.additionsByGap.keys(), ...right.additionsByGap.keys()]);
|
|
180
|
+
for (const gap of gaps) {
|
|
181
|
+
if (additionText(left.additionsByGap.get(gap)) !== additionText(right.additionsByGap.get(gap))) return false;
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function sameGapChildAdditionReasonCodes(baseTokens, workerAdditionsByGap, headAdditionsByGap) {
|
|
187
|
+
for (let gap = 0; gap <= baseTokens.length; gap += 1) {
|
|
188
|
+
const workerText = additionText(workerAdditionsByGap.get(gap));
|
|
189
|
+
const headText = additionText(headAdditionsByGap.get(gap));
|
|
190
|
+
if (workerText && headText && workerText !== headText) return ['jsx-child-addition-same-gap-conflict'];
|
|
191
|
+
}
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function plannedMergedChildTokens(baseTokens, workerAdditionsByGap, headAdditionsByGap) {
|
|
196
|
+
const merged = [];
|
|
197
|
+
for (let gap = 0; gap <= baseTokens.length; gap += 1) {
|
|
198
|
+
const headAdditions = headAdditionsByGap.get(gap);
|
|
199
|
+
const workerAdditions = workerAdditionsByGap.get(gap);
|
|
200
|
+
if (headAdditions?.length) merged.push(...headAdditions);
|
|
201
|
+
else if (workerAdditions?.length) merged.push(...workerAdditions);
|
|
202
|
+
if (gap < baseTokens.length) merged.push(baseTokens[gap]);
|
|
203
|
+
}
|
|
204
|
+
return merged;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function baseInsertionPosition(tokens, element, gap) {
|
|
208
|
+
if (gap < tokens.length) return tokens[gap].start;
|
|
209
|
+
return element.closeStart;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function sideInsertionPosition(tokens, baseTokenIndexes, element, gap) {
|
|
213
|
+
if (baseTokenIndexes.has(gap)) return tokens[baseTokenIndexes.get(gap)].start;
|
|
214
|
+
return element.closeStart;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function additionText(tokens = []) {
|
|
218
|
+
return tokens.map((token) => token.text).join('');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function sameToken(left, right) {
|
|
222
|
+
return left?.kind === right?.kind && left?.text === right?.text && left?.tagName === right?.tagName;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function addedChildSafety(token) {
|
|
226
|
+
if (token?.kind !== 'element' || /^\s*$/.test(token.text)) return { ok: false, reasonCodes: [] };
|
|
227
|
+
if (isFragmentToken(token) && !isKeyedFragmentToken(token)) {
|
|
228
|
+
return { ok: false, reasonCodes: ['jsx-child-fragment-addition-unsupported'] };
|
|
229
|
+
}
|
|
230
|
+
if (token.hasSpreadProp) return { ok: false, reasonCodes: ['jsx-child-spread-prop-addition-unsupported'] };
|
|
231
|
+
if (isJsxComponentTag(token.tagName) && token.stableKey !== true) {
|
|
232
|
+
return { ok: false, reasonCodes: ['jsx-child-component-addition-missing-key'] };
|
|
233
|
+
}
|
|
234
|
+
return { ok: true, reasonCodes: [] };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function sameChildShape(left, right) {
|
|
238
|
+
return childShape(left) === childShape(right);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function childShape(children) {
|
|
242
|
+
return children.map((child) => {
|
|
243
|
+
if (child.kind === 'element') return `element:${child.tagName}`;
|
|
244
|
+
if (child.kind === 'expression') return 'expression';
|
|
245
|
+
return `text:${child.text}`;
|
|
246
|
+
}).join('\0');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function childIdentityConflict(baseChild, ...sideChildren) {
|
|
250
|
+
if (baseChild?.kind !== 'element' || !baseChild.childIdentityKey) return [];
|
|
251
|
+
return sideChildren
|
|
252
|
+
.filter((child) => child?.kind === 'element' && child.childIdentityKey && child.childIdentityKey !== baseChild.childIdentityKey)
|
|
253
|
+
.map(() => 'jsx-child-key-identity-changed');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isReorderedExistingChild(sideToken, baseTokens, baseIndex) {
|
|
257
|
+
if (!sideToken?.childIdentityKey) return false;
|
|
258
|
+
return baseTokens.slice(baseIndex + 1).some((token) => token.childIdentityKey === sideToken.childIdentityKey);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function duplicateStableChildKeyReasonCodes(tokens) {
|
|
262
|
+
const seen = new Set();
|
|
263
|
+
for (const token of tokens) {
|
|
264
|
+
if (token?.kind !== 'element' || !token.childIdentityKey) continue;
|
|
265
|
+
if (seen.has(token.childIdentityKey)) return ['jsx-child-duplicate-key'];
|
|
266
|
+
seen.add(token.childIdentityKey);
|
|
267
|
+
}
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isFragmentToken(token) {
|
|
272
|
+
const tagName = String(token?.tagName ?? '');
|
|
273
|
+
return token?.fragmentKind === 'shorthand' || tagName === 'Fragment' || tagName === 'React.Fragment';
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function isKeyedFragmentToken(token) {
|
|
277
|
+
return isFragmentToken(token) && token?.fragmentKind !== 'shorthand' && token?.stableKey === true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function isJsxComponentTag(tagName) {
|
|
281
|
+
const firstSegment = String(tagName ?? '').split(/[.:]/)[0] ?? '';
|
|
282
|
+
return /^[A-Z]/.test(firstSegment);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function applyEdits(sourceText, edits) {
|
|
286
|
+
return edits.slice()
|
|
287
|
+
.sort((left, right) => right.start - left.start)
|
|
288
|
+
.reduce((text, edit) => text.slice(0, edit.start) + edit.replacement + text.slice(edit.end), sourceText);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function blocked(...reasonCodes) {
|
|
292
|
+
const normalized = uniqueStrings(reasonCodes);
|
|
293
|
+
return {
|
|
294
|
+
ok: false,
|
|
295
|
+
reasonCodes: normalized,
|
|
296
|
+
policyBlocker: normalized.some((reason) => jsxChildPolicyBlockers.has(reason))
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function blockedElement(...reasonCodes) {
|
|
301
|
+
return { status: 'blocked', reasonCodes: uniqueStrings(reasonCodes) };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function isString(value) { return typeof value === 'string'; }
|
|
305
|
+
|
|
306
|
+
const jsxChildPolicyBlockers = new Set([
|
|
307
|
+
'jsx-child-addition-same-gap-conflict',
|
|
308
|
+
'jsx-child-component-addition-missing-key',
|
|
309
|
+
'jsx-child-current-diverged',
|
|
310
|
+
'jsx-child-duplicate-key',
|
|
311
|
+
'jsx-child-conditional-expression-unsupported',
|
|
312
|
+
'jsx-child-expression-conflict',
|
|
313
|
+
'jsx-child-fragment-addition-unsupported',
|
|
314
|
+
'jsx-child-key-identity-changed',
|
|
315
|
+
'jsx-child-reorder-unsupported',
|
|
316
|
+
'jsx-child-spread-prop-addition-unsupported'
|
|
317
|
+
]);
|
|
318
|
+
|
|
319
|
+
export { mergeJsxChildExpressionSources };
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { uniqueStrings } from './js-ts-safe-merge-context.js';
|
|
2
|
+
|
|
3
|
+
function parseJsxSource(sourceText) {
|
|
4
|
+
const elements = [];
|
|
5
|
+
const allElements = [];
|
|
6
|
+
const reasonCodes = [];
|
|
7
|
+
const ordinals = new Map();
|
|
8
|
+
const stack = [];
|
|
9
|
+
let index = 0;
|
|
10
|
+
while (index < sourceText.length) {
|
|
11
|
+
const start = sourceText.indexOf('<', index);
|
|
12
|
+
if (start === -1) break;
|
|
13
|
+
const closing = parseClosingTag(sourceText, start);
|
|
14
|
+
if (closing) {
|
|
15
|
+
const open = stack.pop();
|
|
16
|
+
if (!open || open.tagName !== closing.tagName) {
|
|
17
|
+
reasonCodes.push('jsx-child-expression-tag-mismatch');
|
|
18
|
+
index = closing.end;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const element = { ...open, closeStart: closing.start, closeEnd: closing.end, closeText: closing.text, text: sourceText.slice(open.start, closing.end) };
|
|
22
|
+
elements.push(element);
|
|
23
|
+
allElements.push(element);
|
|
24
|
+
index = closing.end;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const opening = parseOpeningTag(sourceText, start);
|
|
28
|
+
if (!opening) {
|
|
29
|
+
index = start + 1;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const ordinal = (ordinals.get(opening.tagName) ?? 0) + 1;
|
|
33
|
+
ordinals.set(opening.tagName, ordinal);
|
|
34
|
+
const element = {
|
|
35
|
+
tagName: opening.tagName,
|
|
36
|
+
key: `${opening.tagName}#${ordinal}`,
|
|
37
|
+
start,
|
|
38
|
+
openEnd: opening.end,
|
|
39
|
+
closeStart: opening.selfClosing ? opening.end : undefined,
|
|
40
|
+
closeEnd: opening.selfClosing ? opening.end : undefined,
|
|
41
|
+
openText: opening.text,
|
|
42
|
+
closeText: opening.selfClosing ? '' : undefined,
|
|
43
|
+
selfClosing: opening.selfClosing,
|
|
44
|
+
text: opening.selfClosing ? opening.text : undefined
|
|
45
|
+
};
|
|
46
|
+
if (opening.selfClosing) allElements.push(element);
|
|
47
|
+
else stack.push(element);
|
|
48
|
+
index = opening.end;
|
|
49
|
+
}
|
|
50
|
+
if (stack.length) reasonCodes.push('jsx-child-expression-tag-unclosed');
|
|
51
|
+
allElements.sort((left, right) => left.start - right.start);
|
|
52
|
+
return {
|
|
53
|
+
elements,
|
|
54
|
+
allElements,
|
|
55
|
+
byKey: new Map(elements.map((element) => [element.key, element])),
|
|
56
|
+
byStart: new Map(allElements.map((element) => [element.start, element])),
|
|
57
|
+
reasonCodes: uniqueStrings(reasonCodes)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function parseDirectChildren(sourceText, parsed, element) {
|
|
62
|
+
const tokens = [];
|
|
63
|
+
const reasonCodes = [];
|
|
64
|
+
const start = element.openEnd;
|
|
65
|
+
const end = element.closeStart;
|
|
66
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start > end) {
|
|
67
|
+
return { tokens, reasonCodes: ['jsx-child-expression-bounds-unsupported'] };
|
|
68
|
+
}
|
|
69
|
+
let cursor = start;
|
|
70
|
+
while (cursor < end) {
|
|
71
|
+
const childElement = parsed.byStart.get(cursor);
|
|
72
|
+
if (childElement && childElement.closeEnd <= end) {
|
|
73
|
+
tokens.push({
|
|
74
|
+
kind: 'element',
|
|
75
|
+
tagName: childElement.tagName,
|
|
76
|
+
fragmentKind: childElement.fragmentKind,
|
|
77
|
+
start: cursor,
|
|
78
|
+
end: childElement.closeEnd,
|
|
79
|
+
text: sourceText.slice(cursor, childElement.closeEnd),
|
|
80
|
+
...childElementIdentity(childElement)
|
|
81
|
+
});
|
|
82
|
+
cursor = childElement.closeEnd;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (sourceText[cursor] === '{') {
|
|
86
|
+
const expressionEnd = bracedValueEnd(sourceText, cursor, end);
|
|
87
|
+
if (expressionEnd === undefined) return { tokens, reasonCodes: ['jsx-child-expression-unterminated'] };
|
|
88
|
+
tokens.push({ kind: 'expression', start: cursor, end: expressionEnd, text: sourceText.slice(cursor, expressionEnd) });
|
|
89
|
+
cursor = expressionEnd;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
let next = cursor + 1;
|
|
93
|
+
while (next < end && !parsed.byStart.has(next) && sourceText[next] !== '{') next += 1;
|
|
94
|
+
tokens.push({ kind: 'text', start: cursor, end: next, text: sourceText.slice(cursor, next) });
|
|
95
|
+
cursor = next;
|
|
96
|
+
}
|
|
97
|
+
return { tokens, reasonCodes };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function parseOpeningTag(sourceText, start) {
|
|
101
|
+
const afterOpen = start + 1;
|
|
102
|
+
if (sourceText[afterOpen] === '>') {
|
|
103
|
+
return { tagName: 'Fragment', fragmentKind: 'shorthand', start, end: afterOpen + 1, text: '<>', selfClosing: false };
|
|
104
|
+
}
|
|
105
|
+
if (/[/!?>]/.test(sourceText[afterOpen] ?? '')) return undefined;
|
|
106
|
+
const nameMatch = /^[A-Za-z_$][\w$]*(?:[.:][A-Za-z_$][\w$]*|-[\w$]+)*/.exec(sourceText.slice(afterOpen));
|
|
107
|
+
if (!nameMatch) return undefined;
|
|
108
|
+
const tagName = nameMatch[0];
|
|
109
|
+
const end = openingTagEnd(sourceText, afterOpen + tagName.length);
|
|
110
|
+
if (end === undefined) return undefined;
|
|
111
|
+
const text = sourceText.slice(start, end);
|
|
112
|
+
return { tagName, start, end, text, selfClosing: /\/\s*>$/.test(text) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function parseClosingTag(sourceText, start) {
|
|
116
|
+
if (sourceText[start] !== '<' || sourceText[start + 1] !== '/') return undefined;
|
|
117
|
+
const afterSlash = start + 2;
|
|
118
|
+
if (sourceText[afterSlash] === '>') {
|
|
119
|
+
return { tagName: 'Fragment', fragmentKind: 'shorthand', start, end: afterSlash + 1, text: '</>' };
|
|
120
|
+
}
|
|
121
|
+
const nameMatch = /^[A-Za-z_$][\w$]*(?:[.:][A-Za-z_$][\w$]*|-[\w$]+)*/.exec(sourceText.slice(afterSlash));
|
|
122
|
+
if (!nameMatch) return undefined;
|
|
123
|
+
const tagName = nameMatch[0];
|
|
124
|
+
let cursor = afterSlash + tagName.length;
|
|
125
|
+
while (cursor < sourceText.length && /\s/.test(sourceText[cursor])) cursor += 1;
|
|
126
|
+
if (sourceText[cursor] !== '>') return undefined;
|
|
127
|
+
const end = cursor + 1;
|
|
128
|
+
return { tagName, start, end, text: sourceText.slice(start, end) };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function openingTagEnd(sourceText, start) {
|
|
132
|
+
let quote;
|
|
133
|
+
let escaped = false;
|
|
134
|
+
let braceDepth = 0;
|
|
135
|
+
for (let index = start; index < sourceText.length; index += 1) {
|
|
136
|
+
const char = sourceText[index];
|
|
137
|
+
if (quote) {
|
|
138
|
+
if (escaped) escaped = false;
|
|
139
|
+
else if (char === '\\') escaped = true;
|
|
140
|
+
else if (char === quote) quote = undefined;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (char === '"' || char === '\'' || char === '`') quote = char;
|
|
144
|
+
else if (char === '{') braceDepth += 1;
|
|
145
|
+
else if (char === '}') braceDepth = Math.max(0, braceDepth - 1);
|
|
146
|
+
else if (char === '>' && braceDepth === 0) return index + 1;
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function bracedValueEnd(sourceText, start, end) {
|
|
152
|
+
let depth = 0;
|
|
153
|
+
let quote;
|
|
154
|
+
let escaped = false;
|
|
155
|
+
for (let cursor = start; cursor < end; cursor += 1) {
|
|
156
|
+
const char = sourceText[cursor];
|
|
157
|
+
if (quote) {
|
|
158
|
+
if (escaped) escaped = false;
|
|
159
|
+
else if (char === '\\') escaped = true;
|
|
160
|
+
else if (char === quote) quote = undefined;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (char === '"' || char === '\'' || char === '`') quote = char;
|
|
164
|
+
else if (char === '{') depth += 1;
|
|
165
|
+
else if (char === '}') {
|
|
166
|
+
depth -= 1;
|
|
167
|
+
if (depth === 0) return cursor + 1;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function childElementIdentity(element) {
|
|
174
|
+
const key = stableJsxKey(element.openText);
|
|
175
|
+
const hasSpreadProp = /\{\s*\.\.\./.test(String(element.openText ?? ''));
|
|
176
|
+
return {
|
|
177
|
+
keyPropValue: key?.value,
|
|
178
|
+
keyPropText: key?.text,
|
|
179
|
+
stableKey: key?.stable === true,
|
|
180
|
+
childIdentityKey: key?.stable === true ? `key:${key.value}` : undefined,
|
|
181
|
+
hasSpreadProp
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function stableJsxKey(openText) {
|
|
186
|
+
const text = String(openText ?? '');
|
|
187
|
+
let cursor = 1;
|
|
188
|
+
const tagName = jsxAttributeNameAt(text, cursor);
|
|
189
|
+
if (!tagName) return undefined;
|
|
190
|
+
cursor += tagName.length;
|
|
191
|
+
while (cursor < text.length) {
|
|
192
|
+
while (cursor < text.length && /\s/.test(text[cursor])) cursor += 1;
|
|
193
|
+
if (text[cursor] === '/' || text[cursor] === '>') return undefined;
|
|
194
|
+
if (text[cursor] === '{') {
|
|
195
|
+
const expressionEnd = bracedValueEnd(text, cursor, text.length);
|
|
196
|
+
if (expressionEnd === undefined) return undefined;
|
|
197
|
+
cursor = expressionEnd;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const attrStart = cursor;
|
|
201
|
+
const attrName = jsxAttributeNameAt(text, cursor);
|
|
202
|
+
if (!attrName) {
|
|
203
|
+
cursor += 1;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
cursor += attrName.length;
|
|
207
|
+
while (cursor < text.length && /\s/.test(text[cursor])) cursor += 1;
|
|
208
|
+
if (text[cursor] !== '=') continue;
|
|
209
|
+
cursor += 1;
|
|
210
|
+
while (cursor < text.length && /\s/.test(text[cursor])) cursor += 1;
|
|
211
|
+
const quote = text[cursor];
|
|
212
|
+
if (quote === '"' || quote === '\'') {
|
|
213
|
+
const valueStart = cursor + 1;
|
|
214
|
+
const valueEnd = quotedStringEnd(text, cursor);
|
|
215
|
+
if (valueEnd === undefined) return undefined;
|
|
216
|
+
if (attrName === 'key') {
|
|
217
|
+
return { stable: true, value: text.slice(valueStart, valueEnd - 1), text: text.slice(attrStart, valueEnd).trim() };
|
|
218
|
+
}
|
|
219
|
+
cursor = valueEnd;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const valueEnd = skipJsxAttributeValue(text, cursor);
|
|
223
|
+
if (valueEnd === undefined) return undefined;
|
|
224
|
+
cursor = valueEnd;
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function jsxAttributeNameAt(text, cursor) {
|
|
230
|
+
const match = /^[A-Za-z_$][\w$]*(?:[-:.][A-Za-z_$][\w$]*)*/.exec(text.slice(cursor));
|
|
231
|
+
return match?.[0];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function quotedStringEnd(text, start) {
|
|
235
|
+
const quote = text[start];
|
|
236
|
+
let escaped = false;
|
|
237
|
+
for (let cursor = start + 1; cursor < text.length; cursor += 1) {
|
|
238
|
+
const char = text[cursor];
|
|
239
|
+
if (escaped) escaped = false;
|
|
240
|
+
else if (char === '\\') escaped = true;
|
|
241
|
+
else if (char === quote) return cursor + 1;
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function skipJsxAttributeValue(text, cursor) {
|
|
247
|
+
if (text[cursor] === '{') return bracedValueEnd(text, cursor, text.length);
|
|
248
|
+
if (text[cursor] === '"' || text[cursor] === '\'' || text[cursor] === '`') return quotedStringEnd(text, cursor);
|
|
249
|
+
let next = cursor;
|
|
250
|
+
while (next < text.length && !/[\s/>]/.test(text[next])) next += 1;
|
|
251
|
+
return next;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function hasConditionalChildExpressionOperator(text) {
|
|
255
|
+
const value = String(text ?? '');
|
|
256
|
+
let quote;
|
|
257
|
+
let escaped = false;
|
|
258
|
+
let lineComment = false;
|
|
259
|
+
let blockComment = false;
|
|
260
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
261
|
+
const char = value[index];
|
|
262
|
+
const next = value[index + 1];
|
|
263
|
+
if (lineComment) {
|
|
264
|
+
if (char === '\n' || char === '\r') lineComment = false;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (blockComment) {
|
|
268
|
+
if (char === '*' && next === '/') {
|
|
269
|
+
blockComment = false;
|
|
270
|
+
index += 1;
|
|
271
|
+
}
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (quote) {
|
|
275
|
+
if (escaped) escaped = false;
|
|
276
|
+
else if (char === '\\') escaped = true;
|
|
277
|
+
else if (char === quote) quote = undefined;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (char === '/' && next === '/') {
|
|
281
|
+
lineComment = true;
|
|
282
|
+
index += 1;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (char === '/' && next === '*') {
|
|
286
|
+
blockComment = true;
|
|
287
|
+
index += 1;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (char === '"' || char === '\'' || char === '`') {
|
|
291
|
+
quote = char;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if ((char === '&' && next === '&') || (char === '|' && next === '|') || (char === '?' && next === '?')) return true;
|
|
295
|
+
if (char === '?' && next !== '.' && next !== '?') return true;
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export { hasConditionalChildExpressionOperator, parseDirectChildren, parseJsxSource };
|