mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
string-width's `character.codePointAt(0)`, camelcase's `string.toLocaleLowerCase(locale)`, toml's `input.substr(...)` and pretty-bytes' `number.toPrecision(3)` threw "x.y is not a function": the dynamic method dispatch had no answer for these names on strings and numbers. A checked-dynamic receiver calling a String or Number method the runtime dispatch cannot answer (codePointAt, substr, toLocaleLowerCase, toLocaleUpperCase, isWellFormed, toWellFormed, trimLeft, trimRight, toPrecision, toExponential(digits)) now evaluates the receiver and arguments once and dispatches on the runtime kind: a string or number runs the typed lowering, every other kind keeps the runtime dispatch's answer. Names other dyn kinds share (at, concat, slice) and the Annex B HTML names chalk-style builders define (bold, link, ...) keep their existing dispatch. Typed receivers gain substr, the locale case pair, the HTML methods, toPrecision and toExponential(fractionDigits), all previously compile-time refusals. toPrecision/toExponential digits come from exact big-integer arithmetic over the double (ties up on the exact binary value). Locale case mapping follows V8: the first requested locale decides, Turkic dotted/dotless I is implemented, and Lithuanian, Greek uppercasing, objects and malformed tags throw a 'not supported yet' Error. A checker-untyped JS binding holding `string | undefined` boxes into the dyn receiver path for String methods (string-width's baseVisible result). tests/diagnostics/retired-engine-1112-number-methods.ts compiles now and moves back to tests/corpus/1112-number-methods.ts. New runtime functions are reached only from the new lowerings; the existing runtime objects' sections are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
792 B
TypeScript
16 lines
792 B
TypeScript
// The island-backed ambient surface (number methods and Number statics)
|
|
// typechecks against real static types but executes in the embedded
|
|
// engine: in a static build every use site is its own SC2012 naming the
|
|
// flag — never an ICE, never a link error. Static Math methods include
|
|
// the scalar functions and variadic Math.hypot. The .split(string),
|
|
// trim/pad variants, parseInt, isNaN, the global parseFloat/isFinite and
|
|
// Number.parseFloat/Number.parseInt over exactly-typed arguments,
|
|
// string-pattern replacement and toPrecision compile statically now and no
|
|
// longer appear here; toLocaleString without a locale still has no
|
|
// lowering.)
|
|
const up = Math.cbrt(2);
|
|
const tau = Math.PI * 2;
|
|
const price = (19.99).toLocaleString();
|
|
const n = Number.parseFloat("3.14");
|
|
void n;
|