@@ -8,6 +8,7 @@ import { transformError } from "./transforms/error.js";
88import { type ParseOptions , type Root } from "./types.js" ;
99import { removeFakeNodes } from "./utils/remove-fake-nodes.js" ;
1010import { updatePositions } from "./utils/update-positions.js" ;
11+ import type { Document } from "./types.js" ;
1112
1213const MAP_KEY_DUPLICATE_ERROR_MESSAGE_PREFIX = 'Map keys must be unique; "' ;
1314const MAP_KEY_DUPLICATE_ERROR_MESSAGE_SUFFIX = '" is repeated' ;
@@ -35,23 +36,26 @@ export function parse(text: string, options?: ParseOptions): Root {
3536 const context = new Context ( cst , text ) ;
3637 context . setOrigRanges ( ) ;
3738
38- const documents = cst . map ( cstDocument => {
39- const document = new YAML . Document ( {
39+ const documents : Document [ ] = [ ] ;
40+
41+ for ( const cstDocument of cst ) {
42+ const yamlDocument = new YAML . Document ( {
4043 merge : false ,
4144 keepCstNodes : true ,
4245 } ) . parse ( cstDocument ) ;
4346
44- for ( const error of document . errors ) {
47+ for ( const error of yamlDocument . errors ) {
4548 if ( shouldIgnoreError ( error , allowDuplicateKeysInMap ) ) {
4649 continue ;
4750 }
4851 throw transformError ( error , context ) ;
4952 }
5053
51- removeCstBlankLine ( document . cstNode ! ) ;
54+ removeCstBlankLine ( yamlDocument . cstNode ! ) ;
5255
53- return context . transformNode ( document ) ;
54- } ) ;
56+ const document = context . transformNode ( yamlDocument ) ;
57+ documents . push ( document ) ;
58+ }
5559
5660 const root = createRoot (
5761 context . transformRange ( { origStart : 0 , origEnd : text . length } ) ,
0 commit comments