-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
Description
Copied from this Reddit conversation
I'd love to see support for interpolation of template literals in the compiled RegEx from the Babel plugin. For example, I can almost accomplish this with the Babel compiler using Melody's raw method:
// Original
new RegExp(/*melody*/ `
"foo";
\`\${bar}\`;
"baz";
`)
// Compiled
new RegExp("foo${bar}baz")It seems that this could be fixed just by wrapping the string output in backticks instead of quotes. I originally assumed this would have unintended consequences, but since $, {, and } are all special RegEx characters, they're automatically escaped in string literals. This protects us from misinterpreted literals:
// Original
new RegExp(/*melody*/ `
"foo";
"${bar}";
"baz";
`)
// Compiled
new RegExp("foo\$\{bar\}baz")I did come up with this while sleepy, sp=o it's entirely possible that I may be missing something. 🤔
schneiderfelipe