| 263 | if (typeof num === 'number') return num; |
| 264 | const val = Number(num); |
| 265 | if (num[0] === '+') num = num.slice(1); |
| 266 | if (val.toString() === num) { |
| 267 | // If the number roundtrips, it can be represented by a |
| 268 | // JavaScript number |
| 269 | // However, NaN and Infinity cannot be represented by JSON |
| 270 | if (isNaN(val)) return 'NaN'; |
| 271 | if (!isFinite(val) && val < 0) return 'NegativeInfinity'; |
| 272 | if (!isFinite(val) && val > 0) return 'PositiveInfinity'; |
| 273 | return val; |
| 274 | } |
| 275 | return { num }; |
| 276 | } |
| 277 | |
| 278 | function strip(expr: Expression): Expression | null { |
| 279 | if (typeof expr === 'number') return expr; |
| 280 | if (typeof expr === 'string') { |
| 281 | if (expr[0] === "'" && expr[expr.length - 1] === "'") { |
| 282 | return { str: expr.slice(1, -1) }; |