Comparing version 0.4.2 to 0.4.4
@@ -68,2 +68,3 @@ var type = require('./type'); | ||
} | ||
function getDefineAndFactory(context) { | ||
@@ -85,2 +86,8 @@ if(context.hasVid('define')) { | ||
} | ||
var moduleId = null; | ||
if(factory.parent().leaves().length > 1 | ||
&& factory.parent().first().name() === JsNode.PRMREXPR | ||
&& factory.parent().first().first().name() === JsNode.TOKEN ) { | ||
moduleId = factory.parent().first(); | ||
} | ||
return { | ||
@@ -90,3 +97,4 @@ 'define': define[i], | ||
'factory': factory, | ||
'context': context | ||
'context': context, | ||
'moduleId': moduleId | ||
}; | ||
@@ -106,5 +114,14 @@ } | ||
var res = { | ||
'id':null, | ||
'array': null, | ||
'params': null | ||
}; | ||
if(defFact.moduleId){ | ||
var idNode = defFact.moduleId.first(); | ||
res.id = { | ||
'start': idNode.token().sIndex(), | ||
'end': defFact.moduleId.next().token().sIndex() + 1, | ||
'source': idNode.token().content() | ||
}; | ||
} | ||
//factory为函数时,将依赖改写为cmd形式的require | ||
@@ -179,11 +196,13 @@ if(defFact.factory.name() == JsNode.FNEXPR) { | ||
}); | ||
code = (defDeps.array ? (code.slice(0, defDeps.array.start) | ||
+ code.slice(defDeps.array.start, defDeps.array.end).replace(/(["']).+?\1/g, function(s) { | ||
if(/^['"][^./]/.test(s)) { | ||
s = s.charAt(0) + './' + s.slice(1); | ||
} | ||
return s; | ||
}) | ||
+ code.slice(defDeps.array.end, defDeps.params.start) | ||
) : code.slice(0, defDeps.params.start)) | ||
if(defDeps.array && defDeps.params.source.length < defDeps.array.source.length){ | ||
defDeps.array.source.slice(defDeps.params.source.length).forEach(function(s){ | ||
if(/^['"][^./]/.test(s)) { | ||
s = s.charAt(0) + './' + s.slice(1) | ||
} | ||
req += 'require(' + s + ');'; | ||
}); | ||
} | ||
code = code.slice(0, (defDeps.id || defDeps.array || defDeps.params).start) | ||
+ (defDeps.array ? code.slice(defDeps.array.end, defDeps.params.start) : "") | ||
+ 'require, exports, module' + code.slice(defDeps.params.end, defDeps.fnbody) | ||
@@ -215,2 +234,2 @@ + req | ||
} | ||
}; | ||
}; |
{ | ||
"name": "ranma", | ||
"version": "0.4.2", | ||
"version": "0.4.4", | ||
"description": "A converter between CommonJS/AMD/CMD/other", | ||
@@ -40,4 +40,4 @@ "maintainers": [ | ||
"dependencies": { | ||
"homunculus": "^0.3.8", | ||
"jsdc": "^0.4.6" | ||
"homunculus": "^0.7.5", | ||
"jsdc": "^0.5.3" | ||
}, | ||
@@ -44,0 +44,0 @@ "main": "./index", |
@@ -280,3 +280,3 @@ var ranma = require('../'); | ||
var res = ranma.cjsify('var [a] = [1]'); | ||
expect(res).to.eql('var a;!function(){var _0_= [1];a=_0_[0]}();module.exports = a;'); | ||
expect(res).to.eql('var a;!function(){var _0= [1];a=_0[0]}();module.exports = a;'); | ||
}); | ||
@@ -295,7 +295,11 @@ }); | ||
var res = ranma.cmdify('define(["./a", "./b"], function(a, b) {})'); | ||
expect(res).to.eql('define(["./a", "./b"], function(require, exports, module) {var a = require("./a");var b = require("./b");})'); | ||
expect(res).to.eql('define( function(require, exports, module) {var a = require("./a");var b = require("./b");})'); | ||
}); | ||
it('define id and factory in amd style', function() { | ||
var res = ranma.cmdify('define("moduleId", ["./a", "./b"], function(a, b) {})'); | ||
expect(res).to.eql('define( function(require, exports, module) {var a = require("./a");var b = require("./b");})'); | ||
}); | ||
it('define deps not compact to params', function() { | ||
var res = ranma.cmdify('~function(){define(["a", "b"], function f(a){})}()'); | ||
expect(res).to.eql('~function(){define(["./a", "./b"], function f(require, exports, module){var a = require("./a");})}()'); | ||
expect(res).to.eql('~function(){define( function f(require, exports, module){var a = require("./a");require("./b");})}()'); | ||
}); | ||
@@ -316,3 +320,3 @@ it('commonjs', function() { | ||
var res = ranma.cmdify('var [a] = [1]'); | ||
expect(res).to.eql('define(function(require, exports, module) {var a;!function(){var _0_= [1];a=_0_[0]}();module.exports = a;});'); | ||
expect(res).to.eql('define(function(require, exports, module) {var a;!function(){var _0= [1];a=_0[0]}();module.exports = a;});'); | ||
}); | ||
@@ -465,2 +469,3 @@ }); | ||
describe('jquery-1.8.3', function() { | ||
this.timeout(10000); | ||
var s = fs.readFileSync(path.join(__dirname, './src/jquery-1.8.3.js'), { encoding: 'utf-8' }); | ||
@@ -685,2 +690,2 @@ var type = ranma.type.analyse(s); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2160483
63
58083
7
+ Addedhomunculus@0.9.9(transitive)
+ Addedjsdc@0.5.12(transitive)
- Removedhomunculus@0.3.8(transitive)
- Removedjsdc@0.4.16(transitive)
Updatedhomunculus@^0.7.5
Updatedjsdc@^0.5.3