(node: Assignable)
| 8 | /** Throws a SyntaxError for any illegal assignments. */ |
| 9 | export function checkAssignments(node: Node, references: Identifier[], input: string): void { |
| 10 | function checkConst(node: Assignable) { |
| 11 | switch (node.type) { |
| 12 | case "Identifier": |
| 13 | if (references.includes(node)) throw syntaxError(`Assignment to external variable '${node.name}'`, node, input); |
| 14 | if (defaultGlobals.has(node.name)) throw syntaxError(`Assignment to global '${node.name}'`, node, input); |
| 15 | break; |
| 16 | case "ObjectPattern": |
| 17 | node.properties.forEach((node) => checkConst(node.type === "Property" ? node.value : node)); |
| 18 | break; |
| 19 | case "ArrayPattern": |
| 20 | node.elements.forEach((node) => node && checkConst(node)); |
| 21 | break; |
| 22 | case "RestElement": |
| 23 | checkConst(node.argument); |
| 24 | break; |
| 25 | } |
| 26 | } |
| 27 | function checkConstLeft({left}: {left: Assignable}) { |
| 28 | checkConst(left); |
| 29 | } |
no test coverage detected