-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fakeTag.mjs
35 lines (31 loc) · 888 Bytes
/
fakeTag.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// @ts-check
/**
* A fake template literal tag that doesn’t do anything except return the tagged
* template string. Import and use the fake tag with the required name, e.g.
* `gql`.
* @param {TemplateStringsArray} literals The template literal’s text segments.
* @param {...unknown} expressions The template literal’s embedded expressions.
* @returns {string} The tagged template string.
* @example
* Tagging a [GraphQL](https://graphql.org) SDL string with `gql`:
*
* ```js
* import gql from "fake-tag";
*
* const typeDefs = gql`
* "A foo."
* type Foo {
* "The \`Foo\` ID."
* id: ID!
* }
* `;
* ```
*/
export default function fakeTag(literals, ...expressions) {
let string = "";
for (const [index, literal] of literals.entries()) {
string += literal;
if (index in expressions) string += expressions[index];
}
return string;
}