( type: "single" | "double" | "template", input: string, pos: number, lineStart: number, curLine: number, errors: StringContentsErrorHandlers, )
| 47 | }; |
| 48 | |
| 49 | export function readStringContents( |
| 50 | type: "single" | "double" | "template", |
| 51 | input: string, |
| 52 | pos: number, |
| 53 | lineStart: number, |
| 54 | curLine: number, |
| 55 | errors: StringContentsErrorHandlers, |
| 56 | ) { |
| 57 | const initialPos = pos; |
| 58 | const initialLineStart = lineStart; |
| 59 | const initialCurLine = curLine; |
| 60 | |
| 61 | let out = ""; |
| 62 | let firstInvalidLoc = null; |
| 63 | let chunkStart = pos; |
| 64 | const { length } = input; |
| 65 | for (;;) { |
| 66 | if (pos >= length) { |
| 67 | errors.unterminated(initialPos, initialLineStart, initialCurLine); |
| 68 | out += input.slice(chunkStart, pos); |
| 69 | break; |
| 70 | } |
| 71 | const ch = input.charCodeAt(pos); |
| 72 | if (isStringEnd(type, ch, input, pos)) { |
| 73 | out += input.slice(chunkStart, pos); |
| 74 | break; |
| 75 | } |
| 76 | if (ch === charCodes.backslash) { |
| 77 | out += input.slice(chunkStart, pos); |
| 78 | const res = readEscapedChar( |
| 79 | input, |
| 80 | pos, |
| 81 | lineStart, |
| 82 | curLine, |
| 83 | type === "template", |
| 84 | errors, |
| 85 | ); |
| 86 | if (res.ch === null && !firstInvalidLoc) { |
| 87 | firstInvalidLoc = { pos, lineStart, curLine }; |
| 88 | } else { |
| 89 | out += res.ch; |
| 90 | } |
| 91 | ({ pos, lineStart, curLine } = res); |
| 92 | chunkStart = pos; |
| 93 | } else if ( |
| 94 | ch === charCodes.lineSeparator || |
| 95 | ch === charCodes.paragraphSeparator |
| 96 | ) { |
| 97 | ++pos; |
| 98 | ++curLine; |
| 99 | lineStart = pos; |
| 100 | } else if (ch === charCodes.lineFeed || ch === charCodes.carriageReturn) { |
| 101 | if (type === "template") { |
| 102 | out += input.slice(chunkStart, pos) + "\n"; |
| 103 | ++pos; |
| 104 | if ( |
| 105 | ch === charCodes.carriageReturn && |
| 106 | input.charCodeAt(pos) === charCodes.lineFeed |
no test coverage detected