Skip to content

Commit

Permalink
Re: #7 - Fixes to the parameters passed into the IIFE
Browse files Browse the repository at this point in the history
  • Loading branch information
gfranko committed Nov 25, 2013
1 parent 732ad40 commit 4df513e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
32 changes: 29 additions & 3 deletions src/amdclean.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,34 @@
moduleName = obj.moduleName,
dependencies = obj.dependencies,
depLength = dependencies.length,
options = publicAPI.options,
dependencyNames = (function() {
var deps = [],
iterator = -1;
iterator = -1,
currentName;
while(++iterator < depLength) {
deps.push({ type: 'Identifier', name: publicAPI.normalizeModuleName(dependencies[iterator]) });
currentName = dependencies[iterator];
if(options.globalObject === true && options.globalObjectName && currentName !== '{}') {
deps.push({
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': options.globalObjectName
},
'property': {
'type': 'Literal',
'value': publicAPI.normalizeModuleName(currentName),
'raw': "" + publicAPI.normalizeModuleName(currentName) + ""
},
'name': publicAPI.normalizeModuleName(currentName)
});
} else {
deps.push({
'type': 'Identifier',
'name': publicAPI.normalizeModuleName(currentName)
});
}
}
return deps;
}()),
Expand Down Expand Up @@ -393,7 +416,10 @@
if(currentName === 'exports') {
hasExportsParam = true;
}
deps.push({ 'type': 'Identifier', 'name': currentName });
deps.push({
'type': 'Identifier',
'name': currentName
});
}
return deps;
}());
Expand Down
2 changes: 1 addition & 1 deletion test/specs/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('amdclean specs', function() {
it('should support storing modules inside of a global object', function() {
var AMDcode = "define('foo', ['require', 'exports', './bar'], function(require, exports){exports.bar = require('./bar');});",
cleanedCode = amdclean.clean({ globalObject: true, globalObjectName: 'yeabuddy', code: AMDcode, escodegen: { format: { compact: true } } }),
standardJavaScript = "var yeabuddy={};yeabuddy['foo']=function (require,exports,bar){exports.bar=bar;return exports;}({},{},bar);";
standardJavaScript = "var yeabuddy={};yeabuddy['foo']=function (require,exports,bar){exports.bar=bar;return exports;}({},{},yeabuddy['bar']);";

expect(cleanedCode).toBe(standardJavaScript);
});
Expand Down

0 comments on commit 4df513e

Please sign in to comment.