Skip to content

Commit cf96171

Browse files
authoredSep 29, 2023
fix(es/typescript): Preserve default value of an exported binding in a namespace (#8029)
**Related issue:** - Closes: #8025
1 parent d35de64 commit cf96171

37 files changed

+138
-127
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
22
export var Test;
33
(function(Test) {
4-
var content = Test.content = /*#__PURE__*/ React.createElement("div", null, "Content");
4+
Test.content = /*#__PURE__*/ React.createElement("div", null, "Content");
55
})(Test || (Test = {}));
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var A;
22
(function(A) {
3-
var Foo = A.Foo = function() {
3+
A.Foo = function() {
44
return /*#__PURE__*/ React.createElement("div", null);
55
};
66
})(A || (A = {}));

‎crates/swc/tests/fixture/issues-2xxx/2423/output/index.map

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mappings": ";;UAAUA;IACC,MAAMC,MAAAA,IAAI;IACV,SAASC;QACZC,QAAQC,GAAG,CAACH;IAChB;MAFgBC,IAAAA;AAGpB,GALUF,MAAAA",
2+
"mappings": ";;UAAUA;MACOC,IAAI;IACV,SAASC;QACZC,QAAQC,GAAG,GAACH;IAChB;MAFgBC,IAAAA;AAGpB,GALUF,MAAAA",
33
"names": [
44
"A",
55
"v",
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22
var A;
33
(function(A) {
4-
const v = A.v = 25;
4+
A.v = 25;
55
function a() {
6-
console.log(v);
6+
console.log(A.v);
77
}
88
A.a = a;
99
})(A || (A = {}));
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export var RuleInterpreterHelper;
22
(function(RuleInterpreterHelper) {
3-
var fieldNameMap = RuleInterpreterHelper.fieldNameMap = [];
4-
var fieldNameHashMap = RuleInterpreterHelper.fieldNameHashMap = new Map(fieldNameMap);
3+
RuleInterpreterHelper.fieldNameMap = [];
4+
RuleInterpreterHelper.fieldNameHashMap = new Map(RuleInterpreterHelper.fieldNameMap);
55
})(RuleInterpreterHelper || (RuleInterpreterHelper = {}));
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var n;
22
(function(n) {
33
var ref;
4-
var a = (ref = {
4+
ref = {
55
a: 1
6-
}, n.a = ref.a, ref).a;
6+
}, n.a = ref.a, ref;
77
})(n || (n = {}));
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var Foo;
22
(function(Foo) {
33
var ref;
4-
var _ref = (ref = {
4+
ref = {
55
a: 1,
66
b: 2
7-
}, Foo.A = ref.a, Foo.B = ref.b, ref), A = _ref.a, B = _ref.b;
7+
}, Foo.A = ref.a, Foo.B = ref.b, ref;
88
})(Foo || (Foo = {}));
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var foo;
22
(function(foo) {
3-
var bar = foo.bar = 0;
3+
foo.bar = 0;
44
})(foo || (foo = {}));
55
export { foo };

‎crates/swc/tests/fixture/issues-4xxx/4897/output/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ define([
2222
}
2323
var Foo;
2424
(function(Foo) {
25-
const Bar = Foo.Bar = 1234;
25+
Foo.Bar = 1234;
2626
})(Foo || (Foo = {}));
2727
});

‎crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedImportAlias.1.normal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var B;
1212
})(B || (B = {}));
1313
var Geometry;
1414
(function(Geometry) {
15-
var Points = Geometry.Points = A;
15+
Geometry.Points = A;
1616
var Lines = B;
1717
Geometry.Origin = {
1818
x: 0,

‎crates/swc/tests/tsc-references/circularImportAlias.1.normal.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import { _ as _inherits } from "@swc/helpers/_/_inherits";
55
import { _ as _create_super } from "@swc/helpers/_/_create_super";
66
var B;
77
(function(B) {
8-
var a = B.a = A;
9-
var D = /*#__PURE__*/ function(_a_C) {
8+
B.a = A;
9+
var D = /*#__PURE__*/ function(_B_a_C) {
1010
"use strict";
11-
_inherits(D, _a_C);
11+
_inherits(D, _B_a_C);
1212
var _super = _create_super(D);
1313
function D() {
1414
_class_call_check(this, D);
1515
return _super.apply(this, arguments);
1616
}
1717
return D;
18-
}(a.C);
18+
}(B.a.C);
1919
B.D = D;
2020
})(B || (B = {}));
2121
var A;
@@ -25,7 +25,7 @@ var A;
2525
_class_call_check(this, C);
2626
};
2727
A.C = C;
28-
var b = A.b = B;
28+
A.b = B;
2929
})(A || (A = {}));
3030
var c;
3131
var c = new B.a.C();

