UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

56 lines (55 loc) 2.75 kB
/** * Pure static class implementing subset of C-style preprocessor. * inspired by: https://github.com/dcodeIO/Preprocessor.js */ export class Preprocessor { /** * Run c-like preprocessor on the source code, and resolves the code based on the defines and ifdefs * * @param {string} source - The source code to work on. * @param {Map<string, string>} [includes] - A map containing key-value pairs of include names * and their content. These are used for resolving #include directives in the source. * @param {object} [options] - Optional parameters. * @param {boolean} [options.stripUnusedColorAttachments] - If true, strips unused color attachments. * @param {boolean} [options.stripDefines] - If true, strips all defines from the source. * @returns {string|null} Returns preprocessed source code, or null in case of error. */ static run(source: string, includes?: Map<string, string>, options?: { stripUnusedColorAttachments?: boolean; stripDefines?: boolean; }): string | null; static stripComments(source: any): any; static processArraySize(source: any, intDefines: any): any; static RemoveEmptyLines(source: any): any; /** * Process source code, and resolves the code based on the defines and ifdefs. * * @param {string} source - The source code to work on. * @param {Map<string, string>} defines - Supplied defines which are used in addition to those * defined in the source code. Maps a define name to its value. Note that the map is modified * by the function. * @param {Map<string, string>} [includes] - An object containing key-value pairs of include names and their * content. * @param {boolean} [stripDefines] - If true, strips all defines from the source. * @returns {string} Returns preprocessed source code. */ static _preprocess(source: string, defines?: Map<string, string>, includes?: Map<string, string>, stripDefines?: boolean): string; static _keep(stack: any): boolean; /** * Very simple expression evaluation, handles cases: * * - expression * - defined(expression) * - !defined(expression) * - simple comparisons like "XX == 3" or "XX != test" * * But does not handle more complex cases, which would require more complex system: * * - defined(A) || defined(B) * * @param {string} expression - The expression to evaluate. * @param {Map<string, string>} defines - A map containing key-value pairs of defines. * @returns {object} Returns an object containing the result of the evaluation and an error flag. */ static evaluate(expression: string, defines: Map<string, string>): object; }