MCPcopy Create free account
hub / github.com/arktypeio/arktype / isRunSurely

Function isRunSurely

ark/aot/flat.ts:1846–1872  ·  view source on GitHub ↗
(id: Node)

Source from the content-addressed store, hash-verified

1844
1845// a value's read run once, and whenever its statement is, as an element, an argument or a property's value
1846const isRunSurely = (id: Node): boolean => {
1847 let child = id
1848 for (let node = id.parent; node; child = node, node = node.parent) {
1849 switch (node.type) {
1850 case "ArrayExpression":
1851 case "ObjectExpression":
1852 case "ParenthesizedExpression":
1853 case "ExpressionStatement":
1854 case "VariableDeclaration":
1855 case "Program":
1856 continue
1857 case "Property":
1858 if (node.value !== child || node.computed) return false
1859 continue
1860 case "CallExpression":
1861 case "NewExpression":
1862 if (node.callee === child) return false
1863 continue
1864 case "VariableDeclarator":
1865 if (node.init !== child) return false
1866 continue
1867 default:
1868 return false
1869 }
1870 }
1871 return true
1872}
1873
1874const topStatementOf = (node: Node): Node => {
1875 while (node.parent && node.parent.type !== "Program") node = node.parent

Callers 1

writtenWhereReadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected