Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: packages/csslib/lib/src/tree.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/csslib/lib/src/tokenkind.dart ('k') | packages/csslib/lib/src/tree_base.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of csslib.visitor; 5 part of csslib.visitor;
6 6
7 ///////////////////////////////////////////////////////////////////////// 7 /////////////////////////////////////////////////////////////////////////
8 // CSS specific types: 8 // CSS specific types:
9 ///////////////////////////////////////////////////////////////////////// 9 /////////////////////////////////////////////////////////////////////////
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 [int combinator = TokenKind.COMBINATOR_NONE]) 113 [int combinator = TokenKind.COMBINATOR_NONE])
114 : combinator = combinator, 114 : combinator = combinator,
115 super(span); 115 super(span);
116 116
117 bool get isCombinatorNone => combinator == TokenKind.COMBINATOR_NONE; 117 bool get isCombinatorNone => combinator == TokenKind.COMBINATOR_NONE;
118 bool get isCombinatorPlus => combinator == TokenKind.COMBINATOR_PLUS; 118 bool get isCombinatorPlus => combinator == TokenKind.COMBINATOR_PLUS;
119 bool get isCombinatorGreater => combinator == TokenKind.COMBINATOR_GREATER; 119 bool get isCombinatorGreater => combinator == TokenKind.COMBINATOR_GREATER;
120 bool get isCombinatorTilde => combinator == TokenKind.COMBINATOR_TILDE; 120 bool get isCombinatorTilde => combinator == TokenKind.COMBINATOR_TILDE;
121 bool get isCombinatorDescendant => 121 bool get isCombinatorDescendant =>
122 combinator == TokenKind.COMBINATOR_DESCENDANT; 122 combinator == TokenKind.COMBINATOR_DESCENDANT;
123 bool get isCombinatorDeep => combinator == TokenKind.COMBINATOR_DEEP;
124 bool get isCombinatorShadowPiercingDescendant =>
125 combinator == TokenKind.COMBINATOR_SHADOW_PIERCING_DESCENDANT;
123 126
124 String get _combinatorToString => isCombinatorDescendant 127 String get _combinatorToString {
125 ? ' ' 128 switch (combinator) {
126 : isCombinatorPlus 129 case TokenKind.COMBINATOR_SHADOW_PIERCING_DESCENDANT:
127 ? ' + ' 130 return ' >>> ';
128 : isCombinatorGreater ? ' > ' : isCombinatorTilde ? ' ~ ' : ''; 131 case TokenKind.COMBINATOR_DEEP:
132 return ' /deep/ ';
133 case TokenKind.COMBINATOR_DESCENDANT:
134 return ' ';
135 case TokenKind.COMBINATOR_GREATER:
136 return ' > ';
137 case TokenKind.COMBINATOR_PLUS:
138 return ' + ';
139 case TokenKind.COMBINATOR_TILDE:
140 return ' ~ ';
141 default:
142 return '';
143 }
144 }
129 145
130 SimpleSelectorSequence clone() => 146 SimpleSelectorSequence clone() =>
131 new SimpleSelectorSequence(simpleSelector, span, combinator); 147 new SimpleSelectorSequence(simpleSelector, span, combinator);
132 148
133 visit(VisitorBase visitor) => visitor.visitSimpleSelectorSequence(this); 149 visit(VisitorBase visitor) => visitor.visitSimpleSelectorSequence(this);
134 150
135 String toString() => simpleSelector.name; 151 String toString() => simpleSelector.name;
136 } 152 }
137 153
138 /* All other selectors (element, #id, .class, attribute, pseudo, negation, 154 /* All other selectors (element, #id, .class, attribute, pseudo, negation,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 PseudoClassSelector(Identifier name, SourceSpan span) : super(name, span); 292 PseudoClassSelector(Identifier name, SourceSpan span) : super(name, span);
277 visit(VisitorBase visitor) => visitor.visitPseudoClassSelector(this); 293 visit(VisitorBase visitor) => visitor.visitPseudoClassSelector(this);
278 294
279 PseudoClassSelector clone() => new PseudoClassSelector(_name, span); 295 PseudoClassSelector clone() => new PseudoClassSelector(_name, span);
280 296
281 String toString() => ":$name"; 297 String toString() => ":$name";
282 } 298 }
283 299
284 // ::pseudoElement 300 // ::pseudoElement
285 class PseudoElementSelector extends SimpleSelector { 301 class PseudoElementSelector extends SimpleSelector {
286 PseudoElementSelector(Identifier name, SourceSpan span) : super(name, span); 302 // If true, this is a CSS2.1 pseudo-element with only a single ':'.
303 final bool isLegacy;
304
305 PseudoElementSelector(Identifier name, SourceSpan span,
306 {this.isLegacy: false})
307 : super(name, span);
287 visit(VisitorBase visitor) => visitor.visitPseudoElementSelector(this); 308 visit(VisitorBase visitor) => visitor.visitPseudoElementSelector(this);
288 309
289 PseudoElementSelector clone() => new PseudoElementSelector(_name, span); 310 PseudoElementSelector clone() => new PseudoElementSelector(_name, span);
290 311
291 String toString() => "::$name"; 312 String toString() => "${isLegacy ? ':' : '::'}$name";
292 } 313 }
293 314
294 // :pseudoClassFunction(expression) 315 // :pseudoClassFunction(argument)
295 class PseudoClassFunctionSelector extends PseudoClassSelector { 316 class PseudoClassFunctionSelector extends PseudoClassSelector {
296 final SelectorExpression expression; 317 final TreeNode _argument; // Selector, SelectorExpression
297 318
298 PseudoClassFunctionSelector(Identifier name, this.expression, SourceSpan span) 319 PseudoClassFunctionSelector(Identifier name, this._argument, SourceSpan span)
299 : super(name, span); 320 : super(name, span);
300 321
301 PseudoClassFunctionSelector clone() => 322 PseudoClassFunctionSelector clone() =>
302 new PseudoClassFunctionSelector(_name, expression, span); 323 new PseudoClassFunctionSelector(_name, _argument, span);
324
325 TreeNode get argument => _argument;
326 Selector get selector => _argument as Selector;
327 SelectorExpression get expression => _argument as SelectorExpression;
303 328
304 visit(VisitorBase visitor) => visitor.visitPseudoClassFunctionSelector(this); 329 visit(VisitorBase visitor) => visitor.visitPseudoClassFunctionSelector(this);
305 } 330 }
306 331
307 // ::pseudoElementFunction(expression) 332 // ::pseudoElementFunction(expression)
308 class PseudoElementFunctionSelector extends PseudoElementSelector { 333 class PseudoElementFunctionSelector extends PseudoElementSelector {
309 final SelectorExpression expression; 334 final SelectorExpression expression;
310 335
311 PseudoElementFunctionSelector( 336 PseudoElementFunctionSelector(
312 Identifier name, this.expression, SourceSpan span) 337 Identifier name, this.expression, SourceSpan span)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 class Directive extends TreeNode { 428 class Directive extends TreeNode {
404 Directive(SourceSpan span) : super(span); 429 Directive(SourceSpan span) : super(span);
405 430
406 bool get isBuiltIn => true; // Known CSS directive? 431 bool get isBuiltIn => true; // Known CSS directive?
407 bool get isExtension => false; // SCSS extension? 432 bool get isExtension => false; // SCSS extension?
408 433
409 Directive clone() => new Directive(span); 434 Directive clone() => new Directive(span);
410 visit(VisitorBase visitor) => visitor.visitDirective(this); 435 visit(VisitorBase visitor) => visitor.visitDirective(this);
411 } 436 }
412 437
438 class DocumentDirective extends Directive {
439 final List<LiteralTerm> functions;
440 final List<TreeNode> groupRuleBody;
441
442 DocumentDirective(this.functions, this.groupRuleBody, SourceSpan span)
443 : super(span);
444
445 DocumentDirective clone() {
446 var clonedFunctions = <LiteralTerm>[];
447 for (var function in functions) {
448 clonedFunctions.add(function.clone());
449 }
450 var clonedGroupRuleBody = <TreeNode>[];
451 for (var rule in groupRuleBody) {
452 clonedGroupRuleBody.add(rule.clone());
453 }
454 return new DocumentDirective(clonedFunctions, clonedGroupRuleBody, span);
455 }
456
457 visit(VisitorBase visitor) => visitor.visitDocumentDirective(this);
458 }
459
460 class SupportsDirective extends Directive {
461 final SupportsCondition condition;
462 final List<TreeNode> groupRuleBody;
463
464 SupportsDirective(this.condition, this.groupRuleBody, SourceSpan span)
465 : super(span);
466
467 SupportsDirective clone() {
468 var clonedCondition = condition.clone();
469 var clonedGroupRuleBody = <TreeNode>[];
470 for (var rule in groupRuleBody) {
471 clonedGroupRuleBody.add(rule.clone());
472 }
473 return new SupportsDirective(clonedCondition, clonedGroupRuleBody, span);
474 }
475
476 visit(VisitorBase visitor) => visitor.visitSupportsDirective(this);
477 }
478
479 abstract class SupportsCondition extends TreeNode {
480 SupportsCondition(SourceSpan span) : super(span);
481 }
482
483 class SupportsConditionInParens extends SupportsCondition {
484 /// A [Declaration] or nested [SupportsCondition].
485 final TreeNode condition;
486
487 SupportsConditionInParens(Declaration declaration, SourceSpan span)
488 : condition = declaration,
489 super(span);
490
491 SupportsConditionInParens.nested(SupportsCondition condition, SourceSpan span)
492 : condition = condition,
493 super(span);
494
495 SupportsConditionInParens clone() =>
496 new SupportsConditionInParens(condition.clone(), span);
497
498 visit(VisitorBase visitor) => visitor.visitSupportsConditionInParens(this);
499 }
500
501 class SupportsNegation extends SupportsCondition {
502 final SupportsConditionInParens condition;
503
504 SupportsNegation(this.condition, SourceSpan span) : super(span);
505
506 SupportsNegation clone() => new SupportsNegation(condition.clone(), span);
507
508 visit(VisitorBase visitor) => visitor.visitSupportsNegation(this);
509 }
510
511 class SupportsConjunction extends SupportsCondition {
512 final List<SupportsConditionInParens> conditions;
513
514 SupportsConjunction(this.conditions, SourceSpan span) : super(span);
515
516 SupportsConjunction clone() {
517 var clonedConditions = <SupportsCondition>[];
518 for (var condition in conditions) {
519 clonedConditions.add(condition.clone());
520 }
521 return new SupportsConjunction(clonedConditions, span);
522 }
523
524 visit(VisitorBase visitor) => visitor.visitSupportsConjunction(this);
525 }
526
527 class SupportsDisjunction extends SupportsCondition {
528 final List<SupportsConditionInParens> conditions;
529
530 SupportsDisjunction(this.conditions, SourceSpan span) : super(span);
531
532 SupportsDisjunction clone() {
533 var clonedConditions = <SupportsCondition>[];
534 for (var condition in conditions) {
535 clonedConditions.add(condition.clone());
536 }
537 return new SupportsDisjunction(clonedConditions, span);
538 }
539
540 visit(VisitorBase visitor) => visitor.visitSupportsDisjunction(this);
541 }
542
543 class ViewportDirective extends Directive {
544 final String name;
545 final DeclarationGroup declarations;
546
547 ViewportDirective(this.name, this.declarations, SourceSpan span)
548 : super(span);
549
550 ViewportDirective clone() =>
551 new ViewportDirective(name, declarations.clone(), span);
552
553 visit(VisitorBase visitor) => visitor.visitViewportDirective(this);
554 }
555
413 class ImportDirective extends Directive { 556 class ImportDirective extends Directive {
414 /** import name specified. */ 557 /** import name specified. */
415 final String import; 558 final String import;
416 559
417 /** Any media queries for this import. */ 560 /** Any media queries for this import. */
418 final List<MediaQuery> mediaQueries; 561 final List<MediaQuery> mediaQueries;
419 562
420 ImportDirective(this.import, this.mediaQueries, SourceSpan span) 563 ImportDirective(this.import, this.mediaQueries, SourceSpan span)
421 : super(span); 564 : super(span);
422 565
423 ImportDirective clone() { 566 ImportDirective clone() {
424 var cloneMediaQueries = []; 567 var cloneMediaQueries = <MediaQuery>[];
425 for (var mediaQuery in mediaQueries) { 568 for (var mediaQuery in mediaQueries) {
426 cloneMediaQueries.add(mediaQuery.clone()); 569 cloneMediaQueries.add(mediaQuery.clone());
427 } 570 }
428 return new ImportDirective(import, cloneMediaQueries, span); 571 return new ImportDirective(import, cloneMediaQueries, span);
429 } 572 }
430 573
431 visit(VisitorBase visitor) => visitor.visitImportDirective(this); 574 visit(VisitorBase visitor) => visitor.visitImportDirective(this);
432 } 575 }
433 576
434 /** 577 /**
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 : super(span); 619 : super(span);
477 620
478 bool get hasMediaType => _mediaType != null; 621 bool get hasMediaType => _mediaType != null;
479 String get mediaType => _mediaType.name; 622 String get mediaType => _mediaType.name;
480 623
481 bool get hasUnary => _mediaUnary != -1; 624 bool get hasUnary => _mediaUnary != -1;
482 String get unary => 625 String get unary =>
483 TokenKind.idToValue(TokenKind.MEDIA_OPERATORS, _mediaUnary).toUpperCase(); 626 TokenKind.idToValue(TokenKind.MEDIA_OPERATORS, _mediaUnary).toUpperCase();
484 627
485 MediaQuery clone() { 628 MediaQuery clone() {
486 var cloneExpressions = []; 629 var cloneExpressions = <MediaExpression>[];
487 for (var expr in expressions) { 630 for (var expr in expressions) {
488 cloneExpressions.add(expr.clone()); 631 cloneExpressions.add(expr.clone());
489 } 632 }
490 return new MediaQuery(_mediaUnary, _mediaType, cloneExpressions, span); 633 return new MediaQuery(_mediaUnary, _mediaType, cloneExpressions, span);
491 } 634 }
635
492 visit(VisitorBase visitor) => visitor.visitMediaQuery(this); 636 visit(VisitorBase visitor) => visitor.visitMediaQuery(this);
493 } 637 }
494 638
495 class MediaDirective extends Directive { 639 class MediaDirective extends Directive {
496 final List<MediaQuery> mediaQueries; 640 final List<MediaQuery> mediaQueries;
497 final List<RuleSet> rulesets; 641 final List<RuleSet> rulesets;
498 642
499 MediaDirective(this.mediaQueries, this.rulesets, SourceSpan span) 643 MediaDirective(this.mediaQueries, this.rulesets, SourceSpan span)
500 : super(span); 644 : super(span);
501 645
502 MediaDirective clone() { 646 MediaDirective clone() {
503 var cloneQueries = []; 647 var cloneQueries = <MediaQuery>[];
504 for (var mediaQuery in mediaQueries) { 648 for (var mediaQuery in mediaQueries) {
505 cloneQueries.add(mediaQuery.clone()); 649 cloneQueries.add(mediaQuery.clone());
506 } 650 }
507 var cloneRulesets = []; 651 var cloneRulesets = <RuleSet>[];
508 for (var ruleset in rulesets) { 652 for (var ruleset in rulesets) {
509 cloneRulesets.add(ruleset.clone()); 653 cloneRulesets.add(ruleset.clone());
510 } 654 }
511 return new MediaDirective(cloneQueries, cloneRulesets, span); 655 return new MediaDirective(cloneQueries, cloneRulesets, span);
512 } 656 }
513 657
514 visit(VisitorBase visitor) => visitor.visitMediaDirective(this); 658 visit(VisitorBase visitor) => visitor.visitMediaDirective(this);
515 } 659 }
516 660
517 class HostDirective extends Directive { 661 class HostDirective extends Directive {
518 final List<RuleSet> rulesets; 662 final List<RuleSet> rulesets;
519 663
520 HostDirective(this.rulesets, SourceSpan span) : super(span); 664 HostDirective(this.rulesets, SourceSpan span) : super(span);
521 665
522 HostDirective clone() { 666 HostDirective clone() {
523 var cloneRulesets = []; 667 var cloneRulesets = <RuleSet>[];
524 for (var ruleset in rulesets) { 668 for (var ruleset in rulesets) {
525 cloneRulesets.add(ruleset.clone()); 669 cloneRulesets.add(ruleset.clone());
526 } 670 }
527 return new HostDirective(cloneRulesets, span); 671 return new HostDirective(cloneRulesets, span);
528 } 672 }
529 673
530 visit(VisitorBase visitor) => visitor.visitHostDirective(this); 674 visit(VisitorBase visitor) => visitor.visitHostDirective(this);
531 } 675 }
532 676
533 class PageDirective extends Directive { 677 class PageDirective extends Directive {
534 final String _ident; 678 final String _ident;
535 final String _pseudoPage; 679 final String _pseudoPage;
536 final List<DeclarationGroup> _declsMargin; 680 final List<DeclarationGroup> _declsMargin;
537 681
538 PageDirective( 682 PageDirective(
539 this._ident, this._pseudoPage, this._declsMargin, SourceSpan span) 683 this._ident, this._pseudoPage, this._declsMargin, SourceSpan span)
540 : super(span); 684 : super(span);
541 685
542 PageDirective clone() { 686 PageDirective clone() {
543 var cloneDeclsMargin = []; 687 var cloneDeclsMargin = <DeclarationGroup>[];
544 for (var declMargin in _declsMargin) { 688 for (var declMargin in _declsMargin) {
545 cloneDeclsMargin.add(declMargin.clone()); 689 cloneDeclsMargin.add(declMargin.clone());
546 } 690 }
547 return new PageDirective(_ident, _pseudoPage, cloneDeclsMargin, span); 691 return new PageDirective(_ident, _pseudoPage, cloneDeclsMargin, span);
548 } 692 }
549 693
550 visit(VisitorBase visitor) => visitor.visitPageDirective(this); 694 visit(VisitorBase visitor) => visitor.visitPageDirective(this);
551 695
552 bool get hasIdent => _ident != null && _ident.length > 0; 696 bool get hasIdent => _ident != null && _ident.length > 0;
553 bool get hasPseudoPage => _pseudoPage != null && _pseudoPage.length > 0; 697 bool get hasPseudoPage => _pseudoPage != null && _pseudoPage.length > 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 return null; 736 return null;
593 } 737 }
594 738
595 KeyFrameDirective clone() { 739 KeyFrameDirective clone() {
596 var cloneBlocks = []; 740 var cloneBlocks = [];
597 for (var block in _blocks) { 741 for (var block in _blocks) {
598 cloneBlocks.add(block.clone()); 742 cloneBlocks.add(block.clone());
599 } 743 }
600 return new KeyFrameDirective(_keyframeName, cloneBlocks, span); 744 return new KeyFrameDirective(_keyframeName, cloneBlocks, span);
601 } 745 }
746
602 visit(VisitorBase visitor) => visitor.visitKeyFrameDirective(this); 747 visit(VisitorBase visitor) => visitor.visitKeyFrameDirective(this);
603 } 748 }
604 749
605 class KeyFrameBlock extends Expression { 750 class KeyFrameBlock extends Expression {
606 final Expressions _blockSelectors; 751 final Expressions _blockSelectors;
607 final DeclarationGroup _declarations; 752 final DeclarationGroup _declarations;
608 753
609 KeyFrameBlock(this._blockSelectors, this._declarations, SourceSpan span) 754 KeyFrameBlock(this._blockSelectors, this._declarations, SourceSpan span)
610 : super(span); 755 : super(span);
611 756
(...skipping 16 matching lines...) Expand all
628 final String dartClassName; 773 final String dartClassName;
629 final List<RuleSet> rulesets; 774 final List<RuleSet> rulesets;
630 775
631 StyletDirective(this.dartClassName, this.rulesets, SourceSpan span) 776 StyletDirective(this.dartClassName, this.rulesets, SourceSpan span)
632 : super(span); 777 : super(span);
633 778
634 bool get isBuiltIn => false; 779 bool get isBuiltIn => false;
635 bool get isExtension => true; 780 bool get isExtension => true;
636 781
637 StyletDirective clone() { 782 StyletDirective clone() {
638 var cloneRulesets = []; 783 var cloneRulesets = <RuleSet>[];
639 for (var ruleset in rulesets) { 784 for (var ruleset in rulesets) {
640 cloneRulesets.add(ruleset.clone()); 785 cloneRulesets.add(ruleset.clone());
641 } 786 }
642 return new StyletDirective(dartClassName, cloneRulesets, span); 787 return new StyletDirective(dartClassName, cloneRulesets, span);
643 } 788 }
644 789
645 visit(VisitorBase visitor) => visitor.visitStyletDirective(this); 790 visit(VisitorBase visitor) => visitor.visitStyletDirective(this);
646 } 791 }
647 792
648 class NamespaceDirective extends Directive { 793 class NamespaceDirective extends Directive {
(...skipping 19 matching lines...) Expand all
668 VarDefinitionDirective(this.def, SourceSpan span) : super(span); 813 VarDefinitionDirective(this.def, SourceSpan span) : super(span);
669 814
670 VarDefinitionDirective clone() => 815 VarDefinitionDirective clone() =>
671 new VarDefinitionDirective(def.clone(), span); 816 new VarDefinitionDirective(def.clone(), span);
672 817
673 visit(VisitorBase visitor) => visitor.visitVarDefinitionDirective(this); 818 visit(VisitorBase visitor) => visitor.visitVarDefinitionDirective(this);
674 } 819 }
675 820
676 class MixinDefinition extends Directive { 821 class MixinDefinition extends Directive {
677 final String name; 822 final String name;
678 final List definedArgs; 823 final List<TreeNode> definedArgs;
679 final bool varArgs; 824 final bool varArgs;
680 825
681 MixinDefinition(this.name, this.definedArgs, this.varArgs, SourceSpan span) 826 MixinDefinition(this.name, this.definedArgs, this.varArgs, SourceSpan span)
682 : super(span); 827 : super(span);
683 828
684 MixinDefinition clone() { 829 MixinDefinition clone() {
685 var cloneDefinedArgs = []; 830 var cloneDefinedArgs = <TreeNode>[];
686 for (var definedArg in definedArgs) { 831 for (var definedArg in definedArgs) {
687 cloneDefinedArgs.add(definedArg.clone()); 832 cloneDefinedArgs.add(definedArg.clone());
688 } 833 }
689 return new MixinDefinition(name, cloneDefinedArgs, varArgs, span); 834 return new MixinDefinition(name, cloneDefinedArgs, varArgs, span);
690 } 835 }
691 836
692 visit(VisitorBase visitor) => visitor.visitMixinDefinition(this); 837 visit(VisitorBase visitor) => visitor.visitMixinDefinition(this);
693 } 838 }
694 839
695 /** Support a Sass @mixin. See http://sass-lang.com for description. */ 840 /** Support a Sass @mixin. See http://sass-lang.com for description. */
696 class MixinRulesetDirective extends MixinDefinition { 841 class MixinRulesetDirective extends MixinDefinition {
697 final List rulesets; 842 final List<TreeNode> rulesets;
698 843
699 MixinRulesetDirective(String name, List<VarDefinitionDirective> args, 844 MixinRulesetDirective(String name, List<TreeNode> args, bool varArgs,
700 bool varArgs, this.rulesets, SourceSpan span) 845 this.rulesets, SourceSpan span)
701 : super(name, args, varArgs, span); 846 : super(name, args, varArgs, span);
702 847
703 MixinRulesetDirective clone() { 848 MixinRulesetDirective clone() {
704 var clonedArgs = []; 849 var clonedArgs = <VarDefinition>[];
705 for (var arg in definedArgs) { 850 for (var arg in definedArgs) {
706 clonedArgs.add(arg.clone()); 851 clonedArgs.add(arg.clone());
707 } 852 }
708 var clonedRulesets = []; 853 var clonedRulesets = <TreeNode>[];
709 for (var ruleset in rulesets) { 854 for (var ruleset in rulesets) {
710 clonedRulesets.add(ruleset.clone()); 855 clonedRulesets.add(ruleset.clone());
711 } 856 }
712 return new MixinRulesetDirective( 857 return new MixinRulesetDirective(
713 name, clonedArgs, varArgs, clonedRulesets, span); 858 name, clonedArgs, varArgs, clonedRulesets, span);
714 } 859 }
715 860
716 visit(VisitorBase visitor) => visitor.visitMixinRulesetDirective(this); 861 visit(VisitorBase visitor) => visitor.visitMixinRulesetDirective(this);
717 } 862 }
718 863
719 class MixinDeclarationDirective extends MixinDefinition { 864 class MixinDeclarationDirective extends MixinDefinition {
720 final DeclarationGroup declarations; 865 final DeclarationGroup declarations;
721 866
722 MixinDeclarationDirective(String name, List<VarDefinitionDirective> args, 867 MixinDeclarationDirective(String name, List<TreeNode> args, bool varArgs,
723 bool varArgs, this.declarations, SourceSpan span) 868 this.declarations, SourceSpan span)
724 : super(name, args, varArgs, span); 869 : super(name, args, varArgs, span);
725 870
726 MixinDeclarationDirective clone() { 871 MixinDeclarationDirective clone() {
727 var clonedArgs = []; 872 var clonedArgs = <TreeNode>[];
728 for (var arg in definedArgs) { 873 for (var arg in definedArgs) {
729 clonedArgs.add(arg.clone()); 874 clonedArgs.add(arg.clone());
730 } 875 }
731 return new MixinDeclarationDirective( 876 return new MixinDeclarationDirective(
732 name, clonedArgs, varArgs, declarations.clone(), span); 877 name, clonedArgs, varArgs, declarations.clone(), span);
733 } 878 }
734 879
735 visit(VisitorBase visitor) => visitor.visitMixinDeclarationDirective(this); 880 visit(VisitorBase visitor) => visitor.visitMixinDeclarationDirective(this);
736 } 881 }
737 882
738 /** To support consuming a SASS mixin @include. */ 883 /** To support consuming a SASS mixin @include. */
739 class IncludeDirective extends Directive { 884 class IncludeDirective extends Directive {
740 final String name; 885 final String name;
741 final List<List<TreeNode>> args; 886 final List<List<Expression>> args;
742 887
743 IncludeDirective(this.name, this.args, SourceSpan span) : super(span); 888 IncludeDirective(this.name, this.args, SourceSpan span) : super(span);
744 889
745 IncludeDirective clone() { 890 IncludeDirective clone() {
746 var cloneArgs = []; 891 var cloneArgs = <List<Expression>>[];
747 for (var arg in args) { 892 for (var arg in args) {
748 for (var term in arg) { 893 cloneArgs.add(arg.map((term) => term.clone()).toList());
749 cloneArgs.add(term.clone());
750 }
751 } 894 }
752 return new IncludeDirective(name, cloneArgs, span); 895 return new IncludeDirective(name, cloneArgs, span);
753 } 896 }
754 897
755 visit(VisitorBase visitor) => visitor.visitIncludeDirective(this); 898 visit(VisitorBase visitor) => visitor.visitIncludeDirective(this);
756 } 899 }
757 900
758 /** To support SASS @content. */ 901 /** To support SASS @content. */
759 class ContentDirective extends Directive { 902 class ContentDirective extends Directive {
760 ContentDirective(SourceSpan span) : super(span); 903 ContentDirective(SourceSpan span) : super(span);
(...skipping 22 matching lines...) Expand all
783 {important: false, ie7: false}) 926 {important: false, ie7: false})
784 : this.important = important, 927 : this.important = important,
785 this.isIE7 = ie7, 928 this.isIE7 = ie7,
786 super(span); 929 super(span);
787 930
788 String get property => isIE7 ? '*${_property.name}' : _property.name; 931 String get property => isIE7 ? '*${_property.name}' : _property.name;
789 Expression get expression => _expression; 932 Expression get expression => _expression;
790 933
791 bool get hasDartStyle => dartStyle != null; 934 bool get hasDartStyle => dartStyle != null;
792 935
793 Declaration clone() => new Declaration( 936 Declaration clone() =>
794 _property.clone(), _expression.clone(), dartStyle, span, 937 new Declaration(_property.clone(), _expression.clone(), dartStyle, span,
795 important: important); 938 important: important);
796 939
797 visit(VisitorBase visitor) => visitor.visitDeclaration(this); 940 visit(VisitorBase visitor) => visitor.visitDeclaration(this);
798 } 941 }
799 942
800 // TODO(terry): Consider 2 kinds of VarDefinitions static at top-level and 943 // TODO(terry): Consider 2 kinds of VarDefinitions static at top-level and
801 // dynamic when in a declaration. Currently, Less syntax 944 // dynamic when in a declaration. Currently, Less syntax
802 // '@foo: expression' and 'var-foo: expression' in a declaration 945 // '@foo: expression' and 'var-foo: expression' in a declaration
803 // are statically resolved. Better solution, if @foo or var-foo 946 // are statically resolved. Better solution, if @foo or var-foo
804 // are top-level are then statically resolved and var-foo in a 947 // are top-level are then statically resolved and var-foo in a
805 // declaration group (surrounded by a selector) would be dynamic. 948 // declaration group (surrounded by a selector) would be dynamic.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 ExtendDeclaration clone() { 988 ExtendDeclaration clone() {
846 var newSelector = selectors.map((s) => s.clone()).toList(); 989 var newSelector = selectors.map((s) => s.clone()).toList();
847 return new ExtendDeclaration(newSelector, span); 990 return new ExtendDeclaration(newSelector, span);
848 } 991 }
849 992
850 visit(VisitorBase visitor) => visitor.visitExtendDeclaration(this); 993 visit(VisitorBase visitor) => visitor.visitExtendDeclaration(this);
851 } 994 }
852 995
853 class DeclarationGroup extends TreeNode { 996 class DeclarationGroup extends TreeNode {
854 /** Can be either Declaration or RuleSet (if nested selector). */ 997 /** Can be either Declaration or RuleSet (if nested selector). */
855 final List declarations; 998 final List<TreeNode> declarations;
856 999
857 DeclarationGroup(this.declarations, SourceSpan span) : super(span); 1000 DeclarationGroup(this.declarations, SourceSpan span) : super(span);
858 1001
859 DeclarationGroup clone() { 1002 DeclarationGroup clone() {
860 var clonedDecls = declarations.map((d) => d.clone()).toList(); 1003 var clonedDecls = declarations.map((d) => d.clone()).toList();
861 return new DeclarationGroup(clonedDecls, span); 1004 return new DeclarationGroup(clonedDecls, span);
862 } 1005 }
863 1006
864 visit(VisitorBase visitor) => visitor.visitDeclarationGroup(this); 1007 visit(VisitorBase visitor) => visitor.visitDeclarationGroup(this);
865 } 1008 }
866 1009
867 class MarginGroup extends DeclarationGroup { 1010 class MarginGroup extends DeclarationGroup {
868 final int margin_sym; // TokenType for for @margin sym. 1011 final int margin_sym; // TokenType for for @margin sym.
869 1012
870 MarginGroup(this.margin_sym, List<Declaration> decls, SourceSpan span) 1013 MarginGroup(this.margin_sym, List<TreeNode> decls, SourceSpan span)
871 : super(decls, span); 1014 : super(decls, span);
872 MarginGroup clone() => 1015 MarginGroup clone() =>
873 new MarginGroup(margin_sym, super.clone() as dynamic, span); 1016 new MarginGroup(margin_sym, super.clone().declarations, span);
874 visit(VisitorBase visitor) => visitor.visitMarginGroup(this); 1017 visit(VisitorBase visitor) => visitor.visitMarginGroup(this);
875 } 1018 }
876 1019
877 class VarUsage extends Expression { 1020 class VarUsage extends Expression {
878 final String name; 1021 final String name;
879 final List<Expression> defaultValues; 1022 final List<Expression> defaultValues;
880 1023
881 VarUsage(this.name, this.defaultValues, SourceSpan span) : super(span); 1024 VarUsage(this.name, this.defaultValues, SourceSpan span) : super(span);
882 1025
883 VarUsage clone() { 1026 VarUsage clone() {
884 var clonedValues = []; 1027 var clonedValues = <Expression>[];
885 for (var expr in defaultValues) { 1028 for (var expr in defaultValues) {
886 clonedValues.add(expr.clone()); 1029 clonedValues.add(expr.clone());
887 } 1030 }
888 return new VarUsage(name, clonedValues, span); 1031 return new VarUsage(name, clonedValues, span);
889 } 1032 }
890 1033
891 visit(VisitorBase visitor) => visitor.visitVarUsage(this); 1034 visit(VisitorBase visitor) => visitor.visitVarUsage(this);
892 } 1035 }
893 1036
894 class OperatorSlash extends Expression { 1037 class OperatorSlash extends Expression {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 expressions.add(expression); 1301 expressions.add(expression);
1159 } 1302 }
1160 1303
1161 Expressions clone() { 1304 Expressions clone() {
1162 var clonedExprs = new Expressions(span); 1305 var clonedExprs = new Expressions(span);
1163 for (var expr in expressions) { 1306 for (var expr in expressions) {
1164 clonedExprs.add(expr.clone()); 1307 clonedExprs.add(expr.clone());
1165 } 1308 }
1166 return clonedExprs; 1309 return clonedExprs;
1167 } 1310 }
1311
1168 visit(VisitorBase visitor) => visitor.visitExpressions(this); 1312 visit(VisitorBase visitor) => visitor.visitExpressions(this);
1169 } 1313 }
1170 1314
1171 class BinaryExpression extends Expression { 1315 class BinaryExpression extends Expression {
1172 final Token op; 1316 final Token op;
1173 final Expression x; 1317 final Expression x;
1174 final Expression y; 1318 final Expression y;
1175 1319
1176 BinaryExpression(this.op, this.x, this.y, SourceSpan span) : super(span); 1320 BinaryExpression(this.op, this.x, this.y, SourceSpan span) : super(span);
1177 1321
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 1368
1225 visit(VisitorBase visitor) => visitor.visitDartStyleExpression(this); 1369 visit(VisitorBase visitor) => visitor.visitDartStyleExpression(this);
1226 } 1370 }
1227 1371
1228 class FontExpression extends DartStyleExpression { 1372 class FontExpression extends DartStyleExpression {
1229 final Font font; 1373 final Font font;
1230 1374
1231 // font-style font-variant font-weight font-size/line-height font-family 1375 // font-style font-variant font-weight font-size/line-height font-family
1232 // TODO(terry): Only px/pt for now need to handle all possible units to 1376 // TODO(terry): Only px/pt for now need to handle all possible units to
1233 // support calc expressions on units. 1377 // support calc expressions on units.
1234 FontExpression(SourceSpan span, {dynamic size, List<String> family, 1378 FontExpression(SourceSpan span,
1235 int weight, String style, String variant, LineHeight lineHeight}) 1379 {dynamic size,
1380 List<String> family,
1381 int weight,
1382 String style,
1383 String variant,
1384 LineHeight lineHeight})
1236 : font = new Font( 1385 : font = new Font(
1237 size: size is LengthTerm ? size.value : size, 1386 size: size is LengthTerm ? size.value : size,
1238 family: family, 1387 family: family,
1239 weight: weight, 1388 weight: weight,
1240 style: style, 1389 style: style,
1241 variant: variant, 1390 variant: variant,
1242 lineHeight: lineHeight), 1391 lineHeight: lineHeight),
1243 super(DartStyleExpression.fontStyle, span); 1392 super(DartStyleExpression.fontStyle, span);
1244 1393
1245 FontExpression merged(DartStyleExpression newFontExpr) { 1394 FontExpression merged(DartStyleExpression newFontExpr) {
1246 if (newFontExpr is FontExpression && this.isFont && newFontExpr.isFont) { 1395 if (newFontExpr is FontExpression && this.isFont && newFontExpr.isFont) {
1247 return new FontExpression.merge(this, newFontExpr); 1396 return new FontExpression.merge(this, newFontExpr);
1248 } 1397 }
1249 return null; 1398 return null;
1250 } 1399 }
1251 1400
1252 /** 1401 /**
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 return '.clockwiseFromTop($top,$right,$bottom,$left)'; 1439 return '.clockwiseFromTop($top,$right,$bottom,$left)';
1291 } 1440 }
1292 } 1441 }
1293 } 1442 }
1294 1443
1295 class MarginExpression extends BoxExpression { 1444 class MarginExpression extends BoxExpression {
1296 // TODO(terry): Does auto for margin need to be exposed to Dart UI framework? 1445 // TODO(terry): Does auto for margin need to be exposed to Dart UI framework?
1297 /** Margin expression ripped apart. */ 1446 /** Margin expression ripped apart. */
1298 MarginExpression(SourceSpan span, {num top, num right, num bottom, num left}) 1447 MarginExpression(SourceSpan span, {num top, num right, num bottom, num left})
1299 : super(DartStyleExpression.marginStyle, span, 1448 : super(DartStyleExpression.marginStyle, span,
1300 new BoxEdge(left, top, right, bottom)); 1449 new BoxEdge(left, top, right, bottom));
1301 1450
1302 MarginExpression.boxEdge(SourceSpan span, BoxEdge box) 1451 MarginExpression.boxEdge(SourceSpan span, BoxEdge box)
1303 : super(DartStyleExpression.marginStyle, span, box); 1452 : super(DartStyleExpression.marginStyle, span, box);
1304 1453
1305 merged(DartStyleExpression newMarginExpr) { 1454 merged(DartStyleExpression newMarginExpr) {
1306 if (newMarginExpr is MarginExpression && 1455 if (newMarginExpr is MarginExpression &&
1307 this.isMargin && 1456 this.isMargin &&
1308 newMarginExpr.isMargin) { 1457 newMarginExpr.isMargin) {
1309 return new MarginExpression.merge(this, newMarginExpr); 1458 return new MarginExpression.merge(this, newMarginExpr);
1310 } 1459 }
(...skipping 15 matching lines...) Expand all
1326 MarginExpression clone() => new MarginExpression(span, 1475 MarginExpression clone() => new MarginExpression(span,
1327 top: box.top, right: box.right, bottom: box.bottom, left: box.left); 1476 top: box.top, right: box.right, bottom: box.bottom, left: box.left);
1328 1477
1329 visit(VisitorBase visitor) => visitor.visitMarginExpression(this); 1478 visit(VisitorBase visitor) => visitor.visitMarginExpression(this);
1330 } 1479 }
1331 1480
1332 class BorderExpression extends BoxExpression { 1481 class BorderExpression extends BoxExpression {
1333 /** Border expression ripped apart. */ 1482 /** Border expression ripped apart. */
1334 BorderExpression(SourceSpan span, {num top, num right, num bottom, num left}) 1483 BorderExpression(SourceSpan span, {num top, num right, num bottom, num left})
1335 : super(DartStyleExpression.borderStyle, span, 1484 : super(DartStyleExpression.borderStyle, span,
1336 new BoxEdge(left, top, right, bottom)); 1485 new BoxEdge(left, top, right, bottom));
1337 1486
1338 BorderExpression.boxEdge(SourceSpan span, BoxEdge box) 1487 BorderExpression.boxEdge(SourceSpan span, BoxEdge box)
1339 : super(DartStyleExpression.borderStyle, span, box); 1488 : super(DartStyleExpression.borderStyle, span, box);
1340 1489
1341 merged(DartStyleExpression newBorderExpr) { 1490 merged(DartStyleExpression newBorderExpr) {
1342 if (newBorderExpr is BorderExpression && 1491 if (newBorderExpr is BorderExpression &&
1343 this.isBorder && 1492 this.isBorder &&
1344 newBorderExpr.isBorder) { 1493 newBorderExpr.isBorder) {
1345 return new BorderExpression.merge(this, newBorderExpr); 1494 return new BorderExpression.merge(this, newBorderExpr);
1346 } 1495 }
1347 1496
1348 return null; 1497 return null;
1349 } 1498 }
1350 1499
1351 /** 1500 /**
1352 * Merge the two BorderExpression and return the result. 1501 * Merge the two BorderExpression and return the result.
1353 */ 1502 */
1354 factory BorderExpression.merge(BorderExpression x, BorderExpression y) { 1503 factory BorderExpression.merge(BorderExpression x, BorderExpression y) {
1355 return new BorderExpression._merge(x, y, y.span); 1504 return new BorderExpression._merge(x, y, y.span);
1356 } 1505 }
1357 1506
1358 BorderExpression._merge( 1507 BorderExpression._merge(
1359 BorderExpression x, BorderExpression y, SourceSpan span) 1508 BorderExpression x, BorderExpression y, SourceSpan span)
1360 : super(DartStyleExpression.borderStyle, span, 1509 : super(DartStyleExpression.borderStyle, span,
1361 new BoxEdge.merge(x.box, y.box)); 1510 new BoxEdge.merge(x.box, y.box));
1362 1511
1363 BorderExpression clone() => new BorderExpression(span, 1512 BorderExpression clone() => new BorderExpression(span,
1364 top: box.top, right: box.right, bottom: box.bottom, left: box.left); 1513 top: box.top, right: box.right, bottom: box.bottom, left: box.left);
1365 1514
1366 visit(VisitorBase visitor) => visitor.visitBorderExpression(this); 1515 visit(VisitorBase visitor) => visitor.visitBorderExpression(this);
1367 } 1516 }
1368 1517
1369 class HeightExpression extends DartStyleExpression { 1518 class HeightExpression extends DartStyleExpression {
1370 final height; 1519 final height;
1371 1520
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 } 1552 }
1404 1553
1405 WidthExpression clone() => new WidthExpression(span, width); 1554 WidthExpression clone() => new WidthExpression(span, width);
1406 visit(VisitorBase visitor) => visitor.visitWidthExpression(this); 1555 visit(VisitorBase visitor) => visitor.visitWidthExpression(this);
1407 } 1556 }
1408 1557
1409 class PaddingExpression extends BoxExpression { 1558 class PaddingExpression extends BoxExpression {
1410 /** Padding expression ripped apart. */ 1559 /** Padding expression ripped apart. */
1411 PaddingExpression(SourceSpan span, {num top, num right, num bottom, num left}) 1560 PaddingExpression(SourceSpan span, {num top, num right, num bottom, num left})
1412 : super(DartStyleExpression.paddingStyle, span, 1561 : super(DartStyleExpression.paddingStyle, span,
1413 new BoxEdge(left, top, right, bottom)); 1562 new BoxEdge(left, top, right, bottom));
1414 1563
1415 PaddingExpression.boxEdge(SourceSpan span, BoxEdge box) 1564 PaddingExpression.boxEdge(SourceSpan span, BoxEdge box)
1416 : super(DartStyleExpression.paddingStyle, span, box); 1565 : super(DartStyleExpression.paddingStyle, span, box);
1417 1566
1418 merged(DartStyleExpression newPaddingExpr) { 1567 merged(DartStyleExpression newPaddingExpr) {
1419 if (newPaddingExpr is PaddingExpression && 1568 if (newPaddingExpr is PaddingExpression &&
1420 this.isPadding && 1569 this.isPadding &&
1421 newPaddingExpr.isPadding) { 1570 newPaddingExpr.isPadding) {
1422 return new PaddingExpression.merge(this, newPaddingExpr); 1571 return new PaddingExpression.merge(this, newPaddingExpr);
1423 } 1572 }
1424 1573
1425 return null; 1574 return null;
1426 } 1575 }
1427 1576
1428 /** 1577 /**
1429 * Merge the two PaddingExpression and return the result. 1578 * Merge the two PaddingExpression and return the result.
1430 */ 1579 */
1431 factory PaddingExpression.merge(PaddingExpression x, PaddingExpression y) { 1580 factory PaddingExpression.merge(PaddingExpression x, PaddingExpression y) {
1432 return new PaddingExpression._merge(x, y, y.span); 1581 return new PaddingExpression._merge(x, y, y.span);
1433 } 1582 }
1434 1583
1435 PaddingExpression._merge( 1584 PaddingExpression._merge(
1436 PaddingExpression x, PaddingExpression y, SourceSpan span) 1585 PaddingExpression x, PaddingExpression y, SourceSpan span)
1437 : super(DartStyleExpression.paddingStyle, span, 1586 : super(DartStyleExpression.paddingStyle, span,
1438 new BoxEdge.merge(x.box, y.box)); 1587 new BoxEdge.merge(x.box, y.box));
1439 1588
1440 PaddingExpression clone() => new PaddingExpression(span, 1589 PaddingExpression clone() => new PaddingExpression(span,
1441 top: box.top, right: box.right, bottom: box.bottom, left: box.left); 1590 top: box.top, right: box.right, bottom: box.bottom, left: box.left);
1442 visit(VisitorBase visitor) => visitor.visitPaddingExpression(this); 1591 visit(VisitorBase visitor) => visitor.visitPaddingExpression(this);
1443 } 1592 }
OLDNEW
« no previous file with comments | « packages/csslib/lib/src/tokenkind.dart ('k') | packages/csslib/lib/src/tree_base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698