‎crates/swc/tests/tsc-references/circularImportAlias.2.minified.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ var B, A, B1, D, A1;
44
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
55
import { _ as _inherits } from "@swc/helpers/_/_inherits";
66
import { _ as _create_super } from "@swc/helpers/_/_create_super";
7-
D = function(_a_C) {
8-
_inherits(D, _a_C);
7+
(B1 = B || (B = {})).a = A, D = function(_B_a_C) {
8+
_inherits(D, _B_a_C);
99
var _super = _create_super(D);
1010
function D() {
1111
return _class_call_check(this, D), _super.apply(this, arguments);
1212
}
1313
return D;
14-
}(((B1 = B || (B = {})).a = A).C), B1.D = D, (A1 = A || (A = {})).C = function C() {
14+
}(B1.a.C), B1.D = D, (A1 = A || (A = {})).C = function C() {
1515
_class_call_check(this, C);
1616
}, A1.b = B, new B.a.C();

‎crates/swc/tests/tsc-references/es6modulekindWithES5Target12.1.normal.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export var C = function C() {
55
_class_call_check(this, C);
66
};
77
(function(C) {
8-
var x = C.x = 1;
8+
C.x = 1;
99
})(C || (C = {}));
1010
export var E;
1111
(function(E) {
@@ -15,16 +15,16 @@ export var E;
1515
E[E["x"] = 2] = "x";
1616
})(E || (E = {}));
1717
(function(E) {
18-
var y = E.y = 1;
18+
E.y = 1;
1919
})(E || (E = {}));
2020
(function(E) {
21-
var z = E.z = 1;
21+
E.z = 1;
2222
})(E || (E = {}));
2323
export var N;
2424
(function(N) {
25-
var x = N.x = 1;
25+
N.x = 1;
2626
})(N || (N = {}));
2727
export function F() {}
2828
(function(F) {
29-
var x = F.x = 1;
29+
F.x = 1;
3030
})(F || (F = {}));

‎crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12.1.normal.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export var C = function C() {
55
_class_call_check(this, C);
66
};
77
(function(C) {
8-
var x = C.x = 1;
8+
C.x = 1;
99
})(C || (C = {}));
1010
export var E;
1111
(function(E) {
@@ -15,16 +15,16 @@ export var E;
1515
E[E["x"] = 2] = "x";
1616
})(E || (E = {}));
1717
(function(E) {
18-
var y = E.y = 1;
18+
E.y = 1;
1919
})(E || (E = {}));
2020
(function(E) {
21-
var z = E.z = 1;
21+
E.z = 1;
2222
})(E || (E = {}));
2323
export var N;
2424
(function(N) {
25-
var x = N.x = 1;
25+
N.x = 1;
2626
})(N || (N = {}));
2727
export function F() {}
2828
(function(F) {
29-
var x = F.x = 1;
29+
F.x = 1;
3030
})(F || (F = {}));

‎crates/swc/tests/tsc-references/exportImportAlias.1.normal.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var A;
1414
})(A || (A = {}));
1515
var C;
1616
(function(C) {
17-
var a = C.a = A;
17+
C.a = A;
1818
})(C || (C = {}));
1919
var a = C.a.x;
2020
var b = new C.a.Point(0, 0);
@@ -38,7 +38,8 @@ var X;
3838
})(X || (X = {}));
3939
var Z;
4040
(function(Z) {
41-
var y = Z.y = X.Y;
41+
// 'y' should be a fundule here
42+
Z.y = X.Y;
4243
})(Z || (Z = {}));
4344
var m = Z.y();
4445
var n = new Z.y.Point(0, 0);
@@ -56,7 +57,7 @@ var K;
5657
})(K || (K = {}));
5758
var M;
5859
(function(M) {
59-
var D = M.D = K.L;
60+
M.D = K.L;
6061
})(M || (M = {}));
6162
var o;
6263
var o = new M.D("Hello");

