mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/compat): Insert the variable declaration nearest to the available statements (#7067)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/7064.
This commit is contained in:
parent
136c498c80
commit
ae348e32e1
12
crates/swc/tests/fixture/issues-7xxx/7064/case1/input/.swcrc
Normal file
12
crates/swc/tests/fixture/issues-7xxx/7064/case1/input/.swcrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true
|
||||
},
|
||||
"target": "es2020"
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
function method() {
|
||||
const obj = {};
|
||||
obj.prop ??= "x".repeat(10000000);
|
||||
}
|
||||
|
||||
method();
|
||||
// the large string should be eventually GCed along with the large string, but it will never happen in SWC+es2020
|
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
function method() {
|
||||
var _obj;
|
||||
const obj = {};
|
||||
(_obj = obj).prop ?? (_obj.prop = "x".repeat(10000000));
|
||||
}
|
||||
method(); // the large string should be eventually GCed along with the large string, but it will never happen in SWC+es2020
|
@ -174,12 +174,12 @@ impl VisitMut for Operators {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_module(&mut self, n: &mut Module) {
|
||||
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
if !self.vars.is_empty() {
|
||||
prepend_stmt(
|
||||
&mut n.body,
|
||||
n,
|
||||
VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
@ -191,12 +191,12 @@ impl VisitMut for Operators {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_script(&mut self, n: &mut Script) {
|
||||
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
if !self.vars.is_empty() {
|
||||
prepend_stmt(
|
||||
&mut n.body,
|
||||
n,
|
||||
VarDecl {
|
||||
span: DUMMY_SP,
|
||||
kind: VarDeclKind::Var,
|
||||
|
Loading…
Reference in New Issue
Block a user