Skip to content

fix(codemode): coerce any value to a property key - #50479

Merged
rekram1-node merged 1 commit into
v2from
property-key
Sep 22, 2026
Merged

rekram1-node merged 1 commit into
v2from
property-key

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator
const counts = {}
for (const row of rows) counts[row.category] = (counts[row.category] ?? 0) + 1
before   TypeError: Property key must be a string or number, or Symbol.asyncIterator/Symbol.iterator.
         (the moment one row has category: null)
after    { electronics: 12, null: 3 }

ToPropertyKey: a key that is not already a string, number, or one of the two confined symbols becomes its string form, as in JS. o[null] is o["null"], o[true] is o["true"], o[{}] is o["[object Object]"], o[[1, 2]] is o["1,2"]. Applies to reads, writes, compound assignment, object literals, in, and computed destructuring keys — they all go through the one toPropertyKey.

-  private toPropertyKey(value: Value, node: AstNode): PropertyKey {
-    if (typeof value === "string" || typeof value === "number") return value
-    if (value === AsyncIteratorSymbol || value === IteratorSymbol) return value
-    throw typeError("Property key must be a string or number, or …", node)
+  private toPropertyKey(value: Value): PropertyKey {
+    if (typeof value === "string" || typeof value === "number" || typeof value === "symbol") return value
+    return coerceToString(value)
   }

coerceToString is the existing built-in-aware one (Date → ISO string, Promise → [object Promise]); a program object's own toString is not consulted yet — that is the ToPrimitive PR.

Tests

suite before after
codemode 5294 5294 (one test rewritten)
test262 3990 / 403 3997 / 396

Seven skipped.txt entries removed (Array/prototype/{every,filter,forEach,map,reduce,reduceRight,some} tests that index with an object key).

@rekram1-node
rekram1-node merged commit 651529d into v2 Sep 22, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the property-key branch September 22, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant