Permalink
Browse files

Hack around http://code.google.com/p/chromium/issues/detail?id=109362

  • Loading branch information...
1 parent dfd5d5d commit a128af7a16b13cd233c9d68232a20a6963c14d55 @tobie committed Jan 6, 2012
Showing with 50 additions and 33 deletions.
  1. +3 −5 lib/abstract-collector.js
  2. +10 −7 lib/ast-collector.js
  3. +29 −18 lib/collector.js
  4. +8 −3 lib/dev-collector.js
@@ -65,16 +65,14 @@ function AbstractCollector(config) {
var lazyEval = this.getLazyEvaluatedModules();
arr.forEach(function(m) {
- var src;
if (m.duplicateOf) {
// would be pointless to lazy eval these modules.
- src = this.encloseModule(m);
+ buffer.push(this.defineModule(m));
} else if (m.id in lazyEval) {
- src = this.escapeModule(m);
+ buffer.push(this.defineLazyEvaluatedModule(m));
} else {
- src = this.encloseModule(m);
+ buffer.push(this.defineModule(m));
}
- buffer.push(this.makeDefine(m, src));
}, this);
buffer.push(this.renderRequireCall(this._main));
View
@@ -39,15 +39,18 @@ util.inherits(AstCollector, SuperClass);
return ["function", null, ["require", "exports", "module"], toAstBody(ast)];
}
- p.escapeModule = escapeModule;
- function escapeModule(m) {
- var ast = this.getModuleAst(m);
- return ["string", this.generateCode(ast)];
+ p.defineModule = defineModule;
+ function defineModule(m) {
+ var args = [this.getModuleIdAst(m), this.encloseModule(m)];
+ return getFunctionCallStatementAst("define", args);
}
- p.makeDefine = makeDefine;
- function makeDefine(m, subtree) {
- return getFunctionCallStatementAst("define", [this.getModuleIdAst(m), subtree]);
+ p.defineLazyEvaluatedModule = defineLazyEvaluatedModule;
+ function defineLazyEvaluatedModule(m) {
+ var ast = this.getModuleAst(m),
+ args = [this.getModuleIdAst(m), ["string", this.generateCode(ast)]];
+
+ return getFunctionCallStatementAst("define", args);
}
p.renderRequireCall = renderRequireCall;
View
@@ -28,15 +28,6 @@ function Collector(config) {
util.inherits(Collector, SuperClass);
(function(p) {
- p.makeDefine = makeDefine;
- function makeDefine(m, src) {
- var output = '';
- output += '\n// module: ' + m.id;
- output += '\n// file: ' + m.relativePath;
- output += '\ndefine("' + m.id + '", ' + src + ');';
- return output;
- }
-
p.escape = escape;
function escape(str, inlineSafe) {
var regexp = inlineSafe ? INLINE_SCRIPT_SAFE_JS_ESCAPE_REGEXP : JS_ESCAPE_REGEXP;
@@ -67,15 +58,30 @@ util.inherits(Collector, SuperClass);
}).join('\n');
}
- p.encloseModule = encloseModule;
- function encloseModule(m) {
- return 'function(require, exports, module) {\n' + this.getModuleSrc(m) + '\n}';
+ p.makeDefine = makeDefine;
+ function makeDefine(m, src) {
+ var header = this.getCommentHeader(m),
+ id = this.getModuleId(m);
+ return header + 'define("' + id + '", ' + src + ');\n';
+ }
+
+ p.getCommentHeader = getCommentHeader;
+ function getCommentHeader(m) {
+ var output = '';
+ output += '// module: ' + m.id + '\n';
+ output += '// file: ' + m.relativePath + '\n';
+ return output;
+ }
+
+ p.defineModule = defineModule;
+ function defineModule(m) {
+ return this.makeDefine(m, 'function(require, exports, module) {\n' + this.getModuleSrc(m) + '}');
}
- p.escapeModule = escapeModule;
- function escapeModule(m) {
- var body = this.getModuleSrc(m) + '\n//@ sourceURL=' + m.relativePath;
- return '"' + this.escape(body, this.config.inlineSafe) + '"';
+ p.defineLazyEvaluatedModule = defineLazyEvaluatedModule;
+ function defineLazyEvaluatedModule(m) {
+ var body = this.getModuleSrc(m) + this.getSourceUrl(m);
+ return this.makeDefine(m, '"' + this.escape(body, this.config.inlineSafe) + '"');
}
p.getModuleSrc = getModuleSrc;
@@ -86,19 +92,24 @@ util.inherits(Collector, SuperClass);
return m.getSrc();
}
+ p.getSourceUrl = getSourceUrl;
+ function getSourceUrl(m) {
+ return '\n//@ sourceURL=' + m.relativePath + '\n';
+ }
+
p.getModuleId = getModuleId;
function getModuleId(m) {
return m.id;
}
p.renderRequireCall = renderRequireCall;
function renderRequireCall(m) {
- return 'require("' + this.getModuleId(m) + '");'
+ return 'require("' + this.getModuleId(m) + '");\n'
}
p.renderRuntime = renderRuntime;
function renderRuntime() {
- return RUNTIME;
+ return RUNTIME + '\n';
}
})(Collector.prototype);
View
@@ -17,9 +17,14 @@ function DevCollector(config) {
util.inherits(DevCollector, SuperClass);
(function(p) {
- p.encloseModule = encloseModule;
- function encloseModule(m) {
- return 'new Function("require", "exports", "module", ' + this.escapeModule(m) + ')';
+ p.defineModule = defineModule;
+ function defineModule(m) {
+ var body = this.getModuleSrc(m) + this.getSourceUrl(m),
+ id = this.getModuleId(m),
+ program = 'define("' + id + '", function(require, exports, module) { ' + body + '});',
+ header = this.getCommentHeader(m);
+
+ return header + 'eval("' + this.escape(program, this.config.inlineSafe) + '");\n'
}
})(DevCollector.prototype);

0 comments on commit a128af7

Please sign in to comment.