mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-04 01:18:49 +08:00
* feat: support static non-UTF-8 TextDecoder labels - Recognize static WHATWG labels and aliases during builtin lowering. - Add feature-gated portable decoders generated against the pinned Node runtime. - Cover legacy encodings, malformed input, and unsupported dynamic labels. * fix: match Node legacy decoder recovery * fix TextDecoder edge-case parity * fix(runtime): match Node malformed text decoding * fix TextDecoder recovery edge cases
21 lines
815 B
TypeScript
21 lines
815 B
TypeScript
const bytes = new Uint8Array([0x41]);
|
|
|
|
const runtimeLabel: string = process.argv[2] ?? "utf-8";
|
|
console.log(new TextDecoder(runtimeLabel).decode(bytes));
|
|
|
|
// WHATWG's replacement labels deliberately fail TextDecoder construction.
|
|
console.log(new TextDecoder("replacement").decode(bytes));
|
|
|
|
// Vertical tab is not WHATWG ASCII whitespace and must not be trimmed.
|
|
console.log(new TextDecoder("\vutf-8").decode(bytes));
|
|
|
|
// A literal-typed variable read is still runtime constructor evaluation. Do
|
|
// not drop its TDZ behavior after selecting the static decoder id.
|
|
function forwardLabelRead(): void {
|
|
// @ts-expect-error Deliberately retain the runtime TDZ shape.
|
|
console.log(new TextDecoder(forwardLabel).decode(bytes));
|
|
const forwardLabel = "windows-1252" as const;
|
|
void forwardLabel;
|
|
}
|
|
forwardLabelRead();
|