Validate dynamic children.

This commit is contained in:
Natalie Weizenbaum 2016-08-28 01:37:53 -07:00 committed by Natalie Weizenbaum
parent 0f20b58044
commit c4cda30bc0
5 changed files with 19 additions and 6 deletions

View File

@ -13,7 +13,6 @@ class CssMediaRule extends CssParentNode {
final FileSpan span; final FileSpan span;
// TODO: validate that children contains only at-rule and style rule nodes?
CssMediaRule(this.queries, {this.span}); CssMediaRule(this.queries, {this.span});
/*=T*/ accept/*<T>*/(CssVisitor/*<T>*/ visitor) => /*=T*/ accept/*<T>*/(CssVisitor/*<T>*/ visitor) =>

View File

@ -38,7 +38,6 @@ abstract class CssParentNode extends CssNode {
children = new UnmodifiableListView<CssNode>(children); children = new UnmodifiableListView<CssNode>(children);
void addChild(CssNode child) { void addChild(CssNode child) {
// TODO: validate that children are valid?
child._parent = this; child._parent = this;
child._indexInParent = _children.length; child._indexInParent = _children.length;
_children.add(child); _children.add(child);

View File

@ -17,8 +17,6 @@ class AtRule implements Statement {
final FileSpan span; final FileSpan span;
// TODO: validate that children only contains variable, at-rule, declaration,
// or style nodes?
AtRule(this.name, {this.value, Iterable<Statement> children, this.span}) AtRule(this.name, {this.value, Iterable<Statement> children, this.span})
: children = children == null ? null : new List.unmodifiable(children); : children = children == null ? null : new List.unmodifiable(children);

View File

@ -15,8 +15,6 @@ class StyleRule implements Statement {
final FileSpan span; final FileSpan span;
// TODO: validate that children only contains variable, at-rule, declaration,
// or style nodes?
StyleRule(this.selector, Iterable<Statement> children, {this.span}) StyleRule(this.selector, Iterable<Statement> children, {this.span})
: children = new List.unmodifiable(children); : children = new List.unmodifiable(children);

View File

@ -98,6 +98,10 @@ class PerformVisitor extends StatementVisitor
} }
void visitExtendRule(ExtendRule node) { void visitExtendRule(ExtendRule node) {
if (_selector == null || _declarationName != null) {
throw node.span.message("@extend may only be used within style rules.");
}
var targetText = _interpolationToValue(node.selector); var targetText = _interpolationToValue(node.selector);
// TODO: recontextualize parse errors. // TODO: recontextualize parse errors.
@ -107,6 +111,11 @@ class PerformVisitor extends StatementVisitor
} }
void visitAtRule(AtRule node) { void visitAtRule(AtRule node) {
if (_declarationName != null) {
throw node.span.message(
"At-rules may not be used within nested declarations.");
}
var value = node.value == null var value = node.value == null
? null ? null
: _interpolationToValue(node.value, trim: true); : _interpolationToValue(node.value, trim: true);
@ -171,6 +180,11 @@ class PerformVisitor extends StatementVisitor
} }
void visitMediaRule(MediaRule node) { void visitMediaRule(MediaRule node) {
if (_declarationName != null) {
throw node.span.message(
"Media rules may not be used within nested declarations.");
}
var queryIterable = node.queries.map(_visitMediaQuery); var queryIterable = node.queries.map(_visitMediaQuery);
var queries = _mediaQueries == null var queries = _mediaQueries == null
? new List<CssMediaQuery>.unmodifiable(queryIterable) ? new List<CssMediaQuery>.unmodifiable(queryIterable)
@ -224,6 +238,11 @@ class PerformVisitor extends StatementVisitor
Value visitReturn(Return node) => node.expression.accept(this); Value visitReturn(Return node) => node.expression.accept(this);
void visitStyleRule(StyleRule node) { void visitStyleRule(StyleRule node) {
if (_declarationName != null) {
throw node.span.message(
"Style rules may not be used within nested declarations.");
}
var selectorText = _interpolationToValue(node.selector, trim: true); var selectorText = _interpolationToValue(node.selector, trim: true);
var parsedSelector = new Parser(selectorText.value).parseSelector(); var parsedSelector = new Parser(selectorText.value).parseSelector();