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

Side by Side Diff: pkg/dev_compiler/web/web_command.dart

Issue 2752163002: Format all dart dev compiler files (Closed)
Patch Set: Created 3 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
« no previous file with comments | « pkg/dev_compiler/web/main.dart ('k') | no next file » | 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 @JS() 4 @JS()
5 library dev_compiler.web.web_command; 5 library dev_compiler.web.web_command;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:html' show HttpRequest; 9 import 'dart:html' show HttpRequest;
10 10
11 import 'package:analyzer/dart/element/element.dart' 11 import 'package:analyzer/dart/element/element.dart'
12 show 12 show
13 LibraryElement, 13 LibraryElement,
14 ImportElement, 14 ImportElement,
15 ShowElementCombinator, 15 ShowElementCombinator,
16 HideElementCombinator; 16 HideElementCombinator;
17 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; 17 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver;
18 import 'package:analyzer/file_system/memory_file_system.dart' 18 import 'package:analyzer/file_system/memory_file_system.dart'
19 show MemoryResourceProvider; 19 show MemoryResourceProvider;
20 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 20 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
21 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; 21 import 'package:analyzer/src/summary/idl.dart' show PackageBundle;
22 import 'package:analyzer/src/summary/package_bundle_reader.dart' 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'
23 show 23 show SummaryDataStore, InSummaryUriResolver, InSummarySource;
24 SummaryDataStore,
25 InSummaryUriResolver,
26 InSummarySource;
27 import 'package:analyzer/src/dart/resolver/scope.dart' show Scope; 24 import 'package:analyzer/src/dart/resolver/scope.dart' show Scope;
28 25
29 import 'package:args/command_runner.dart'; 26 import 'package:args/command_runner.dart';
30 27
31 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions; 28 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions;
32 import 'package:dev_compiler/src/compiler/compiler.dart' 29 import 'package:dev_compiler/src/compiler/compiler.dart'
33 show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler; 30 show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler;
34 31
35 import 'package:dev_compiler/src/compiler/module_builder.dart'; 32 import 'package:dev_compiler/src/compiler/module_builder.dart';
36 import 'package:js/js.dart'; 33 import 'package:js/js.dart';
(...skipping 22 matching lines...) Expand all
59 : this.messageHandler = messageHandler ?? print { 56 : this.messageHandler = messageHandler ?? print {
60 CompilerOptions.addArguments(argParser); 57 CompilerOptions.addArguments(argParser);
61 AnalyzerOptions.addArguments(argParser); 58 AnalyzerOptions.addArguments(argParser);
62 } 59 }
63 60
64 @override 61 @override
65 Function run() { 62 Function run() {
66 return requestSummaries; 63 return requestSummaries;
67 } 64 }
68 65
69 void requestSummaries(String summaryRoot, String sdkUrl, List<String> summaryU rls, 66 void requestSummaries(String summaryRoot, String sdkUrl,
70 Function onCompileReady, Function onError) { 67 List<String> summaryUrls, Function onCompileReady, Function onError) {
71 HttpRequest 68 HttpRequest
72 .request(sdkUrl, 69 .request(sdkUrl,
73 responseType: "arraybuffer", mimeType: "application/octet-stream") 70 responseType: "arraybuffer", mimeType: "application/octet-stream")
74 .then((sdkRequest) { 71 .then((sdkRequest) {
75 var sdkBytes = sdkRequest.response.asUint8List(); 72 var sdkBytes = sdkRequest.response.asUint8List();
76 73
77 // Map summary URLs to HttpRequests. 74 // Map summary URLs to HttpRequests.
78 var summaryRequests = summaryUrls.map((summary) => new Future(() => 75 var summaryRequests = summaryUrls.map((summary) => new Future(() =>
79 HttpRequest.request(summaryRoot + summary, 76 HttpRequest.request(summaryRoot + summary,
80 responseType: "arraybuffer", 77 responseType: "arraybuffer",
81 mimeType: "application/octet-stream"))); 78 mimeType: "application/octet-stream")));
82 79
83 Future.wait(summaryRequests).then((summaryResponses) { 80 Future.wait(summaryRequests).then((summaryResponses) {
84 // Map summary responses to summary bytes. 81 // Map summary responses to summary bytes.
85 var summaryBytes = <List<int>>[]; 82 var summaryBytes = <List<int>>[];
86 for (var response in summaryResponses) { 83 for (var response in summaryResponses) {
87 summaryBytes.add(response.response.asUint8List()); 84 summaryBytes.add(response.response.asUint8List());
88 } 85 }
89 86
90 onCompileReady(setUpCompile(sdkBytes, summaryBytes, summaryUrls)); 87 onCompileReady(setUpCompile(sdkBytes, summaryBytes, summaryUrls));
91 }).catchError((error) => onError('Summaries failed to load: $error')); 88 }).catchError((error) => onError('Summaries failed to load: $error'));
92 }).catchError( 89 }).catchError((error) =>
93 (error) => onError('Dart sdk summaries failed to load: $error. url: $sdkUrl')); 90 onError('Dart sdk summaries failed to load: $error. url: $sdkUrl'));
94 } 91 }
95 92
96 List<Function> setUpCompile(List<int> sdkBytes, List<List<int>> summaryBytes, 93 List<Function> setUpCompile(List<int> sdkBytes, List<List<int>> summaryBytes,
97 List<String> summaryUrls) { 94 List<String> summaryUrls) {
98 var dartSdkSummaryPath = '/dart-sdk/lib/_internal/web_sdk.sum'; 95 var dartSdkSummaryPath = '/dart-sdk/lib/_internal/web_sdk.sum';
99 96
100 var resourceProvider = new MemoryResourceProvider() 97 var resourceProvider = new MemoryResourceProvider()
101 ..newFileWithBytes(dartSdkSummaryPath, sdkBytes); 98 ..newFileWithBytes(dartSdkSummaryPath, sdkBytes);
102 99
103 var resourceUriResolver = new ResourceUriResolver(resourceProvider); 100 var resourceUriResolver = new ResourceUriResolver(resourceProvider);
104 101
105 var options = new AnalyzerOptions.basic( 102 var options = new AnalyzerOptions.basic(
106 dartSdkPath: '/dart-sdk', dartSdkSummaryPath: dartSdkSummaryPath); 103 dartSdkPath: '/dart-sdk', dartSdkSummaryPath: dartSdkSummaryPath);
107 104
108 var summaryDataStore = 105 var summaryDataStore = new SummaryDataStore(options.summaryPaths,
109 new SummaryDataStore(options.summaryPaths, resourceProvider: resourcePro vider, recordDependencyInfo: true); 106 resourceProvider: resourceProvider, recordDependencyInfo: true);
110 for (var i = 0; i < summaryBytes.length; i++) { 107 for (var i = 0; i < summaryBytes.length; i++) {
111 var bytes = summaryBytes[i]; 108 var bytes = summaryBytes[i];
112 var url = '/' + summaryUrls[i]; 109 var url = '/' + summaryUrls[i];
113 var summaryBundle = new PackageBundle.fromBuffer(bytes); 110 var summaryBundle = new PackageBundle.fromBuffer(bytes);
114 summaryDataStore.addBundle(url, summaryBundle); 111 summaryDataStore.addBundle(url, summaryBundle);
115 } 112 }
116 var summaryResolver = 113 var summaryResolver =
117 new InSummaryUriResolver(resourceProvider, summaryDataStore); 114 new InSummaryUriResolver(resourceProvider, summaryDataStore);
118 115
119 var fileResolvers = [summaryResolver, resourceUriResolver]; 116 var fileResolvers = [summaryResolver, resourceUriResolver];
120 117
121 var compiler = new ModuleCompiler( 118 var compiler = new ModuleCompiler(options,
122 options,
123 analysisRoot: '/web-compile-root', 119 analysisRoot: '/web-compile-root',
124 fileResolvers: fileResolvers, 120 fileResolvers: fileResolvers,
125 resourceProvider: resourceProvider, 121 resourceProvider: resourceProvider,
126 summaryData: summaryDataStore); 122 summaryData: summaryDataStore);
127 123
128 var context = compiler.context as AnalysisContextImpl; 124 var context = compiler.context as AnalysisContextImpl;
129 125
130 var compilerOptions = new CompilerOptions.fromArguments(argResults); 126 var compilerOptions = new CompilerOptions.fromArguments(argResults);
131 127
132 var resolveFn = (String url) { 128 var resolveFn = (String url) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (source is InSummarySource) { 276 if (source is InSummarySource) {
281 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); 277 return source.summaryPath.substring(1).replaceAll('.api.ds', '');
282 } 278 }
283 return source.toString().substring(1).replaceAll('.dart', ''); 279 return source.toString().substring(1).replaceAll('.dart', '');
284 } 280 }
285 281
286 /// Thrown when the input source code has errors. 282 /// Thrown when the input source code has errors.
287 class CompileErrorException implements Exception { 283 class CompileErrorException implements Exception {
288 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 284 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
289 } 285 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/web/main.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698