Files
scriptc/tests/diagnostics/text-codec-value.ts
Chris Tate 52459a86d4 feat(compiler): lower stored text codec calls (#85)
* feat(compiler): lower stored text codec calls

- Lower same-scope const TextEncoder and TextDecoder call receivers without runtime instances.
- Preserve fences for escaping, captured, and imported codec values with actionable diagnostics.
- Add differential, diagnostic, and preflight baseline coverage for the supported idiom.

* fix(compiler): fence deferred text codec calls

* fix text codec switch-clause TDZ handling
2026-08-02 21:24:33 -05:00

26 lines
656 B
TypeScript

const encoder = new TextEncoder();
console.log(encoder);
function encodeCaptured(s: string): Uint8Array {
return sharedEncoder.encode(s);
}
const sharedEncoder = new TextEncoder();
console.log(encodeCaptured("x").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;
}