API Reference
jspicl
Entry point for transpiling your JavaScript code.
function jspicl(source: string, options?: JspiclOptions): JspiclOutput;
-
rootNode
Root node of your AST. jspicl will transpile the entire hierarchy. -
options
Configuration options that affect the final output.
JspiclOptions
type JspiclOptions = {
prettify?: boolean;
customMappers?: Record<string, AstNodeParser>;
};
-
prettify = true
Prettifies the transpiled code. By default, jspicl formats the Lua output for you but if performance ever becomes an issue you can turn this off by setting this to false. -
customMappers
Custom handlers for transpiling expressions, declarations or statements.
JspiclOutput
type JspiclOutput = {
code: string;
polyfills: Record<string, string>;
};
-
code
The transpiled Lua code. -
polyfills
A hashmap of detected polyfills. The polyfills are recommended but you can replace them with your own implementation if needed. Generate the final result by joining the values:Object.values(polyfills).join("\n")
AstNode
Represents a node in the syntax tree. All nodes contain at least a type property.
type AstNode = {
type: string;
[key: string]: any;
};
AstNodeParser
Contract for a parser function. The function should be named after the AST node type. Binding a scopeBoundary field on the function will create a new scope for all variables defined inside the hieararchy.
type AstNodeParser = {
(node: Omit<AstNode, "type">, options: AstNodeParserOptions): string;
scopeBoundary?: boolean;
};
AstNodeParserOptions
Includes references to the transpile function and scope.
type AstNodeParserOptions = {
transpile: TranspileFunction;
scope: {
variables: Record<string, any>;
[key: string]: any;
};
};
TranspileFunction
type TranspileFunction = (node: AstNode, options?: TranspileOptions) => string;
TranspileOptions
type TranspileOptions = { arraySeparator?: string };