()
| 971 | // 7.8.4 String Literals |
| 972 | |
| 973 | function scanStringLiteral() { |
| 974 | var str = '', quote, start, ch, code, unescaped, octal = false; |
| 975 | |
| 976 | quote = source[index]; |
| 977 | assert((quote === '\'' || quote === '"'), |
| 978 | 'String literal must starts with a quote'); |
| 979 | |
| 980 | start = index; |
| 981 | ++index; |
| 982 | |
| 983 | while (index < length) { |
| 984 | ch = source[index++]; |
| 985 | |
| 986 | if (ch === quote) { |
| 987 | quote = ''; |
| 988 | break; |
| 989 | } else if (ch === '\\') { |
| 990 | ch = source[index++]; |
| 991 | if (!ch || !isLineTerminator(ch.charCodeAt(0))) { |
| 992 | switch (ch) { |
| 993 | case 'u': |
| 994 | case 'x': |
| 995 | if (source[index] === '{') { |
| 996 | ++index; |
| 997 | str += scanUnicodeCodePointEscape(); |
| 998 | } else { |
| 999 | unescaped = scanHexEscape(ch); |
| 1000 | if (!unescaped) { |
| 1001 | throw throwUnexpectedToken(); |
| 1002 | } |
| 1003 | str += unescaped; |
| 1004 | } |
| 1005 | break; |
| 1006 | case 'n': |
| 1007 | str += '\n'; |
| 1008 | break; |
| 1009 | case 'r': |
| 1010 | str += '\r'; |
| 1011 | break; |
| 1012 | case 't': |
| 1013 | str += '\t'; |
| 1014 | break; |
| 1015 | case 'b': |
| 1016 | str += '\b'; |
| 1017 | break; |
| 1018 | case 'f': |
| 1019 | str += '\f'; |
| 1020 | break; |
| 1021 | case 'v': |
| 1022 | str += '\x0B'; |
| 1023 | break; |
| 1024 | case '8': |
| 1025 | case '9': |
| 1026 | throw throwUnexpectedToken(); |
| 1027 | |
| 1028 | default: |
| 1029 | if (isOctalDigit(ch)) { |
| 1030 | code = '01234567'.indexOf(ch); |
no test coverage detected