feat: expose code block structure info from the source map - #142
Merged
Merged
Conversation
This was referenced Sep 29, 2026
Merged
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
MarkdownSourceMap.getCodeSourceInfo(node).{ kind: 'indented' }or{ kind: 'fenced', openingFence, infoInsertPoint }.emptyOffset.CodeSourceInfo,FencedCodeSourceInfo, andIndentedCodeSourceInfo.Closes #141.
API
openingFenceis the fence sequence range. It excludes the container prefix,the indentation, the info string, and the line ending.
infoInsertPointis the end of the opening fence line, before its line ending.Insert an info string there when
node.langis absent. The point stays before\rin a CRLF ending. If the opening fence line has no line ending, the pointis the end of the input.
getCodeSourceInfothrowsSourceMapUnavailableErrorfor a node from anotherdocument, a node added after parsing, or a node that is not a block
codenode.Implementation
The parser already separates the two code paths.
onentercodefencedandonexitcodefencedbuild aFencedCodeRecording.onentercodeindentedandonexitcodeindentedbuild aCodeValueRecording.This change adds
codeSourceInfos: WeakMap<object, RecordedCodeSourceInfo>.The fenced path records the opening fence sequence and the opening line end.
The indented path records
{ kind: 'indented' }.build-source-map.tsonlyconverts the recorded offsets to
ParsedPoint.The
openingFencerange and the info insert point both come from the parserevents:
codeFencedFenceSequencegives the fence run, andcodeFencedFencegives its line end. No code re-derives them from
codeFencedstart offsets.Tests
__tests__/source-map/code-source-info.spec.tshas 38 cases:__tests__/types/package-exports.mtsandpackage-exports.ctsreference thethree new types and call
getCodeSourceInfo, so a dropped CJS/ESM export failstest:types.Validation
pnpm test: 2017 tests passed.pnpm run lintpassed.pnpm run test:typespassed.pnpm run test:packagepassed.pnpm run buildpassed. The API Extractor report is updated.