angular_ast 0.5.11

Dart native
Flutter Android iOS

Parser and utilities for AngularDart templates

angular_ast #

Pub
Package

Parser and utilities for AngularDart templates.

This package is platform agnostic (no HTML or Dart VM dependencies).

Usage #

Currently in development and not stable.

import 'package:angular_ast/angular_ast.dart';

main() {
  // Create an AST tree by parsing an AngularDart template.
  var tree = parse('<button [title]="someTitle">Hello</button>');

  // Print to console.
  print(tree);

  // Output:
  // [
  //    ElementAst <button> {
  //      properties=
  //        PropertyAst {
  //          title="ExpressionAst {someTitle}"}
  //          childNodes=TextAst {Hello}
  //      }
  //    }
  // ]
}

Additional flags can be passed to change the behavior of the parser:

Data typeNameDescriptionDefault Value
StringsourceUrlString describing the path of the HTML string.
booldesugarEnabled desugaring of banana-syntax, star syntax, and pipes.true
boolparseExpressionsParses Dart expressions raises exceptions if occurred.true
ExceptionHandlerexceptionHandlerSwitch to 'new RecoveringExceptionHandler()' to enable error recovery.ThrowingExceptionHandler

When using RecoveringExceptionHandler, the accumulated exceptions can be accessed through the RecoveringExceptionHandler object. Refer to the following example:

void parse(String content, String sourceUrl) {
  var exceptionHandler = new RecoveringExceptionHandler();
  var asts = parse(
    content,
    sourceUrl: sourceUrl,
    desugar: false,
    parseExpressions: false,
    exceptionHandler: exceptionHandler,
  );
  for (AngularParserException e in exceptionHandler.exceptions) {
    // Do something with exception.
  }
}
1
likes
60
pub points
95%
popularity

Publisher

angulardart.dev

Parser and utilities for AngularDart templates

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, charcode, collection, meta, source_span, string_scanner

More

Packages that depend on angular_ast