diff --git a/src/createTag/createTag.js b/src/createTag/createTag.js index 01cc5d6..7f04b03 100644 --- a/src/createTag/createTag.js +++ b/src/createTag/createTag.js @@ -94,6 +94,12 @@ export default function createTag(...rawTransformers) { return tag([strings]); } + if (typeof strings[0] === 'undefined') { + throw TypeError(`input string is undefined: Check your template string. + (e.g. \\4 will throw SyntaxError with 'Octal escape sequences are not allowed') + `); + } + const tagCallInfo = getTagCallInfo(transformers); // if the first argument is an array, return a transformed end result of processing the template with our tag diff --git a/src/createTag/createTag.test.js b/src/createTag/createTag.test.js index 390140d..c812319 100644 --- a/src/createTag/createTag.test.js +++ b/src/createTag/createTag.test.js @@ -298,3 +298,16 @@ test('accepts other tags as arguments and applies them in order', () => { expect(superTag`foo`).toBe('foo1234'); }); + +test('invalid template string should throw error message', () => { + const getInitialContext = jest.fn(); + const tag = createTag({ getInitialContext }); + + let actual = () => { + tag`\4`; + }; + + expect(actual).toThrow( + `input string is undefined: Check your template string.`, + ); +});