Skip to content

Commit 4df513e

Browse files
committed
Re: #7 - Fixes to the parameters passed into the IIFE
1 parent 732ad40 commit 4df513e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/amdclean.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,34 @@
357357
moduleName = obj.moduleName,
358358
dependencies = obj.dependencies,
359359
depLength = dependencies.length,
360+
options = publicAPI.options,
360361
dependencyNames = (function() {
361362
var deps = [],
362-
iterator = -1;
363+
iterator = -1,
364+
currentName;
363365
while(++iterator < depLength) {
364-
deps.push({ type: 'Identifier', name: publicAPI.normalizeModuleName(dependencies[iterator]) });
366+
currentName = dependencies[iterator];
367+
if(options.globalObject === true && options.globalObjectName && currentName !== '{}') {
368+
deps.push({
369+
'type': 'MemberExpression',
370+
'computed': true,
371+
'object': {
372+
'type': 'Identifier',
373+
'name': options.globalObjectName
374+
},
375+
'property': {
376+
'type': 'Literal',
377+
'value': publicAPI.normalizeModuleName(currentName),
378+
'raw': "" + publicAPI.normalizeModuleName(currentName) + ""
379+
},
380+
'name': publicAPI.normalizeModuleName(currentName)
381+
});
382+
} else {
383+
deps.push({
384+
'type': 'Identifier',
385+
'name': publicAPI.normalizeModuleName(currentName)
386+
});
387+
}
365388
}
366389
return deps;
367390
}()),
@@ -393,7 +416,10 @@
393416
if(currentName === 'exports') {
394417
hasExportsParam = true;
395418
}
396-
deps.push({ 'type': 'Identifier', 'name': currentName });
419+
deps.push({
420+
'type': 'Identifier',
421+
'name': currentName
422+
});
397423
}
398424
return deps;
399425
}());

test/specs/convert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('amdclean specs', function() {
6868
it('should support storing modules inside of a global object', function() {
6969
var AMDcode = "define('foo', ['require', 'exports', './bar'], function(require, exports){exports.bar = require('./bar');});",
7070
cleanedCode = amdclean.clean({ globalObject: true, globalObjectName: 'yeabuddy', code: AMDcode, escodegen: { format: { compact: true } } }),
71-
standardJavaScript = "var yeabuddy={};yeabuddy['foo']=function (require,exports,bar){exports.bar=bar;return exports;}({},{},bar);";
71+
standardJavaScript = "var yeabuddy={};yeabuddy['foo']=function (require,exports,bar){exports.bar=bar;return exports;}({},{},yeabuddy['bar']);";
7272

7373
expect(cleanedCode).toBe(standardJavaScript);
7474
});

0 commit comments

Comments
 (0)