Skip to content

Commit 833aa70

Browse files
authored
Refactor to use composer.compose (#252)
* refactor to use `composer.compose` * update
1 parent d93a4c1 commit 833aa70

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/yaml-cst-parse.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,17 @@ export function parseAllDocsToCST(ctx: Context): ParsedCSTDocs {
1717
keepSourceTokens: true,
1818
lineCounter,
1919
});
20-
const cstNodes: CST.Token[] = [];
20+
const cstNodes: CST.Token[] = [...parser.parse(ctx.code)];
2121
const nodes: Document.Parsed[] = [];
22-
23-
/**
24-
* Process for Document
25-
*/
26-
function processDoc(node: Document.Parsed) {
27-
for (const error of node.errors) {
22+
for (const doc of composer.compose(cstNodes)) {
23+
for (const error of doc.errors) {
2824
throw ctx.throwError(error.message, error.pos[0]);
2925
}
3026
// ignore warns
3127
// for (const error of doc.warnings) {
3228
// throw ctx.throwError(error.message, error.pos[0])
3329
// }
34-
nodes.push(node);
35-
}
36-
37-
for (const cst of parser.parse(ctx.code)) {
38-
cstNodes.push(cst);
39-
for (const doc of composer.next(cst)) {
40-
processDoc(doc);
41-
}
42-
}
43-
for (const doc of composer.end()) {
44-
processDoc(doc);
30+
nodes.push(doc);
4531
}
4632

4733
return { nodes, cstNodes, streamInfo: composer.streamInfo() };

0 commit comments

Comments
 (0)