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<'_> {
let prop_value = match prop {
// TODO avoid clone
MemberProp::Ident(i) => Box::new(i.sym.clone().into()),
MemberProp::PrivateName(_) => {
return;
}
MemberProp::PrivateName(_) => Box::new(JsValue::unknown_empty(
false,
"private names in member expressions are not supported",
)),
MemberProp::Computed(ComputedPropName { expr, .. }) => {
Box::new(self.eval_context.eval(expr))
}
......
[
ImportedBinding {
esm_reference_index: 3,
export: Some(
"useMemo",
),
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Decl,
),
Decl(
Var,
),
VarDecl(
Decls(
0,
),
),
VarDeclarator(
Init,
),
Expr(
Call,
),
CallExpr(
Callee,
),
Callee(
Expr,
),
Expr(
Ident,
),
],
span: 268..275,
in_try: false,
},
Call {
func: Member(
3,
Module(
ModuleValue {
module: "react",
annotations: ImportAnnotations {
map: {},
},
},
),
Constant(
Str(
Atom(
"useMemo",
),
),
),
),
args: [
Closure(
Variable(
(
"*arrow function 276*",
#0,
),
),
EffectsBlock {
effects: [
Call {
func: Variable(
(
"HelloWorld",
#2,
),
),
args: [],
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Decl,
),
Decl(
Var,
),
VarDecl(
Decls(
0,
),
),
VarDeclarator(
Init,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
Expr,
),
Expr(
New,
),
],
span: 280..296,
in_try: false,
new: true,
},
],
range: Exact(
[
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Decl,
),
Decl(
Var,
),
VarDecl(
Decls(
0,
),
),
VarDeclarator(
Init,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
Expr,
),
],
),
},
),
Value(
Array {
total_nodes: 1,
items: [],
mutable: true,
},
),
],
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Decl,
),
Decl(
Var,
),
VarDecl(
Decls(
0,
),
),
VarDeclarator(
Init,
),
Expr(
Call,
),
],
span: 268..301,
in_try: false,
new: false,
},
ImportedBinding {
esm_reference_index: 1,
export: Some(
"jsx",
),
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
1,
),
),
Stmt(
Return,
),
ReturnStmt(
Arg,
),
Expr(
Call,
),
CallExpr(
Callee,
),
Callee(
Expr,
),
Expr(
Ident,
),
],
span: 328..332,
in_try: false,
},
Member {
obj: Variable(
(
"helloWorld",
#3,
),
),
prop: Constant(
Str(
Atom(
"hi",
),
),
),
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
1,
),
),
Stmt(
Return,
),
ReturnStmt(
Arg,
),
Expr(
Call,
),
CallExpr(
Args(
1,
),
),
ExprOrSpread(
Expr,
),
Expr(
Object,
),
ObjectLit(
Props(
0,
),
),
PropOrSpread(
Prop,
),
Prop(
KeyValue,
),
KeyValueProp(
Value,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
Expr,
),
Expr(
Call,
),
CallExpr(
Callee,
),
Callee(
Expr,
),
Expr(
Member,
),
],
span: 366..379,
in_try: false,
},
MemberCall {
obj: Variable(
(
"helloWorld",
#3,
),
),
prop: Constant(
Str(
Atom(
"hi",
),
),
),
args: [],
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
1,
),
),
Stmt(
Return,
),
ReturnStmt(
Arg,
),
Expr(
Call,
),
CallExpr(
Args(
1,
),
),
ExprOrSpread(
Expr,
),
Expr(
Object,
),
ObjectLit(
Props(
0,
),
),
PropOrSpread(
Prop,
),
Prop(
KeyValue,
),
KeyValueProp(
Value,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
Expr,
),
Expr(
Call,
),
],
span: 366..381,
in_try: false,
new: false,
},
Call {
func: Member(
3,
Module(
ModuleValue {
module: "https://esm.sh/preact/jsx-runtime",
annotations: ImportAnnotations {
map: {},
},
},
),
Constant(
Str(
Atom(
"jsx",
),
),
),
),
args: [
Value(
Constant(
Str(
Atom(
"button",
),
),
),
),
Value(
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,
},
),
],
ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
1,
),
),
Stmt(
Return,
),
ReturnStmt(
Arg,
),
Expr(
Call,
),
],
span: 328..418,
in_try: false,
new: false,
},
Unreachable {
start_ast_path: [
Program(
Module,
),
Module(
Body(
4,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDefaultDecl,
),
ExportDefaultDecl(
Decl,
),
DefaultDecl(
Fn,
),
FnExpr(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
1,
),
),
Stmt(
Return,
),
],
},
MemberCall {
obj: Unknown {
original_value: None,
reason: "unsupported expression",
has_side_effects: true,
},
prop: Unknown {
original_value: None,
reason: "private names in member expressions are not supported",
has_side_effects: false,
},
args: [
Closure(
Variable(
(
"*arrow function 471*",
#0,
),
),
EffectsBlock {
effects: [
FreeVar {
var: FreeVar(
"alert",
),
ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
0,
),
),
ClassMember(
Method,
),
ClassMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
BlockStmt,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Callee,
),
Callee(
Expr,
),
Expr(
Ident,
),
],
span: 489..494,
in_try: false,
},
ImportedBinding {
esm_reference_index: 5,
export: Some(
"fooBar",
),
ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
0,
),
),
ClassMember(
Method,
),
ClassMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
BlockStmt,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Call,
),
CallExpr(
Callee,
),
Callee(
Expr,
),
Expr(
Ident,
),
],
span: 495..501,
in_try: false,
},
Call {
func: Member(
3,
Module(
ModuleValue {
module: "./external",
annotations: ImportAnnotations {
map: {},
},
},
),
Constant(
Str(
Atom(
"fooBar",
),
),
),
),
args: [],
ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
0,
),
),
ClassMember(
Method,
),
ClassMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
BlockStmt,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Call,
),
],
span: 495..503,
in_try: false,
new: false,
},
Call {
func: FreeVar(
"alert",
),
args: [
Value(
Call(
4,
Member(
3,
Module(
ModuleValue {
module: "./external",
annotations: ImportAnnotations {
map: {},
},
},
),
Constant(
Str(
Atom(
"fooBar",
),
),
),
),
[],
),
),
],
ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
0,
),
),
ClassMember(
Method,
),
ClassMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
BlockStmt,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
],
span: 489..504,
in_try: false,
new: false,
},
],
range: Exact(
[
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
0,
),
),
ClassMember(
Method,
),
ClassMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
CallExpr(
Args(
0,
),
),
ExprOrSpread(
Expr,
),
Expr(
Arrow,
),
ArrowExpr(
Body,
),
BlockStmtOrExpr(
BlockStmt,
),
],
),
},
),
],
ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
0,
),
),
ClassMember(
Method,
),
ClassMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
],
span: 460..516,
in_try: false,
new: false,
},
Call {
func: Variable(
(
"cb",
#6,
),
),
args: [],
ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
1,
),
),
ClassMember(
PrivateMethod,
),
PrivateMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Return,
),
ReturnStmt(
Arg,
),
Expr(
Call,
),
],
span: 555..559,
in_try: false,
new: false,
},
Unreachable {
start_ast_path: [
Program(
Module,
),
Module(
Body(
5,
),
),
ModuleItem(
Stmt,
),
Stmt(
Decl,
),
Decl(
Class,
),
ClassDecl(
Class,
),
Class(
Body(
1,
),
),
ClassMember(
PrivateMethod,
),
PrivateMethod(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Return,
),
],
},
]
*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