{"ScriptPreparationCode":"const illegalChars = new Map\r\nillegalChars.set(\u0027\\\\\u0027, \u0027\\\\\\\\\u0027)\r\nillegalChars.set(\u0027\u0060\u0027, \u0027\\\\\u0060\u0027)\r\nillegalChars.set(\u0027$\u0027, \u0027\\\\$\u0027)\r\n\r\nfunction escapeTaggedTemplate1(s) {\r\n if (!s) return \u0027\u0060\u0060\u0027\r\n\r\n let res = \u0027\u0027\r\n for (let i = 0, l = s.length; i \u003C l; \u002B\u002Bi) {\r\n const c = s.charAt(i)\r\n res \u002B= illegalChars.get(c) || c\r\n }\r\n return \u0060\\\u0060${res}\\\u0060\u0060;\r\n}\r\n\r\nfunction escapeTaggedTemplate2(source) {\r\n return source\r\n .replaceAll(\u0027\\\\\u0027, \u0027\\\\\\\\\u0027)\r\n .replaceAll(\u0027\u0060\u0027, \u0027\\\\\u0060\u0027)\r\n .replaceAll(\u0027$\u0027, \u0027\\\\$\u0027);\r\n}\r\n","TestCases":[{"Name":"Adding characters up","Code":"escapeTaggedTemplate1(\u0027\u0027)\r\nescapeTaggedTemplate1(\u0027this is a string which does not need to be escaped\u0027)\r\nescapeTaggedTemplate1(\u0027\\\\this\\\\ \u0060string\u0060 \u0060has to\u0060 $be$ \\\\escaped\\\\ \u0060at\u0060 \\\\the\\\\ $end$\u0027)","IsDeferred":false},{"Name":"Replacing special characters","Code":"escapeTaggedTemplate2(\u0027\u0027)\r\nescapeTaggedTemplate2(\u0027this is a string which does not need to be escaped\u0027)\r\nescapeTaggedTemplate2(\u0027\\\\this\\\\ \u0060string\u0060 \u0060has to\u0060 $be$ \\\\escaped\\\\ \u0060at\u0060 \\\\the\\\\ $end$\u0027)","IsDeferred":false}]}