You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a template literal with a regular expression that contains an odd number of quotes is highlighted, the last quote is treated as beginning a string and extends until closing it, at which point you still need to close the placeholder and the template literal itself.
I am testing with the javascript, but the same goes for the typescript grammar.
I am not using the language detection.
Here is some example code to test this on:
`${/"/}`doStuff()// "}`
I expected the quote to not open a string at all, and just be treated as part of the regular expression.
Here's the code this was found in (TypeScript):
constor=(fns: readonly(()=>string)[])=>{for(constfnoffns){try{returnfn();}catch{continue;}}thrownewError("or failed");};function*many(fn: ()=>string){while(code.length){try{yieldfn();}catch(_){break;}}}constoptional=(chr: string)=>t(newRegExp(`^\\${chr}?`))||chr;constt=(re: RegExp)=>{code=code.slice(code.search(/[^ ]/));constmatch=code.match(re)![0];// throws if no matchcode=code.slice(match.length);returnmatch;};constchain=()=>or([triad,dyad,monad,infix]);constarr=()=>t(/^\[/)+[...many(()=>expr()+optional(","))].join("")+optional("]");constnum=()=>`new $N(${Number(t(/^[+-]?(?:\d*\.\d+|\d+)/))})`;conststr=()=>`new $S(${t(/^"(?:\\.|[^"])*"/)})`;constchr=()=>`new $S('${t(/^'./)[1]}')`;constnme=()=>t(/^[A-Z]/);constarr=()=>t(/^\[/)+[...many(()=>expr()+optional(","))].join("")+optional("]");constnilad=()=>or([arr,num,str,chr,nme]);consttriad=()=>`.${t(/^[a-z][\u0324:]/)[0]}(${arg()},${arg()})`;constdyad=()=>`.${t(/^[a-z][\u0323\.]/)[0]}(${arg()})`;constmonad=()=>`.${t(/^[a-z]/)}()`;constinfix=()=>t(/^[+\-*/]/)+arg();constchain=()=>or([triad,dyad,monad,infix]);functionarg(): string{constz=()=>or([nilad,()=>"X"+chain()]);constp=()=>t(/^\(/)+expr()+optional(")");returnor([p,z]);}functionexpr(){returnarg()+[...many(chain)].join("");}
The text was updated successfully, but these errors were encountered:
Regex is really hard to deal with without a full context-aware parser. I'll leave this open a bit to see if anyone wants to try and tackle this - and solve BOTH issues... but eventually if no one shows up we'll auto-close it a cant-fix.
If a template literal with a regular expression that contains an odd number of quotes is highlighted, the last quote is treated as beginning a string and extends until closing it, at which point you still need to close the placeholder and the template literal itself.
I am testing with the
javascript
, but the same goes for thetypescript
grammar.I am not using the language detection.
Here is some example code to test this on:
I expected the quote to not open a string at all, and just be treated as part of the regular expression.
Here's the code this was found in (TypeScript):
The text was updated successfully, but these errors were encountered: