emit-portable: token alignment window for Doc/edit (S2, #57)#63
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Slice 2 of #57 (portable incremental
edit). Builds on the S1Doc/editAPI (#61):kind/off/end/nl) across edits. After eachedit(), the doc relexes in full and computes a token alignment window{oldN, newN, prefix, suffix}— the longest common token prefix (matching kind/offset/end/newline-flag + source text) and suffix (same, shifted by the byte-length delta), constrained soprefix + suffix ≤ min(oldN, newN).edit-sessionrunner protocol emits the alignment quadruple as one JSON line on stderr (before parse outcome), so the gate can assert it even on rejected final texts. Plain-mode stdout/stderr are unchanged.edit()now clampsstart/endto[0, len]withend ≥ startin all three targets, matchingString.prototype.slicesemantics (Go/Rust previously panicked on out-of-range edits that JS silently clamped).This slice computes the damage window but does not yet use it —
parsepaths are untouched (still full reparse). Windowed relexing and tree reuse come in later slices.Validation
node test/check.ts emit-parity— 5/5 gatesnode test/portable-targets.ts— calc/javascript: 5/5 edit-sessions + 5/5 token-alignments × 3 targetsnode test/newline-mode.ts— 29/29npx tsc --noEmit— cleana b→ab), first-token change — alignment parity across all 3 targets vs oracle-lexer expectations