| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // This sample demonstrates how to run the compiler in a loop reading | 5 // This sample demonstrates how to run the compiler in a loop reading |
| 6 // all sources from memory, instead of using dart:io. | 6 // all sources from memory, instead of using dart:io. |
| 7 library sample.compile_loop; | 7 library sample.compile_loop; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // TODO(ahe): Use new Future.error. | 21 // TODO(ahe): Use new Future.error. |
| 22 throw new Exception('Error: Cannot read: $uri'); | 22 throw new Exception('Error: Cannot read: $uri'); |
| 23 } | 23 } |
| 24 return new Future.value(value); | 24 return new Future.value(value); |
| 25 } else if ('$uri' == 'memory:/main.dart') { | 25 } else if ('$uri' == 'memory:/main.dart') { |
| 26 return new Future.value(source); | 26 return new Future.value(source); |
| 27 } | 27 } |
| 28 // TODO(ahe): Use new Future.error. | 28 // TODO(ahe): Use new Future.error. |
| 29 throw new Exception('Error: Cannot read: $uri'); | 29 throw new Exception('Error: Cannot read: $uri'); |
| 30 } | 30 } |
| 31 void handler(Uri uri, int begin, int end, | 31 void handler( |
| 32 String message, compiler.Diagnostic kind) { | 32 Uri uri, int begin, int end, String message, compiler.Diagnostic kind) { |
| 33 // TODO(ahe): Remove dart:io import from | 33 // TODO(ahe): Remove dart:io import from |
| 34 // ../../lib/src/source_file_provider.dart and use | 34 // ../../lib/src/source_file_provider.dart and use |
| 35 // FormattingDiagnosticHandler instead. | 35 // FormattingDiagnosticHandler instead. |
| 36 print({ 'uri': '$uri', | 36 print({ |
| 37 'begin': begin, | 37 'uri': '$uri', |
| 38 'end': end, | 38 'begin': begin, |
| 39 'message': message, | 39 'end': end, |
| 40 'kind': kind.name }); | 40 'message': message, |
| 41 'kind': kind.name |
| 42 }); |
| 41 if (kind == compiler.Diagnostic.ERROR) { | 43 if (kind == compiler.Diagnostic.ERROR) { |
| 42 throw new Exception('Unexpected error occurred.'); | 44 throw new Exception('Unexpected error occurred.'); |
| 43 } | 45 } |
| 44 } | 46 } |
| 45 return compiler.compile( | 47 return compiler.compile(Uri.parse('memory:/main.dart'), |
| 46 Uri.parse('memory:/main.dart'), | 48 Uri.parse('sdk:/sdk/'), null, inputProvider, handler, []); |
| 47 Uri.parse('sdk:/sdk/'), | |
| 48 null, | |
| 49 inputProvider, | |
| 50 handler, | |
| 51 []); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 int iterations = 10; | 51 int iterations = 10; |
| 55 | 52 |
| 56 main() { | 53 main() { |
| 57 compile(EXAMPLE_HELLO_HTML).then((jsResult) { | 54 compile(EXAMPLE_HELLO_HTML).then((jsResult) { |
| 58 if (jsResult == null) throw 'Compilation failed'; | 55 if (jsResult == null) throw 'Compilation failed'; |
| 59 if (--iterations > 0) main(); | 56 if (--iterations > 0) main(); |
| 60 }); | 57 }); |
| 61 } | 58 } |
| 62 | 59 |
| 63 const String EXAMPLE_HELLO_HTML = r''' | 60 const String EXAMPLE_HELLO_HTML = r''' |
| 64 // Go ahead and modify this example. | 61 // Go ahead and modify this example. |
| 65 | 62 |
| 66 import "dart:html"; | 63 import "dart:html"; |
| 67 | 64 |
| 68 var greeting = "Hello, World!"; | 65 var greeting = "Hello, World!"; |
| 69 | 66 |
| 70 // Displays a greeting. | 67 // Displays a greeting. |
| 71 void main() { | 68 void main() { |
| 72 // This example uses HTML to display the greeting and it will appear | 69 // This example uses HTML to display the greeting and it will appear |
| 73 // in a nested HTML frame (an iframe). | 70 // in a nested HTML frame (an iframe). |
| 74 document.body.append(new HeadingElement.h1()..appendText(greeting)); | 71 document.body.append(new HeadingElement.h1()..appendText(greeting)); |
| 75 } | 72 } |
| 76 '''; | 73 '''; |
| OLD | NEW |