mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-13 04:30:16 +08:00
* 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
26 lines
656 B
TypeScript
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;
|
|
}
|