| 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:args/args.dart' show ArgParser, ArgResults; | 5 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 6 import 'package:path/path.dart' as path; | 6 import 'package:path/path.dart' as path; |
| 7 | 7 |
| 8 import '../js_ast/js_ast.dart'; | 8 import '../js_ast/js_ast.dart'; |
| 9 import 'js_names.dart'; | 9 import 'js_names.dart'; |
| 10 | 10 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 .add(js.statement('#.# = #;', [exportsVar, name.name, name])); | 189 .add(js.statement('#.# = #;', [exportsVar, name.name, name])); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 var resultModule = | 194 var resultModule = |
| 195 js.call("function(#) { 'use strict'; #; }", [parameters, statements]); | 195 js.call("function(#) { 'use strict'; #; }", [parameters, statements]); |
| 196 var functionName = | 196 var functionName = |
| 197 'load__' + pathToJSIdentifier(module.name.replaceAll('.', '_')); | 197 'load__' + pathToJSIdentifier(module.name.replaceAll('.', '_')); |
| 198 resultModule = | 198 resultModule = |
| 199 new NamedFunction(new Identifier(functionName), resultModule); | 199 new NamedFunction(new Identifier(functionName), resultModule, true); |
| 200 | 200 |
| 201 var moduleDef = js.statement("dart_library.library(#, #, #, #)", [ | 201 var moduleDef = js.statement("dart_library.library(#, #, #, #)", [ |
| 202 js.string(module.name, "'"), | 202 js.string(module.name, "'"), |
| 203 new LiteralNull(), | 203 new LiteralNull(), |
| 204 js.commentExpression( | 204 js.commentExpression( |
| 205 "Imports", new ArrayInitializer(importNames, multiline: true)), | 205 "Imports", new ArrayInitializer(importNames, multiline: true)), |
| 206 resultModule | 206 resultModule |
| 207 ]); | 207 ]); |
| 208 return new Program(<ModuleItem>[moduleDef]); | 208 return new Program(<ModuleItem>[moduleDef]); |
| 209 } | 209 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 assert(names != null); | 295 assert(names != null); |
| 296 for (var name in names) { | 296 for (var name in names) { |
| 297 exportedProps.add(new Property(js.string(name.name), name)); | 297 exportedProps.add(new Property(js.string(name.name), name)); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 statements.add(js.comment('Exports:')); | 300 statements.add(js.comment('Exports:')); |
| 301 statements.add( | 301 statements.add( |
| 302 new Return(new ObjectInitializer(exportedProps, multiline: true))); | 302 new Return(new ObjectInitializer(exportedProps, multiline: true))); |
| 303 } | 303 } |
| 304 | 304 |
| 305 // TODO(vsm): Consider using an immediately invoked named function pattern |
| 306 // (see legacy code above). |
| 305 var block = singleOutFile | 307 var block = singleOutFile |
| 306 ? js.statement("define(#, #, function(#) { 'use strict'; #; });", [ | 308 ? js.statement("define(#, #, function(#) { 'use strict'; #; });", [ |
| 307 js.string(module.name, "'"), | 309 js.string(module.name, "'"), |
| 308 new ArrayInitializer(dependencies), | 310 new ArrayInitializer(dependencies), |
| 309 fnParams, | 311 fnParams, |
| 310 statements | 312 statements |
| 311 ]) | 313 ]) |
| 312 : js.statement("define(#, function(#) { 'use strict'; #; });", | 314 : js.statement("define(#, function(#) { 'use strict'; #; });", |
| 313 [new ArrayInitializer(dependencies), fnParams, statements]); | 315 [new ArrayInitializer(dependencies), fnParams, statements]); |
| 314 | 316 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 342 // Ensure the identifier first character is not numeric and that the whole | 344 // Ensure the identifier first character is not numeric and that the whole |
| 343 // identifier is not a keyword. | 345 // identifier is not a keyword. |
| 344 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { | 346 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { |
| 345 return '\$$result'; | 347 return '\$$result'; |
| 346 } | 348 } |
| 347 return result; | 349 return result; |
| 348 } | 350 } |
| 349 | 351 |
| 350 // Invalid characters for identifiers, which would need to be escaped. | 352 // Invalid characters for identifiers, which would need to be escaped. |
| 351 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); | 353 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); |
| OLD | NEW |