Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit a8b4424

Browse files
Unescape : during parsing; add tests for if/else escaping
1 parent ae5bc55 commit a8b4424

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/snippet-body.pegjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ escaped = '\\' char:. {
166166
switch (char) {
167167
case '$':
168168
case '\\':
169+
case ':':
169170
case '\x7D': // back brace; PEGjs would treat it as the JS scope end though
170171
return char
171172
default:

spec/body-parser-spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,55 @@ describe("Snippet Body Parser", () => {
361361
);
362362
});
363363

364+
it('recognizes escape characters in if/else syntax', () => {
365+
366+
expectMatch(
367+
'$1 ${1/(?:(wat)|^.*$)$/${1:?hey\\:hey:nah}/}',
368+
[
369+
{index: 1, content: []},
370+
" ",
371+
{
372+
index: 1,
373+
content: [],
374+
substitution: {
375+
find: /(?:(wat)|^.*$)$/,
376+
replace: [
377+
{
378+
backreference: 1,
379+
iftext: "hey:hey",
380+
elsetext: "nah"
381+
}
382+
],
383+
},
384+
},
385+
]
386+
);
387+
388+
expectMatch(
389+
'$1 ${1/(?:(wat)|^.*$)$/${1:?hey:n\\}ah}/}',
390+
[
391+
{index: 1, content: []},
392+
" ",
393+
{
394+
index: 1,
395+
content: [],
396+
substitution: {
397+
find: /(?:(wat)|^.*$)$/,
398+
replace: [
399+
{
400+
backreference: 1,
401+
iftext: "hey",
402+
elsetext: "n}ah"
403+
}
404+
],
405+
},
406+
},
407+
]
408+
);
409+
410+
});
411+
412+
364413
it('parses nested tabstops', () => {
365414
expectMatch(
366415
'${1:place${2:hol${3:der}}}',

0 commit comments

Comments
 (0)