/** * Context (`m`) analysis for BrightScript. * * In BrightScript, `m` is a special variable: * - When a function is called from a SceneGraph component → `m` = component scope * - When called from an associative array → `m` = that AA * - When called standalone → `m` = module-level global AA * * This module tracks: * 1. What fields are assigned to `m` (m.field = value) * 2. Where functions are stored in AAs (aa.func = myFunc) * 3. The possible `m` contexts for each function based on call patterns * * This enables the extension to show: * - "m.top" is available because this function runs in a component context * - "m.data" was assigned in init() → type is roArray * - Warnings when m.field types are inconsistent */ import { SyntaxNode } from '../syntaxNode.js'; /** A field assignment on `m`: m.fieldName = value */ export interface ContextField { /** Field name (lowercased). */ name: string; /** Original casing. */ originalName: string; /** Inferred type of the assigned value (if determinable). */ typeName?: string; /** The function where this assignment occurs. */ assignedInFunction: string; /** Line of the assignment. */ line: number; /** Column. */ column: number; } /** A function stored in an AA: aa.funcField = someFunction */ export interface FunctionBinding { /** The AA variable name (lowercased). */ aaName: string; /** The field name in the AA. */ fieldName: string; /** The function name being stored (lowercased). */ functionName: string; /** Line of the binding. */ line: number; } /** A function defined inline as an AA literal field: `{ init: function() ... end function }`. */ export interface InlineAAFunction { /** The field name (lowercased). */ aaFieldName: string; /** The field name (original casing). */ aaFieldNameOriginal: string; /** Line of the field name. */ line: number; /** Column of the field name. */ column: number; /** Original-casing name of the enclosing function this AA literal appears in, or `''` for file scope. */ enclosingFunction: string; } /** An inline function assigned directly via dot: `aa.methodName = function(...) ... end function`. */ export interface DotAssignedFunction { /** The AA variable name (original casing). */ aaName: string; /** The field/method name being assigned (original casing). */ fieldName: string; /** Line of the field name. */ line: number; /** Column of the field name. */ column: number; /** Original-casing name of the enclosing function this assignment appears in, or `''` for file scope. */ enclosingFunction: string; } /** Represents the known context for a function. */ export interface FunctionContext { /** Function name (lowercased). */ functionName: string; /** Fields known to be available on `m` when this function runs. */ contextFields: ContextField[]; /** How this function is invoked: 'component' | 'aa' | 'standalone' | 'unknown'. */ invocationStyle: 'component' | 'aa' | 'standalone' | 'unknown'; /** If invoked as aa.func(), the AA name. */ aaOwner?: string; } export interface ContextAnalysis { /** All m.field assignments across the file. */ contextFields: ContextField[]; /** Functions stored in AAs (e.g., obj.handler = myFunc). */ functionBindings: FunctionBinding[]; /** Functions defined inline in AA literals (e.g., { init: function() ... }). */ inlineAAFunctions: InlineAAFunction[]; /** Functions assigned inline via dot (e.g., obj.init = function() ... end function). */ dotAssignedFunctions: DotAssignedFunction[]; /** * Best-effort invocation context per top-level function, derived only from * evidence within this file. See `analyzeContext`'s doc comment for what * `'component'` deliberately never means here. */ functionContexts: FunctionContext[]; /** Get all context fields assigned within a specific function. */ getFieldsInFunction(funcName: string): ContextField[]; /** Get all context fields across all functions (the full m scope). */ getAllFields(): ContextField[]; /** Get the invocation context for a specific top-level function (lowercased lookup). */ getFunctionContext(funcName: string): FunctionContext | undefined; } /** * Analyzes `m` context usage across the file. * * `functionContexts[].invocationStyle` is derived only from evidence visible * in this single file: * - `'aa'` — the function is bound as an AA field (`obj.field = funcName`), * so it is provably invoked as `obj.field()` and `m` is that AA. * - `'standalone'` — the function is called directly as a bare identifier * somewhere in this file (`funcName()`), so `m` is the module-level AA. * - `'unknown'` — neither is true. This deliberately covers the SceneGraph * component-callback case (a function referenced only from a component's * XML ``/`onChange`, e.g. `init`) as well as functions called * only from other files — this module has no XML access and does not * guess. A caller with XML access (cross-referencing `` * function names) can upgrade `'unknown'` to `'component'` with real * evidence; this module will never fabricate that distinction itself. */ export declare function analyzeContext(root: SyntaxNode): ContextAnalysis; //# sourceMappingURL=contextAnalysis.d.ts.map