Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix the require detection, switch to define detction instead, using t…

…he standard define.amd definition. Will allow including require without needing the includeRequire build option.
  • Loading branch information...
commit 078f32d415060cc5c7dc833a03e6fcfb5e8984a5 1 parent ed771b2
@jrburke jrburke authored
Showing with 11 additions and 9 deletions.
  1. +6 −5 build/jslib/parse.js
  2. +4 −4 build/tests/parse.js
  3. +1 −0  tasks.txt
View
11 build/jslib/parse.js
@@ -224,7 +224,7 @@ define(['uglifyjs/index'], function (uglify) {
* @returns {Boolean}
*/
parse.nodeHasRequire = function (node) {
- if (this.isRequireNode(node)) {
+ if (this.isDefineNode(node)) {
return true;
}
@@ -241,12 +241,13 @@ define(['uglifyjs/index'], function (uglify) {
};
/**
- * Is the given node the actual definition of require()
+ * Is the given node the actual definition of define(). Actually uses
+ * the definition of define.amd to find require.
* @param {Array} node
* @returns {Boolean}
*/
- parse.isRequireNode = function (node) {
- //Actually look for the require.s = assignment, since
+ parse.isDefineNode = function (node) {
+ //Actually look for the define.amd = assignment, since
//that is more indicative of RequireJS vs a plain require definition.
var assign;
if (!node) {
@@ -256,7 +257,7 @@ define(['uglifyjs/index'], function (uglify) {
if (node[0] === 'assign' && node[1] === true) {
assign = node[2];
if (assign[0] === 'dot' && assign[1][0] === 'name' &&
- assign[1][1] === 'require' && assign[2] === 's') {
+ assign[1][1] === 'define' && assign[2] === 'amd') {
return true;
}
}
View
8 build/tests/parse.js
@@ -88,10 +88,10 @@ define(['parse'], function (parse) {
doh.register('parseHasRequire',
[
function parseHasRequire(t) {
- var good1 = "var require; (function(){ require = function(){}; s = require.s = {};}());",
- good2 = "var myGlobalRequire = (function () { var require = {}; (function(){ require = function(){}; s = require.s = {};}()); }());",
- bad1 = "var require; function boom(){ var require = function(){}; }",
- bad2 = "(function(require) { require(); }(myvar));";
+ var good1 = "var require, define; (function(){ define = function(){}; define.amd = {};}());",
+ good2 = "var myGlobalRequire = (function () { var define = {}; (function(){ define = function(){}; define.amd = {};}()); }());",
+ bad1 = "var define; function boom(){ var define = function(){}; define.amd(); }",
+ bad2 = "(function(define) { define(); }(myvar));";
t.is(true, parse.definesRequire("good1", good1));
t.is(true, parse.definesRequire("good2", good2));
View
1  tasks.txt
@@ -6,6 +6,7 @@ Next release
--------------
- Removal of includeRequire option? Scrub all references, mention on list.
+ - paths: {requireLib: "../../require"} to get require in it.
- text plugins after a build load xdomain?
- move urlFetched outside of load function and do the check before load.
Please sign in to comment.
Something went wrong with that request. Please try again.