Skip to content

Commit 30108cc

Browse files
ovrclaude
andauthored
Parse the first block mapping key once (#800)
Insert the MAPPING event via splice before the already parsed key events instead of rolling back and re-parsing the key. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 494400b commit 30108cc

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

‎src/parser/parser.ts‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,20 +1100,18 @@ function readBlockMapping (state: ParserState, nodeIndent: number, flowIndent: n
11001100
}
11011101

11021102
if (!mappingOpened) {
1103-
restoreState(state, beforeKey)
1104-
addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK)
1103+
// The key is already parsed; insert the MAPPING event before its
1104+
// events instead of rolling back and re-reading the key.
1105+
state.events.splice(beforeKey.eventsLength, 0, {
1106+
type: EVENT_ID.MAPPING,
1107+
start: beforeKey.position,
1108+
anchorStart: props.anchorStart,
1109+
anchorEnd: props.anchorEnd,
1110+
tagStart: props.tagStart,
1111+
tagEnd: props.tagEnd,
1112+
style: COLLECTION_STYLE.BLOCK
1113+
})
11051114
mappingOpened = true
1106-
// The key, the `:` and the space after it were already validated
1107-
// above, before the rollback. Re-reading the same input cannot
1108-
// fail, so just consume it again without error checks.
1109-
parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)
1110-
1111-
ch = state.input.charCodeAt(state.position)
1112-
while (isWhiteSpace(ch)) {
1113-
ch = state.input.charCodeAt(++state.position)
1114-
}
1115-
1116-
state.position++
11171115
}
11181116

11191117
detected = true

0 commit comments

Comments
 (0)