Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/compat): Handle TDZ correctly #8779

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8776/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"target": "es2021",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
6 changes: 6 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8776/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let capturedPrivateAccess;
class A {
static #x = 42;
static [(class {}, (capturedPrivateAccess = () => A.#x))];
}
console.log(capturedPrivateAccess());
13 changes: 13 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8776/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { _ as _class_static_private_field_spec_get } from "@swc/helpers/_/_class_static_private_field_spec_get";
import { _ as _define_property } from "@swc/helpers/_/_define_property";
let capturedPrivateAccess;
let _ref = (class {
}, capturedPrivateAccess = ()=>_class_static_private_field_spec_get(A, A, _x));
class A {
}
var _x = {
writable: true,
value: 42
};
_define_property(A, _ref, void 0);
console.log(capturedPrivateAccess());
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,47 @@ pub(super) struct ClassNameTdzFolder<'a> {
impl<'a> VisitMut for ClassNameTdzFolder<'a> {
noop_visit_mut_type!();

noop_visit_mut_type!(visit_mut_function, Function);

noop_visit_mut_type!(visit_mut_arrow_expr, ArrowExpr);

fn visit_mut_class_member(&mut self, n: &mut ClassMember) {
match n {
ClassMember::Method(ClassMethod {
key: PropName::Computed(computed),
..
})
| ClassMember::ClassProp(ClassProp {
key: PropName::Computed(computed),
..
}) => {
computed.visit_mut_with(self);
}
_ => {}
}
}

fn visit_mut_prop(&mut self, n: &mut Prop) {
match n {
Prop::KeyValue(..) => {
n.visit_mut_children_with(self);
}
Prop::Getter(GetterProp {
key: PropName::Computed(computed),
..
})
| Prop::Setter(SetterProp {
key: PropName::Computed(computed),
..
})
| Prop::Method(MethodProp {
key: PropName::Computed(computed),
..
}) => computed.visit_mut_children_with(self),
_ => {}
}
}

fn visit_mut_expr(&mut self, expr: &mut Expr) {
match expr {
Expr::Ident(i) => {
Expand Down
Loading