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

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

Issue 196943024: Adding some asset-related utilities to code_transformers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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; 11 import 'package:html5lib/dom.dart' show Document, Element;
12 import 'package:analyzer/src/generated/ast.dart'; 12 import 'package:analyzer/src/generated/ast.dart';
13 import 'package:barback/barback.dart'; 13 import 'package:barback/barback.dart';
14 import 'package:code_transformers/assets.dart';
14 import 'package:path/path.dart' as path; 15 import 'package:path/path.dart' as path;
15 import 'package:source_maps/span.dart' show SourceFile; 16 import 'package:source_maps/span.dart' show SourceFile;
16 17
17 import 'import_inliner.dart' show ImportInliner; // just for docs. 18 import 'import_inliner.dart' show ImportInliner; // just for docs.
18 import 'common.dart'; 19 import 'common.dart';
19 20
20 /// Combines Dart script tags into a single script tag, and creates a new Dart 21 /// Combines Dart script tags into a single script tag, and creates a new Dart
21 /// file that calls the main function of each of the original script tags. 22 /// file that calls the main function of each of the original script tags.
22 /// 23 ///
23 /// This transformer assumes that all script tags point to external files. To 24 /// This transformer assumes that all script tags point to external files. To
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 'ScriptCompactor transformer should run after running the ' 96 'ScriptCompactor transformer should run after running the '
96 'InlineCodeExtractor', span: tag.sourceSpan); 97 'InlineCodeExtractor', span: tag.sourceSpan);
97 continue; 98 continue;
98 } 99 }
99 if (mainLibraryId != null) { 100 if (mainLibraryId != null) {
100 logger.warning('unexpected script. Only one Dart script tag ' 101 logger.warning('unexpected script. Only one Dart script tag '
101 'per document is allowed.', span: tag.sourceSpan); 102 'per document is allowed.', span: tag.sourceSpan);
102 tag.remove(); 103 tag.remove();
103 continue; 104 continue;
104 } 105 }
105 mainLibraryId = resolve(docId, src, logger, tag.sourceSpan); 106 mainLibraryId = uriToAssetId(docId, src, logger, tag.sourceSpan);
106 mainScriptTag = tag; 107 mainScriptTag = tag;
107 } 108 }
108 } 109 }
109 110
110 /// Emits the main HTML and Dart bootstrap code for the application. If there 111 /// Emits the main HTML and Dart bootstrap code for the application. If there
111 /// were not Dart entry point files, then this simply emits the original HTML. 112 /// were not Dart entry point files, then this simply emits the original HTML.
112 Future _emitNewEntrypoint(_) { 113 Future _emitNewEntrypoint(_) {
113 if (mainScriptTag == null) { 114 if (mainScriptTag == null) {
114 // We didn't find any main library, nothing to do. 115 // We didn't find any main library, nothing to do.
115 transform.addOutput(transform.primaryInput); 116 transform.addOutput(transform.primaryInput);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 /// labeled with @initMethod. 165 /// labeled with @initMethod.
165 Future<List<_Initializer>> _initializersOf(AssetId dartLibrary) { 166 Future<List<_Initializer>> _initializersOf(AssetId dartLibrary) {
166 var result = []; 167 var result = [];
167 return transform.readInputAsString(dartLibrary).then((code) { 168 return transform.readInputAsString(dartLibrary).then((code) {
168 var file = new SourceFile.text(_simpleUriForSource(dartLibrary), code); 169 var file = new SourceFile.text(_simpleUriForSource(dartLibrary), code);
169 var unit = parseCompilationUnit(code); 170 var unit = parseCompilationUnit(code);
170 171
171 return Future.forEach(unit.directives, (directive) { 172 return Future.forEach(unit.directives, (directive) {
172 // Include anything from parts. 173 // Include anything from parts.
173 if (directive is PartDirective) { 174 if (directive is PartDirective) {
174 var targetId = resolve(dartLibrary, directive.uri.stringValue, 175 var targetId = uriToAssetId(dartLibrary, directive.uri.stringValue,
175 logger, _getSpan(file, directive)); 176 logger, _getSpan(file, directive));
176 return _initializersOf(targetId).then(result.addAll); 177 return _initializersOf(targetId).then(result.addAll);
177 } 178 }
178 179
179 // Similarly, include anything from exports except what's filtered by 180 // Similarly, include anything from exports except what's filtered by
180 // the show/hide combinators. 181 // the show/hide combinators.
181 if (directive is ExportDirective) { 182 if (directive is ExportDirective) {
182 var targetId = resolve(dartLibrary, directive.uri.stringValue, 183 var targetId = uriToAssetId(dartLibrary, directive.uri.stringValue,
183 logger, _getSpan(file, directive)); 184 logger, _getSpan(file, directive));
184 return _initializersOf(targetId).then( 185 return _initializersOf(targetId).then(
185 (r) => _processExportDirective(directive, r, result)); 186 (r) => _processExportDirective(directive, r, result));
186 } 187 }
187 }).then((_) { 188 }).then((_) {
188 // Scan the code for classes and top-level functions. 189 // Scan the code for classes and top-level functions.
189 for (var node in unit.declarations) { 190 for (var node in unit.declarations) {
190 if (node is ClassDeclaration) { 191 if (node is ClassDeclaration) {
191 _processClassDeclaration(node, result, file, logger); 192 _processClassDeclaration(node, result, file, logger);
192 } else if (node is FunctionDeclaration && 193 } else if (node is FunctionDeclaration &&
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 291 }
291 292
292 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end); 293 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end);
293 294
294 const MAIN_HEADER = """ 295 const MAIN_HEADER = """
295 library app_bootstrap; 296 library app_bootstrap;
296 297
297 import 'package:polymer/polymer.dart'; 298 import 'package:polymer/polymer.dart';
298 import 'package:smoke/static.dart' as smoke; 299 import 'package:smoke/static.dart' as smoke;
299 """; 300 """;
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