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

Side by Side Diff: pkg/observe/lib/transformer.dart

Issue 63173009: Ensure we run the observable transform on PolymerElement (fixes issue 14942) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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/observe/lib/transform.dart ('k') | pkg/observe/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 /** 5 /**
6 * Code transform for @observable. The core transformation is relatively 6 * Code transform for @observable. The core transformation is relatively
7 * straightforward, and essentially like an editor refactoring. 7 * straightforward, and essentially like an editor refactoring.
8 */ 8 */
9 library observe.transform; 9 library observe.transformer;
10 10
11 import 'dart:async'; 11 import 'dart:async';
12 12
13 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; 13 import 'package:analyzer/src/generated/java_core.dart' show CharSequence;
14 import 'package:analyzer/src/generated/ast.dart'; 14 import 'package:analyzer/src/generated/ast.dart';
15 import 'package:analyzer/src/generated/error.dart'; 15 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 16 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/scanner.dart'; 17 import 'package:analyzer/src/generated/scanner.dart';
18 import 'package:barback/barback.dart'; 18 import 'package:barback/barback.dart';
19 import 'package:source_maps/refactor.dart'; 19 import 'package:source_maps/refactor.dart';
20 import 'package:source_maps/span.dart' show SourceFile; 20 import 'package:source_maps/span.dart' show SourceFile;
21 21
22 /** 22 /**
23 * A [Transformer] that replaces observables based on dirty-checking with an 23 * A [Transformer] that replaces observables based on dirty-checking with an
24 * implementation based on change notifications. 24 * implementation based on change notifications.
25 * 25 *
26 * The transformation adds hooks for field setters and notifies the observation 26 * The transformation adds hooks for field setters and notifies the observation
27 * system of the change. 27 * system of the change.
28 */ 28 */
29 class ObservableTransformer extends Transformer { 29 class ObservableTransformer extends Transformer {
30 30
31 final List<String> _files;
32 ObservableTransformer();
33 ObservableTransformer.asPlugin(BarbackSettings settings)
34 : _files = _readFiles(settings.configuration['files']);
35
36 static List<String> _readFiles(value) {
37 if (value == null) return null;
38 var files = [];
39 bool error;
40 if (value is List) {
41 files = value;
42 error = value.any((e) => e is! String);
43 } else if (value is String) {
44 files = [value];
45 error = false;
46 } else {
47 error = true;
48 }
49 if (error) print('Invalid value for "files" in the observe transformer.');
50 return files;
51 }
52
31 Future<bool> isPrimary(Asset input) { 53 Future<bool> isPrimary(Asset input) {
32 if (input.id.extension != '.dart') return new Future.value(false); 54 if (input.id.extension != '.dart' ||
55 (_files != null && !_files.contains(input.id.path))) {
56 return new Future.value(false);
57 }
33 // Note: technically we should parse the file to find accurately the 58 // Note: technically we should parse the file to find accurately the
34 // observable annotation, but that seems expensive. It would require almost 59 // observable annotation, but that seems expensive. It would require almost
35 // as much work as applying the transform. We rather have some false 60 // as much work as applying the transform. We rather have some false
36 // positives here, and then generate no outputs when we apply this 61 // positives here, and then generate no outputs when we apply this
37 // transform. 62 // transform.
38 return input.readAsString().then( 63 return input.readAsString().then(
39 (c) => c.contains("@observable") || c.contains("@published")); 64 (c) => c.contains("@observable") || c.contains("@published"));
40 } 65 }
41 66
42 Future apply(Transform transform) { 67 Future apply(Transform transform) {
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 431
407 Token _findFieldSeperator(Token token) { 432 Token _findFieldSeperator(Token token) {
408 while (token != null) { 433 while (token != null) {
409 if (token.type == TokenType.COMMA || token.type == TokenType.SEMICOLON) { 434 if (token.type == TokenType.COMMA || token.type == TokenType.SEMICOLON) {
410 break; 435 break;
411 } 436 }
412 token = token.next; 437 token = token.next;
413 } 438 }
414 return token; 439 return token;
415 } 440 }
OLDNEW
« no previous file with comments | « pkg/observe/lib/transform.dart ('k') | pkg/observe/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698