* Create strict violation syntax error matching native error. * * @param {string} str * @param {string} char * @return {Error} * @private
(str, char)
| 154 | */ |
| 155 | |
| 156 | function createStrictSyntaxError (str, char) { |
| 157 | var index = str.indexOf(char) |
| 158 | var partial = '' |
| 159 | |
| 160 | if (index !== -1) { |
| 161 | partial = str.substring(0, index) + JSON_SYNTAX_CHAR |
| 162 | |
| 163 | for (var i = index + 1; i < str.length; i++) { |
| 164 | partial += JSON_SYNTAX_CHAR |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | try { |
| 169 | JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation') |
| 170 | } catch (e) { |
| 171 | return normalizeJsonSyntaxError(e, { |
| 172 | message: e.message.replace(JSON_SYNTAX_REGEXP, function (placeholder) { |
| 173 | return str.substring(index, index + placeholder.length) |
| 174 | }), |
| 175 | stack: e.stack |
| 176 | }) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Get the first non-whitespace character in a string. |
no test coverage detected