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

Side by Side Diff: web/web_command.dart

Issue 2249233002: fix #626, add AMD module format and make it default (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: merged Created 4 years, 3 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 | « tool/input_sdk/private/ddc_runtime/operations.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:html' show HttpRequest; 8 import 'dart:html' show HttpRequest;
9 import 'dart:convert' show BASE64; 9 import 'dart:convert' show BASE64;
10 10
11 import 'package:analyzer/file_system/file_system.dart' 11 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver;
12 show ResourceUriResolver;
13 import 'package:analyzer/file_system/memory_file_system.dart' 12 import 'package:analyzer/file_system/memory_file_system.dart'
14 show MemoryResourceProvider; 13 show MemoryResourceProvider;
15 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 14 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
16 import 'package:analyzer/src/generated/source.dart' 15 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
17 show DartUriResolver;
18 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; 16 import 'package:analyzer/src/summary/idl.dart' show PackageBundle;
19 import 'package:analyzer/src/summary/package_bundle_reader.dart' 17 import 'package:analyzer/src/summary/package_bundle_reader.dart'
20 show 18 show
21 SummaryDataStore, 19 SummaryDataStore,
22 InSummaryPackageUriResolver, 20 InSummaryPackageUriResolver,
23 InputPackagesResultProvider, 21 InputPackagesResultProvider,
24 InSummarySource; 22 InSummarySource;
25 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; 23 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
26 24
27 import 'package:args/command_runner.dart'; 25 import 'package:args/command_runner.dart';
28 26
29 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions; 27 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions;
30 import 'package:dev_compiler/src/compiler/compiler.dart' 28 import 'package:dev_compiler/src/compiler/compiler.dart'
31 show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler; 29 show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler;
32 30
31 import 'package:dev_compiler/src/compiler/module_builder.dart';
33 import 'package:js/js.dart'; 32 import 'package:js/js.dart';
34 33
35 typedef void MessageHandler(Object message); 34 typedef void MessageHandler(Object message);
36 35
37 /// The command for invoking the modular compiler. 36 /// The command for invoking the modular compiler.
38 class WebCompileCommand extends Command { 37 class WebCompileCommand extends Command {
39 get name => 'compile'; 38 get name => 'compile';
40 39
41 get description => 'Compile a set of Dart files into a JavaScript module.'; 40 get description => 'Compile a set of Dart files into a JavaScript module.';
42 final MessageHandler messageHandler; 41 final MessageHandler messageHandler;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 96
98 var fileResolvers = [summaryResolver, resourceUriResolver]; 97 var fileResolvers = [summaryResolver, resourceUriResolver];
99 98
100 var compiler = new ModuleCompiler( 99 var compiler = new ModuleCompiler(
101 new AnalyzerOptions(dartSdkPath: '/dart-sdk'), 100 new AnalyzerOptions(dartSdkPath: '/dart-sdk'),
102 sdkResolver: sdkResolver, 101 sdkResolver: sdkResolver,
103 fileResolvers: fileResolvers, 102 fileResolvers: fileResolvers,
104 resourceProvider: resourceProvider); 103 resourceProvider: resourceProvider);
105 104
106 (compiler.context as AnalysisContextImpl).resultProvider = 105 (compiler.context as AnalysisContextImpl).resultProvider =
107 new InputPackagesResultProvider(compiler.context, summaryDataStore); 106 new InputPackagesResultProvider(compiler.context, summaryDataStore);
108 107
109 var compilerOptions = new CompilerOptions.fromArguments(argResults); 108 var compilerOptions = new CompilerOptions.fromArguments(argResults);
110 109
111 var compileFn = (String dart, int number) { 110 var compileFn = (String dart, int number) {
112 // Create a new virtual File that contains the given Dart source. 111 // Create a new virtual File that contains the given Dart source.
113 resourceProvider.newFile("/expression${number}.dart", dart); 112 resourceProvider.newFile("/expression${number}.dart", dart);
114 113
115 var unit = new BuildUnit("expression${number}", "", 114 var unit = new BuildUnit("expression${number}", "",
116 ["file:///expression${number}.dart"], _moduleForLibrary); 115 ["file:///expression${number}.dart"], _moduleForLibrary);
117 116
118 JSModuleFile module = compiler.compile(unit, compilerOptions); 117 JSModuleFile module = compiler.compile(unit, compilerOptions);
119 module.errors.forEach(messageHandler); 118 module.errors.forEach(messageHandler);
120 119
121 if (!module.isValid) throw new CompileErrorException(); 120 if (!module.isValid) throw new CompileErrorException();
122 return module.code; 121
122 var code =
123 module.getCode(ModuleFormat.amd, unit.name, unit.name + '.map');
124 return code.code;
123 }; 125 };
124 126
125 return allowInterop(compileFn); 127 return allowInterop(compileFn);
126 } 128 }
127 } 129 }
128 130
129 // Given path, determine corresponding dart library. 131 // Given path, determine corresponding dart library.
130 String _moduleForLibrary(source) { 132 String _moduleForLibrary(source) {
131 if (source is InSummarySource) { 133 if (source is InSummarySource) {
132 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); 134 return source.summaryPath.substring(1).replaceAll('.api.ds', '');
133 } 135 }
134 return source.toString().substring(1).replaceAll('.dart', ''); 136 return source.toString().substring(1).replaceAll('.dart', '');
135 } 137 }
136 138
137 /// Thrown when the input source code has errors. 139 /// Thrown when the input source code has errors.
138 class CompileErrorException implements Exception { 140 class CompileErrorException implements Exception {
139 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 141 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
140 } 142 }
OLDNEW
« no previous file with comments | « tool/input_sdk/private/ddc_runtime/operations.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698