Chromium Code Reviews| 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_helper; | 5 library compiler_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 import 'package:compiler/compiler.dart' as api; | |
| 11 | |
| 12 import 'package:compiler/src/elements/elements.dart' | 10 import 'package:compiler/src/elements/elements.dart' |
| 13 as lego; | 11 as lego; |
| 14 export 'package:compiler/src/elements/elements.dart'; | 12 export 'package:compiler/src/elements/elements.dart'; |
| 15 | 13 |
| 16 import 'package:compiler/src/js_backend/js_backend.dart' | 14 import 'package:compiler/src/js_backend/js_backend.dart' |
| 17 as js; | 15 as js; |
| 18 | 16 |
| 19 import 'package:compiler/src/commandline_options.dart'; | 17 import 'package:compiler/src/commandline_options.dart'; |
| 20 import 'package:compiler/src/common/codegen.dart'; | 18 import 'package:compiler/src/common/codegen.dart'; |
| 21 import 'package:compiler/src/common/resolution.dart'; | 19 import 'package:compiler/src/common/resolution.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 33 export 'package:compiler/src/util/util.dart'; | 31 export 'package:compiler/src/util/util.dart'; |
| 34 | 32 |
| 35 import 'package:compiler/src/compiler.dart' | 33 import 'package:compiler/src/compiler.dart' |
| 36 show Compiler; | 34 show Compiler; |
| 37 | 35 |
| 38 export 'package:compiler/src/tree/tree.dart'; | 36 export 'package:compiler/src/tree/tree.dart'; |
| 39 | 37 |
| 40 import 'mock_compiler.dart'; | 38 import 'mock_compiler.dart'; |
| 41 export 'mock_compiler.dart'; | 39 export 'mock_compiler.dart'; |
| 42 | 40 |
| 43 import 'memory_compiler.dart'; | 41 import 'memory_compiler.dart' hide compilerFor; |
| 44 | 42 |
| 45 import 'output_collector.dart'; | 43 import 'output_collector.dart'; |
| 46 export 'output_collector.dart'; | 44 export 'output_collector.dart'; |
| 47 | 45 |
| 48 /// Compile [code] and returns the code for [entry]. | 46 /// Compile [code] and returns the code for [entry]. |
| 49 /// | 47 /// |
| 50 /// If [check] is provided, it is executed on the code for [entry] before | 48 /// If [check] is provided, it is executed on the code for [entry] before |
| 51 /// returning. If [useMock] is `true` the [MockCompiler] is used for | 49 /// returning. If [useMock] is `true` the [MockCompiler] is used for |
| 52 /// compilation, otherwise the memory compiler is used. | 50 /// compilation, otherwise the memory compiler is used. |
| 53 Future<String> compile(String code, | 51 Future<String> compile(String code, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 lego.Element element = compiler.mainApp.find(entry); | 123 lego.Element element = compiler.mainApp.find(entry); |
| 126 js.JavaScriptBackend backend = compiler.backend; | 124 js.JavaScriptBackend backend = compiler.backend; |
| 127 String generated = backend.getGeneratedCode(element); | 125 String generated = backend.getGeneratedCode(element); |
| 128 if (check != null) { | 126 if (check != null) { |
| 129 check(generated); | 127 check(generated); |
| 130 } | 128 } |
| 131 return generated; | 129 return generated; |
| 132 } | 130 } |
| 133 } | 131 } |
| 134 | 132 |
| 135 // TODO(herhut): Disallow warnings and errors during compilation by default. | |
|
Johnni Winther
2015/09/11 14:02:55
Moved to mock_compiler.dart
| |
| 136 MockCompiler compilerFor(String code, Uri uri, | |
| 137 {bool analyzeAll: false, | |
| 138 bool analyzeOnly: false, | |
| 139 Map<String, String> coreSource, | |
| 140 bool disableInlining: true, | |
| 141 bool minify: false, | |
| 142 bool trustTypeAnnotations: false, | |
| 143 bool enableTypeAssertions: false, | |
| 144 int expectedErrors, | |
| 145 int expectedWarnings, | |
| 146 api.CompilerOutputProvider outputProvider}) { | |
| 147 MockCompiler compiler = new MockCompiler.internal( | |
| 148 analyzeAll: analyzeAll, | |
| 149 analyzeOnly: analyzeOnly, | |
| 150 coreSource: coreSource, | |
| 151 disableInlining: disableInlining, | |
| 152 enableMinification: minify, | |
| 153 trustTypeAnnotations: trustTypeAnnotations, | |
| 154 enableTypeAssertions: enableTypeAssertions, | |
| 155 expectedErrors: expectedErrors, | |
| 156 expectedWarnings: expectedWarnings, | |
| 157 outputProvider: outputProvider); | |
| 158 compiler.registerSource(uri, code); | |
| 159 compiler.diagnosticHandler = createHandler(compiler, code); | |
| 160 return compiler; | |
| 161 } | |
| 162 | |
| 163 Future<String> compileAll(String code, | 133 Future<String> compileAll(String code, |
| 164 {Map<String, String> coreSource, | 134 {Map<String, String> coreSource, |
| 165 bool disableInlining: true, | 135 bool disableInlining: true, |
| 166 bool trustTypeAnnotations: false, | 136 bool trustTypeAnnotations: false, |
| 167 bool minify: false, | 137 bool minify: false, |
| 168 int expectedErrors, | 138 int expectedErrors, |
| 169 int expectedWarnings}) { | 139 int expectedWarnings}) { |
| 170 Uri uri = new Uri(scheme: 'source'); | 140 Uri uri = new Uri(scheme: 'source'); |
| 171 OutputCollector outputCollector = new OutputCollector(); | 141 OutputCollector outputCollector = new OutputCollector(); |
| 172 MockCompiler compiler = compilerFor( | 142 MockCompiler compiler = compilerFor( |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 280 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 311 final spaceRe = new RegExp('\\s+'); | 281 final spaceRe = new RegExp('\\s+'); |
| 312 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 282 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 313 if (shouldMatch) { | 283 if (shouldMatch) { |
| 314 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 284 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 315 } else { | 285 } else { |
| 316 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 286 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 317 } | 287 } |
| 318 }); | 288 }); |
| 319 } | 289 } |
| OLD | NEW |