Skip to content

Commit 14cfd70

Browse files
authored
fix(es/compat): Skip getter and setter as FlowHelper function do (#9580)
**Related issue:** - Closes: #9579 - #9161 (comment)
1 parent fc0ba2a commit 14cfd70

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

Diff for: .changeset/shy-eagles-shake.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_compat_es2015: patch
3+
swc_core: patch
4+
---
5+
6+
fix(es/compat): Skip `getter` and `setter` as FlowHelper `function` do
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": true
6+
},
7+
"target": "es5",
8+
"loose": false,
9+
"minify": {
10+
"compress": false,
11+
"mangle": false
12+
}
13+
},
14+
"module": {
15+
"type": "es6"
16+
},
17+
"minify": false,
18+
"isModule": true
19+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function expectA(a) {
2+
console.log(a.b === 1)
3+
}
4+
5+
export function test() {
6+
// any loop
7+
for (let i = 0; i < 1; i++) {
8+
const a = {
9+
get b() {
10+
return 1
11+
}
12+
}
13+
const c = 2
14+
; () => {
15+
// create any arrow function that references value in loop
16+
c
17+
}
18+
// We expect a.b to be 1
19+
expectA(a)
20+
}
21+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function expectA(a) {
2+
console.log(a.b === 1);
3+
}
4+
export function test() {
5+
var _loop = function(i) {
6+
var a = {
7+
get b () {
8+
return 1;
9+
}
10+
};
11+
var c = 2;
12+
(function() {
13+
c;
14+
});
15+
expectA(a);
16+
};
17+
for(var i = 0; i < 1; i++)_loop(i);
18+
}

Diff for: crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,12 @@ impl VisitMut for FlowHelper<'_> {
750750
/// noop
751751
fn visit_mut_function(&mut self, _f: &mut Function) {}
752752

753+
/// noop
754+
fn visit_mut_getter_prop(&mut self, _f: &mut GetterProp) {}
755+
756+
/// noop
757+
fn visit_mut_setter_prop(&mut self, _f: &mut SetterProp) {}
758+
753759
fn visit_mut_labeled_stmt(&mut self, l: &mut LabeledStmt) {
754760
self.inner_label.insert(l.label.sym.clone());
755761

0 commit comments

Comments
 (0)