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

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

Issue 223553008: Only pass an AssetId to isPrimary and declareOutputs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix script_compactor Created 6 years, 8 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/code_transformers/test/resolver_test.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 /// Code transform for @observable. The core transformation is relatively 5 /// Code transform for @observable. The core transformation is relatively
6 /// straightforward, and essentially like an editor refactoring. 6 /// straightforward, and essentially like an editor refactoring.
7 library observe.transformer; 7 library observe.transformer;
8 8
9 import 'dart:async'; 9 import 'dart:async';
10 10
(...skipping 27 matching lines...) Expand all
38 } else if (value is String) { 38 } else if (value is String) {
39 files = [value]; 39 files = [value];
40 error = false; 40 error = false;
41 } else { 41 } else {
42 error = true; 42 error = true;
43 } 43 }
44 if (error) print('Invalid value for "files" in the observe transformer.'); 44 if (error) print('Invalid value for "files" in the observe transformer.');
45 return files; 45 return files;
46 } 46 }
47 47
48 Future<bool> isPrimary(Asset input) { 48 // TODO(nweiz): This should just take an AssetId when barback <0.13.0 support
49 if (input.id.extension != '.dart' || 49 // is dropped.
50 (_files != null && !_files.contains(input.id.path))) { 50 Future<bool> isPrimary(idOrAsset) {
51 return new Future.value(false); 51 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id;
52 } 52 return new Future.value(id.extension == '.dart' &&
53 // Note: technically we should parse the file to find accurately the 53 (_files == null || _files.contains(id.path)));
54 // observable annotation, but that seems expensive. It would require almost
55 // as much work as applying the transform. We rather have some false
56 // positives here, and then generate no outputs when we apply this
57 // transform.
58 return input.readAsString().then(
59 (c) => c.contains("@observable") || c.contains("@published"));
60 } 54 }
61 55
62 Future apply(Transform transform) { 56 Future apply(Transform transform) {
63 return transform.primaryInput.readAsString().then((content) { 57 return transform.primaryInput.readAsString().then((content) {
58 // Do a quick string check to determine if this is this file even
59 // plausibly might need to be transformed. If not, we can avoid an
60 // expensive parse.
61 if (!content.contains("@observable") && !content.contains("@published")) {
62 return;
63 }
64
64 var id = transform.primaryInput.id; 65 var id = transform.primaryInput.id;
65 // TODO(sigmund): improve how we compute this url 66 // TODO(sigmund): improve how we compute this url
66 var url = id.path.startsWith('lib/') 67 var url = id.path.startsWith('lib/')
67 ? 'package:${id.package}/${id.path.substring(4)}' : id.path; 68 ? 'package:${id.package}/${id.path.substring(4)}' : id.path;
68 var sourceFile = new SourceFile.text(url, content); 69 var sourceFile = new SourceFile.text(url, content);
69 var transaction = _transformCompilationUnit( 70 var transaction = _transformCompilationUnit(
70 content, sourceFile, transform.logger); 71 content, sourceFile, transform.logger);
71 if (!transaction.hasEdits) { 72 if (!transaction.hasEdits) {
72 transform.addOutput(transform.primaryInput); 73 transform.addOutput(transform.primaryInput);
73 return; 74 return;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 427
427 Token _findFieldSeperator(Token token) { 428 Token _findFieldSeperator(Token token) {
428 while (token != null) { 429 while (token != null) {
429 if (token.type == TokenType.COMMA || token.type == TokenType.SEMICOLON) { 430 if (token.type == TokenType.COMMA || token.type == TokenType.SEMICOLON) {
430 break; 431 break;
431 } 432 }
432 token = token.next; 433 token = token.next;
433 } 434 }
434 return token; 435 return token;
435 } 436 }
OLDNEW
« no previous file with comments | « pkg/code_transformers/test/resolver_test.dart ('k') | pkg/observe/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698