-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tagged template literal invocation syntax (fixes #3)
- Loading branch information
Showing
6 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// @flow | ||
|
||
export {default as mapTaggedTemplateLiteralInvocation} from './mapTaggedTemplateLiteralInvocation'; | ||
export {default as normalizeAnonymousValuePlaceholders} from './normalizeAnonymousValuePlaceholders'; | ||
export {default as normalizeNamedValuePlaceholders} from './normalizeNamedValuePlaceholders'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @flow | ||
|
||
// eslint-disable-next-line flowtype/no-weak-types | ||
export default (targetMethod: Function) => { | ||
// eslint-disable-next-line flowtype/no-weak-types | ||
return (maybeQuery: string | Array<string>, ...args: any) => { | ||
if (typeof maybeQuery === 'string') { | ||
return targetMethod(maybeQuery, args[0]); | ||
} else { | ||
const strings = maybeQuery; | ||
|
||
return targetMethod(strings.join('?'), args); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// @flow | ||
|
||
import test from 'ava'; | ||
import sinon from 'sinon'; | ||
import { | ||
mapTaggedTemplateLiteralInvocation | ||
} from '../../src/utilities'; | ||
|
||
test('works with regular invocation', (t) => { | ||
const spy = sinon.spy(); | ||
|
||
const method = mapTaggedTemplateLiteralInvocation(spy); | ||
|
||
method('query', 'parameters'); | ||
|
||
t.true(spy.calledWith('query', 'parameters')); | ||
}); | ||
|
||
test('works with tagged template literals', (t) => { | ||
const spy = sinon.spy(); | ||
|
||
const method = mapTaggedTemplateLiteralInvocation(spy); | ||
|
||
const bar = 'BAR'; | ||
|
||
method`foo${bar}baz`; | ||
|
||
t.true(spy.calledWith('foo?baz', ['BAR'])); | ||
}); |