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 library pub.dart2js_transformer; | 5 library pub.dart2js_transformer; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
11 import 'package:barback/barback.dart'; | 11 import 'package:barback/barback.dart'; |
12 import 'package:path/path.dart' as path; | 12 import 'package:path/path.dart' as path; |
13 import 'package:stack_trace/stack_trace.dart'; | 13 import 'package:stack_trace/stack_trace.dart'; |
14 | 14 |
15 import '../../../../compiler/compiler.dart' as compiler; | 15 import '../../../../compiler/compiler.dart' as compiler; |
16 import '../../../../compiler/implementation/dart2js.dart' | 16 import '../../../../compiler/implementation/dart2js.dart' |
17 show AbortLeg; | 17 show AbortLeg; |
18 import '../../../../compiler/implementation/source_file.dart'; | 18 import '../../../../compiler/implementation/source_file.dart'; |
19 import '../barback.dart'; | 19 import '../barback.dart'; |
20 import '../dart.dart' as dart; | 20 import '../dart.dart' as dart; |
21 import '../pool.dart'; | 21 import '../pool.dart'; |
22 import '../utils.dart'; | 22 import '../utils.dart'; |
23 import 'asset_environment.dart'; | 23 import 'asset_environment.dart'; |
24 | 24 |
25 /// The set of all valid configuration options for this transformer. | 25 /// The set of all valid configuration options for this transformer. |
26 final _validOptions = new Set<String>.from([ | 26 final _validOptions = new Set<String>.from([ |
27 'commandLineOptions', 'checked', 'minify', 'verbose', 'environment', | 27 'commandLineOptions', 'checked', 'csp', 'minify', 'verbose', 'environment', |
28 'analyzeAll', 'suppressWarnings', 'suppressHints', 'suppressPackageWarnings', | 28 'analyzeAll', 'suppressWarnings', 'suppressHints', 'suppressPackageWarnings', |
29 'terse' | 29 'terse' |
30 ]); | 30 ]); |
31 | 31 |
32 /// A [Transformer] that uses dart2js's library API to transform Dart | 32 /// A [Transformer] that uses dart2js's library API to transform Dart |
33 /// entrypoints in "web" to JavaScript. | 33 /// entrypoints in "web" to JavaScript. |
34 class Dart2JSTransformer extends Transformer implements LazyTransformer { | 34 class Dart2JSTransformer extends Transformer implements LazyTransformer { |
35 /// We use this to ensure that only one compilation is in progress at a time. | 35 /// We use this to ensure that only one compilation is in progress at a time. |
36 /// | 36 /// |
37 /// Dart2js uses lots of memory, so if we try to actually run compiles in | 37 /// Dart2js uses lots of memory, so if we try to actually run compiles in |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 var entrypoint = path.join(_environment.graph.packages[id.package].dir, | 128 var entrypoint = path.join(_environment.graph.packages[id.package].dir, |
129 id.path); | 129 id.path); |
130 | 130 |
131 // TODO(rnystrom): Should have more sophisticated error-handling here. Need | 131 // TODO(rnystrom): Should have more sophisticated error-handling here. Need |
132 // to report compile errors to the user in an easily visible way. Need to | 132 // to report compile errors to the user in an easily visible way. Need to |
133 // make sure paths in errors are mapped to the original source path so they | 133 // make sure paths in errors are mapped to the original source path so they |
134 // can understand them. | 134 // can understand them. |
135 return Chain.track(dart.compile( | 135 return Chain.track(dart.compile( |
136 entrypoint, provider, | 136 entrypoint, provider, |
137 commandLineOptions: _configCommandLineOptions, | 137 commandLineOptions: _configCommandLineOptions, |
| 138 csp: _configBool('csp'), |
138 checked: _configBool('checked'), | 139 checked: _configBool('checked'), |
139 minify: _configBool( | 140 minify: _configBool( |
140 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE), | 141 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE), |
141 verbose: _configBool('verbose'), | 142 verbose: _configBool('verbose'), |
142 environment: _configEnvironment, | 143 environment: _configEnvironment, |
143 packageRoot: path.join(_environment.rootPackage.dir, "packages"), | 144 packageRoot: path.join(_environment.rootPackage.dir, "packages"), |
144 analyzeAll: _configBool('analyzeAll'), | 145 analyzeAll: _configBool('analyzeAll'), |
145 suppressWarnings: _configBool('suppressWarnings'), | 146 suppressWarnings: _configBool('suppressWarnings'), |
146 suppressHints: _configBool('suppressHints'), | 147 suppressHints: _configBool('suppressHints'), |
147 suppressPackageWarnings: _configBool( | 148 suppressPackageWarnings: _configBool( |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 405 } |
405 } | 406 } |
406 | 407 |
407 /// An [EventSink] that discards all data. Provided to dart2js when we don't | 408 /// An [EventSink] that discards all data. Provided to dart2js when we don't |
408 /// want an actual output. | 409 /// want an actual output. |
409 class NullSink<T> implements EventSink<T> { | 410 class NullSink<T> implements EventSink<T> { |
410 void add(T event) {} | 411 void add(T event) {} |
411 void addError(errorEvent, [StackTrace stackTrace]) {} | 412 void addError(errorEvent, [StackTrace stackTrace]) {} |
412 void close() {} | 413 void close() {} |
413 } | 414 } |
OLD | NEW |