Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/tools/expression_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ main(args) {
var packageRoots =
(args.length < 6) ? [Platform.packageRoot] : args.sublist(5);
var sourceCrawler = new SourceCrawlerImpl(packageRoots);
var sourceMetadataExtractor = new SourceMetadataExtractor(sourceCrawler);
var sourceMetadataExtractor = new SourceMetadataExtractor();
List<DirectiveInfo> directives =
sourceMetadataExtractor.gatherDirectiveInfo(args[0]);
var htmlExtractor = new HtmlExpressionExtractor(directives, ioService);
htmlExtractor.crawl(args[1]);
sourceMetadataExtractor.gatherDirectiveInfo(args[0], sourceCrawler);
var htmlExtractor = new HtmlExpressionExtractor(directives);
htmlExtractor.crawl(args[1], ioService);

var expressions = htmlExtractor.expressions;
expressions.add('null');
Expand Down
23 changes: 11 additions & 12 deletions lib/tools/html_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ RegExp _NG_REPEAT_SYNTAX = new RegExp(r'^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s

class HtmlExpressionExtractor {
List<DirectiveInfo> directiveInfos;
IoService ioService;

HtmlExpressionExtractor(this.directiveInfos, this.ioService);
HtmlExpressionExtractor(this.directiveInfos) {
for (DirectiveInfo directiveInfo in directiveInfos) {
expressions.addAll(directiveInfo.expressions);
if (directiveInfo.template != null) {
parseHtml(directiveInfo.template);
}
}
}

Set<String> expressions = new Set<String>();

void crawl(root) {
void crawl(String root, IoService ioService) {
ioService.visitFs(root, (String file) {
if (!file.endsWith('.html')) return;

_parseHtml(ioService.readAsStringSync(file));
parseHtml(ioService.readAsStringSync(file));
});
for (DirectiveInfo directiveInfo in directiveInfos) {
expressions.addAll(directiveInfo.expressions);
if (directiveInfo.template != null) {
_parseHtml(directiveInfo.template);
}
}
}

void _parseHtml(String html) {
void parseHtml(String html) {
var document = parse(html);
visitNodes([document], (Node node) {
if (matchesNode(node, r'[*=/{{.*}}/]')) {
Expand Down
5 changes: 2 additions & 3 deletions lib/tools/source_metadata_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ const Map<String, String> _attrAnnotationsToSpec = const {
};

class SourceMetadataExtractor {
SourceCrawler sourceCrawler;
DirectiveMetadataCollectingVisitor metadataVisitor;

SourceMetadataExtractor(this.sourceCrawler, [ this.metadataVisitor ]) {
SourceMetadataExtractor([ this.metadataVisitor ]) {
if (metadataVisitor == null) {
metadataVisitor = new DirectiveMetadataCollectingVisitor();
}
}

List<DirectiveInfo> gatherDirectiveInfo(root) {
List<DirectiveInfo> gatherDirectiveInfo(root, SourceCrawler sourceCrawler) {
sourceCrawler.crawl(root, metadataVisitor);

List<DirectiveInfo> directives = <DirectiveInfo>[];
Expand Down
8 changes: 4 additions & 4 deletions test/io/expression_extractor_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ main() => describe('expression_extractor', () {

IoService ioService = new IoServiceImpl();
var sourceCrawler = new SourceCrawlerImpl(['packages/']);
var sourceMetadataExtractor = new SourceMetadataExtractor(sourceCrawler);
var sourceMetadataExtractor = new SourceMetadataExtractor();
List<DirectiveInfo> directives =
sourceMetadataExtractor
.gatherDirectiveInfo('test/io/test_files/main.dart');
var htmlExtractor = new HtmlExpressionExtractor(directives, ioService);
htmlExtractor.crawl('test/io/test_files/');
.gatherDirectiveInfo('test/io/test_files/main.dart', sourceCrawler);
var htmlExtractor = new HtmlExpressionExtractor(directives);
htmlExtractor.crawl('test/io/test_files/', ioService);

var expressions = htmlExtractor.expressions;
expect(expressions, unorderedEquals([
Expand Down
4 changes: 2 additions & 2 deletions test/io/source_metadata_extractor_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import 'package:unittest/unittest.dart';
main() => describe('source_metadata_extractor', () {
it('should extract all attribute mappings including annotations', () {
var sourceCrawler = new SourceCrawlerImpl(['packages/']);
var sourceMetadataExtractor = new SourceMetadataExtractor(sourceCrawler);
var sourceMetadataExtractor = new SourceMetadataExtractor();
List<DirectiveInfo> directives =
sourceMetadataExtractor
.gatherDirectiveInfo('test/io/test_files/main.dart');
.gatherDirectiveInfo('test/io/test_files/main.dart', sourceCrawler);

expect(directives, hasLength(2));

Expand Down
24 changes: 12 additions & 12 deletions test/tools/html_extractor_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ main() => describe('html_extractor', () {
'''
});

var extractor = new HtmlExpressionExtractor([], ioService);
extractor.crawl('/');
var extractor = new HtmlExpressionExtractor([]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
equals(['aux', 'ctrl.bar']));
});
Expand All @@ -29,8 +29,8 @@ main() => describe('html_extractor', () {
'''
});

var extractor = new HtmlExpressionExtractor([], ioService);
extractor.crawl('/');
var extractor = new HtmlExpressionExtractor([]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
equals(['aux', 'ctrl.bar']));
});
Expand All @@ -42,8 +42,8 @@ main() => describe('html_extractor', () {
'''
});

var extractor = new HtmlExpressionExtractor([], ioService);
extractor.crawl('/');
var extractor = new HtmlExpressionExtractor([]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
equals(['ctrl.bar']));
});
Expand All @@ -53,8 +53,8 @@ main() => describe('html_extractor', () {

var extractor = new HtmlExpressionExtractor([
new DirectiveInfo('', [], ['foo', 'bar'])
], ioService);
extractor.crawl('/');
]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
equals(['bar', 'foo']));
});
Expand All @@ -68,8 +68,8 @@ main() => describe('html_extractor', () {

var extractor = new HtmlExpressionExtractor([
new DirectiveInfo('foo', ['bar'])
], ioService);
extractor.crawl('/');
]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
equals(['ctrl.baz']));
});
Expand All @@ -83,8 +83,8 @@ main() => describe('html_extractor', () {

var extractor = new HtmlExpressionExtractor([
new DirectiveInfo('[ng-repeat]', ['ng-repeat'])
], ioService);
extractor.crawl('/');
]);
extractor.crawl('/', ioService);
// Basically we don't want to extract "foo in ctrl.bar".
expect(extractor.expressions.toList()..sort(),
equals(['ctrl.bar']));
Expand Down
4 changes: 2 additions & 2 deletions test/tools/source_metadata_extractor_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ flattenList(list, map) => list.map(map).fold([], (prev, exprs) =>
List<DirectiveInfo> extractDirectiveInfo(List<DirectiveMetadata> metadata) {
var sourceCrawler = new MockSourceCrawler();
var metadataCollector = new MockDirectiveMetadataCollectingVisitor(metadata);
var extractor = new SourceMetadataExtractor(sourceCrawler, metadataCollector);
return extractor.gatherDirectiveInfo('');
var extractor = new SourceMetadataExtractor(metadataCollector);
return extractor.gatherDirectiveInfo('', sourceCrawler);
}

class MockDirectiveMetadataCollectingVisitor
Expand Down