angular_ast 0.5.11

  • Readme
  • Changelog
  • Installing
  • 87

angular_ast #


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.

  // 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(
    sourceUrl: sourceUrl,
    desugar: false,
    parseExpressions: false,
    exceptionHandler: exceptionHandler,
  for (AngularParserException e in exceptionHandler.exceptions) {
    // Do something with exception.

0.5.11 #

  • Maintenance release to support Dart 2.5 dev.

0.5.10 #

  • New ThrowingTemplateAstVisitor which throws by default in each visit method.

0.5.9 #

  • Errors caused by parsing an invalid micro expression (i.e. *ngFor) are now reported to the registered ExceptionHandler rather than thrown.

0.5.8 #

  • Fixed a type error that occurred when recovering from a missing closing banana ')]'.

0.5.7 #

  • Annotations may now have compound names (for example

  • It is now an error to use @deferred on a <template> tag or combined with a structural (i.e. *ngIf) directive.

  • Ignores right-trailing spaces when parsing micro expression let-assignments.

  • When parsing a failed micro expression (i.e. *ngFor), avoids a type error.

  • vellip is now a recognized char.

  • Whitespace inside preformatted text (<pre> tags) is now always preserved.

0.5.6 #

  • Maintenance release to support Dart 2.0 stable.

0.5.5 #

  • Maintenance release for -dev.68.

0.5.4 #

  • Add CloseElementAst complement into ContainerAst.
  • Added support for annotations on <template>.
  • The whitespace transformer now understands @preserveWhitespace.

0.5.3+3 #

  • Maintenance release for -dev.60.

0.5.3+2 #

  • Maintenance release for -dev.56.

0.5.3+1 #

  • Fixed source span range of AttributeAst which would extend past EOF when recovering from a value with an unclosed quote.

0.5.3 #

  • Exported ParsedAnnotationAst.

  • Added ContainerAst.

  • Annotations may now be assigned values.

  • Added support for annotations on ContainerAst.

  • The * micro-syntax now supports leading whitespace.

  • Whitespace between <ng-content> and </ng-content> will no longer yield a parsing error.

0.5.2 #

  • The * micro-syntax now supports newlines after an identifier.

0.5.1 #

  • The minimum SDK version is now sdk: ">=2.0.0-dev.46.0 <2.0.0".

  • The * micro-syntax now supports binding to the primary input when followed by additional input or let bindings. Previously the micro-syntax supported binding to the primary input only in isolation.

    Example usage enabled by this change.


    <template [foo]="expr1" [fooContext]="expr2">


    <div *foo="expr1; context: expr2"></div>

0.5.0 #

  • BREAKING CHANGE: We no longer support parsing Dart expressions as part of parsing the template AST. We hope to re-add some support for this by migrating the existing parser in package:angular, but we are likely not to have a stable API for some time.

  • BREAKING CHANGE: Deleted ExpressionParserVisitor (related to above).

0.4.4 #

  • Added MinimizeWhitespaceVisitor.

0.4.3+1 #

  • Maintenance release, supporting newer package versions.

0.4.3 #

  • Maintenance release, supporting newer package versions.

0.4.2 #

  • Supports the latest version of quiver.

0.4.1 #

Bug fixes #

  • Un-escape HTML characters, such as &lt;, &#8721;, or &#x2211;, when they appear in text. Note, we do not do any un-escaping when these characters appear inside elements.

0.4.0 #

First stable release in a while! Going forward we'll be versioning this package normally as needed to support the AngularDart template compiler and analyzer plugin.

New features #

  • Add RecursiveTemplateAstVisitor, which will visit all AST nodes accessible from the given node.
  • Support ngProjectAs decorator on <ng-content>.

Bug fixes #

  • DesugarVisitor now desugars AST nodes which were the (indirect) children of EmbeddedTemplateAst nodes.

0.4.0-alpha.1 #

  • Update version from 0.4.0-alpha+2 to make it come after 0.4.0-alpha.0 which was published in August 2017.

0.4.0-alpha+2 #

  • Requires analyzer: ^0.31.0-alpha.1.

New Features #

  • Now supports AnnotationAsts, like @deferred.
  • Parse SVG tags as either void or non-void with no error.

Bug fixes #

  • Fixed sourceSpan calculation to not include the space before the start of an element decorator.
  • Sets the origin in all synthetic nodes. Previously, we were missing a few cases.
  • Fixed a NPE in DesugarVisitor.

0.4.0-alpha+1 #

Bug fix #

  • Fixed event name for banana syntax [(name)] from nameChanged to nameChange.

0.2.0 #

  • Add an experimental flag to NgParser (toolFriendlyAstOrigin) which wraps de-sugared AST origins in another synthetic AST that represents the intermediate value (i.e. BananaAst or StarAst)
  • Add support for parsing expressions, including de-sugaring pipes. When parsing templates, expression AST objects automatically use the Dart expression parser.
new ExpressionAst.parse('some + dart + expression')
  • One exception: The | operator is not respected, as it is used for pipes in AngularDart. Instead, this operator is converted into a special PipeExpression.
  • Added TemplateAstVisitor and two examples:
    • HumanizingTemplateAstVisitor
    • IdentityTemplateAstVisitor
  • De-sugars the *ngFor-style micro expressions; see micro/*_test.dart.
    • Added attributes as a valid property of EmbeddedTemplateAst

0.1.0 #

  • Initial commit

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  angular_ast: ^0.5.11

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:angular_ast/angular_ast.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health suggestions

Fix lib/angular_ast.dart. (-0.50 points)

Analysis of lib/angular_ast.dart reported 1 hint:

line 89 col 5: 'parseExpressions' is deprecated and shouldn't be used.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

Homepage URL isn't helpful. (-10 points)

Update the homepage field from pubspec.yaml: link to a website about the package or use the source repository URL.

The package description is too short. (-14 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and angular_ast.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0-dev.1.0 <3.0.0
analyzer ^0.37.0 0.37.1+1 0.39.10
charcode ^1.1.0 1.1.3
collection ^1.14.5 1.14.12
meta ^1.1.4 1.1.8
source_span ^1.4.0 1.7.0
string_scanner ^1.0.1 1.0.5
Transitive dependencies
args 1.6.0
async 2.4.1
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
front_end 0.1.21+1 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
kernel 0.3.21+1 0.3.29
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pedantic 1.9.0
pub_semver 1.4.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner ^1.0.0
build_test ^0.10.2+5
path ^1.6.1 1.7.0
test ^1.3.0