import { Program } from 'estree'; import { EnumsApi } from '../../vpt/enums'; import { GlobalApi } from '../../vpt/global-api'; import { Table } from '../../vpt/table/table'; import { Stdlib } from '../stdlib'; import { Transformer } from './transformer'; /** * In the Visual Pinball table script, everything is global. In JavaScript we * decided to properly manage the scope in order not to pollute the global * namespace. * * This transformer goes through all variables and determines to which of the * following name spaces it belongs to (in that order): * - items: table elements * - enums: enum values exposed in Visual Pinball's VBScript API * - stdlib: the VBScript Standard Library implemented in JavaScript * - global: reference to Visual Pinball's global API * - eval: `ExecuteGlobal()` calls are directly handled here because they * cannot be wrapped into another method without losing the current * execution context. * * To match a namespace, the transformer looks at the actual values of each * name space. That's possible because at compile time, the table and the * player are already set up and thus accessible. * * To match an object or property, the transformer uses a special API that * allows matching in a case-insensitive way. When matched, the resulting * identifier is properly cased. * * Examples: * - `BallRelease.CreateBall()` would become `__items.BallRelease.CreateBall()`. * - `ImageAlignment.ImageAlignWorld` would become `__enums.ImageAlignment.ImageAlignWorld`. * - `PlaySound()` would become `__global.PlaySound()`. */ export declare class ReferenceTransformer extends Transformer { private readonly table; private readonly itemApis; private readonly enumApis; private readonly globalApi; private readonly stdlib; constructor(ast: Program, table: Table, itemApis: { [p: string]: any; }, enumApis: EnumsApi, globalApi: GlobalApi, stdlib: Stdlib); transform(): Program; /** * Adds the scope as argument to the GetRef call so we can actually retrieve the reference. * @param ast */ replaceGetRef(ast: Program): void; /** * Replaces global variables that refer to table elements by a member * expression given by an object name. */ replaceElementObjectNames(ast: Program): void; replaceEnumObjectNames(ast: Program): void; replaceGlobalApiNames(ast: Program): void; replaceStdlibNames(ast: Program): void; private isEligible; /** * The `eval()` command can't be wrapped into a function, because it messes * up the execution context. So we transpile and execute directly. * * Example: * ExecuteGlobal GetTextFile("controller.vbs") * becomes: * eval(__vbsHelper.transpileInline(__global.GetTextFile('controller.vbs'))); * * @param ast */ replaceExecuteGlobal(ast: Program): void; }