Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 4 |
| 5 import 'dart:collection' show HashSet, Queue; | 5 import 'dart:collection' show HashSet, Queue; |
| 6 import 'package:analyzer/dart/element/element.dart' show LibraryElement; | 6 import 'package:analyzer/dart/element/element.dart' show LibraryElement; |
| 7 import 'package:analyzer/analyzer.dart' | 7 import 'package:analyzer/analyzer.dart' |
| 8 show AnalysisError, CompilationUnit, ErrorSeverity; | 8 show AnalysisError, CompilationUnit, ErrorSeverity; |
| 9 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; | 9 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; |
| 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 if (!options.unsafeForceCompile && | 136 if (!options.unsafeForceCompile && |
| 137 errors.any((e) => errorSeverity(context, e) == ErrorSeverity.ERROR)) { | 137 errors.any((e) => errorSeverity(context, e) == ErrorSeverity.ERROR)) { |
| 138 return new JSModuleFile.invalid(unit.name, messages); | 138 return new JSModuleFile.invalid(unit.name, messages); |
| 139 } | 139 } |
| 140 | 140 |
| 141 var codeGenerator = new CodeGenerator(context, options, _extensionTypes); | 141 var codeGenerator = new CodeGenerator(context, options, _extensionTypes); |
| 142 return codeGenerator.compile(unit, trees, messages); | 142 return codeGenerator.compile(unit, trees, messages); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 enum ModuleFormat { es6, legacy, node } | 146 enum ModuleFormat { es6, commonjs, requirejs, legacy } |
| 147 | 147 |
| 148 ModuleFormat parseModuleFormat(String s) => { | 148 ModuleFormat parseModuleFormat(String s) => { |
| 149 'es6': ModuleFormat.es6, | 149 'es6': ModuleFormat.es6, |
| 150 'node': ModuleFormat.node, | 150 'commonjs': ModuleFormat.commonjs, |
| 151 'requirejs': ModuleFormat.requirejs, | |
| 152 // Deprecated: | |
| 153 'node': ModuleFormat.commonjs, | |
| 151 'legacy': ModuleFormat.legacy | 154 'legacy': ModuleFormat.legacy |
| 152 }[s]; | 155 }[s]; |
| 153 | 156 |
| 154 class CompilerOptions { | 157 class CompilerOptions { |
| 155 /// Whether to emit the source mapping file. | 158 /// Whether to emit the source mapping file. |
| 156 /// | 159 /// |
| 157 /// This supports debugging the original source code instead of the generated | 160 /// This supports debugging the original source code instead of the generated |
| 158 /// code. | 161 /// code. |
| 159 final bool sourceMap; | 162 final bool sourceMap; |
| 160 | 163 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 218 |
| 216 const CompilerOptions( | 219 const CompilerOptions( |
| 217 {this.sourceMap: true, | 220 {this.sourceMap: true, |
| 218 this.sourceMapComment: true, | 221 this.sourceMapComment: true, |
| 219 this.summarizeApi: true, | 222 this.summarizeApi: true, |
| 220 this.summaryExtension: 'sum', | 223 this.summaryExtension: 'sum', |
| 221 this.unsafeForceCompile: false, | 224 this.unsafeForceCompile: false, |
| 222 this.emitMetadata: false, | 225 this.emitMetadata: false, |
| 223 this.closure: false, | 226 this.closure: false, |
| 224 this.destructureNamedParams: false, | 227 this.destructureNamedParams: false, |
| 225 this.moduleFormat: ModuleFormat.legacy, | 228 this.moduleFormat: ModuleFormat.requirejs, |
| 226 this.hoistInstanceCreation: true, | 229 this.hoistInstanceCreation: true, |
| 227 this.hoistSignatureTypes: false, | 230 this.hoistSignatureTypes: false, |
| 228 this.nameTypeTests: true, | 231 this.nameTypeTests: true, |
| 229 this.hoistTypeTests: true, | 232 this.hoistTypeTests: true, |
| 230 this.useAngular2Whitelist: false}); | 233 this.useAngular2Whitelist: false}); |
| 231 | 234 |
| 232 CompilerOptions.fromArguments(ArgResults args) | 235 CompilerOptions.fromArguments(ArgResults args) |
| 233 : sourceMap = args['source-map'], | 236 : sourceMap = args['source-map'], |
| 234 sourceMapComment = args['source-map-comment'], | 237 sourceMapComment = args['source-map-comment'], |
| 235 summarizeApi = args['summarize'], | 238 summarizeApi = args['summarize'], |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 251 ..addOption('summary-extension', | 254 ..addOption('summary-extension', |
| 252 help: 'file extension for Dart summary files', | 255 help: 'file extension for Dart summary files', |
| 253 defaultsTo: 'sum', | 256 defaultsTo: 'sum', |
| 254 hide: true) | 257 hide: true) |
| 255 ..addFlag('source-map', help: 'emit source mapping', defaultsTo: true) | 258 ..addFlag('source-map', help: 'emit source mapping', defaultsTo: true) |
| 256 ..addFlag('source-map-comment', | 259 ..addFlag('source-map-comment', |
| 257 help: 'adds a sourceMappingURL comment to the end of the JS,\n' | 260 help: 'adds a sourceMappingURL comment to the end of the JS,\n' |
| 258 'disable if using X-SourceMap header', | 261 'disable if using X-SourceMap header', |
| 259 defaultsTo: true, | 262 defaultsTo: true, |
| 260 hide: true) | 263 hide: true) |
| 261 ..addOption('modules', | 264 ..addOption('modules', |
| 262 help: 'module pattern to emit', | 265 help: 'module pattern to emit', |
| 263 allowed: ['es6', 'legacy', 'node'], | 266 allowed: [ |
| 264 allowedHelp: { | 267 'es6', |
| 265 'es6': 'es6 modules', | 268 'commonjs', |
| 266 'legacy': 'a custom format used by dartdevc, similar to AMD', | 269 'requirejs', |
| 267 'node': 'node.js modules (https://nodejs.org/api/modules.html)' | 270 /*deprecated*/ 'legacy', |
| 268 }, | 271 /*renamed to commonjs*/ 'node' |
| 269 defaultsTo: 'legacy') | 272 ], |
| 273 allowedHelp: { | |
| 274 'es6': 'es6 modules', | |
| 275 'commonjs': 'commonjs/node.js modules', | |
| 276 'requirejs': 'requirejs/amd modules' | |
|
nweiz
2016/08/16 22:14:53
Nit: add capitalization to the help strings here.
Jennifer Messerly
2016/08/24 22:39:51
Done.
| |
| 277 }, | |
| 278 defaultsTo: 'requirejs') | |
|
vsm
2016/08/16 21:23:23
We should keep the default until we fix downstream
Jennifer Messerly
2016/08/16 21:29:27
it's really easy to tweak our internal build rules
Jennifer Messerly
2016/08/16 21:34:45
I just sent you a CL that pins internal build rule
Jennifer Messerly
2016/08/24 22:39:51
update: and this was landed.
| |
| 270 ..addFlag('emit-metadata', | 279 ..addFlag('emit-metadata', |
| 271 help: 'emit metadata annotations queriable via mirrors', | 280 help: 'emit metadata annotations queriable via mirrors', |
| 272 defaultsTo: false) | 281 defaultsTo: false) |
| 273 ..addFlag('closure-experimental', | 282 ..addFlag('closure-experimental', |
| 274 help: 'emit Closure Compiler-friendly code (experimental)', | 283 help: 'emit Closure Compiler-friendly code (experimental)', |
| 275 defaultsTo: false) | 284 defaultsTo: false) |
| 276 ..addFlag('destructure-named-params', | 285 ..addFlag('destructure-named-params', |
| 277 help: 'Destructure named parameters', defaultsTo: false, hide: true) | 286 help: 'Destructure named parameters', defaultsTo: false, hide: true) |
| 278 ..addFlag('unsafe-force-compile', | 287 ..addFlag('unsafe-force-compile', |
| 279 help: 'Compile code even if it has errors. ಠ_ಠ\n' | 288 help: 'Compile code even if it has errors. ಠ_ಠ\n' |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 | 376 |
| 368 var map = new Map.from(this.sourceMap); | 377 var map = new Map.from(this.sourceMap); |
| 369 List list = new List.from(map['sources']); | 378 List list = new List.from(map['sources']); |
| 370 map['sources'] = list; | 379 map['sources'] = list; |
| 371 for (int i = 0; i < list.length; i++) { | 380 for (int i = 0; i < list.length; i++) { |
| 372 list[i] = path.relative(list[i], from: dir); | 381 list[i] = path.relative(list[i], from: dir); |
| 373 } | 382 } |
| 374 return map; | 383 return map; |
| 375 } | 384 } |
| 376 } | 385 } |
| OLD | NEW |