Skip to content

Commit 1ac8d82

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

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/stripIndentTransformer/stripIndentTransformer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const stripIndentTransformer = (type = 'initial') => {
1212

1313
return {
1414
onEndResult(endResult) {
15+
if (typeof(endResult) === 'undefined') {
16+
throw TypeError(`input string is undefined: Check your template string.
17+
(e.g. \\4 will throw SyntaxError with 'Octal escape sequences are not allowed')
18+
`);
19+
}
1520
if (type === 'all') {
1621
// remove all indentation from each line
1722
return endResult.replace(/^[^\S\n]+/gm, '');

src/stripIndentTransformer/stripIndentTransformer.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,16 @@ test('throws an error if encounters invalid type', () => {
4848
stripIndentTransformer('blue');
4949
}).toThrow(/not supported/);
5050
});
51+
52+
test('invalid template string should throw error message with ', () => {
53+
const stripIndent = createTag(
54+
stripIndentTransformer(),
55+
trimResultTransformer('smart'),
56+
);
57+
58+
const actual = () => {
59+
stripIndent`
60+
\4
61+
`};
62+
expect(actual).toThrow(`input string is undefined: Check your template string.`);
63+
});

0 commit comments

Comments
 (0)