From e53ca567619c2f1b982f0ccb33eb302230ff1be5 Mon Sep 17 00:00:00 2001 From: seongwon-kang Date: Fri, 27 Nov 2020 07:01:09 +0000 Subject: [PATCH 1/2] fix: check undefined string and show how to correct --- src/createTag/createTag.js | 6 ++++++ src/createTag/createTag.test.js | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/createTag/createTag.js b/src/createTag/createTag.js index 01cc5d6..45dad8d 100644 --- a/src/createTag/createTag.js +++ b/src/createTag/createTag.js @@ -93,6 +93,12 @@ export default function createTag(...rawTransformers) { if (!Array.isArray(strings)) { 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); diff --git a/src/createTag/createTag.test.js b/src/createTag/createTag.test.js index 390140d..c2eba60 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.`, + ); +}); \ No newline at end of file From 60de0ac321e9e1db8a9689645b14f9e20c0707c1 Mon Sep 17 00:00:00 2001 From: seongwon-kang Date: Fri, 27 Nov 2020 07:05:12 +0000 Subject: [PATCH 2/2] Linting --- src/createTag/createTag.js | 2 +- src/createTag/createTag.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/createTag/createTag.js b/src/createTag/createTag.js index 45dad8d..7f04b03 100644 --- a/src/createTag/createTag.js +++ b/src/createTag/createTag.js @@ -93,7 +93,7 @@ export default function createTag(...rawTransformers) { if (!Array.isArray(strings)) { 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') diff --git a/src/createTag/createTag.test.js b/src/createTag/createTag.test.js index c2eba60..c812319 100644 --- a/src/createTag/createTag.test.js +++ b/src/createTag/createTag.test.js @@ -303,11 +303,11 @@ test('invalid template string should throw error message', () => { const getInitialContext = jest.fn(); const tag = createTag({ getInitialContext }); - let actual = ()=> { + let actual = () => { tag`\4`; }; expect(actual).toThrow( `input string is undefined: Check your template string.`, ); -}); \ No newline at end of file +});