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

Side by Side Diff: pkg/polymer/lib/src/build/script_compactor.dart

Issue 421503004: Switch transformers over to source_span (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/lib/src/build/linter.dart ('k') | pkg/polymer/pubspec.yaml » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Transfomer that combines multiple dart script tags into a single one. 5 /// Transfomer that combines multiple dart script tags into a single one.
6 library polymer.src.build.script_compactor; 6 library polymer.src.build.script_compactor;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 10
11 import 'package:html5lib/dom.dart' show Document, Element, Text; 11 import 'package:html5lib/dom.dart' show Document, Element, Text;
12 import 'package:html5lib/dom_parsing.dart'; 12 import 'package:html5lib/dom_parsing.dart';
13 import 'package:html5lib/parser.dart' show parseFragment; 13 import 'package:html5lib/parser.dart' show parseFragment;
14 import 'package:analyzer/src/generated/ast.dart'; 14 import 'package:analyzer/src/generated/ast.dart';
15 import 'package:analyzer/src/generated/element.dart' hide Element; 15 import 'package:analyzer/src/generated/element.dart' hide Element;
16 import 'package:analyzer/src/generated/element.dart' as analyzer show Element; 16 import 'package:analyzer/src/generated/element.dart' as analyzer show Element;
17 import 'package:barback/barback.dart'; 17 import 'package:barback/barback.dart';
18 import 'package:path/path.dart' as path; 18 import 'package:path/path.dart' as path;
19 import 'package:source_maps/span.dart' show SourceFile, Span; 19 import 'package:source_span/source_span.dart';
20 import 'package:smoke/codegen/generator.dart'; 20 import 'package:smoke/codegen/generator.dart';
21 import 'package:smoke/codegen/recorder.dart'; 21 import 'package:smoke/codegen/recorder.dart';
22 import 'package:code_transformers/resolver.dart'; 22 import 'package:code_transformers/resolver.dart';
23 import 'package:code_transformers/src/dart_sdk.dart'; 23 import 'package:code_transformers/src/dart_sdk.dart';
24 import 'package:template_binding/src/mustache_tokens.dart' show MustacheTokens; 24 import 'package:template_binding/src/mustache_tokens.dart' show MustacheTokens;
25 25
26 import 'package:polymer_expressions/expression.dart' as pe; 26 import 'package:polymer_expressions/expression.dart' as pe;
27 import 'package:polymer_expressions/parser.dart' as pe; 27 import 'package:polymer_expressions/parser.dart' as pe;
28 import 'package:polymer_expressions/visitor.dart' as pe; 28 import 'package:polymer_expressions/visitor.dart' as pe;
29 29
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 final AssetId assetId; 495 final AssetId assetId;
496 final String tagName; 496 final String tagName;
497 final String typeName; 497 final String typeName;
498 String get symbolName => typeName; 498 String get symbolName => typeName;
499 _CustomTagInitializer(this.assetId, this.tagName, this.typeName); 499 _CustomTagInitializer(this.assetId, this.tagName, this.typeName);
500 500
501 String asCode(String prefix) => 501 String asCode(String prefix) =>
502 "() => Polymer.register('$tagName', $prefix.$typeName)"; 502 "() => Polymer.register('$tagName', $prefix.$typeName)";
503 } 503 }
504 504
505 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end);
506
507 const MAIN_HEADER = """ 505 const MAIN_HEADER = """
508 library app_bootstrap; 506 library app_bootstrap;
509 507
510 import 'package:polymer/polymer.dart'; 508 import 'package:polymer/polymer.dart';
511 """; 509 """;
512 510
513 const NO_INITIALIZERS_ERROR = 511 const NO_INITIALIZERS_ERROR =
514 'No polymer initializers were found. Make sure to either ' 512 'No polymer initializers were found. Make sure to either '
515 'annotate your polymer elements with @CustomTag or include a ' 513 'annotate your polymer elements with @CustomTag or include a '
516 'top level method annotated with @initMethod that registers your ' 514 'top level method annotated with @initMethod that registers your '
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 tag == 'select' && (name == 'selectedindex' || name == 'value') || 586 tag == 'select' && (name == 'selectedindex' || name == 'value') ||
589 tag == 'textarea' && name == 'value'); 587 tag == 'textarea' && name == 'value');
590 } 588 }
591 for (var exp in bindings.expressions) { 589 for (var exp in bindings.expressions) {
592 _addExpression(exp, isEvent, isTwoWay, node.sourceSpan); 590 _addExpression(exp, isEvent, isTwoWay, node.sourceSpan);
593 } 591 }
594 }); 592 });
595 } 593 }
596 594
597 void _addExpression(String stringExpression, bool inEvent, bool isTwoWay, 595 void _addExpression(String stringExpression, bool inEvent, bool isTwoWay,
598 Span span) { 596 SourceSpan span) {
599 597
600 if (inEvent) { 598 if (inEvent) {
601 if (stringExpression.startsWith('@')) { 599 if (stringExpression.startsWith('@')) {
602 logger.warning('event bindings with @ are no longer supported', 600 logger.warning('event bindings with @ are no longer supported',
603 span: span); 601 span: span);
604 return; 602 return;
605 } 603 }
606 604
607 if (stringExpression == '') return; 605 if (stringExpression == '') return;
608 if (stringExpression.startsWith('_')) { 606 if (stringExpression.startsWith('_')) {
609 logger.warning('private symbols cannot be used in event handlers', 607 logger.warning('private symbols cannot be used in event handlers',
610 span: span); 608 span: span);
611 return; 609 return;
612 } 610 }
613 generator.addGetter(stringExpression); 611 generator.addGetter(stringExpression);
614 generator.addSymbol(stringExpression); 612 generator.addSymbol(stringExpression);
615 } 613 }
616 expressionVisitor.run(pe.parse(stringExpression), isTwoWay, span); 614 expressionVisitor.run(pe.parse(stringExpression), isTwoWay, span);
617 } 615 }
618 } 616 }
619 617
620 /// A polymer-expression visitor that records every getter and setter that will 618 /// A polymer-expression visitor that records every getter and setter that will
621 /// be needed to evaluate a single expression at runtime. 619 /// be needed to evaluate a single expression at runtime.
622 class _SubExpressionVisitor extends pe.RecursiveVisitor { 620 class _SubExpressionVisitor extends pe.RecursiveVisitor {
623 final SmokeCodeGenerator generator; 621 final SmokeCodeGenerator generator;
624 final TransformLogger logger; 622 final TransformLogger logger;
625 bool _includeSetter; 623 bool _includeSetter;
626 Span _currentSpan; 624 SourceSpan _currentSpan;
627 625
628 _SubExpressionVisitor(this.generator, this.logger); 626 _SubExpressionVisitor(this.generator, this.logger);
629 627
630 /// Visit [exp], and record getters and setters that are needed in order to 628 /// Visit [exp], and record getters and setters that are needed in order to
631 /// evaluate it at runtime. [includeSetter] is only true if this expression 629 /// evaluate it at runtime. [includeSetter] is only true if this expression
632 /// occured in a context where it could be updated, for example in two-way 630 /// occured in a context where it could be updated, for example in two-way
633 /// bindings such as `<input value={{exp}}>`. 631 /// bindings such as `<input value={{exp}}>`.
634 void run(pe.Expression exp, bool includeSetter, span) { 632 void run(pe.Expression exp, bool includeSetter, span) {
635 _currentSpan = span; 633 _currentSpan = span;
636 _includeSetter = includeSetter; 634 _includeSetter = includeSetter;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 for (var c in combinators) { 823 for (var c in combinators) {
826 if (c is ShowElementCombinator) { 824 if (c is ShowElementCombinator) {
827 var show = c.shownNames.toSet(); 825 var show = c.shownNames.toSet();
828 elements.retainWhere((e) => show.contains(e.displayName)); 826 elements.retainWhere((e) => show.contains(e.displayName));
829 } else if (c is HideElementCombinator) { 827 } else if (c is HideElementCombinator) {
830 var hide = c.hiddenNames.toSet(); 828 var hide = c.hiddenNames.toSet();
831 elements.removeWhere((e) => hide.contains(e.displayName)); 829 elements.removeWhere((e) => hide.contains(e.displayName));
832 } 830 }
833 } 831 }
834 } 832 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/build/linter.dart ('k') | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698