| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 'package:path/path.dart' as path; | 5 import 'package:path/path.dart' as path; |
| 6 | 6 |
| 7 import '../js/js_ast.dart' as JS; | 7 import '../js/js_ast.dart' as JS; |
| 8 import '../js/js_ast.dart' show js; | 8 import '../js/js_ast.dart' show js; |
| 9 import '../options.dart' show ModuleFormat; | 9 import '../options.dart' show ModuleFormat; |
| 10 | 10 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 moduleStatements.addAll(_flattenBlocks(moduleItems)); | 148 moduleStatements.addAll(_flattenBlocks(moduleItems)); |
| 149 | 149 |
| 150 if (_exports.isNotEmpty) { | 150 if (_exports.isNotEmpty) { |
| 151 moduleStatements.add(js.comment('Exports:')); | 151 moduleStatements.add(js.comment('Exports:')); |
| 152 // TODO(jmesserly): make these immutable in JS? | 152 // TODO(jmesserly): make these immutable in JS? |
| 153 _exports.forEach((name, exportName) { | 153 _exports.forEach((name, exportName) { |
| 154 moduleStatements | 154 moduleStatements |
| 155 .add(js.statement('#.# = #;', [exportsVar, exportName, name])); | 155 .add(js.statement('#.# = #;', [exportsVar, exportName, name])); |
| 156 }); | 156 }); |
| 157 } | 157 } |
| 158 moduleStatements | 158 moduleStatements.add(new JS.ExportDeclaration(exportsVar, isDefault: true)); |
| 159 .add(new JS.ExportDeclaration(exportsVar, isDefault: true)); | |
| 160 // TODO(ochafik): What to do with jsModuleValue? | 159 // TODO(ochafik): What to do with jsModuleValue? |
| 161 return new JS.Program(moduleStatements); | 160 return new JS.Program(moduleStatements); |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 /// Generates node modules. | 164 /// Generates node modules. |
| 166 class NodeModuleBuilder extends ModuleBuilder { | 165 class NodeModuleBuilder extends ModuleBuilder { |
| 167 NodeModuleBuilder() : super._(); | 166 NodeModuleBuilder() : super._(); |
| 168 | 167 |
| 169 JS.Program build(String jsPath, String jsModuleValue, | 168 JS.Program build(String jsPath, String jsModuleValue, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 196 | 195 |
| 197 /// Flattens blocks in [stats] to a single list of module items. | 196 /// Flattens blocks in [stats] to a single list of module items. |
| 198 /// Note that in general, blocks should not be flattened, because it can | 197 /// Note that in general, blocks should not be flattened, because it can |
| 199 /// mess up with block-level scoping (let, const). | 198 /// mess up with block-level scoping (let, const). |
| 200 // TODO(ochafik): Remove this / find better pattern (adding statements as they | 199 // TODO(ochafik): Remove this / find better pattern (adding statements as they |
| 201 // are generated from [JSCodegenVisitor], instead of composing them with | 200 // are generated from [JSCodegenVisitor], instead of composing them with |
| 202 // [_statements]). | 201 // [_statements]). |
| 203 Iterable<JS.ModuleItem> _flattenBlocks(List<JS.ModuleItem> stats) => | 202 Iterable<JS.ModuleItem> _flattenBlocks(List<JS.ModuleItem> stats) => |
| 204 stats.expand( | 203 stats.expand( |
| 205 (item) => item is JS.Block ? _flattenBlocks(item.statements) : [item]); | 204 (item) => item is JS.Block ? _flattenBlocks(item.statements) : [item]); |
| OLD | NEW |