Skip to content

Commit

Permalink
fix(es/compat): Skip getter and setter as FlowHelper function do (
Browse files Browse the repository at this point in the history
#9580)

**Related issue:**

- Closes: #9579 
- #9161 (comment)
  • Loading branch information
magic-akari authored Sep 23, 2024
1 parent fc0ba2a commit 14cfd70
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/shy-eagles-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_compat_es2015: patch
swc_core: patch
---

fix(es/compat): Skip `getter` and `setter` as FlowHelper `function` do
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9579/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
21 changes: 21 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9579/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function expectA(a) {
console.log(a.b === 1)
}

export function test() {
// any loop
for (let i = 0; i < 1; i++) {
const a = {
get b() {
return 1
}
}
const c = 2
; () => {
// create any arrow function that references value in loop
c
}
// We expect a.b to be 1
expectA(a)
}
}
18 changes: 18 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9579/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function expectA(a) {
console.log(a.b === 1);
}
export function test() {
var _loop = function(i) {
var a = {
get b () {
return 1;
}
};
var c = 2;
(function() {
c;
});
expectA(a);
};
for(var i = 0; i < 1; i++)_loop(i);
}
6 changes: 6 additions & 0 deletions crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ impl VisitMut for FlowHelper<'_> {
/// noop
fn visit_mut_function(&mut self, _f: &mut Function) {}

/// noop
fn visit_mut_getter_prop(&mut self, _f: &mut GetterProp) {}

/// noop
fn visit_mut_setter_prop(&mut self, _f: &mut SetterProp) {}

fn visit_mut_labeled_stmt(&mut self, l: &mut LabeledStmt) {
self.inner_label.insert(l.label.sym.clone());

Expand Down

0 comments on commit 14cfd70

Please sign in to comment.