Comparing version 0.5.0 to 0.5.1
17
index.js
@@ -5,3 +5,8 @@ 'use strict'; | ||
var esrefactor = require('esrefactor'); | ||
function rename(code, tokenTo, tokenFrom){ | ||
function testParse (code) { | ||
try{ | ||
return esprima.parse(code,{range:true}); | ||
}catch(e){} | ||
} | ||
function rename(code, tokenTo, tokenFrom) { | ||
tokenTo = tokenTo || '_dereq_'; | ||
@@ -12,5 +17,9 @@ tokenFrom = tokenFrom || 'require'; | ||
} | ||
var inCode = '!function(){'+code+'}'; | ||
var inCode = '!function(){'+code+'\n;}'; | ||
var ast = testParse(inCode); | ||
if(!ast){ | ||
return code; | ||
} | ||
var ctx = new esrefactor.Context(inCode);; | ||
var ast = esprima.parse(inCode,{range:true}); | ||
estraverse.traverse(ast,{ | ||
@@ -28,3 +37,3 @@ enter:function(node, parent) { | ||
}); | ||
return ctx._code.slice(12, -1); | ||
return ctx._code.slice(12, -3); | ||
} | ||
@@ -31,0 +40,0 @@ |
{ | ||
"name": "derequire", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "remove requires", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,2 +22,6 @@ var should = require('chai').should(); | ||
}); | ||
it('should work with a comment on the end', function(){ | ||
var exampleText = 'var x=function(require,module,exports){var process=require("__browserify_process");var requireText = "require";}//lala'; | ||
derequire(exampleText).should.equal('var x=function(_dereq_,module,exports){var process=_dereq_("__browserify_process");var requireText = "require";}//lala'); | ||
}); | ||
it('should throw an error if you try to change things of different sizes', function(){ | ||
@@ -28,2 +32,5 @@ should.throw(function(){ | ||
}); | ||
it("should return the code back if it can't parse it", function(){ | ||
derequire("/*").should.equal("/*"); | ||
}); | ||
it('should work on something big', function(done){ | ||
@@ -30,0 +37,0 @@ fs.readFile('./test/pouchdb.js', {encoding:'utf8'}, function(err, data){ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
348187
10441
14