| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 compiler; | 5 library compiler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:package_config/packages.dart'; | 8 import 'package:package_config/packages.dart'; |
| 9 import 'compiler_new.dart' as new_api; | 9 import 'compiler_new.dart' as new_api; |
| 10 import 'src/options.dart' show CompilerOptions; | 10 import 'src/options.dart' show CompilerOptions; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 * At least the following extensions can be expected: | 45 * At least the following extensions can be expected: |
| 46 * | 46 * |
| 47 * * "js" for JavaScript output. | 47 * * "js" for JavaScript output. |
| 48 * * "js.map" for source maps. | 48 * * "js.map" for source maps. |
| 49 * * "dart" for Dart output. | 49 * * "dart" for Dart output. |
| 50 * * "dart.map" for source maps. | 50 * * "dart.map" for source maps. |
| 51 * | 51 * |
| 52 * As more features are added to the compiler, new names and | 52 * As more features are added to the compiler, new names and |
| 53 * extensions may be introduced. | 53 * extensions may be introduced. |
| 54 */ | 54 */ |
| 55 typedef EventSink<String> CompilerOutputProvider(String name, | 55 typedef EventSink<String> CompilerOutputProvider(String name, String extension); |
| 56 String extension); | |
| 57 | 56 |
| 58 /** | 57 /** |
| 59 * Invoked by the compiler to report diagnostics. If [uri] is | 58 * Invoked by the compiler to report diagnostics. If [uri] is |
| 60 * [:null:], so are [begin] and [end]. No other arguments may be | 59 * [:null:], so are [begin] and [end]. No other arguments may be |
| 61 * [:null:]. If [uri] is not [:null:], neither are [begin] and | 60 * [:null:]. If [uri] is not [:null:], neither are [begin] and |
| 62 * [end]. [uri] indicates the compilation unit from where the | 61 * [end]. [uri] indicates the compilation unit from where the |
| 63 * diagnostic originates. [begin] and [end] are zero-based character | 62 * diagnostic originates. [begin] and [end] are zero-based character |
| 64 * offsets from the beginning of the compilation unit. [message] is the | 63 * offsets from the beginning of the compilation unit. [message] is the |
| 65 * diagnostic message, and [kind] indicates indicates what kind of | 64 * diagnostic message, and [kind] indicates indicates what kind of |
| 66 * diagnostic it is. | 65 * diagnostic it is. |
| 67 */ | 66 */ |
| 68 typedef void DiagnosticHandler(Uri uri, int begin, int end, | 67 typedef void DiagnosticHandler( |
| 69 String message, Diagnostic kind); | 68 Uri uri, int begin, int end, String message, Diagnostic kind); |
| 70 | 69 |
| 71 /** | 70 /** |
| 72 * Provides a package lookup mechanism in the case that no package root or | 71 * Provides a package lookup mechanism in the case that no package root or |
| 73 * package resolution configuration file are explicitly specified. | 72 * package resolution configuration file are explicitly specified. |
| 74 */ | 73 */ |
| 75 typedef Future<Packages> PackagesDiscoveryProvider(Uri uri); | 74 typedef Future<Packages> PackagesDiscoveryProvider(Uri uri); |
| 76 | 75 |
| 77 /// Information resulting from the compilation. | 76 /// Information resulting from the compilation. |
| 78 class CompilationResult { | 77 class CompilationResult { |
| 79 /// `true` if the compilation succeeded, that is, compilation didn't fail due | 78 /// `true` if the compilation succeeded, that is, compilation didn't fail due |
| (...skipping 17 matching lines...) Expand all Loading... |
| 97 * | 96 * |
| 98 * If the compilation fails, the future's value will be [:null:] and | 97 * If the compilation fails, the future's value will be [:null:] and |
| 99 * [handler] will have been invoked at least once with [:kind == | 98 * [handler] will have been invoked at least once with [:kind == |
| 100 * Diagnostic.ERROR:] or [:kind == Diagnostic.CRASH:]. | 99 * Diagnostic.ERROR:] or [:kind == Diagnostic.CRASH:]. |
| 101 * | 100 * |
| 102 * Deprecated: if no [outputProvider] is given, the future completes | 101 * Deprecated: if no [outputProvider] is given, the future completes |
| 103 * to the compiled script. This behavior will be removed in the future | 102 * to the compiled script. This behavior will be removed in the future |
| 104 * as the compiler may create multiple files to support lazy loading | 103 * as the compiler may create multiple files to support lazy loading |
| 105 * of libraries. | 104 * of libraries. |
| 106 */ | 105 */ |
| 107 Future<CompilationResult> compile( | 106 Future<CompilationResult> compile(Uri script, Uri libraryRoot, Uri packageRoot, |
| 108 Uri script, | 107 CompilerInputProvider inputProvider, DiagnosticHandler handler, |
| 109 Uri libraryRoot, | |
| 110 Uri packageRoot, | |
| 111 CompilerInputProvider inputProvider, | |
| 112 DiagnosticHandler handler, | |
| 113 [List<String> options = const [], | 108 [List<String> options = const [], |
| 114 CompilerOutputProvider outputProvider, | 109 CompilerOutputProvider outputProvider, |
| 115 Map<String, dynamic> environment = const {}, | 110 Map<String, dynamic> environment = const {}, |
| 116 Uri packageConfig, | 111 Uri packageConfig, |
| 117 PackagesDiscoveryProvider packagesDiscoveryProvider]) { | 112 PackagesDiscoveryProvider packagesDiscoveryProvider]) { |
| 118 | |
| 119 CompilerOptions compilerOptions = new CompilerOptions.parse( | 113 CompilerOptions compilerOptions = new CompilerOptions.parse( |
| 120 entryPoint: script, | 114 entryPoint: script, |
| 121 libraryRoot: libraryRoot, | 115 libraryRoot: libraryRoot, |
| 122 packageRoot: packageRoot, | 116 packageRoot: packageRoot, |
| 123 packageConfig: packageConfig, | 117 packageConfig: packageConfig, |
| 124 packagesDiscoveryProvider: packagesDiscoveryProvider, | 118 packagesDiscoveryProvider: packagesDiscoveryProvider, |
| 125 options: options, | 119 options: options, |
| 126 environment: environment); | 120 environment: environment); |
| 127 | 121 |
| 128 new_api.CompilerInput compilerInput = new LegacyCompilerInput(inputProvider); | 122 new_api.CompilerInput compilerInput = new LegacyCompilerInput(inputProvider); |
| 129 new_api.CompilerDiagnostics compilerDiagnostics = | 123 new_api.CompilerDiagnostics compilerDiagnostics = |
| 130 new LegacyCompilerDiagnostics(handler); | 124 new LegacyCompilerDiagnostics(handler); |
| 131 new_api.CompilerOutput compilerOutput = | 125 new_api.CompilerOutput compilerOutput = |
| 132 new LegacyCompilerOutput(outputProvider); | 126 new LegacyCompilerOutput(outputProvider); |
| 133 | 127 |
| 134 return new_api.compile(compilerOptions, compilerInput, | 128 return new_api |
| 135 compilerDiagnostics, compilerOutput) | 129 .compile( |
| 130 compilerOptions, compilerInput, compilerDiagnostics, compilerOutput) |
| 136 .then((new_api.CompilationResult result) { | 131 .then((new_api.CompilationResult result) { |
| 137 return new CompilationResult(result.compiler, isSuccess: result.isSuccess); | 132 return new CompilationResult(result.compiler, isSuccess: result.isSuccess); |
| 138 }); | 133 }); |
| 139 } | 134 } |
| 140 | 135 |
| 141 /** | 136 /** |
| 142 * Kind of diagnostics that the compiler can report. | 137 * Kind of diagnostics that the compiler can report. |
| 143 */ | 138 */ |
| 144 class Diagnostic { | 139 class Diagnostic { |
| 145 /** | 140 /** |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 final String name; | 198 final String name; |
| 204 | 199 |
| 205 /** | 200 /** |
| 206 * This constructor is not private to support user-defined | 201 * This constructor is not private to support user-defined |
| 207 * diagnostic kinds. | 202 * diagnostic kinds. |
| 208 */ | 203 */ |
| 209 const Diagnostic(this.ordinal, this.name); | 204 const Diagnostic(this.ordinal, this.name); |
| 210 | 205 |
| 211 String toString() => name; | 206 String toString() => name; |
| 212 } | 207 } |
| OLD | NEW |