Skip to content

Commit e53ca56

Browse files
committed
fix: check undefined string and show how to correct
1 parent d3f7042 commit e53ca56

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/createTag/createTag.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ export default function createTag(...rawTransformers) {
9393
if (!Array.isArray(strings)) {
9494
return tag([strings]);
9595
}
96+
97+
if (typeof strings[0] === 'undefined') {
98+
throw TypeError(`input string is undefined: Check your template string.
99+
(e.g. \\4 will throw SyntaxError with 'Octal escape sequences are not allowed')
100+
`);
101+
}
96102

97103
const tagCallInfo = getTagCallInfo(transformers);
98104

src/createTag/createTag.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,16 @@ test('accepts other tags as arguments and applies them in order', () => {
298298

299299
expect(superTag`foo`).toBe('foo1234');
300300
});
301+
302+
test('invalid template string should throw error message', () => {
303+
const getInitialContext = jest.fn();
304+
const tag = createTag({ getInitialContext });
305+
306+
let actual = ()=> {
307+
tag`\4`;
308+
};
309+
310+
expect(actual).toThrow(
311+
`input string is undefined: Check your template string.`,
312+
);
313+
});

0 commit comments

Comments
 (0)