next.js
c0d6a5d8 - Guard against Object/Array shadowing in 'use cache' transform (#88229)

Commit
54 days ago
Guard against Object/Array shadowing in 'use cache' transform (#88229) The transform output for 'use cache' uses `Object.defineProperty` and `Array.prototype.slice`. In theory, it's possible for a module to shadow those names and break it: ```ts // i want to suffer! const Array = {} const Object = {} async function cached() { "use cache" ... } ``` We should defensively make sure that our transform's output refers to the actual Object/Array builtins, not whatever's in scope for that name. We can do this by using an unresolved syntax context for the identifiers. This is what we do for `require()` elsewhere: https://github.com/vercel/next.js/blob/6805af48baf1128e6b2a9e8f1752ee5982f02c60/crates/next-custom-transforms/src/transforms/track_dynamic_imports.rs#L119-L122 Using `quote_ident!(unresolved_ctxt, "Array")` will cause SWC to rename any local redefinitions of `Array` to something that doesn't clash (which can be seen in the added snapshots).
Author
Parents
Loading