Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: templates/modules.js.tmpl

Issue 29399569: Issue 5060 - Move require into modules template, make info a module (Closed)
Left Patch Set: Don't redeclare require Created March 31, 2017, 6:48 a.m.
Right Patch Set: Improve check for require Created April 1, 2017, 1:27 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « templates/geckoInfo.js.tmpl ('k') | tests/test_packagerEdge.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 {%- if args["module"] -%} 1 {%- if args["module"] -%}
2 if (!("require" in window)) 2 if (typeof require != "function")
Sebastian Noack 2017/03/31 10:42:01 The assumption of the global object being "window"
kzar 2017/03/31 14:03:01 Done.
kzar 2017/04/01 01:32:57 As discussed in IRC this is safer, since if a webp
Sebastian Noack 2017/04/01 10:02:56 Wow, I never noticed that named elements become au
3 { 3 {
4 window.require = function(module) 4 var require = function(module)
5 { 5 {
6 if (!(module in require.scopes)) 6 if (!(module in require.scopes))
7 { 7 {
8 let scope = {exports: {}}; 8 let scope = {exports: {}};
9 require.scopes[module] = require.modules[module](scope, scope.exports); 9 require.scopes[module] = require.modules[module](scope, scope.exports);
10 } 10 }
11 return require.scopes[module]; 11 return require.scopes[module];
12 } 12 };
13 require.modules = Object.create(null); 13 require.modules = Object.create(null);
14 require.scopes = Object.create(null); 14 require.scopes = Object.create(null);
15 } 15 }
16
17 {% if args["injectinfomodule"] %}
18 require.modules["info"] = function(module, exports)
19 {
20 {% if type == "gecko-webext" %}
21 {% include "geckoInfo.js.tmpl" %}
22 {% elif type == "chrome" or type == "edge" %}
23 {% include "chromeInfo.js.tmpl" %}
24 {% endif %}
25 return module.exports;
26 };
27 {% endif %}
28
16 {%- for module_name, script in modules -%} 29 {%- for module_name, script in modules -%}
17 require.modules[{{ module_name|json }}] = function(module, exports) 30 require.modules[{{ module_name|json }}] = function(module, exports)
18 { 31 {
19 {{ script }} 32 {{ script }}
20 return module.exports; 33 return module.exports;
21 }; 34 };
22 35
23 {% endfor -%} 36 {% endfor -%}
24 {%- set modules = dict(modules) -%} 37 {%- set modules = dict(modules) -%}
25 {%- for module_name in args["autoload"] -%} 38 {%- for module_name in args["autoload"] -%}
26 {%- if module_name in modules -%} 39 {%- if module_name in modules -%}
27 require({{ module_name|json }}); 40 require({{ module_name|json }});
28 {% endif %} 41 {% endif %}
29 {%- endfor -%} 42 {%- endfor -%}
30 {%- else -%} 43 {%- else -%}
31 {%- for module_name, script in modules -%} 44 {%- for module_name, script in modules -%}
32 {{ script }} 45 {{ script }}
33 {% endfor -%} 46 {% endfor -%}
34 {%- endif -%} 47 {%- endif -%}
LEFTRIGHT

Powered by Google App Engine
This is Rietveld