Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: pkg/dev_compiler/lib/src/compiler/module_builder.dart

Issue 2337213003: Support generating inlined source maps and wrapping module contents within a JavaScript eval block … (Closed)
Patch Set: Refactor based on John's offline comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/compiler.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/module_builder.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/module_builder.dart b/pkg/dev_compiler/lib/src/compiler/module_builder.dart
index 7a4e845d2a5c350cd04c83238b1e471eec0ecae2..828a0fa2a81927f68323e7802b168a31e19842ad 100644
--- a/pkg/dev_compiler/lib/src/compiler/module_builder.dart
+++ b/pkg/dev_compiler/lib/src/compiler/module_builder.dart
@@ -46,23 +46,28 @@ List<ModuleFormat> parseModuleFormatOption(ArgResults argResults) {
/// [allowMultiple] formats to be specified, with each emitted into a separate
/// file.
void addModuleFormatOptions(ArgParser argParser, {bool allowMultiple: false}) {
- argParser.addOption('modules',
- help: 'module pattern to emit',
- allowed: [
- 'es6',
- 'common',
- 'amd',
- 'legacy', // deprecated
- 'node', // renamed to commonjs
- 'all' // to emit all flavors for the SDK
- ],
- allowedHelp: {
- 'es6': 'ECMAScript 6 modules',
- 'common': 'CommonJS/Node.js modules',
- 'amd': 'AMD/RequireJS modules'
- },
- allowMultiple: allowMultiple,
- defaultsTo: 'amd');
+ argParser
+ ..addOption('modules',
+ help: 'module pattern to emit',
+ allowed: [
+ 'es6',
+ 'common',
+ 'amd',
+ 'legacy', // deprecated
+ 'node', // renamed to commonjs
+ 'all' // to emit all flavors for the SDK
+ ],
+ allowedHelp: {
+ 'es6': 'ECMAScript 6 modules',
+ 'common': 'CommonJS/Node.js modules',
+ 'amd': 'AMD/RequireJS modules'
+ },
+ allowMultiple: allowMultiple,
+ defaultsTo: 'amd')
+ ..addFlag('single-out-file',
+ help: 'emit output so that libraries can be concatenated together into '
+ 'a single file. Only compatible with legacy and amd module formats.',
+ defaultsTo: false);
}
/// Transforms an ES6 [module] into a given module [format].
@@ -73,15 +78,17 @@ void addModuleFormatOptions(ArgParser argParser, {bool allowMultiple: false}) {
/// structure as possible with the original. The transformation is a shallow one
/// that affects the top-level module items, especially [ImportDeclaration]s and
/// [ExportDeclaration]s.
-Program transformModuleFormat(ModuleFormat format, Program module) {
+Program transformModuleFormat(
+ ModuleFormat format, bool singleOutFile, Program module) {
switch (format) {
case ModuleFormat.legacy:
- return new LegacyModuleBuilder().build(module);
+ return new LegacyModuleBuilder(singleOutFile).build(module);
case ModuleFormat.common:
- return new CommonJSModuleBuilder().build(module);
+ return new CommonJSModuleBuilder(singleOutFile).build(module);
case ModuleFormat.amd:
- return new AmdModuleBuilder().build(module);
+ return new AmdModuleBuilder(singleOutFile).build(module);
case ModuleFormat.es6:
+ assert(singleOutFile == false);
return module;
}
return null; // unreachable. suppresses a bogus analyzer message
@@ -130,6 +137,10 @@ abstract class _ModuleBuilder {
/// Generates modules for with our legacy `dart_library.js` loading mechanism.
// TODO(jmesserly): remove this and replace with something that interoperates.
class LegacyModuleBuilder extends _ModuleBuilder {
+ /// The legacy module format always generates output compatible with a single
+ /// file mode.
+ LegacyModuleBuilder(bool singleOutFile);
+
Program build(Program module) {
// Collect imports/exports/statements.
visitProgram(module);
@@ -187,6 +198,14 @@ class LegacyModuleBuilder extends _ModuleBuilder {
/// Generates CommonJS modules (used by Node.js).
class CommonJSModuleBuilder extends _ModuleBuilder {
+ final bool singleOutFile;
+
+ CommonJSModuleBuilder(this.singleOutFile) {
+ // singleOutFile mode is not currently supported by the CommonJS module
+ // builder.
+ assert(singleOutFile == false);
+ }
+
Program build(Program module) {
var importStatements = <Statement>[];
@@ -236,6 +255,10 @@ class CommonJSModuleBuilder extends _ModuleBuilder {
/// Generates AMD modules (used in browsers with RequireJS).
class AmdModuleBuilder extends _ModuleBuilder {
+ final bool singleOutFile;
+
+ AmdModuleBuilder(this.singleOutFile);
+
Program build(Program module) {
var importStatements = <Statement>[];
@@ -277,8 +300,15 @@ class AmdModuleBuilder extends _ModuleBuilder {
new Return(new ObjectInitializer(exportedProps, multiline: true)));
}
- var block = js.statement("define(#, function(#) { 'use strict'; #; });",
- [new ArrayInitializer(dependencies), fnParams, statements]);
+ var block = singleOutFile
+ ? js.statement("define(#, #, function(#) { 'use strict'; #; });", [
+ js.string(module.name, "'"),
+ new ArrayInitializer(dependencies),
+ fnParams,
+ statements
+ ])
+ : js.statement("define(#, function(#) { 'use strict'; #; });",
+ [new ArrayInitializer(dependencies), fnParams, statements]);
return new Program([block]);
}
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/compiler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698