(node: Ast.Node)
| 2 | import type * as Ast from '../node.js'; |
| 3 | |
| 4 | export function nodeToJs(node: Ast.Node): JsValue { |
| 5 | switch (node.type) { |
| 6 | case 'arr': return node.value.map(item => nodeToJs(item)); |
| 7 | case 'bool': return node.value; |
| 8 | case 'null': return null; |
| 9 | case 'num': return node.value; |
| 10 | case 'obj': { |
| 11 | const obj: { [keys: string]: JsValue } = {}; |
| 12 | for (const [k, v] of node.value.entries()) { |
| 13 | // TODO: keyが__proto__とかじゃないかチェック |
| 14 | obj[k] = nodeToJs(v); |
| 15 | } |
| 16 | return obj; |
| 17 | } |
| 18 | case 'str': return node.value; |
| 19 | default: return undefined; |
| 20 | } |
| 21 | } |
no outgoing calls
no test coverage detected