* Asserts that the node is of the given type and returns it with stricter * typing. Throws if the node's type does not match.
(node, type)
| 5974 | * typing. Throws if the node's type does not match. |
| 5975 | */ |
| 5976 | function assertNodeType(node, type) { |
| 5977 | const typedNode = checkNodeType(node, type); |
| 5978 | |
| 5979 | if (!typedNode) { |
| 5980 | throw new Error(`Expected node of type ${type}, but got ` + (node ? `node of type ${node.type}` : String(node))); |
| 5981 | } // $FlowFixMe: Unsure why. |
| 5982 | |
| 5983 | |
| 5984 | return typedNode; |
| 5985 | } |
| 5986 | /** |
| 5987 | * Returns the node more strictly typed iff it is of the given type. Otherwise, |
| 5988 | * returns null. |
no test coverage detected