(source, start, open, close)
| 1051 | } |
| 1052 | |
| 1053 | function readBalanced(source, start, open, close) { |
| 1054 | let depth = 0; |
| 1055 | let textStart = start + 1; |
| 1056 | for (let index = start; index < source.length; index += 1) { |
| 1057 | const char = source[index]; |
| 1058 | if (char === '"' || char === "'") { |
| 1059 | index = skipQuoted(source, index); |
| 1060 | continue; |
| 1061 | } |
| 1062 | if (char === "/" && source[index + 1] === "/") { |
| 1063 | index = skipLineComment(source, index); |
| 1064 | continue; |
| 1065 | } |
| 1066 | if (char === "/" && source[index + 1] === "*") { |
| 1067 | index = skipBlockComment(source, index); |
| 1068 | continue; |
| 1069 | } |
| 1070 | if (char === open) { |
| 1071 | depth += 1; |
| 1072 | } else if (char === close) { |
| 1073 | depth -= 1; |
| 1074 | if (depth === 0) { |
| 1075 | return { end: index, text: source.slice(textStart, index) }; |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | throw new Error(`Unbalanced ${open}${close} block near offset ${start}.`); |
| 1080 | } |
| 1081 | |
| 1082 | function firstStringLiteral(text) { |
| 1083 | const match = text.match(/"((?:\\"|[^"])*)"/); |
no test coverage detected