Files
scriptc/tests/diagnostics/text-codec-value.ts
Chris Tate be1426a5cb feat(compiler): advance static OpenTUI support
- Extend native FFI with additional scalar widths and writable byte spans.
- Compile stored text codecs and supported bundled module patterns without a JavaScript engine.
- Document supported limits.
2026-09-27 21:49:40 -05:00

43 lines
1.2 KiB
TypeScript

const encoder = new TextEncoder();
console.log(encoder);
function encodeCaptured(s: string): Uint8Array {
return sharedEncoder.encode(s);
}
const decoder = new TextDecoder();
decoder.decode(new Uint8Array([0xc3]), { stream: true });
new TextDecoder("utf-8", { fatal: true });
encoder.encodeInto("hello", new Uint8Array(10));
const forged = JSON.parse("{}") as TextDecoder;
console.log(forged.decode());
const sharedEncoder = new TextEncoder();
console.log(encodeCaptured("x").length);
// A module var's pre-initialization value is not a codec instance.
var varEncoder = new TextEncoder();
let uninitializedDecoder: TextDecoder;
function earlyVarCapture(): Uint8Array {
const use = () => localEncoder.encode("x");
const bytes = use();
var localEncoder = new TextEncoder();
return bytes;
}
console.log(earlyVarCapture().length);
let codecCase = 1;
switch (codecCase) {
case 0:
const caseEncoder = new TextEncoder();
break;
case 1:
const Encoded = class {
bytes = caseEncoder.encode("should fence");
};
console.log(new Encoded().bytes.length);
break;
case 2:
// @ts-expect-error -- dispatch can enter here while caseEncoder is in its TDZ
console.log(caseEncoder.encode("should fence directly").length);
break;
}