| 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 library dart2js.src.options; | 5 library dart2js.src.options; |
| 6 | 6 |
| 7 import '../compiler.dart' show PackagesDiscoveryProvider; | 7 import '../compiler.dart' show PackagesDiscoveryProvider; |
| 8 import 'commandline_options.dart' show Flags; | 8 import 'commandline_options.dart' show Flags; |
| 9 | 9 |
| 10 /// Options used for parsing. | 10 /// Options used for parsing. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 /// Whether to trust primitive types during inference and optimizations. | 212 /// Whether to trust primitive types during inference and optimizations. |
| 213 final bool trustPrimitives; | 213 final bool trustPrimitives; |
| 214 | 214 |
| 215 /// Whether to trust type annotations during inference and optimizations. | 215 /// Whether to trust type annotations during inference and optimizations. |
| 216 final bool trustTypeAnnotations; | 216 final bool trustTypeAnnotations; |
| 217 | 217 |
| 218 /// Whether to generate code compliant with content security policy (CSP). | 218 /// Whether to generate code compliant with content security policy (CSP). |
| 219 final bool useContentSecurityPolicy; | 219 final bool useContentSecurityPolicy; |
| 220 | 220 |
| 221 /// Use the experimental CPS based backend. | |
| 222 final bool useCpsIr; | |
| 223 | |
| 224 /// When obfuscating for minification, whether to use the frequency of a name | 221 /// When obfuscating for minification, whether to use the frequency of a name |
| 225 /// as an heuristic to pick shorter names. | 222 /// as an heuristic to pick shorter names. |
| 226 final bool useFrequencyNamer; | 223 final bool useFrequencyNamer; |
| 227 | 224 |
| 228 /// Whether to use the new source-information implementation for source-maps. | 225 /// Whether to use the new source-information implementation for source-maps. |
| 229 /// (experimental) | 226 /// (experimental) |
| 230 final bool useNewSourceInfo; | 227 final bool useNewSourceInfo; |
| 231 | 228 |
| 232 /// Whether the user requested to use the fast startup emitter. The full | 229 /// Whether the user requested to use the fast startup emitter. The full |
| 233 /// emitter might still be used if the program uses dart:mirrors. | 230 /// emitter might still be used if the program uses dart:mirrors. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 resolveOnly: _hasOption(options, Flags.resolveOnly), | 308 resolveOnly: _hasOption(options, Flags.resolveOnly), |
| 312 sourceMapUri: _extractUriOption(options, '--source-map='), | 309 sourceMapUri: _extractUriOption(options, '--source-map='), |
| 313 strips: _extractCsvOption(options, '--force-strip='), | 310 strips: _extractCsvOption(options, '--force-strip='), |
| 314 testMode: _hasOption(options, Flags.testMode), | 311 testMode: _hasOption(options, Flags.testMode), |
| 315 trustJSInteropTypeAnnotations: | 312 trustJSInteropTypeAnnotations: |
| 316 _hasOption(options, Flags.trustJSInteropTypeAnnotations), | 313 _hasOption(options, Flags.trustJSInteropTypeAnnotations), |
| 317 trustPrimitives: _hasOption(options, Flags.trustPrimitives), | 314 trustPrimitives: _hasOption(options, Flags.trustPrimitives), |
| 318 trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations), | 315 trustTypeAnnotations: _hasOption(options, Flags.trustTypeAnnotations), |
| 319 useContentSecurityPolicy: | 316 useContentSecurityPolicy: |
| 320 _hasOption(options, Flags.useContentSecurityPolicy), | 317 _hasOption(options, Flags.useContentSecurityPolicy), |
| 321 useCpsIr: _hasOption(options, Flags.useCpsIr), | |
| 322 useFrequencyNamer: | 318 useFrequencyNamer: |
| 323 !_hasOption(options, Flags.noFrequencyBasedMinification), | 319 !_hasOption(options, Flags.noFrequencyBasedMinification), |
| 324 useNewSourceInfo: _hasOption(options, Flags.useNewSourceInfo), | 320 useNewSourceInfo: _hasOption(options, Flags.useNewSourceInfo), |
| 325 useStartupEmitter: _hasOption(options, Flags.fastStartup), | 321 useStartupEmitter: _hasOption(options, Flags.fastStartup), |
| 326 verbose: _hasOption(options, Flags.verbose)); | 322 verbose: _hasOption(options, Flags.verbose)); |
| 327 } | 323 } |
| 328 | 324 |
| 329 /// Creates an option object for the compiler. | 325 /// Creates an option object for the compiler. |
| 330 /// | 326 /// |
| 331 /// This validates and normalizes dependent options to be consistent. For | 327 /// This validates and normalizes dependent options to be consistent. For |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 List<Uri> resolutionInputs: null, | 368 List<Uri> resolutionInputs: null, |
| 373 Uri resolutionOutput: null, | 369 Uri resolutionOutput: null, |
| 374 bool resolveOnly: false, | 370 bool resolveOnly: false, |
| 375 Uri sourceMapUri: null, | 371 Uri sourceMapUri: null, |
| 376 List<String> strips: const [], | 372 List<String> strips: const [], |
| 377 bool testMode: false, | 373 bool testMode: false, |
| 378 bool trustJSInteropTypeAnnotations: false, | 374 bool trustJSInteropTypeAnnotations: false, |
| 379 bool trustPrimitives: false, | 375 bool trustPrimitives: false, |
| 380 bool trustTypeAnnotations: false, | 376 bool trustTypeAnnotations: false, |
| 381 bool useContentSecurityPolicy: false, | 377 bool useContentSecurityPolicy: false, |
| 382 bool useCpsIr: false, | |
| 383 bool useFrequencyNamer: true, | 378 bool useFrequencyNamer: true, |
| 384 bool useNewSourceInfo: false, | 379 bool useNewSourceInfo: false, |
| 385 bool useStartupEmitter: false, | 380 bool useStartupEmitter: false, |
| 386 bool verbose: false}) { | 381 bool verbose: false}) { |
| 387 // TODO(sigmund): should entrypoint be here? should we validate it is not | 382 // TODO(sigmund): should entrypoint be here? should we validate it is not |
| 388 // null? In unittests we use the same compiler to analyze or build multiple | 383 // null? In unittests we use the same compiler to analyze or build multiple |
| 389 // entrypoints. | 384 // entrypoints. |
| 390 if (libraryRoot == null) { | 385 if (libraryRoot == null) { |
| 391 throw new ArgumentError("[libraryRoot] is null."); | 386 throw new ArgumentError("[libraryRoot] is null."); |
| 392 } | 387 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 resolutionInputs: resolutionInputs, | 440 resolutionInputs: resolutionInputs, |
| 446 resolutionOutput: resolutionOutput, | 441 resolutionOutput: resolutionOutput, |
| 447 resolveOnly: resolveOnly, | 442 resolveOnly: resolveOnly, |
| 448 sourceMapUri: sourceMapUri, | 443 sourceMapUri: sourceMapUri, |
| 449 strips: strips, | 444 strips: strips, |
| 450 testMode: testMode, | 445 testMode: testMode, |
| 451 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, | 446 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, |
| 452 trustPrimitives: trustPrimitives, | 447 trustPrimitives: trustPrimitives, |
| 453 trustTypeAnnotations: trustTypeAnnotations, | 448 trustTypeAnnotations: trustTypeAnnotations, |
| 454 useContentSecurityPolicy: useContentSecurityPolicy, | 449 useContentSecurityPolicy: useContentSecurityPolicy, |
| 455 useCpsIr: useCpsIr, | |
| 456 useFrequencyNamer: useFrequencyNamer, | 450 useFrequencyNamer: useFrequencyNamer, |
| 457 useNewSourceInfo: useNewSourceInfo, | 451 useNewSourceInfo: useNewSourceInfo, |
| 458 useStartupEmitter: useStartupEmitter, | 452 useStartupEmitter: useStartupEmitter, |
| 459 verbose: verbose); | 453 verbose: verbose); |
| 460 } | 454 } |
| 461 | 455 |
| 462 CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot, | 456 CompilerOptions._(this.entryPoint, this.libraryRoot, this.packageRoot, |
| 463 this.packageConfig, this.packagesDiscoveryProvider, this.environment, | 457 this.packageConfig, this.packagesDiscoveryProvider, this.environment, |
| 464 {this.allowMockCompilation: false, | 458 {this.allowMockCompilation: false, |
| 465 this.allowNativeExtensions: false, | 459 this.allowNativeExtensions: false, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 495 this.resolutionInputs: null, | 489 this.resolutionInputs: null, |
| 496 this.resolutionOutput: null, | 490 this.resolutionOutput: null, |
| 497 this.resolveOnly: false, | 491 this.resolveOnly: false, |
| 498 this.sourceMapUri: null, | 492 this.sourceMapUri: null, |
| 499 this.strips: const [], | 493 this.strips: const [], |
| 500 this.testMode: false, | 494 this.testMode: false, |
| 501 this.trustJSInteropTypeAnnotations: false, | 495 this.trustJSInteropTypeAnnotations: false, |
| 502 this.trustPrimitives: false, | 496 this.trustPrimitives: false, |
| 503 this.trustTypeAnnotations: false, | 497 this.trustTypeAnnotations: false, |
| 504 this.useContentSecurityPolicy: false, | 498 this.useContentSecurityPolicy: false, |
| 505 this.useCpsIr: false, | |
| 506 this.useFrequencyNamer: false, | 499 this.useFrequencyNamer: false, |
| 507 this.useNewSourceInfo: false, | 500 this.useNewSourceInfo: false, |
| 508 this.useStartupEmitter: false, | 501 this.useStartupEmitter: false, |
| 509 this.verbose: false}) | 502 this.verbose: false}) |
| 510 : _shownPackageWarnings = shownPackageWarnings; | 503 : _shownPackageWarnings = shownPackageWarnings; |
| 511 | 504 |
| 512 /// Creates a copy of the [CompilerOptions] where the provided non-null | 505 /// Creates a copy of the [CompilerOptions] where the provided non-null |
| 513 /// option values replace existing. | 506 /// option values replace existing. |
| 514 static CompilerOptions copy(CompilerOptions options, | 507 static CompilerOptions copy(CompilerOptions options, |
| 515 {entryPoint, | 508 {entryPoint, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 resolutionInputs, | 545 resolutionInputs, |
| 553 resolutionOutput, | 546 resolutionOutput, |
| 554 resolveOnly, | 547 resolveOnly, |
| 555 sourceMapUri, | 548 sourceMapUri, |
| 556 strips, | 549 strips, |
| 557 testMode, | 550 testMode, |
| 558 trustJSInteropTypeAnnotations, | 551 trustJSInteropTypeAnnotations, |
| 559 trustPrimitives, | 552 trustPrimitives, |
| 560 trustTypeAnnotations, | 553 trustTypeAnnotations, |
| 561 useContentSecurityPolicy, | 554 useContentSecurityPolicy, |
| 562 useCpsIr, | |
| 563 useFrequencyNamer, | 555 useFrequencyNamer, |
| 564 useNewSourceInfo, | 556 useNewSourceInfo, |
| 565 useStartupEmitter, | 557 useStartupEmitter, |
| 566 verbose}) { | 558 verbose}) { |
| 567 return new CompilerOptions._( | 559 return new CompilerOptions._( |
| 568 entryPoint ?? options.entryPoint, | 560 entryPoint ?? options.entryPoint, |
| 569 libraryRoot ?? options.libraryRoot, | 561 libraryRoot ?? options.libraryRoot, |
| 570 packageRoot ?? options.packageRoot, | 562 packageRoot ?? options.packageRoot, |
| 571 packageConfig ?? options.packageConfig, | 563 packageConfig ?? options.packageConfig, |
| 572 packagesDiscoveryProvider ?? options.packagesDiscoveryProvider, | 564 packagesDiscoveryProvider ?? options.packagesDiscoveryProvider, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 sourceMapUri: sourceMapUri ?? options.sourceMapUri, | 613 sourceMapUri: sourceMapUri ?? options.sourceMapUri, |
| 622 strips: strips ?? options.strips, | 614 strips: strips ?? options.strips, |
| 623 testMode: testMode ?? options.testMode, | 615 testMode: testMode ?? options.testMode, |
| 624 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations ?? | 616 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations ?? |
| 625 options.trustJSInteropTypeAnnotations, | 617 options.trustJSInteropTypeAnnotations, |
| 626 trustPrimitives: trustPrimitives ?? options.trustPrimitives, | 618 trustPrimitives: trustPrimitives ?? options.trustPrimitives, |
| 627 trustTypeAnnotations: | 619 trustTypeAnnotations: |
| 628 trustTypeAnnotations ?? options.trustTypeAnnotations, | 620 trustTypeAnnotations ?? options.trustTypeAnnotations, |
| 629 useContentSecurityPolicy: | 621 useContentSecurityPolicy: |
| 630 useContentSecurityPolicy ?? options.useContentSecurityPolicy, | 622 useContentSecurityPolicy ?? options.useContentSecurityPolicy, |
| 631 useCpsIr: useCpsIr ?? options.useCpsIr, | |
| 632 useFrequencyNamer: useFrequencyNamer ?? options.useFrequencyNamer, | 623 useFrequencyNamer: useFrequencyNamer ?? options.useFrequencyNamer, |
| 633 useNewSourceInfo: useNewSourceInfo ?? options.useNewSourceInfo, | 624 useNewSourceInfo: useNewSourceInfo ?? options.useNewSourceInfo, |
| 634 useStartupEmitter: useStartupEmitter ?? options.useStartupEmitter, | 625 useStartupEmitter: useStartupEmitter ?? options.useStartupEmitter, |
| 635 verbose: verbose ?? options.verbose); | 626 verbose: verbose ?? options.verbose); |
| 636 } | 627 } |
| 637 | 628 |
| 638 /// Returns `true` if warnings and hints are shown for all packages. | 629 /// Returns `true` if warnings and hints are shown for all packages. |
| 639 bool get showAllPackageWarnings { | 630 bool get showAllPackageWarnings { |
| 640 return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty; | 631 return _shownPackageWarnings != null && _shownPackageWarnings.isEmpty; |
| 641 } | 632 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 } | 720 } |
| 730 | 721 |
| 731 /// Locations of the platform descriptor files relative to the library root. | 722 /// Locations of the platform descriptor files relative to the library root. |
| 732 const String _clientPlatform = "lib/dart_client.platform"; | 723 const String _clientPlatform = "lib/dart_client.platform"; |
| 733 const String _serverPlatform = "lib/dart_server.platform"; | 724 const String _serverPlatform = "lib/dart_server.platform"; |
| 734 const String _sharedPlatform = "lib/dart_shared.platform"; | 725 const String _sharedPlatform = "lib/dart_shared.platform"; |
| 735 | 726 |
| 736 const String _UNDETERMINED_BUILD_ID = "build number could not be determined"; | 727 const String _UNDETERMINED_BUILD_ID = "build number could not be determined"; |
| 737 const bool _forceIncrementalSupport = | 728 const bool _forceIncrementalSupport = |
| 738 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); | 729 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); |
| OLD | NEW |