| 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; | 5 import 'dart:collection' show HashSet; |
| 6 import 'package:args/args.dart' show ArgParser, ArgResults; | 6 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 7 import 'package:analyzer/analyzer.dart' | 7 import 'package:analyzer/analyzer.dart' |
| 8 show | 8 show |
| 9 AnalysisError, | 9 AnalysisError, |
| 10 CompilationUnit, | 10 CompilationUnit, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 /// time. (Currently there is no warm up, but there may be in the future.) | 35 /// time. (Currently there is no warm up, but there may be in the future.) |
| 36 /// | 36 /// |
| 37 /// The SDK source code is assumed to be immutable for the life of this class. | 37 /// The SDK source code is assumed to be immutable for the life of this class. |
| 38 /// | 38 /// |
| 39 /// For all other files, it is up to the [AnalysisContext] to decide whether or | 39 /// For all other files, it is up to the [AnalysisContext] to decide whether or |
| 40 /// not any caching is performed. By default an analysis context will assume | 40 /// not any caching is performed. By default an analysis context will assume |
| 41 /// sources are immutable for the life of the context, and cache information | 41 /// sources are immutable for the life of the context, and cache information |
| 42 /// about them. | 42 /// about them. |
| 43 class ModuleCompiler { | 43 class ModuleCompiler { |
| 44 final AnalysisContext context; | 44 final AnalysisContext context; |
| 45 final _extensionTypes = new ExtensionTypeSet(); | 45 final ExtensionTypeSet _extensionTypes; |
| 46 | 46 |
| 47 ModuleCompiler.withContext(this.context); | 47 ModuleCompiler.withContext(AnalysisContext context) |
| 48 : context = context, |
| 49 _extensionTypes = new ExtensionTypeSet(context) { |
| 50 if (!context.analysisOptions.strongMode) { |
| 51 throw new ArgumentError('AnalysisContext must be strong mode'); |
| 52 } |
| 53 if (!context.sourceFactory.dartSdk.context.analysisOptions.strongMode) { |
| 54 throw new ArgumentError('AnalysisContext must have strong mode SDK'); |
| 55 } |
| 56 } |
| 48 | 57 |
| 49 ModuleCompiler(AnalyzerOptions analyzerOptions) | 58 ModuleCompiler(AnalyzerOptions analyzerOptions) |
| 50 : this.withContext(createAnalysisContextWithSources(analyzerOptions)); | 59 : this.withContext(createAnalysisContextWithSources(analyzerOptions)); |
| 51 | 60 |
| 52 /// Compiles a single Dart build unit into a JavaScript module. | 61 /// Compiles a single Dart build unit into a JavaScript module. |
| 53 /// | 62 /// |
| 54 /// *Warning* - this may require resolving the entire world. | 63 /// *Warning* - this may require resolving the entire world. |
| 55 /// If that is not desired, the analysis context must be pre-configured using | 64 /// If that is not desired, the analysis context must be pre-configured using |
| 56 /// summaries before calling this method. | 65 /// summaries before calling this method. |
| 57 JSModuleFile compile(BuildUnit unit, CompilerOptions options) { | 66 JSModuleFile compile(BuildUnit unit, CompilerOptions options) { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 300 } |
| 292 } | 301 } |
| 293 | 302 |
| 294 /// (Public for tests) the error code used when a part is missing. | 303 /// (Public for tests) the error code used when a part is missing. |
| 295 final missingPartErrorCode = const CompileTimeErrorCode( | 304 final missingPartErrorCode = const CompileTimeErrorCode( |
| 296 'MISSING_PART', 'The part was not supplied as an input to the compiler.'); | 305 'MISSING_PART', 'The part was not supplied as an input to the compiler.'); |
| 297 | 306 |
| 298 /// (Public for tests) the error code used when a part is unused. | 307 /// (Public for tests) the error code used when a part is unused. |
| 299 final unusedPartWarningCode = const StaticWarningCode( | 308 final unusedPartWarningCode = const StaticWarningCode( |
| 300 'UNUSED_PART', 'The part was not used by any libraries being compiled.'); | 309 'UNUSED_PART', 'The part was not used by any libraries being compiled.'); |
| OLD | NEW |