How to use the ember-template-recast.transform function in ember-template-recast

To help you get started, we’ve selected a few ember-template-recast 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 ember-template-lint / ember-template-lint / lib / linter.js View on Github external
let message = buildErrorMessage(options.moduleId, error);
      messages.push(message);
    }

    let rules = this.buildRules({
      results: messages,
      pending: pendingStatus,
      moduleId: options.moduleId,
      moduleName: options.moduleId,
      configResolver: options.configResolver,
      rawSource: source,
    });

    for (let rule of rules) {
      try {
        transform(templateAST, () => rule.getVisitor());
      } catch (error) {
        let message = buildErrorMessage(options.moduleId, error);
        messages.push(message);
      }
    }

    if (pendingStatus) {
      if (messages.length === 0) {
        messages.push({
          rule: 'invalid-pending-module',
          message: `Pending module (\`${options.moduleId}\`) passes all rules. Please remove \`${options.moduleId}\` from pending list.`,
          moduleId: options.moduleId,
          severity: 2,
        });
      } else {
        if (pendingStatus.only) {
github ember-codemods / ember-angle-brackets-codemod / transforms / angle-brackets / transform.js View on Github external
module.exports = function transform(fileInfo, config, invokableData = {}) {
  config = config || {};
  config.helpers = config.helpers || [];
  config.skipBuiltInComponents =
    'skipBuiltInComponents' in config ? config.skipBuiltInComponents : false;
  config.skipFilesThatMatchRegex = config.skipFilesThatMatchRegex || null;

  if (shouldSkipFile(fileInfo, config)) {
    return fileInfo.source;
  }

  let { code: toAngleBracket } = recast.transform(fileInfo.source, () =>
    transformToAngleBracket(fileInfo, config, invokableData)
  );

  let attrEqualEmptyString = new RegExp(_EMPTY_STRING_, 'gi');
  let dataEqualsNoValue = /(data-\S+)=""/gim;

  toAngleBracket = toAngleBracket.replace(attrEqualEmptyString, '');
  toAngleBracket = toAngleBracket.replace(dataEqualsNoValue, '$1');
  return toAngleBracket;
};

ember-template-recast

Non-destructive template transformer.

MIT
Latest version published 5 months ago

Package Health Score

76 / 100
Full package analysis