Unverified Commit c6ab3d53 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

fix(turbopack): Fix analysis of private properties (#76654)

### What?

Still look for effects even if a private property exists.

### Why?

It's valid ECMAScript input.

### How?

Closes https://github.com/vercel/next.js/issues/75938
parent 0b699b1c
...@@ -1141,9 +1141,10 @@ impl Analyzer<'_> { ...@@ -1141,9 +1141,10 @@ impl Analyzer<'_> {
let prop_value = match prop { let prop_value = match prop {
// TODO avoid clone // TODO avoid clone
MemberProp::Ident(i) => Box::new(i.sym.clone().into()), MemberProp::Ident(i) => Box::new(i.sym.clone().into()),
MemberProp::PrivateName(_) => { MemberProp::PrivateName(_) => Box::new(JsValue::unknown_empty(
return; false,
} "private names in member expressions are not supported",
)),
MemberProp::Computed(ComputedPropName { expr, .. }) => { MemberProp::Computed(ComputedPropName { expr, .. }) => {
Box::new(self.eval_context.eval(expr)) Box::new(self.eval_context.eval(expr))
} }
......
*arrow function 276* = (...) => new HelloWorld()
*arrow function 362* = (...) => helloWorld["hi"]()
*arrow function 471* = (...) => undefined
HelloWorld = ???*0*
- *0* unsupported expression
⚠️ This value might have side effects
Home = (...) => module<https://esm.sh/preact/jsx-runtime, {}>["jsx"](
"button",
{"onClick": *arrow function 362*, "children": "Click me"}
)
cb = arguments[0]
helloWorld = module<react, {}>["useMemo"](*arrow function 276*, [])
[
(
"*arrow function 276*",
Function(
3,
276,
New(
2,
Variable(
(
"HelloWorld",
#2,
),
),
[],
),
),
),
(
"*arrow function 362*",
Function(
4,
362,
MemberCall(
3,
Variable(
(
"helloWorld",
#3,
),
),
Constant(
Str(
Atom(
"hi",
),
),
),
[],
),
),
),
(
"*arrow function 471*",
Function(
2,
471,
Constant(
Undefined,
),
),
),
(
"HelloWorld",
Unknown {
original_value: None,
reason: "unsupported expression",
has_side_effects: true,
},
),
(
"Home",
Function(
11,
227,
Call(
10,
Member(
3,
Module(
ModuleValue {
module: "https://esm.sh/preact/jsx-runtime",
annotations: ImportAnnotations {
map: {},
},
},
),
Constant(
Str(
Atom(
"jsx",
),
),
),
),
[
Constant(
Str(
Atom(
"button",
),
),
),
Object {
total_nodes: 5,
parts: [
KeyValue(
Constant(
Str(
Atom(
"onClick",
),
),
),
Variable(
(
"*arrow function 362*",
#0,
),
),
),
KeyValue(
Constant(
Str(
Atom(
"children",
),
),
),
Constant(
Str(
Atom(
"Click me",
),
),
),
),
],
mutable: true,
},
],
),
),
),
(
"cb",
Argument(
0,
0,
),
),
(
"helloWorld",
Call(
6,
Member(
3,
Module(
ModuleValue {
module: "react",
annotations: ImportAnnotations {
map: {},
},
},
),
Constant(
Str(
Atom(
"useMemo",
),
),
),
),
[
Variable(
(
"*arrow function 276*",
#0,
),
),
Array {
total_nodes: 1,
items: [],
mutable: true,
},
],
),
),
]
"use client";
import { jsx as _jsx } from "https://esm.sh/preact/jsx-runtime";
import { useMemo } from "react";
import { fooBar } from "./external";
/** Add your relevant code here for the issue to reproduce */ export default function Home() {
const helloWorld = useMemo(()=>new HelloWorld(), []);
return /*#__PURE__*/ _jsx("button", {
onClick: ()=>helloWorld.hi(),
children: "Click me"
});
}
class HelloWorld {
hi() {
this.#wrap(()=>{
alert(fooBar());
});
}
#wrap(cb) {
return cb();
}
}
0 -> 2 call = module<react, {}>["useMemo"]((...) => new HelloWorld(), [])
2 -> 3 call = new ???*0*()
- *0* unsupported expression
⚠️ This value might have side effects
0 -> 6 member call = module<react, {}>["useMemo"]((...) => ???*0*, [])["hi"]()
- *0* new HelloWorld()
⚠️ nested operation
0 -> 7 call = module<https://esm.sh/preact/jsx-runtime, {}>["jsx"](
"button",
{"onClick": (...) => helloWorld["hi"](), "children": "Click me"}
)
0 -> 8 unreachable = ???*0*
- *0* unreachable
⚠️ This value might have side effects
0 -> 9 member call = ???*0*[???*1*]((...) => undefined)
- *0* unsupported expression
⚠️ This value might have side effects
- *1* private names in member expressions are not supported
9 -> 10 free var = FreeVar(alert)
9 -> 12 call = module<./external, {}>["fooBar"]()
9 -> 13 call = ???*0*(module<./external, {}>["fooBar"]())
- *0* FreeVar(alert)
⚠️ unknown global
⚠️ This value might have side effects
0 -> 14 call = ???*0*()
- *0* arguments[0]
⚠️ function calls are not analysed yet
0 -> 15 unreachable = ???*0*
- *0* unreachable
⚠️ This value might have side effects
*arrow function 276* = (...) => new HelloWorld()
*arrow function 362* = (...) => helloWorld["hi"]()
*arrow function 471* = (...) => undefined
HelloWorld = ???*0*
- *0* unsupported expression
⚠️ This value might have side effects
Home = (...) => module<https://esm.sh/preact/jsx-runtime, {}>["jsx"](
"button",
{"onClick": *arrow function 362*, "children": "Click me"}
)
cb = ???*0*
- *0* arguments[0]
⚠️ function calls are not analysed yet
helloWorld = module<react, {}>["useMemo"]((...) => ???*0*, [])
- *0* new HelloWorld()
⚠️ nested operation
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment