UNPKG

@casual-simulation/aux-runtime

Version:
200 lines 6.65 kB
import * as Acorn from 'acorn'; import type { Text } from 'yjs'; import { Doc } from 'yjs'; import type { CodeLocation } from './TranspilerUtils'; /** * The symbol that is used in script dependencies to represent any argument. */ export declare const anyArgument: unique symbol; declare module 'acorn' { /** * Extends the acorn parser interface. */ interface Parser { type: Acorn.TokenType; start: number; startLoc: number; value: string; pos: number; next(): void; parseLiteral(value: string): Acorn.Node; parseIdent(): Acorn.Node; parseExprSubscripts(): Acorn.Node; parseSubscript(base: Acorn.Node, startPos: number, startLoc: number): Acorn.Node; unexpected(): void; startNodeAt(start: number, startLoc: number): Acorn.Node; readToken(code: number): any; finishToken(token: Acorn.TokenType): any; finishNode(node: Acorn.Node, type: string): Acorn.Node; parseExprAtom(refShortHandDefaultPos: any): Acorn.Node; parseParenAndDistinguishExpression(canBeArrow: boolean): Acorn.Node; } } export type ExJsNode = TokenValueNode | ObjectValueNode; export interface TokenValueNode extends Acorn.Node { type: 'TokenValue'; identifier: Acorn.Node; } export interface ObjectValueNode extends Acorn.Node { type: 'ObjectValue'; identifier: Acorn.Node; } export interface TranspilerMacro { test: RegExp; replacement: (val: string) => string; } /** * The estraverse visitor keys that are used for TypeScript nodes. */ export declare const TypeScriptVisistorKeys: { [nodeType: string]: string[]; }; /** * Replaces macros in the given text. * @param text The text that the macros should be replaced in. */ export declare function replaceMacros(text: string): string; export interface TranspilerOptions { jsxFactory?: string; jsxFragment?: string; forceSync?: boolean; /** * The name of the function that should be called for ES Module imports. */ importFactory?: string; /** * The name of the variable that should be used to access the import.meta object. */ importMetaFactory?: string; /** * The name of the function that should be called for ES Module exports. */ exportFactory?: string; } /** * Defines a class that is able to compile code from AUX's custom JavaScript dialect * into pure ES6 JavaScript. Does not preserve spacing or comments. * * See https://docs.google.com/document/d/1WQXQPjdXxyx_lau15WPpwTTYvt66_wPCu3x-08rpLoY/edit?usp=sharing */ export declare class Transpiler { private _parser; private _jsxFactory; private _jsxFragment; private _importFactory; private _importMetaFactory; private _exportFactory; private _forceSync; private _cache; get forceSync(): boolean; set forceSync(value: boolean); constructor(options?: TranspilerOptions); parse(code: string): any; /** * Transpiles the given code into ES6 JavaScript Code. */ transpile(code: string): string; /** * Transpiles the given code and returns the result with the generated metadata. * @param code The code that should be transpiled. */ transpileWithMetadata(code: string): TranspilerResult; /** * Determines if the given node contains any await expressions. * @param node The node. */ private _isAsyncNode; /** * Transpiles the given code into ES6 JavaScript Code. */ private _transpile; /** * Parses the given code into a syntax tree. * @param code */ private _parse; getTagNodeValues(n: any): { tag: string; args: any[]; nodes: any[]; }; toJs(node: Acorn.Node): string; private _replace; private _replaceImportDeclaration; private _replaceImportExpression; private _replaceImportMeta; private _replaceExportNamedDeclaration; private _replaceExportVariableDeclaration; private _replaceExportSpecifiersDeclaration; private _replaceExportFromSourceDeclaration; private _replaceExportDefaultDeclaration; private _replaceExportAllDeclaration; private _replaceWhileStatement; private _replaceDoWhileStatement; private _replaceForStatement; private _replaceForInStatement; private _replaceForOfStatement; private _removeClassImplements; private _removeClassAbstract; private _removeAccessibility; private _removeAsExpression; private _removeNodeOrReplaceWithUndefined; private _removeOptionalFromIdentifier; private _replaceJSXElement; private _replaceJSXFragment; private _replaceJSXEmptyExpression; private _insertJSXFactoryCall; private _replaceJSXElementAttributes; private _replaceJSXElementChildren; private _replaceJSXText; private _replaceJSXExpressionContainer; private _removeTag; private _insertEnergyCheckIntoStatement; private _insertEnergyCheck; private _replaceAsyncFunction; private _replaceAwaitExpression; } export interface TranspilerResult { /** * The code that resulted from the transpiler. */ code: string; /** * The original code. */ original: string; /** * The metadata that the transpiler produced for the code. */ metadata: { /** * The document that was used to edit the code. */ doc: Doc; /** * The text structure that was used to edit the code. */ text: Text; /** * Whether the code is a module (contains import or export statements). */ isModule: boolean; /** * Whether the code is async (contains await expressions). */ isAsync: boolean; }; } /** * Calculates the original location that the given line and column numbers occurred at in the given transpiler result. * @param result The transpiler result. * @param location The location that should be converted from the transpiler output space to the transpiler input space. */ export declare function calculateOriginalLineLocation(result: TranspilerResult, location: CodeLocation): CodeLocation; /** * Calculates the final location that the given line and column numbers occurr at in the given transpiler result. * @param result The transpiler result. * @param location The location that should be converted from the transpiler input space to the output space. */ export declare function calculateFinalLineLocation(result: TranspilerResult, location: CodeLocation): CodeLocation; //# sourceMappingURL=Transpiler.d.ts.map