Comparing version 0.6.0 to 0.6.1
@@ -5,2 +5,4 @@ 'use strict'; | ||
var esrefactor = require('esrefactor'); | ||
var requireRegexp = /require.*\(.*['"]/m; | ||
function testParse (code) { | ||
@@ -12,2 +14,4 @@ try{ | ||
function rename(code, tokenTo, tokenFrom) { | ||
if (!requireRegexp.test(code)) return code; | ||
tokenTo = tokenTo || '_dereq_'; | ||
@@ -23,3 +27,3 @@ tokenFrom = tokenFrom || 'require'; | ||
} | ||
var ctx = new esrefactor.Context(inCode);; | ||
var ctx = new esrefactor.Context(inCode); | ||
@@ -26,0 +30,0 @@ estraverse.traverse(ast,{ |
{ | ||
"name": "derequire", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "remove requires", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ derequire | ||
var derequire = require('derequire'); | ||
var transformedCode = derequire(code [,tokenTo='_dereq_', tokenFrom='require'); | ||
var transformedCode = derequire(code, /*tokenTo=*/'_dereq_', /*tokenFrom=*/'require'); | ||
``` | ||
@@ -13,0 +13,0 @@ |
@@ -26,14 +26,25 @@ var should = require('chai').should(); | ||
}); | ||
it('should work with whitespace inside require statement', function(){ | ||
var exampleText = 'var x=function(require,module,exports){var process=require( "__browserify_process" )}'; | ||
derequire(exampleText).should.equal('var x=function(_dereq_,module,exports){var process=_dereq_( "__browserify_process" )}'); | ||
}); | ||
it('should work with single quoted requires', function(){ | ||
var exampleText = 'var x=function(require,module,exports){var process=require(\'__browserify_process\')}'; | ||
derequire(exampleText).should.equal('var x=function(_dereq_,module,exports){var process=_dereq_(\'__browserify_process\')}'); | ||
}); | ||
it('should throw an error if you try to change things of different sizes', function(){ | ||
should.throw(function(){ | ||
derequire('lalalalla', 'la'); | ||
derequire('require("x")', 'lalalalla', 'la'); | ||
}); | ||
}); | ||
it("should return the code back if it can't parse it", function(){ | ||
it("should return notthe code back if it can't parse it", function(){ | ||
derequire("/*").should.equal("/*"); | ||
}); | ||
it("should return the code back if it can't parse it and it has a require", function(){ | ||
derequire("/*require('").should.equal("/*require('"); | ||
}); | ||
it('should work on something big', function(done){ | ||
fs.readFile('./test/pouchdb.js', {encoding:'utf8'}, function(err, data){ | ||
if(err){ | ||
done(err); | ||
return done(err); | ||
} | ||
@@ -40,0 +51,0 @@ var transformed = derequire(data); |
349142
10454