mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
chore: remove duplicate test and document constructability issue
- Remove duplicate ArrowToBindNoTransformWithCallArgs test (already covered by ArrowToBindNoTransformWithArgs) - Add constructability to the list of reasons the optimization is disabled (arrows are not constructable but bound functions may be) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,11 +162,14 @@ pub fn Visit(
|
||||
/// semantics in cases where:
|
||||
/// 1. The property (method) is reassigned after the arrow is created
|
||||
/// 2. The property is a getter that returns different values on each access
|
||||
/// 3. Constructability differs: arrows are not constructable but bound
|
||||
/// functions derived from regular methods may be
|
||||
///
|
||||
/// To safely enable this optimization, we would need to track:
|
||||
/// - Property assignments to the receiver object
|
||||
/// - Whether the property is defined as a getter
|
||||
/// - Whether the object escapes to code that could modify it
|
||||
/// - Whether the arrow could be used with `new`
|
||||
///
|
||||
/// For now, we conservatively disable the transformation entirely.
|
||||
pub fn tryMarkArrowForBindCallTransform(p: *P, arrow: *E.Arrow) void {
|
||||
|
||||
@@ -1476,26 +1476,6 @@ describe("bundler", () => {
|
||||
stdout: "42",
|
||||
},
|
||||
});
|
||||
itBundled("minify/ArrowToBindNoTransformWithCallArgs", {
|
||||
files: {
|
||||
"/entry.js": /* js */ `
|
||||
const obj = { greet(name) { return "Hello, " + name; } };
|
||||
// Arrow with call that has arguments - cannot transform
|
||||
const fn = () => obj.greet("World");
|
||||
console.log(fn());
|
||||
`,
|
||||
},
|
||||
minifySyntax: true,
|
||||
target: "bun",
|
||||
onAfterBundle(api) {
|
||||
const code = api.readFile("/out.js");
|
||||
// Should NOT transform because the call has arguments
|
||||
expect(code).not.toContain(".bind(");
|
||||
},
|
||||
run: {
|
||||
stdout: "Hello, World",
|
||||
},
|
||||
});
|
||||
itBundled("minify/ArrowToBindNoTransformArgumentsAccess", {
|
||||
files: {
|
||||
"/entry.js": /* js */ `
|
||||
|
||||
Reference in New Issue
Block a user