| 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_ast/js_ast.dart'; | 7 import '../js_ast/js_ast.dart'; |
| 8 import 'js_names.dart'; | 8 import 'js_names.dart'; |
| 9 | 9 |
| 10 /// Base class for compiling ES6 modules into various ES5 module patterns. | 10 /// Base class for compiling ES6 modules into various ES5 module patterns. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 "Imports", new ArrayInitializer(importNames, multiline: true)), | 101 "Imports", new ArrayInitializer(importNames, multiline: true)), |
| 102 resultModule | 102 resultModule |
| 103 ]); | 103 ]); |
| 104 return new Program(<ModuleItem>[moduleDef]); | 104 return new Program(<ModuleItem>[moduleDef]); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 /// Generates node modules. | 108 /// Generates node modules. |
| 109 class NodeModuleBuilder extends _ModuleBuilder { | 109 class NodeModuleBuilder extends _ModuleBuilder { |
| 110 Program build(Program module) { | 110 Program build(Program module) { |
| 111 var importStatements = []; | 111 var importStatements = <Statement>[]; |
| 112 | 112 |
| 113 // Collect imports/exports/statements. | 113 // Collect imports/exports/statements. |
| 114 visitProgram(module); | 114 visitProgram(module); |
| 115 | 115 |
| 116 for (var import in imports) { | 116 for (var import in imports) { |
| 117 // TODO(jmesserly): we could use destructuring once Atom supports it. | 117 // TODO(jmesserly): we could use destructuring once Atom supports it. |
| 118 var moduleVar = | 118 var moduleVar = |
| 119 new TemporaryId(pathToJSIdentifier(import.from.valueWithoutQuotes)); | 119 new TemporaryId(pathToJSIdentifier(import.from.valueWithoutQuotes)); |
| 120 importStatements | 120 importStatements |
| 121 .add(js.statement('const # = require(#);', [moduleVar, import.from])); | 121 .add(js.statement('const # = require(#);', [moduleVar, import.from])); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Ensure the identifier first character is not numeric and that the whole | 178 // Ensure the identifier first character is not numeric and that the whole |
| 179 // identifier is not a keyword. | 179 // identifier is not a keyword. |
| 180 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { | 180 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { |
| 181 return '\$$result'; | 181 return '\$$result'; |
| 182 } | 182 } |
| 183 return result; | 183 return result; |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Invalid characters for identifiers, which would need to be escaped. | 186 // Invalid characters for identifiers, which would need to be escaped. |
| 187 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); | 187 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); |
| OLD | NEW |