estilo
Version:
Create color schemes for Vim, NeoVim, Airline and Lightline
37 lines (36 loc) • 1.24 kB
JavaScript
import { EtaParseError } from "./err.js";
/* END TYPES */
/* istanbul ignore next */
const AsyncFunction = async function () { }.constructor; // eslint-disable-line @typescript-eslint/no-empty-function
/**
* Takes a template string and returns a template function that can be called with (data, config)
*
* @param str - The template string
* @param config - A custom configuration object (optional)
*/
export function compile(str, options) {
const config = this.config;
/* ASYNC HANDLING */
// code gratefully taken from https://github.com/mde/ejs and adapted
const ctor = options && options.async
? AsyncFunction
: Function;
/* END ASYNC HANDLING */
try {
return new ctor(config.varName, "options", this.compileToString.call(this, str, options)); // eslint-disable-line no-new-func
}
catch (e) {
if (e instanceof SyntaxError) {
throw new EtaParseError("Bad template syntax\n\n" +
e.message +
"\n" +
Array(e.message.length + 1).join("=") +
"\n" +
this.compileToString.call(this, str, options) +
"\n");
}
else {
throw e;
}
}
}