(node: Node, source: string)
| 901 | } |
| 902 | |
| 903 | const isPureExpression = (node: Node, source: string): boolean => { |
| 904 | node = unwrapExpression(node) |
| 905 | switch (node.type) { |
| 906 | case "Literal": |
| 907 | case "Identifier": |
| 908 | case "ArrowFunctionExpression": |
| 909 | case "FunctionExpression": |
| 910 | return true |
| 911 | case "TemplateLiteral": |
| 912 | return node.expressions.every(e => isPureExpression(e, source)) |
| 913 | case "ArrayExpression": |
| 914 | return node.elements.every( |
| 915 | e => !e || (e.type !== "SpreadElement" && isPureExpression(e, source)) |
| 916 | ) |
| 917 | // e.g. `schemas = { user: User }`, which a bundler drops with the |
| 918 | // validators only it reads. A computed key other than a literal may call toString |
| 919 | case "ObjectExpression": |
| 920 | return node.properties.every( |
| 921 | p => |
| 922 | p.type === "Property" && |
| 923 | (!p.computed || p.key.type === "Literal") && |
| 924 | isPureExpression(p.value, source) |
| 925 | ) |
| 926 | case "CallExpression": |
| 927 | case "NewExpression": |
| 928 | return pureAnnotationOf(source, node) !== undefined |
| 929 | } |
| 930 | return false |
| 931 | } |
| 932 | |
| 933 | // each after those it reads, or undefined where one can't be written into a function |
| 934 | const unitsOf = ( |
no test coverage detected