Skip to content

Commit

Permalink
fix(pattern return statement): allow undefined be the matched return …
Browse files Browse the repository at this point in the history
…value
  • Loading branch information
jhe committed Jul 25, 2016
1 parent 7297a87 commit 7e7a308
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const isUndefined = (value) => typeof value === 'undefined'

const evalMatchedPatternByStatmentsType = {
'undefined': (_obj, value, _args) => undefined,
'string': (_obj, value, _args) => value,
'number': (_obj, value, _args) => value,
'boolean': (_obj, value, _args) => value,
Expand Down
8 changes: 8 additions & 0 deletions test/misc.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ describe 'Miscellaneous useages', ->
)
expect(m).to.be.equal 'TEN'

it 'statements value could be undefined', ->
m = match('undefined')(
[1, 'ONE'],
['undefined', undefined],
[2, 'TWO']
)
expect(m).to.be.equal undefined

it 'pass additional parameters to matched patial function', ->
m = match(1)(
[1, (x,y,z)->
Expand Down
8 changes: 8 additions & 0 deletions test/misc.spec.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ describe('Miscellaneous useages', function() {
);
expect(m).to.be.equal('TEN');
});
it('statements value could be undefined', function() {
var m = match('undefined')(
[1, 'ONE'],
['undefined', undefined],
[2, 'TWO']
);
expect(m).to.be.equal(undefined);
});
it('pass additional parameters to matched patial function', function() {
var m = match(1)(
[1, function(x,y,z){
Expand Down
8 changes: 8 additions & 0 deletions test/misc.spec.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ describe('Miscellaneous useages', function () {
)
expect(m).to.be.equal('TEN');
});
it('statements value could be undefined', () => {
const m = match('undefined')(
[1, 'ONE'],
['undefined', undefined],
[2, 'TWO']
)
expect(m).to.be.equal(undefined)
});
it('pass additional parameters to matched patial function', () => {
const m = match(1)(
[1, (x,y,z)=>{
Expand Down

0 comments on commit 7e7a308

Please sign in to comment.