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 27 matching lines...) Expand all Loading... |
38 var format = argResults['modules']; | 38 var format = argResults['modules']; |
39 if (format is String) { | 39 if (format is String) { |
40 return [parseModuleFormat(format)]; | 40 return [parseModuleFormat(format)]; |
41 } | 41 } |
42 return (format as List<String>).map(parseModuleFormat).toList(); | 42 return (format as List<String>).map(parseModuleFormat).toList(); |
43 } | 43 } |
44 | 44 |
45 /// Adds an option to the [argParser] for choosing the module format, optionally | 45 /// Adds an option to the [argParser] for choosing the module format, optionally |
46 /// [allowMultiple] formats to be specified, with each emitted into a separate | 46 /// [allowMultiple] formats to be specified, with each emitted into a separate |
47 /// file. | 47 /// file. |
48 void addModuleFormatOptions(ArgParser argParser, {bool allowMultiple: false}) { | 48 void addModuleFormatOptions(ArgParser argParser, |
| 49 {bool allowMultiple: false, bool hide: true}) { |
49 argParser | 50 argParser |
50 ..addOption('modules', | 51 ..addOption('modules', |
51 help: 'module pattern to emit', | 52 help: 'module pattern to emit', |
52 allowed: [ | 53 allowed: [ |
53 'es6', | 54 'es6', |
54 'common', | 55 'common', |
55 'amd', | 56 'amd', |
56 'legacy', // deprecated | 57 'legacy', // deprecated |
57 'node', // renamed to commonjs | 58 'node', // renamed to commonjs |
58 'all' // to emit all flavors for the SDK | 59 'all' // to emit all flavors for the SDK |
59 ], | 60 ], |
60 allowedHelp: { | 61 allowedHelp: { |
61 'es6': 'ECMAScript 6 modules', | 62 'es6': 'ECMAScript 6 modules', |
62 'common': 'CommonJS/Node.js modules', | 63 'common': 'CommonJS/Node.js modules', |
63 'amd': 'AMD/RequireJS modules' | 64 'amd': 'AMD/RequireJS modules' |
64 }, | 65 }, |
65 allowMultiple: allowMultiple, | 66 allowMultiple: allowMultiple, |
66 defaultsTo: 'amd') | 67 defaultsTo: 'amd') |
67 ..addFlag('single-out-file', | 68 ..addFlag('single-out-file', |
68 help: 'emit modules that can be concatenated into one file.\n' | 69 help: 'emit modules that can be concatenated into one file.\n' |
69 'Only compatible with legacy and amd module formats.', | 70 'Only compatible with legacy and amd module formats.', |
70 defaultsTo: false, | 71 defaultsTo: false, |
71 hide: true); | 72 hide: hide); |
72 } | 73 } |
73 | 74 |
74 /// Transforms an ES6 [module] into a given module [format]. | 75 /// Transforms an ES6 [module] into a given module [format]. |
75 /// | 76 /// |
76 /// If the format is [ModuleFormat.es6] this will return [module] unchanged. | 77 /// If the format is [ModuleFormat.es6] this will return [module] unchanged. |
77 /// | 78 /// |
78 /// Because JS ASTs are immutable the resulting module will share as much | 79 /// Because JS ASTs are immutable the resulting module will share as much |
79 /// structure as possible with the original. The transformation is a shallow one | 80 /// structure as possible with the original. The transformation is a shallow one |
80 /// that affects the top-level module items, especially [ImportDeclaration]s and | 81 /// that affects the top-level module items, especially [ImportDeclaration]s and |
81 /// [ExportDeclaration]s. | 82 /// [ExportDeclaration]s. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Ensure the identifier first character is not numeric and that the whole | 334 // Ensure the identifier first character is not numeric and that the whole |
334 // identifier is not a keyword. | 335 // identifier is not a keyword. |
335 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { | 336 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { |
336 return '\$$result'; | 337 return '\$$result'; |
337 } | 338 } |
338 return result; | 339 return result; |
339 } | 340 } |
340 | 341 |
341 // Invalid characters for identifiers, which would need to be escaped. | 342 // Invalid characters for identifiers, which would need to be escaped. |
342 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); | 343 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); |
OLD | NEW |