‎crates/swc/tests/tsc-references/filterNamespace_import.1.normal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var ns;
77
_class_call_check(this, Class);
88
};
99
ns.Class = Class;
10-
var Value = ns.Value = "";
10+
ns.Value = "";
1111
var nested;
1212
(function(nested) {
1313
var NestedClass = function NestedClass() {

‎crates/swc/tests/tsc-references/typeOnlyMerge3.1.normal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export { };
44
//// [b.ts]
55
var A;
66
(function(A) {
7-
var displayName = A.displayName = "A";
7+
A.displayName = "A";
88
})(A || (A = {}));
99
export { A };
1010
//// [c.ts]

‎crates/swc/tests/tsc-references/valuesMergingAcrossModules.1.normal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { A } from "./a";
66
//// [c.ts]
77
var A;
88
(function(A) {
9-
var displayName = A.displayName = "A";
9+
A.displayName = "A";
1010
})(A || (A = {}));
1111
A();
1212
A.displayName;

‎crates/swc/tests/tsc-references/verbatimModuleSyntaxInternalImportEquals.1.normal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { };
33
var f1 = NonExistent;
44
var Foo;
55
(function(Foo) {
6-
var foo = Foo.foo = 1;
6+
Foo.foo = 1;
77
})(Foo || (Foo = {}));
88
var f2 = Foo.foo;
99
var f3 = Foo.T;

‎crates/swc/tests/tsc-references/verbatimModuleSyntaxNoElisionCJS.1.normal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const I = require("./a");
1313
"use strict";
1414
var I;
1515
(function(I) {
16-
const x = I.x = 1;
16+
I.x = 1;
1717
})(I || (I = {}));
1818
module.exports = I;
1919
//// [/d.ts]

‎crates/swc/tests/tsc-references/verbatimModuleSyntaxRestrictionsCJS.1.normal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./
3939
const x = 1; // error
4040
var Values;
4141
(function(Values) {
42-
const x = Values.x = 1;
42+
Values.x = 1;
4343
})(Values || (Values = {}));
4444
// sketchy, but ok
4545
//// [/main2.ts]
@@ -51,7 +51,7 @@ module.exports = {
5151
"use strict";
5252
var ns;
5353
(function(ns) {
54-
const x = ns.x = 1;
54+
ns.x = 1;
5555
})(ns || (ns = {}));
5656
module.exports = ns;
5757
//// [/main4.ts]

‎crates/swc_ecma_transforms_typescript/src/transform.rs

+38-41
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,8 @@ impl Transform {
578578
}
579579

580580
/// Note:
581-
/// Const exported declarations are transformed into immutable bindings.
582-
/// `export` from `export let` / ` export var` will be stripped,
583-
/// and a mutable binding will be transformed into assignment to the
584-
/// namespace. All references to the mutable binding will be replaced with
581+
/// All exported variable declarations are transformed into assignment to the
582+
/// namespace. All references to the exported binding will be replaced with
585583
/// qualified access to the namespace property.
586584
///
587585
/// Exported function and class will be treat as const exported which is in
@@ -592,7 +590,7 @@ impl Transform {
592590
///
593591
/// Input:
594592
/// ```TypeScript
595-
/// export const foo = init, { bar: baz } = init;
593+
/// export const foo = init, { bar: baz = init } = init;
596594
///
597595
/// export function a() {}
598596
///
@@ -601,7 +599,7 @@ impl Transform {
601599
///
602600
/// Output:
603601
/// ```TypeScript
604-
/// const foo = NS.foo = init, { bar: baz } = { bar: NS.baz } = init;
602+
/// NS.foo = init, { bar: NS.baz = init } = init;
605603
///
606604
/// function a() {}
607605
/// NS.a = a;
@@ -640,18 +638,14 @@ impl Transform {
640638
) -> Option<Stmt> {
641639
debug_assert!(!var_decl.declare);
642640

643-
var_decl.decls.iter_mut().for_each(|var_declarator| {
644-
Self::assign_init_to_ns_id(var_declarator, id);
645-
});
646-
647-
if var_decl.kind == VarDeclKind::Const {
648-
return Some(var_decl.into());
649-
}
650-
651641
let mut collector = ExportedIdentCollector::default();
652642
var_decl.visit_with(&mut collector);
653643
mutable_export_ids.extend(collector.export_list);
654644

645+
var_decl.decls.visit_mut_with(&mut ExportedPatRewriter {
646+
id: id.clone().into(),
647+
});
648+
655649
let mut expr_list: Vec<Box<Expr>> =
656650
var_decl.decls.into_iter().filter_map(|d| d.init).collect();
657651

@@ -672,31 +666,6 @@ impl Transform {
672666

673667
Some(Stmt::Expr(ExprStmt { span, expr }))
674668
}
675-
676-
/// Input:
677-
/// ```TypeScript
678-
/// const foo = init;
679-
/// ```
680-
/// Output:
681-
/// ```TypeScript
682-
/// const foo = NS.foo = init;
683-
/// ```
684-
fn assign_init_to_ns_id(var_declarator: &mut VarDeclarator, id: &Id) {
685-
let Some(right) = var_declarator.init.take() else {
686-
return;
687-
};
688-
689-
let mut left = var_declarator.name.clone();
690-
left.visit_mut_with(&mut ExportedPatRewriter {
691-
id: id.clone().into(),
692-
});
693-
694-
var_declarator.init = Some(
695-
right
696-
.make_assign_to(op!("="), PatOrExpr::Pat(left.into()))
697-
.into(),
698-
);
699-
}
700669
}
701670

702671
impl Transform {
@@ -1135,6 +1104,21 @@ struct ExportedPatRewriter {
11351104
impl VisitMut for ExportedPatRewriter {
11361105
noop_visit_mut_type!();
11371106

1107+
fn visit_mut_var_declarator(&mut self, n: &mut VarDeclarator) {
1108+
let Some(right) = n.init.take() else {
1109+
return;
1110+
};
1111+
1112+
let mut left = n.name.take();
1113+
left.visit_mut_with(self);
1114+
1115+
n.init = Some(
1116+
right
1117+
.make_assign_to(op!("="), PatOrExpr::Pat(left.into()))
1118+
.into(),
1119+
);
1120+
}
1121+
11381122
fn visit_mut_pat(&mut self, n: &mut Pat) {
11391123
if let Pat::Ident(BindingIdent { id, .. }) = n {
11401124
*n = Pat::Expr(Box::new(self.id.clone().make_member(id.take())));
@@ -1145,10 +1129,23 @@ impl VisitMut for ExportedPatRewriter {
11451129
}
11461130

11471131
fn visit_mut_object_pat_prop(&mut self, n: &mut ObjectPatProp) {
1148-
if let ObjectPatProp::Assign(AssignPatProp { key, .. }) = n {
1132+
if let ObjectPatProp::Assign(AssignPatProp { key, value, .. }) = n {
1133+
let left = Box::new(Pat::Expr(self.id.clone().make_member(key.clone()).into()));
1134+
1135+
let value = if let Some(right) = value.take() {
1136+
Pat::Assign(AssignPat {
1137+
span: DUMMY_SP,
1138+
left,
1139+
right,
1140+
})
1141+
.into()
1142+
} else {
1143+
left
1144+
};
1145+
11491146
*n = ObjectPatProp::KeyValue(KeyValuePatProp {
11501147
key: PropName::Ident(key.clone()),
1151-
value: Box::new(Pat::Expr(self.id.clone().make_member(key.clone()).into())),
1148+
value,
11521149
});
11531150
return;
11541151
}

‎crates/swc_ecma_transforms_typescript/tests/fixture/issue-1653/output.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ var X;
22
(function(X) {
33
let Z;
44
(function(Z) {
5-
const foo = Z.foo = 0;
5+
Z.foo = 0;
66
})(Z = X.Z || (X.Z = {}));
77
})(X || (X = {}));
88
var Y;
99
(function(Y) {
1010
let Z;
1111
(function(Z) {
12-
const bar = Z.bar = 1;
12+
Z.bar = 1;
1313
})(Z = Y.Z || (Y.Z = {}));
1414
})(Y || (Y = {}));

‎crates/swc_ecma_transforms_typescript/tests/fixture/issue-2243/output.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function Colors(member) {
22
return Colors.ValueFor(member);
33
}
44
(function(Colors) {
5-
const ValueMap = Colors.ValueMap = {
5+
Colors.ValueMap = {
66
Red: {
77
value: 0.0,
88
label: "Red"
@@ -16,17 +16,17 @@ export function Colors(member) {
1616
label: "Green"
1717
}
1818
};
19-
const Values = Colors.Values = [
19+
Colors.Values = [
2020
0.0,
2121
1.0,
2222
2.0
2323
];
2424
function ValueFor(member) {
25-
return ValueMap[member]?.value;
25+
return Colors.ValueMap[member]?.value;
2626
}
2727
Colors.ValueFor = ValueFor;
2828
async function LabelFor(member) {
29-
return ValueMap[member]?.label;
29+
return Colors.ValueMap[member]?.label;
3030
}
3131
Colors.LabelFor = LabelFor;
3232
})(Colors || (Colors = {}));
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export var TEST;
22
(function(TEST) {
3-
const VALUE = TEST.VALUE = "value";
3+
TEST.VALUE = "value";
44
})(TEST || (TEST = {}));
55
export default TEST;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export var TEST;
22
(function(TEST) {
3-
const VAL1 = TEST.VAL1 = "value1";
4-
const VAL2 = TEST.VAL2 = `${VAL1}_value2`;
3+
TEST.VAL1 = "value1";
4+
TEST.VAL2 = `${TEST.VAL1}_value2`;
55
})(TEST || (TEST = {}));
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var Foo;
22
(function(Foo) {
3-
const { a } = { a: Foo.a } = {
3+
({ a: Foo.a } = {
44
a: 1
5-
};
5+
});
66
})(Foo || (Foo = {}));
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var Bar;
22
(function(Bar) {
3-
const { a, b } = { a: Bar.a, b: Bar.b } = {
3+
({ a: Bar.a, b: Bar.b } = {
44
a: 1,
55
b: 2
6-
};
6+
});
77
})(Bar || (Bar = {}));

‎crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var Baz;
22
(function(Baz) {
3-
const baz = Baz.baz = {
3+
Baz.baz = {
44
a: 1,
55
b: 2
66
};

‎crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/output.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ var A;
22
(function(A) {
33
const a = 1;
44
const b = 2;
5-
const { a: A1 } = { a: A.A } = {
5+
({ a: A.A } = {
66
a
7-
};
8-
const { b: B } = { b: A.B } = {
7+
});
8+
({ b: A.B } = {
99
b
10-
};
10+
});
1111
})(A || (A = {}));
1212
(function(A) {
1313
const c = 3;
1414
const d = 4;
15-
const { c: C } = { c: A.C } = {
15+
({ c: A.C } = {
1616
c: c
17-
};
18-
const { d: D } = { d: A.D } = {
17+
});
18+
({ d: A.D } = {
1919
d: d
20-
};
20+
});
2121
})(A || (A = {}));
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var Foo;
22
(function(Foo) {
3-
const bar = Foo.bar = 42;
4-
const foo = Foo.foo = function() {
3+
Foo.bar = 42;
4+
Foo.foo = function() {
55
return 20;
66
};
77
function xyz() {
8-
return foo() * bar;
8+
return Foo.foo() * Foo.bar;
99
}
1010
Foo.xyz = xyz;
1111
})(Foo || (Foo = {}));

‎crates/swc_ecma_transforms_typescript/tests/fixture/issue-3158/2/output.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var Test;
44
return 10;
55
}
66
Test.abc = abc;
7-
const foo = Test.foo = function() {
7+
Test.foo = function() {
88
return 20;
99
};
1010
function xyz() {
11-
return abc() * foo();
11+
return abc() * Test.foo();
1212
}
1313
Test.xyz = xyz;
1414
})(Test || (Test = {}));
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var foo;
22
(function(foo) {
3-
const bar = foo.bar = 0;
3+
foo.bar = 0;
44
})(foo || (foo = {}));
55
export { foo };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as I from "./ABC";
22
export var IE;
33
(function(IE) {
4-
const A = IE.A = I.A;
5-
const C = IE.C = I.C;
6-
const D = IE.D = I.D;
4+
IE.A = I.A;
5+
IE.C = I.C;
6+
IE.D = I.D;
77
})(IE || (IE = {}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Foo {
2+
export let { a = 1 } = {};
3+
export const { b = 2 } = {};
4+
export const [c = 3, { d = 4 } = {}] = [];
5+
6+
console.log("inner", a, b, c, d);
7+
}
8+
9+
console.log("outer", Foo.a, Foo.b, Foo.c, Foo.d);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Foo;
2+
(function(Foo) {
3+
({ a: Foo.a = 1 } = {});
4+
({ b: Foo.b = 2 } = {});
5+
[Foo.c = 3, { d: Foo.d = 4 } = {}] = [];
6+
console.log("inner", Foo.a, Foo.b, Foo.c, Foo.d);
7+
})(Foo || (Foo = {}));
8+
console.log("outer", Foo.a, Foo.b, Foo.c, Foo.d);

‎crates/swc_ecma_transforms_typescript/tests/strip.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -3365,14 +3365,10 @@ to!(
33653365
throw new Error();
33663366
}
33673367
util.assertNever = assertNever;
3368-
const arrayToEnum = util.arrayToEnum = (items)=>{
3369-
};
3370-
const getValidEnumValues = util.getValidEnumValues = (obj)=>{
3371-
};
3372-
const getValues = util.getValues = (obj)=>{
3373-
};
3374-
const objectValues = util.objectValues = (obj)=>{
3375-
};
3368+
util.arrayToEnum = (items)=>{};
3369+
util.getValidEnumValues = (obj)=>{};
3370+
util.getValues = (obj)=>{};
3371+
util.objectValues = (obj)=>{};
33763372
})(util || (util = {}));
33773373
"
33783374
);
@@ -3389,7 +3385,7 @@ to!(
33893385
export var util;
33903386
(function (util) {
33913387
const c = 3;
3392-
const [a, b] = [util.a, util.b] = [1, 2, 3];
3388+
[util.a, util.b] = [1, 2, 3];
33933389
})(util || (util = {}));
33943390
"
33953391
);
@@ -3435,7 +3431,7 @@ to!(
34353431
var Test;
34363432
(function (Test) {
34373433
(function (Inner) {
3438-
const c = Inner.c = 3;
3434+
Inner.c = 3;
34393435
})(Test.Inner || (Test.Inner = {}));
34403436
})(Test || (Test = {}));
34413437
"
@@ -3490,7 +3486,7 @@ to!(
34903486
})(MyEnum = MyNamespace.MyEnum || (MyNamespace.MyEnum = {}));
34913487
let MyInnerNamespace;
34923488
(function (MyInnerNamespace) {
3493-
const Dec2 = MyInnerNamespace.Dec2 = 2;
3489+
MyInnerNamespace.Dec2 = 2;
34943490
})(MyInnerNamespace = MyNamespace.MyInnerNamespace || (MyNamespace.MyInnerNamespace = {}));
34953491
})(MyNamespace || (MyNamespace = {}));
34963492
(function (MyNamespace) {
@@ -3524,8 +3520,8 @@ to!(
35243520
})(A || (A = {}));
35253521
var B;
35263522
(function (B) {
3527-
const a = B.a = A;
3528-
console.log(a.Test);
3523+
B.a = A;
3524+
console.log(B.a.Test);
35293525
const b = A;
35303526
console.log(b.Test);
35313527
})(B || (B = {}));

1 commit comments

Comments
 (1)

github-actions[bot] commented on Sep 29, 2023

@github-actions[bot]

Benchmark

Benchmark suite Current: cf96171 Previous: 8214b9e Ratio
es/full/bugs-1 276721 ns/iter (± 6210) 275102 ns/iter (± 2583) 1.01
es/full/minify/libraries/antd 1285832357 ns/iter (± 12153756) 1318521059 ns/iter (± 15535694) 0.98
es/full/minify/libraries/d3 270680100 ns/iter (± 3067727) 273599669 ns/iter (± 7159486) 0.99
es/full/minify/libraries/echarts 1034147287 ns/iter (± 4018881) 1045250218 ns/iter (± 9958916) 0.99
es/full/minify/libraries/jquery 83346969 ns/iter (± 109023) 83977148 ns/iter (± 329319) 0.99
es/full/minify/libraries/lodash 96544472 ns/iter (± 188095) 97436571 ns/iter (± 157526) 0.99
es/full/minify/libraries/moment 49280804 ns/iter (± 115809) 49720752 ns/iter (± 357443) 0.99
es/full/minify/libraries/react 17882682 ns/iter (± 80684) 18005136 ns/iter (± 92710) 0.99
es/full/minify/libraries/terser 214825610 ns/iter (± 1737310) 216751277 ns/iter (± 583051) 0.99
es/full/minify/libraries/three 380392231 ns/iter (± 1724691) 384344625 ns/iter (± 1901744) 0.99
es/full/minify/libraries/typescript 2581755264 ns/iter (± 18434478) 2645353468 ns/iter (± 10687292) 0.98
es/full/minify/libraries/victory 565202909 ns/iter (± 5042799) 567467876 ns/iter (± 4184440) 1.00
es/full/minify/libraries/vue 117959671 ns/iter (± 168678) 119417047 ns/iter (± 2683822) 0.99
es/full/codegen/es3 34115 ns/iter (± 139) 34329 ns/iter (± 141) 0.99
es/full/codegen/es5 33998 ns/iter (± 105) 34275 ns/iter (± 140) 0.99
es/full/codegen/es2015 34119 ns/iter (± 103) 34362 ns/iter (± 65) 0.99
es/full/codegen/es2016 34020 ns/iter (± 117) 34254 ns/iter (± 122) 0.99
es/full/codegen/es2017 33987 ns/iter (± 183) 34247 ns/iter (± 82) 0.99
es/full/codegen/es2018 34061 ns/iter (± 166) 34364 ns/iter (± 157) 0.99
es/full/codegen/es2019 33954 ns/iter (± 154) 34283 ns/iter (± 129) 0.99
es/full/codegen/es2020 34095 ns/iter (± 140) 34308 ns/iter (± 99) 0.99
es/full/all/es3 163536715 ns/iter (± 848902) 165651725 ns/iter (± 710876) 0.99
es/full/all/es5 156870098 ns/iter (± 1035393) 158321742 ns/iter (± 1141284) 0.99
es/full/all/es2015 116050191 ns/iter (± 650928) 118194302 ns/iter (± 1816704) 0.98
es/full/all/es2016 115686831 ns/iter (± 796787) 117275947 ns/iter (± 600779) 0.99
es/full/all/es2017 114922968 ns/iter (± 1153785) 115455982 ns/iter (± 681033) 1.00
es/full/all/es2018 113076497 ns/iter (± 699821) 113896739 ns/iter (± 519485) 0.99
es/full/all/es2019 112606016 ns/iter (± 785839) 113517013 ns/iter (± 1355946) 0.99
es/full/all/es2020 107782843 ns/iter (± 543518) 109968865 ns/iter (± 720229) 0.98
es/full/parser 482436 ns/iter (± 5552) 494442 ns/iter (± 4356) 0.98
es/full/base/fixer 17875 ns/iter (± 105) 21039 ns/iter (± 230) 0.85
es/full/base/resolver_and_hygiene 80623 ns/iter (± 421) 81898 ns/iter (± 115) 0.98
serialization of serde 284 ns/iter (± 3) 287 ns/iter (± 0) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.