Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CJS-style AMD to execute in require-order. #1484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4044,6 +4044,8 @@ function amd(loader) {
var deps = modDeps;
var factory = modFactory;
var isESModule = false;
var isCJS = false;
var firstSpecialIndex = -1;
if (typeof name != 'string') {
factory = deps;
deps = name;
Expand All @@ -4067,6 +4069,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
isCJS = true;
firstSpecialIndex = requireIndex;

deps.splice(requireIndex, 1);

Expand All @@ -4077,6 +4081,10 @@ function amd(loader) {


if ((exportsIndex = indexOf.call(deps, 'exports')) != -1) {
if(exportsIndex > firstSpecialIndex) {
firstSpecialIndex = exportsIndex;
}

deps.splice(exportsIndex, 1);

// Detect esModule
Expand All @@ -4087,16 +4095,31 @@ function amd(loader) {
}


if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
deps.splice(moduleIndex, 1);
if ((moduleIndex = indexOf.call(deps, 'module')) != -1) {
if(moduleIndex > firstSpecialIndex) {
firstSpecialIndex = moduleIndex;
}
deps.splice(moduleIndex, 1);
}


var define = {
deps: deps,
executingRequire: isCJS,
execute: function(require, exports, module) {

var depValues = [];
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));

if(!define.executingRequire) {
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));
} else if(firstSpecialIndex > 0 && deps.length) {
var currentIndex = 0;
do {
depValues.push(require(deps[currentIndex]));
currentIndex++;
} while(currentIndex < firstSpecialIndex);
}

module.uri = loader.baseURL + module.id;

Expand Down Expand Up @@ -4168,7 +4191,7 @@ function amd(loader) {
defineBundle = true;

// define the module through the register registry
loader.register(name, define.deps, false, define.execute);
loader.register(name, define.deps, isCJS, define.execute);
}
if(loader.defined[name]) {
loader.defined[name].isESModule = isESModule;
Expand Down
33 changes: 28 additions & 5 deletions src/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,8 @@ function amd(loader) {
var deps = modDeps;
var factory = modFactory;
var isESModule = false;
var isCJS = false;
var firstSpecialIndex = -1;
if (typeof name != 'string') {
factory = deps;
deps = name;
Expand All @@ -1628,6 +1630,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
isCJS = true;
firstSpecialIndex = requireIndex;

deps.splice(requireIndex, 1);

Expand All @@ -1638,6 +1642,10 @@ function amd(loader) {


if ((exportsIndex = indexOf.call(deps, 'exports')) != -1) {
if(exportsIndex > firstSpecialIndex) {
firstSpecialIndex = exportsIndex;
}

deps.splice(exportsIndex, 1);

// Detect esModule
Expand All @@ -1648,16 +1656,31 @@ function amd(loader) {
}


if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
deps.splice(moduleIndex, 1);
if ((moduleIndex = indexOf.call(deps, 'module')) != -1) {
if(moduleIndex > firstSpecialIndex) {
firstSpecialIndex = moduleIndex;
}
deps.splice(moduleIndex, 1);
}


var define = {
deps: deps,
executingRequire: isCJS,
execute: function(require, exports, module) {

var depValues = [];
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));

if(!define.executingRequire) {
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));
} else if(firstSpecialIndex > 0 && deps.length) {
var currentIndex = 0;
do {
depValues.push(require(deps[currentIndex]));
currentIndex++;
} while(currentIndex < firstSpecialIndex);
}

module.uri = loader.baseURL + module.id;

Expand Down Expand Up @@ -1729,7 +1752,7 @@ function amd(loader) {
defineBundle = true;

// define the module through the register registry
loader.register(name, define.deps, false, define.execute);
loader.register(name, define.deps, isCJS, define.execute);
}
if(loader.defined[name]) {
loader.defined[name].isESModule = isESModule;
Expand Down
33 changes: 28 additions & 5 deletions src/base/lib/extension-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ function amd(loader) {
var deps = modDeps;
var factory = modFactory;
var isESModule = false;
var isCJS = false;
var firstSpecialIndex = -1;
if (typeof name != 'string') {
factory = deps;
deps = name;
Expand All @@ -182,6 +184,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
isCJS = true;
firstSpecialIndex = requireIndex;

deps.splice(requireIndex, 1);

Expand All @@ -192,6 +196,10 @@ function amd(loader) {


if ((exportsIndex = indexOf.call(deps, 'exports')) != -1) {
if(exportsIndex > firstSpecialIndex) {
firstSpecialIndex = exportsIndex;
}

deps.splice(exportsIndex, 1);

// Detect esModule
Expand All @@ -202,16 +210,31 @@ function amd(loader) {
}


if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
deps.splice(moduleIndex, 1);
if ((moduleIndex = indexOf.call(deps, 'module')) != -1) {
if(moduleIndex > firstSpecialIndex) {
firstSpecialIndex = moduleIndex;
}
deps.splice(moduleIndex, 1);
}


var define = {
deps: deps,
executingRequire: isCJS,
execute: function(require, exports, module) {

var depValues = [];
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));

if(!define.executingRequire) {
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));
} else if(firstSpecialIndex > 0 && deps.length) {
var currentIndex = 0;
do {
depValues.push(require(deps[currentIndex]));
currentIndex++;
} while(currentIndex < firstSpecialIndex);
}

module.uri = loader.baseURL + module.id;

Expand Down Expand Up @@ -283,7 +306,7 @@ function amd(loader) {
defineBundle = true;

// define the module through the register registry
loader.register(name, define.deps, false, define.execute);
loader.register(name, define.deps, isCJS, define.execute);
}
if(loader.defined[name]) {
loader.defined[name].isESModule = isESModule;
Expand Down
33 changes: 28 additions & 5 deletions steal-with-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -5195,6 +5195,8 @@ function amd(loader) {
var deps = modDeps;
var factory = modFactory;
var isESModule = false;
var isCJS = false;
var firstSpecialIndex = -1;
if (typeof name != 'string') {
factory = deps;
deps = name;
Expand All @@ -5218,6 +5220,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
isCJS = true;
firstSpecialIndex = requireIndex;

deps.splice(requireIndex, 1);

Expand All @@ -5228,6 +5232,10 @@ function amd(loader) {


if ((exportsIndex = indexOf.call(deps, 'exports')) != -1) {
if(exportsIndex > firstSpecialIndex) {
firstSpecialIndex = exportsIndex;
}

deps.splice(exportsIndex, 1);

// Detect esModule
Expand All @@ -5238,16 +5246,31 @@ function amd(loader) {
}


if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
deps.splice(moduleIndex, 1);
if ((moduleIndex = indexOf.call(deps, 'module')) != -1) {
if(moduleIndex > firstSpecialIndex) {
firstSpecialIndex = moduleIndex;
}
deps.splice(moduleIndex, 1);
}


var define = {
deps: deps,
executingRequire: isCJS,
execute: function(require, exports, module) {

var depValues = [];
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));

if(!define.executingRequire) {
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));
} else if(firstSpecialIndex > 0 && deps.length) {
var currentIndex = 0;
do {
depValues.push(require(deps[currentIndex]));
currentIndex++;
} while(currentIndex < firstSpecialIndex);
}

module.uri = loader.baseURL + module.id;

Expand Down Expand Up @@ -5319,7 +5342,7 @@ function amd(loader) {
defineBundle = true;

// define the module through the register registry
loader.register(name, define.deps, false, define.execute);
loader.register(name, define.deps, isCJS, define.execute);
}
if(loader.defined[name]) {
loader.defined[name].isESModule = isESModule;
Expand Down
2 changes: 1 addition & 1 deletion steal-with-promises.production.js

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions steal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3925,6 +3925,8 @@ function amd(loader) {
var deps = modDeps;
var factory = modFactory;
var isESModule = false;
var isCJS = false;
var firstSpecialIndex = -1;
if (typeof name != 'string') {
factory = deps;
deps = name;
Expand All @@ -3948,6 +3950,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
isCJS = true;
firstSpecialIndex = requireIndex;

deps.splice(requireIndex, 1);

Expand All @@ -3958,6 +3962,10 @@ function amd(loader) {


if ((exportsIndex = indexOf.call(deps, 'exports')) != -1) {
if(exportsIndex > firstSpecialIndex) {
firstSpecialIndex = exportsIndex;
}

deps.splice(exportsIndex, 1);

// Detect esModule
Expand All @@ -3968,16 +3976,31 @@ function amd(loader) {
}


if ((moduleIndex = indexOf.call(deps, 'module')) != -1)
deps.splice(moduleIndex, 1);
if ((moduleIndex = indexOf.call(deps, 'module')) != -1) {
if(moduleIndex > firstSpecialIndex) {
firstSpecialIndex = moduleIndex;
}
deps.splice(moduleIndex, 1);
}


var define = {
deps: deps,
executingRequire: isCJS,
execute: function(require, exports, module) {

var depValues = [];
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));

if(!define.executingRequire) {
for (var i = 0; i < deps.length; i++)
depValues.push(require(deps[i]));
} else if(firstSpecialIndex > 0 && deps.length) {
var currentIndex = 0;
do {
depValues.push(require(deps[currentIndex]));
currentIndex++;
} while(currentIndex < firstSpecialIndex);
}

module.uri = loader.baseURL + module.id;

Expand Down Expand Up @@ -4049,7 +4072,7 @@ function amd(loader) {
defineBundle = true;

// define the module through the register registry
loader.register(name, define.deps, false, define.execute);
loader.register(name, define.deps, isCJS, define.execute);
}
if(loader.defined[name]) {
loader.defined[name].isESModule = isESModule;
Expand Down
2 changes: 1 addition & 1 deletion steal.production.js

Large diffs are not rendered by default.

Loading