| 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 @JS() | 4 @JS() |
| 5 library dev_compiler.web.web_command; | 5 library dev_compiler.web.web_command; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:html' show HttpRequest; | 9 import 'dart:html' show HttpRequest; |
| 10 | 10 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 190 } |
| 191 sb.write(body); | 191 sb.write(body); |
| 192 sourceCode = sb.toString(); | 192 sourceCode = sb.toString(); |
| 193 } | 193 } |
| 194 resourceProvider.newFile(fileName, sourceCode); | 194 resourceProvider.newFile(fileName, sourceCode); |
| 195 | 195 |
| 196 var unit = new BuildUnit(libraryName, "", [fileName], _moduleForLibrary); | 196 var unit = new BuildUnit(libraryName, "", [fileName], _moduleForLibrary); |
| 197 | 197 |
| 198 JSModuleFile module = compiler.compile(unit, compilerOptions); | 198 JSModuleFile module = compiler.compile(unit, compilerOptions); |
| 199 | 199 |
| 200 var moduleCode = module.isValid | 200 var moduleCode = ''; |
| 201 ? module | 201 if (module.isValid) { |
| 202 .getCode(ModuleFormat.legacy, true, unit.name, unit.name + '.map') | 202 moduleCode = module |
| 203 .code | 203 .getCode(ModuleFormat.legacy, unit.name, unit.name + '.map', |
| 204 : ''; | 204 singleOutFile: true) |
| 205 .code; |
| 206 } |
| 205 | 207 |
| 206 return new CompileResult( | 208 return new CompileResult( |
| 207 code: moduleCode, isValid: module.isValid, errors: module.errors); | 209 code: moduleCode, isValid: module.isValid, errors: module.errors); |
| 208 }; | 210 }; |
| 209 | 211 |
| 210 return allowInterop(compileFn); | 212 return allowInterop(compileFn); |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 | 215 |
| 214 // Given path, determine corresponding dart library. | 216 // Given path, determine corresponding dart library. |
| 215 String _moduleForLibrary(source) { | 217 String _moduleForLibrary(source) { |
| 216 if (source is InSummarySource) { | 218 if (source is InSummarySource) { |
| 217 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); | 219 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); |
| 218 } | 220 } |
| 219 return source.toString().substring(1).replaceAll('.dart', ''); | 221 return source.toString().substring(1).replaceAll('.dart', ''); |
| 220 } | 222 } |
| 221 | 223 |
| 222 /// Thrown when the input source code has errors. | 224 /// Thrown when the input source code has errors. |
| 223 class CompileErrorException implements Exception { | 225 class CompileErrorException implements Exception { |
| 224 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 226 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; |
| 225 } | 227 } |
| OLD | NEW |