Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
1.fix commonjs中的require获取模块路径错误问题
2.fix use中模块的路径解析错误,默认解析到baseUrl
3.fix 配置path路径解析错误问题,path中的相对路径全部基于baseUrl
  • Loading branch information
yanhaijing committed Jan 25, 2015
1 parent 8164470 commit d0d1740
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lodjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g;
var interactiveScript = null;
var currentlyAddingScript = null;
var curExecModName = null;
var t = (new Date).getTime();

var o = {};
Expand Down Expand Up @@ -204,7 +205,12 @@
return ids.join('/');
}
function getDepUrl(id, url) {
return fixSuffix(getUrl(replacePath(id), url || o.baseUrl), 'js');
var pathId = replacePath(id);
//找到path 基于baseUrl
if (pathId !== id) {
url = o.baseUrl;
}
return fixSuffix(getUrl(pathId, url || o.baseUrl), 'js');
}
function getIdUrl(id){
//没有id的情况
Expand All @@ -217,8 +223,8 @@
}
return fixSuffix(getUrl(id, o.baseUrl), 'js');
}
function require(id) {
var url = getDepUrl(id, getCurSrc());
function require(id, url) {
var url = getDepUrl(id, url || curExecModName);
return moduleMap[url] && moduleMap[url].exports;
}
function fixPath(path) {
Expand Down Expand Up @@ -256,8 +262,10 @@
if (!params) {
moduleMap[modName].exports = modMap[modName].callback;
} else {
curExecModName = modName;
//commonjs
var exp = modMap[modName].callback.apply(null, params);
curExecModName = null;
//amd和返回值的commonjs
if (exp) {
moduleMap[modName].exports = exp;
Expand Down Expand Up @@ -368,7 +376,7 @@
if (!isObj(option)) {
option = {};
}
option.baseUrl = option.baseUrl || getCurSrc() || o.baseUrl;
option.baseUrl = option.baseUrl || o.baseUrl;

if (deps.length === 0) {
callback();
Expand Down

0 comments on commit d0d1740

Please sign in to comment.