Skip to content

Commit

Permalink
fix: check undefined string and show how to correct
Browse files Browse the repository at this point in the history
  • Loading branch information
seongwon-kang committed Nov 27, 2020
1 parent d3f7042 commit e53ca56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/createTag/createTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions src/createTag/createTag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
});

0 comments on commit e53ca56

Please sign in to comment.