MCPcopy Create free account
hub / github.com/observablehq/framework / checkConst

Function checkConst

src/javascript/assignments.ts:10–26  ·  view source on GitHub ↗
(node: Assignable)

Source from the content-addressed store, hash-verified

8/** Throws a SyntaxError for any illegal assignments. */
9export 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 }

Callers 2

checkConstLeftFunction · 0.85
checkConstArgumentFunction · 0.85

Calls 1

syntaxErrorFunction · 0.85

Tested by

no test coverage detected