( source: string, node: Record<string, unknown>, path: string, previousEnd: number, details: Array<ComposerInputValidationIssue> )
| 305 | } |
| 306 | |
| 307 | function validateBaseNode( |
| 308 | source: string, |
| 309 | node: Record<string, unknown>, |
| 310 | path: string, |
| 311 | previousEnd: number, |
| 312 | details: Array<ComposerInputValidationIssue> |
| 313 | ): void { |
| 314 | if (typeof node.kind !== `string` || node.kind.length === 0) { |
| 315 | details.push({ |
| 316 | path: `${path}/kind`, |
| 317 | message: `must be a non-empty string`, |
| 318 | }) |
| 319 | } |
| 320 | |
| 321 | if (!Number.isInteger(node.start)) { |
| 322 | details.push({ path: `${path}/start`, message: `must be an integer` }) |
| 323 | } |
| 324 | |
| 325 | if (!Number.isInteger(node.end)) { |
| 326 | details.push({ path: `${path}/end`, message: `must be an integer` }) |
| 327 | } |
| 328 | |
| 329 | if (typeof node.raw !== `string`) { |
| 330 | details.push({ path: `${path}/raw`, message: `must be a string` }) |
| 331 | } |
| 332 | |
| 333 | if (!Number.isInteger(node.start) || !Number.isInteger(node.end)) { |
| 334 | return |
| 335 | } |
| 336 | |
| 337 | const start = node.start as number |
| 338 | const end = node.end as number |
| 339 | |
| 340 | if (start < 0) { |
| 341 | details.push({ path: `${path}/start`, message: `must be >= 0` }) |
| 342 | } |
| 343 | |
| 344 | if (end < start) { |
| 345 | details.push({ path: `${path}/end`, message: `must be >= start` }) |
| 346 | } |
| 347 | |
| 348 | if (end > source.length) { |
| 349 | details.push({ path: `${path}/end`, message: `must be within source` }) |
| 350 | } |
| 351 | |
| 352 | if (start < previousEnd) { |
| 353 | details.push({ |
| 354 | path: `${path}/start`, |
| 355 | message: `must not overlap the previous node`, |
| 356 | }) |
| 357 | } |
| 358 | |
| 359 | if (typeof node.raw === `string` && source.slice(start, end) !== node.raw) { |
| 360 | details.push({ |
| 361 | path: `${path}/raw`, |
| 362 | message: `must equal source.slice(start, end)`, |
| 363 | }) |
| 364 | } |
no test coverage detected