opencode/packages/codemode-rust/conformance/cases/lang-delete.js
kommander 03066b4ba3 fix(codemode): delete, arguments, await names and iterator errors match the reference
- delete: optional and parenthesized targets delete; an identifier fails when it runs; built-in constants and prototypes refuse; a function's name and length can be deleted; strings and nullish bases get the reference's errors; tool references refuse.
- arguments: delete leaves a hole, length is a hidden writable property, the binding can be reassigned, and iterating it reads its enumerable own values.
- await is a plain name at the top level unless an expression starts with it, and an escaped await is a label.
- A named function expression's own name is bound before its parameters, so their defaults see it read-only.
- Iterators that break the protocol get the reference's errors everywhere they are opened, stepped or closed, including async yield* over a non-iterable.
- Promise.all, allSettled, any and race reject when their input is not iterable or iterating it fails.
- An accessor in an object literal fails when the literal runs, and export is a parse error, as in the reference.

Drops 77 files from rust-skipped.txt.
2026-11-18 18:56:10 +01:00

38 lines
1.5 KiB
JavaScript

// delete: what may be deleted, what refuses, and with which errors.
const attempt = (f) => {
try {
return f()
} catch (error) {
return String(error)
}
}
const o = { a: { b: 1 }, c: 2 }
return {
plain: [delete o.c, "c" in o, delete o.missing],
optional: [delete o?.a.b, o.a, delete o.x?.y, delete undefined?.a],
parenthesized: [delete (o.a), "a" in o],
identifier: attempt(() => {
let q = 1
return delete q
}),
global: attempt(() => delete NaN),
other: [delete 1, delete String(1)],
constants: [attempt(() => delete Math.PI), attempt(() => delete Number.MAX_VALUE), attempt(() => delete Array.prototype)],
configurable: attempt(() => [delete Math.max, typeof Math.max]),
frozen: [attempt(() => delete Object.freeze({ a: 1 }).a), attempt(() => delete Object.seal([1])[0])],
arrayLength: attempt(() => delete [].length),
strings: [attempt(() => delete "abc".length), attempt(() => delete "abc"[0]), delete "abc"[9], delete "abc".foo],
primitives: [delete (5).x, attempt(() => delete null.a)],
bytes: [attempt(() => delete new Uint8Array(2)[0]), delete new Uint8Array(2)[5]],
functionKeys: (() => {
function g(a, b) {}
const before = [g.name, g.length]
const deleted = [delete g.name, delete g.length]
return [before, deleted, g.name, g.length, g.hasOwnProperty("length"), "length" in g]
})(),
nativeKeys: (() => {
const f = Math.min
return [delete f.name, delete f.length, f.name, f.length]
})(),
tools: attempt(() => delete tools.echo),
}