Skip to content

Commit 81c6b14

Browse files
committed
Experimental single parameter module definition and exports with @as module
1 parent 3b77f06 commit 81c6b14

5 files changed

Lines changed: 47 additions & 15 deletions

File tree

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"boss": true,
1212
"eqnull": true,
1313
"node": true,
14+
"scripturl": true,
1415
"expr": true,
1516
"predef": [
1617
"describe",

lib/cocktail.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,17 @@ cocktail = {
211211
}
212212
}
213213

214-
215214
return isClassDef;
216215
},
217216

217+
/**
218+
* @private
219+
* returns true if the given subject is a module definition object.
220+
*/
221+
_isModuleDefinition: function (subject) {
222+
return (subject && subject['@as'] && subject['@as'].toLowerCase() === 'module');
223+
},
224+
218225
/**
219226
* @private
220227
* If the subject has a property construtor returns it,
@@ -267,16 +274,30 @@ cocktail = {
267274
}
268275
options = subject;
269276
return this.mix(defaultConstructor, options);
277+
},
270278

279+
/**
280+
* @private
281+
* @experimental 0.5.1
282+
* returns a call to mix() with the subject module and options
283+
*/
284+
_processModuleDefinition: function (subject) {
285+
var options = subject;
286+
return this.mix(subject, options);
271287
},
272288

273289
/**
274290
* @public
275291
*/
276292
mix: function(subject, options){
277-
if(!options && this._isClassDefition(subject)) {
278-
return this._processClassDefition(subject);
279-
}
293+
if(!options){
294+
if (this._isClassDefition(subject)) {
295+
return this._processClassDefition(subject);
296+
}
297+
if (this._isModuleDefinition(subject)) {
298+
return this._processModuleDefinition(subject);
299+
}
300+
}
280301

281302
if(subject){
282303
this._pushQueue();
@@ -291,7 +312,6 @@ cocktail = {
291312

292313
};
293314

294-
295315
module.exports = cocktail;
296316

297317
/**
@@ -300,7 +320,7 @@ module.exports = cocktail;
300320
*/
301321
cocktail._DEFAULT_PROCESSORS = {
302322
'no-op' : require('./processor/NoOp'),
303-
'@as' : undefined,
323+
'@as' : undefined, /*pseudo-processor*/
304324
'@merge' : require('./processor/annotation/Merge'),
305325
'@extends' : require('./processor/annotation/Extends'),
306326
'@properties' : require('./processor/annotation/Properties'),
@@ -315,10 +335,8 @@ cocktail._DEFAULT_PROCESSORS = {
315335

316336
cocktail.registerProcessors(cocktail._DEFAULT_PROCESSORS);
317337

318-
cocktail.mix(cocktail, {
319-
/**
320-
* @public
321-
* SEQUENCE is used to define a enumeration of priorities for annotations
322-
*/
323-
SEQUENCE: sequence
324-
});
338+
/**
339+
* @public
340+
* SEQUENCE is used to define an enumeration of priorities for annotations
341+
*/
342+
cocktail.SEQUENCE = sequence;

lib/processor/annotation/Exports.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Exports.prototype = {
3131
if(value && typeof value === 'object'){
3232
value['exports'] = subject;
3333
}
34-
3534
}
3635
};
3736

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"sinon-chai": "~2.5",
3939
"sinon": "~1.9",
4040
"grunt-cli": "~0.1.13"
41-
4241
},
4342
"keywords": [
4443
"oop",

test/integration/Cocktail.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,21 @@ describe('cocktail Integration Test', function(){
531531

532532
});
533533

534+
it('returns a module if one single argument is specified with a @as annotation with a "module" value.', function(){
535+
var sut;
536+
537+
sut = cocktail.mix({
538+
'@as': 'module',
539+
540+
method: function() {}
541+
});
542+
543+
expect(sut).to.be.an('object');
544+
545+
expect(sut).to.respondTo('method');
546+
547+
});
548+
534549
it('did not return a class if one single argument is specified with a @as annotation with a value different of "class".', function(){
535550
var sut;
536551

0 commit comments

Comments
 (0)