extractReadsAndWrites
function extractReadsAndWrites(tokens): { reads: string[]; writes: string[];};Defined in: packages/engine/src/engine/ExpressionEngineSafety.ts:205
Extract variable reads and writes from a token stream.
Handles both IDENT and UNIT tokens as potential variable references. UNIT tokens occur when the variable name collides with a known unit (e.g., “b” for bits, “s” for seconds). The colon prefix unambiguously signals a variable definition context (handled by VariableParselet). A standalone UNIT token is only a real variable reference when it isn’t in unit-literal position (see isUnitLiteralContext) otherwise it’s a quantity/conversion unit name, never LOAD_VAR’d.
Also detects user-defined-function DEFINITIONS (name(params) = body)
as a read+write of the function’s own name, mirroring :name = value’s
existing convention of registering the defined name as both, and
excludes the definition’s own PARAMETER names from reads/writes
entirely (see collectFunctionParamNames). A function CALL
(name(args), no trailing =) needs no special detection: the call’s
own name falls through to the ordinary bare-identifier read-tracking
below, the same as any other LOAD_VAR-producing identifier. This is
already correct once calls compile successfully, no change needed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tokens | Token[] |
Returns
Section titled “Returns”{ reads: string[]; writes: string[];}reads: string[];writes
Section titled “writes”writes: string[];