ReviewOS

also looking at this

stacks/dtsx

fix(inference): read every spelling of a number literal

#3121
Open mkantautas wants to merge fix/numeric-literal-spellings into main
3 files +141 -40
packages/dtsx/src/extractor/scanner.tsmodified+1-17
Changes to packages/dtsx/src/extractor/scanner.ts
@@ -5,7 +5,7 @@
55 */
66
77import type { Declaration } from '../types'
8import { inferFunctionBodyReturnType, inferNarrowType } from '../processor/type-inference'
8import { inferFunctionBodyReturnType, inferNarrowType, isNumericLiteral } from '../processor/type-inference'
99
1010// Character codes for fast comparison
1111const CH_SPACE = 32
@@ -1897,22 +1897,6 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
18971897 return `${name}${optionalMarker}: ${type}`
18981898 }
18991899
1900 /** Check if string is a numeric literal (integer or decimal, optionally negative) */
1901 function isNumericLiteral(v: string): boolean {
1902 let i = 0
1903 if (i < v.length && v.charCodeAt(i) === 45 /* - */) i++
1904 if (i >= v.length) return false
1905 const c = v.charCodeAt(i)
1906 if (c < 48 || c > 57) return false // not a digit
1907 while (i < v.length && v.charCodeAt(i) >= 48 && v.charCodeAt(i) <= 57) i++
1908 if (i < v.length && v.charCodeAt(i) === 46 /* . */) {
1909 i++
1910 if (i >= v.length || v.charCodeAt(i) < 48 || v.charCodeAt(i) > 57) return false
1911 while (i < v.length && v.charCodeAt(i) >= 48 && v.charCodeAt(i) <= 57) i++
1912 }
1913 return i === v.length
1914 }
1915
19161900 /** Infer type from a default value expression (simple cases) */
19171901 function inferTypeFromDefault(value: string): string {
19181902 const v = value.trim()