diff --git a/lib/angular_ast.dart b/lib/angular_ast.dart index ebc6d77..c0bb973 100644 --- a/lib/angular_ast.dart +++ b/lib/angular_ast.dart @@ -13,8 +13,6 @@ export 'package:angular_ast/src/ast.dart' CloseElementAst, CommentAst, ElementAst, - EmbeddedContentAst, - EmbeddedTemplateAst, EventAst, ExpressionAst, InterpolationAst, @@ -22,7 +20,6 @@ export 'package:angular_ast/src/ast.dart' ParsedBananaAst, ParsedCloseElementAst, ParsedDecoratorAst, - ParsedEmbeddedContentAst, ParsedEventAst, ParsedInterpolationAst, ParsedElementAst, diff --git a/lib/src/ast.dart b/lib/src/ast.dart index 9af8907..1b9193e 100644 --- a/lib/src/ast.dart +++ b/lib/src/ast.dart @@ -7,8 +7,6 @@ export 'package:angular_ast/src/ast/attribute.dart' export 'package:angular_ast/src/ast/close_element.dart' show CloseElementAst, ParsedCloseElementAst; export 'package:angular_ast/src/ast/comment.dart' show CommentAst; -export 'package:angular_ast/src/ast/content.dart' - show EmbeddedContentAst, ParsedEmbeddedContentAst; export 'package:angular_ast/src/ast/element.dart' show ElementAst, ParsedElementAst; export 'package:angular_ast/src/ast/event.dart' show EventAst, ParsedEventAst; @@ -26,7 +24,6 @@ export 'package:angular_ast/src/ast/property.dart' show PropertyAst, ParsedPropertyAst; export 'package:angular_ast/src/ast/reference.dart' show ReferenceAst, ParsedReferenceAst; -export 'package:angular_ast/src/ast/template.dart' show EmbeddedTemplateAst; export 'package:angular_ast/src/ast/text.dart' show TextAst; export 'package:angular_ast/src/ast/sugar/banana.dart' show BananaAst, ParsedBananaAst; diff --git a/lib/src/ast/content.dart b/lib/src/ast/content.dart deleted file mode 100644 index f1c26da..0000000 --- a/lib/src/ast/content.dart +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:angular_ast/src/ast.dart'; -import 'package:angular_ast/src/token/tokens.dart'; -import 'package:angular_ast/src/visitor.dart'; -import 'package:quiver/core.dart'; -import 'package:source_span/source_span.dart'; - -/// Represents an `` element AST. -/// -/// Embedded content is _like_ an `ElementAst`, but only contains children. -/// -/// Clients should not extend, implement, or mix-in this class. -abstract class EmbeddedContentAst implements StandaloneTemplateAst { - /// Create a synthetic embedded content AST. - factory EmbeddedContentAst([String selector]) = _SyntheticEmbeddedContentAst; - - /// Create a synthetic [EmbeddedContentAst] that originated from [origin]. - factory EmbeddedContentAst.from( - TemplateAst origin, [ - String selector, - ]) = _SyntheticEmbeddedContentAst.from; - - /// Create a new [EmbeddedContentAst] parsed from tokens in [sourceFile]. - factory EmbeddedContentAst.parsed( - SourceFile sourceFile, - NgToken startElementToken, - NgToken elementIdentifierToken, - NgToken endElementToken, - CloseElementAst closeComplement, [ - NgToken selectToken, - NgToken equalSign, - NgAttributeValueToken selectorValueToken, - ]) = ParsedEmbeddedContentAst; - - @override - /*=R*/ accept/**/(TemplateAstVisitor/**/ visitor, [C context]) { - return visitor.visitEmbeddedContent(this, context); - } - - /// A CSS selector denoting what elements should be embedded. - /// - /// May be null if and only if decorator 'select' is defined, - /// but no value is assigned. - /// If 'select' is not defined at all (simple ), then the value - /// will default to '*'. - String get selector; - - /// that is paired to this . - CloseElementAst get closeComplement; - set closeComplement(CloseElementAst closeComplement); - - @override - bool operator ==(Object o) { - return o is EmbeddedContentAst && - o.selector == selector && - o.closeComplement == closeComplement; - } - - @override - int get hashCode => hash2(selector.hashCode, closeComplement); - - @override - String toString() => '$EmbeddedContentAst {$selector}'; -} - -class ParsedEmbeddedContentAst extends TemplateAst with EmbeddedContentAst { - // Token for 'ng-content'. - final NgToken identifierToken; - - // Token for 'select'. May be null. - final NgToken selectToken; - - // Token for '='. May be null. - final NgToken equalSign; - - // Token for value paired to 'select'. May be null. - final NgAttributeValueToken selectorValueToken; - - @override - CloseElementAst closeComplement; - - ParsedEmbeddedContentAst( - SourceFile sourceFile, - NgToken startElementToken, - this.identifierToken, - NgToken endElementToken, - this.closeComplement, [ - this.selectToken, - this.equalSign, - this.selectorValueToken, - ]) - : super.parsed( - startElementToken, - endElementToken, - sourceFile, - ); - - @override - String get selector { - // '' ; no value was defined. - // Return null to handle later. - if (selectToken != null && equalSign == null) { - return null; - } - return selectorValueToken?.innerValue?.lexeme ?? '*'; - } -} - -class _SyntheticEmbeddedContentAst extends SyntheticTemplateAst - with EmbeddedContentAst { - @override - final String selector; - - @override - CloseElementAst closeComplement; - - _SyntheticEmbeddedContentAst([this.selector = '*', this.closeComplement]) { - this.closeComplement = new CloseElementAst('ng-content'); - } - - _SyntheticEmbeddedContentAst.from( - TemplateAst origin, [ - this.selector = '*', - ]) - : super.from(origin) { - this.closeComplement = new CloseElementAst('ng-content'); - } -} diff --git a/lib/src/ast/element.dart b/lib/src/ast/element.dart index 778b6f6..aba486b 100644 --- a/lib/src/ast/element.dart +++ b/lib/src/ast/element.dart @@ -97,6 +97,12 @@ abstract class ElementAst implements StandaloneTemplateAst { /// Determines whether the element tag name is void element. bool get isVoidElement; + /// Determines if the element tag name is 'template'. + bool get isTemplate; + + /// Determines if the element tag name is 'ng-content'. + bool get isNgContent; + /// CloseElement complement /// /// If [closeComplement] == null, then [isVoidElement] is true. @@ -238,6 +244,14 @@ class ParsedElementAst extends TemplateAst with ElementAst { /// Star assignments. @override final List stars; + + /// Indicates if 'template'. + @override + bool get isTemplate => name == 'template'; + + /// Indicates if 'ng-content'. + @override + bool get isNgContent => name == 'ng-content'; } class _SyntheticElementAst extends SyntheticTemplateAst with ElementAst { @@ -296,4 +310,10 @@ class _SyntheticElementAst extends SyntheticTemplateAst with ElementAst { @override final List stars; + + @override + bool get isTemplate => name == 'template'; + + @override + bool get isNgContent => name == 'ng-content'; } diff --git a/lib/src/ast/template.dart b/lib/src/ast/template.dart deleted file mode 100644 index 62f2cbf..0000000 --- a/lib/src/ast/template.dart +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:angular_ast/src/ast.dart'; -import 'package:angular_ast/src/token/tokens.dart'; -import 'package:angular_ast/src/visitor.dart'; -import 'package:collection/collection.dart'; -import 'package:quiver/core.dart'; -import 'package:source_span/source_span.dart'; - -const _listEquals = const ListEquality(); - -/// Represents an embedded template (i.e. is not directly rendered in DOM). -/// -/// It shares many properties with an [ElementAst], but is not one. It may be -/// considered invalid to a `