All files / lib jazz.js

100% Statements 41/41
100% Branches 5/5
100% Functions 1/1
100% Lines 41/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 423x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x  
"use strict";
 
import { createCompiler } from "./jazz/compiler.js";
import { SyntaxError } from "./jazz/error.js";
import { createParser } from "./jazz/parser.js";
import { createScanner } from "./jazz/scanner.js";
 
/**
 * Compile a Jazz template into an executable program.
 *
 * @param {string} source: template source text
 * @param {Object} [options]: optional compiler and parser options
 * @param {string} [options.filename]: filename used for error reporting
 * @param {boolean} [options["parser:debug"]]: enable parser debug mode
 * @param {boolean} [options["compiler:debug"]]: enable compiler debug mode
 * @returns {Object} compiled program with process(namespace, cb)
 */
function compile(source, options) {
  const opts = options || {};
  const scanner = createScanner(source, opts.filename);
  const parser = createParser(scanner);
  parser.debug = opts["parser:debug"] || false;
 
  const compiler = createCompiler();
  compiler.debug = opts["compiler:debug"] || false;
 
  const parsed = parser.parse();
  return compiler.compile(parsed);
}
 
const jazz = {
  SyntaxError,
  createScanner,
  createParser,
  createCompiler,
  compile,
};
 
export { SyntaxError, createScanner, createParser, createCompiler, compile };
 
export default jazz;