How to use the @angular/compiler.visitAll function in @angular/compiler

To help you get started, we’ve selected a few @angular/compiler 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 angular / angular / packages / localize / src / tools / src / translate / translation_files / message_serialization / message_serializer.ts View on Github external
visitContainedNodes(nodes: Node[]): void {
    const length = nodes.length;
    let index = 0;
    while (index < length) {
      if (!this.isPlaceholderContainer(nodes[index])) {
        const startOfContainedNodes = index;
        while (index < length - 1) {
          index++;
          if (this.isPlaceholderContainer(nodes[index])) {
            break;
          }
        }
        if (index - startOfContainedNodes > 1) {
          // Only create a container if there are two or more contained Nodes in a row
          this.renderer.startContainer();
          visitAll(this, nodes.slice(startOfContainedNodes, index - 1));
          this.renderer.closeContainer();
        }
      }
      if (index < length) {
        nodes[index].visit(this, undefined);
      }
      index++;
    }
  }
github angular / angular / packages / language-service / src / utils.ts View on Github external
export function getPathToNodeAtPosition(nodes: Node[], position: number): HtmlAstPath {
  const path: Node[] = [];
  const visitor = new class extends RecursiveVisitor {
    visit(ast: Node) {
      const span = spanOf(ast);
      if (inSpan(position, span)) {
        path.push(ast);
      } else {
        // Returning a truthy value here will skip all children and terminate
        // the visit.
        return true;
      }
    }
  };
  visitAll(visitor, nodes);
  return new AstPath(path, position);
}
github angular / angular / packages / localize / src / tools / src / translate / translation_files / translation_parsers / xliff2_translation_parser.ts View on Github external
visitElement(element: Element, context: any): any {
    if (element.name === 'unit') {
      const externalId = getAttrOrThrow(element, 'id');
      if (this.translations[externalId] !== undefined) {
        throw new TranslationParseError(
            element.sourceSpan, `Duplicated translations for message "${externalId}"`);
      }
      visitAll(this, element.children, {unit: externalId});
    } else if (element.name === 'segment') {
      assertTranslationUnit(element, context);
      const targetMessage = element.children.find(isTargetElement);
      if (targetMessage === undefined) {
        throw new TranslationParseError(element.sourceSpan, 'Missing required  element');
      }
      this.translations[context.unit] = serializeTargetMessage(targetMessage);
    } else {
      return visitAll(this, element.children);
    }
  }
}
github vokeit-oss / ng-i18n-aot-loader / src / index.js View on Github external
let i18nHtmlParser = new compiler.I18NHtmlParser(htmlParser);
        let parsed         = i18nHtmlParser.parse(content, this.resourcePath, false);
        
        if(1 > parsed.errors.length) {
            if(!templatesGenerated) {
                visitor.generateTemplates(true);
                
                templatesGenerated = true;
            }
            else {
                visitor.generateTemplates(false);
            }
            
            result =
                containers +
                '' + compiler.visitAll(visitor, parsed.rootNodes).join('') + '' +
                visitor.getTemplates(true);
        }
        else {
            console.error(parsed.errors);
        }
    }
    
    return result;
};
github angular / angular / packages / localize / src / tools / src / translate / translation_files / translation_parsers / xliff2_translation_parser.ts View on Github external
if (element.name === 'unit') {
      const externalId = getAttrOrThrow(element, 'id');
      if (this.translations[externalId] !== undefined) {
        throw new TranslationParseError(
            element.sourceSpan, `Duplicated translations for message "${externalId}"`);
      }
      visitAll(this, element.children, {unit: externalId});
    } else if (element.name === 'segment') {
      assertTranslationUnit(element, context);
      const targetMessage = element.children.find(isTargetElement);
      if (targetMessage === undefined) {
        throw new TranslationParseError(element.sourceSpan, 'Missing required  element');
      }
      this.translations[context.unit] = serializeTargetMessage(targetMessage);
    } else {
      return visitAll(this, element.children);
    }
  }
}
github angular / angular / packages / localize / src / tools / src / translate / translation_files / translation_parsers / xliff2_translation_parser.ts View on Github external
visitElement(element: Element, {parsedLocale}: BundleVisitorContext): any {
    if (element.name === 'xliff') {
      parsedLocale = getAttribute(element, 'trgLang');
      return visitAll(this, element.children, {parsedLocale});
    } else if (element.name === 'file') {
      this.bundle = {
        locale: parsedLocale,
        translations: Xliff2TranslationVisitor.extractTranslations(element)
      };
    } else {
      return visitAll(this, element.children, {parsedLocale});
    }
  }
}
github angular / angular / packages / localize / src / tools / src / translate / translation_files / translation_parsers / xliff2_translation_parser.ts View on Github external
static extractTranslations(file: Element): Record {
    const visitor = new this();
    visitAll(visitor, file.children);
    return visitor.translations;
  }
github angular / angular / packages / localize / src / tools / src / translate / translation_files / message_serialization / message_serializer.ts View on Github external
visitExpansionCase(expansionCase: ExpansionCase): void {
    this.renderer.text(` ${expansionCase.value} {`);
    this.renderer.startContainer();
    visitAll(this, expansionCase.expression);
    this.renderer.closeContainer();
    this.renderer.text(`}`);
  }
github angular / angular / packages / language-service / src / html_path.ts View on Github external
function visit(children: T[] | undefined) {
      if (children) results.push(visitAll(visitor, children, context));
    }
    cb(visit);
github angular / angular / packages / localize / src / tools / src / translate / translation_files / translation_parsers / xliff1_translation_parser.ts View on Github external
static extractBundle(xliff: Node[]): ParsedTranslationBundle|undefined {
    const visitor = new this();
    visitAll(visitor, xliff);
    return visitor.bundle;
  }