How to use the @babel/template.statements function in @babel/template

To help you get started, we’ve selected a few @babel/template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FujitsuLaboratories / escapin / src / util.ts View on Github external
): t.Statement[] {
  // eslint-disable-next-line no-undef
  const file = Path.resolve(
    __dirname,
    `../templates/snippet/${specifier.replace(/\./g, '/').toLowerCase()}.js`,
  );
  if (!fs.existsSync(file)) {
    throw new Error(
      `Template file '${file}' not found. The type may be invalid or renamed due to an update.`,
    );
  }
  const tpl = fs.readFileSync(file, 'utf8');
  if (vars === undefined) {
    return parse(tpl).program.body;
  }
  return template.statements(tpl, {
    placeholderPattern: PLACEHOLDER_PATTERN,
  })(vars);
}
github FujitsuLaboratories / escapin / src / util.ts View on Github external
export function statements(tpl: string, vars: { [x: string]: OneOrMore }): t.Statement[] {
  return template.statements(tpl, {
    placeholderPattern: PLACEHOLDER_PATTERN,
  })(vars);
}