Skip to content

Commit 5056017

Browse files
committed
test: tokenizer terminates on trailing backslash at end of source
1 parent cf7d76b commit 5056017

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/__tests__/__snapshots__/function-tokenizer.test.ts.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,53 @@ exports[`tokenizer includes equals token but skips value correctly 2`] = `
409409
},
410410
]
411411
`;
412+
413+
exports[`tokenizer terminates when an escape sequence dangles at the end 1`] = `
414+
[
415+
{
416+
"type": "function",
417+
},
418+
{
419+
"type": "ident",
420+
"value": "rofl",
421+
},
422+
{
423+
"type": "(",
424+
},
425+
{
426+
"type": "ident",
427+
"value": "p1",
428+
},
429+
{
430+
"type": "=",
431+
},
432+
{
433+
"type": "EOF",
434+
},
435+
]
436+
`;
437+
438+
exports[`tokenizer terminates when the last character is a backslash 1`] = `
439+
[
440+
{
441+
"type": "function",
442+
},
443+
{
444+
"type": "ident",
445+
"value": "rofl",
446+
},
447+
{
448+
"type": "(",
449+
},
450+
{
451+
"type": "ident",
452+
"value": "p1",
453+
},
454+
{
455+
"type": "=",
456+
},
457+
{
458+
"type": "EOF",
459+
},
460+
]
461+
`;

src/__tests__/function-tokenizer.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ describe('tokenizer', () => {
6363
).toMatchSnapshot()
6464
})
6565

66+
it('terminates when the last character is a backslash', () => {
67+
expect(getTokens(`function rofl(p1 = 'test\\`)).toMatchSnapshot()
68+
})
69+
70+
it('terminates when an escape sequence dangles at the end', () => {
71+
expect(getTokens(`function rofl(p1 = 'test\\\\`)).toMatchSnapshot()
72+
})
73+
6674
it('can skip interpolated strings', () => {
6775
expect(
6876
getTokens(`function intstring1(p1 = \`Hello \${world}\`, p2 = 123)`),

0 commit comments

Comments
 (0)