(
type: T,
params: Omit<Extract<Ast.Node, { type: T }>, 'type' | 'loc'>,
start: Ast.Pos,
end: Ast.Pos,
)
| 4 | import type * as Ast from '../node.js'; |
| 5 | |
| 6 | export function NODE<T extends Ast.Node['type']>( |
| 7 | type: T, |
| 8 | params: Omit<Extract<Ast.Node, { type: T }>, 'type' | 'loc'>, |
| 9 | start: Ast.Pos, |
| 10 | end: Ast.Pos, |
| 11 | ): Extract<Ast.Node, { type: T }> { |
| 12 | const node: Record<string, unknown> = { type }; |
| 13 | for (const key of Object.keys(params)) { |
| 14 | type Key = keyof typeof params; |
| 15 | if (params[key as Key] !== undefined) { |
| 16 | node[key] = params[key as Key]; |
| 17 | } |
| 18 | } |
| 19 | node.loc = { start, end }; |
| 20 | return node as Extract<Ast.Node, { type: T }>; |
| 21 | } |
| 22 | |
| 23 | export function CALL_NODE( |
| 24 | name: string, |
no outgoing calls
no test coverage detected