| 197 | } |
| 198 | |
| 199 | export default function parser(tokens: Token[], args?: string | ParserArgs) { |
| 200 | const doc = new Node('document'); |
| 201 | const nodes = [doc]; |
| 202 | |
| 203 | if (typeof args === 'string') args = { file: args }; |
| 204 | |
| 205 | for (const token of tokens) |
| 206 | handleToken(token, nodes, args?.file, args?.slots, args?.location); |
| 207 | |
| 208 | if (nodes.length > 1) |
| 209 | for (const node of nodes.slice(1)) |
| 210 | node.errors.push({ |
| 211 | id: 'missing-closing', |
| 212 | level: 'critical', |
| 213 | message: `Node '${node.tag || node.type}' is missing closing`, |
| 214 | }); |
| 215 | |
| 216 | for (const transform of transforms) transform(doc, args?.conditionalTags); |
| 217 | |
| 218 | return doc; |
| 219 | } |