Skip to content

Commit

Permalink
fix(es/typescript): Preserve default value of an exported binding in …
Browse files Browse the repository at this point in the history
…a namespace (#8029)

**Related issue:**

 - Closes: #8025
  • Loading branch information
magic-akari authored Sep 29, 2023
1 parent d35de64 commit cf96171
Show file tree
Hide file tree
Showing 37 changed files with 138 additions and 127 deletions.
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-2xxx/2214/output/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
export var Test;
(function(Test) {
var content = Test.content = /*#__PURE__*/ React.createElement("div", null, "Content");
Test.content = /*#__PURE__*/ React.createElement("div", null, "Content");
})(Test || (Test = {}));
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-2xxx/2310/output/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var A;
(function(A) {
var Foo = A.Foo = function() {
A.Foo = function() {
return /*#__PURE__*/ React.createElement("div", null);
};
})(A || (A = {}));
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-2xxx/2423/output/index.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": ";;UAAUA;IACC,MAAMC,MAAAA,IAAI;IACV,SAASC;QACZC,QAAQC,GAAG,CAACH;IAChB;MAFgBC,IAAAA;AAGpB,GALUF,MAAAA",
"mappings": ";;UAAUA;MACOC,IAAI;IACV,SAASC;QACZC,QAAQC,GAAG,GAACH;IAChB;MAFgBC,IAAAA;AAGpB,GALUF,MAAAA",
"names": [
"A",
"v",
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-2xxx/2423/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
var A;
(function(A) {
const v = A.v = 25;
A.v = 25;
function a() {
console.log(v);
console.log(A.v);
}
A.a = a;
})(A || (A = {}));
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-2xxx/2636/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export var RuleInterpreterHelper;
(function(RuleInterpreterHelper) {
var fieldNameMap = RuleInterpreterHelper.fieldNameMap = [];
var fieldNameHashMap = RuleInterpreterHelper.fieldNameHashMap = new Map(fieldNameMap);
RuleInterpreterHelper.fieldNameMap = [];
RuleInterpreterHelper.fieldNameHashMap = new Map(RuleInterpreterHelper.fieldNameMap);
})(RuleInterpreterHelper || (RuleInterpreterHelper = {}));
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-3xxx/3073/1/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var n;
(function(n) {
var ref;
var a = (ref = {
ref = {
a: 1
}, n.a = ref.a, ref).a;
}, n.a = ref.a, ref;
})(n || (n = {}));
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-3xxx/3073/2/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var Foo;
(function(Foo) {
var ref;
var _ref = (ref = {
ref = {
a: 1,
b: 2
}, Foo.A = ref.a, Foo.B = ref.b, ref), A = _ref.a, B = _ref.b;
}, Foo.A = ref.a, Foo.B = ref.b, ref;
})(Foo || (Foo = {}));
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var foo;
(function(foo) {
var bar = foo.bar = 0;
foo.bar = 0;
})(foo || (foo = {}));
export { foo };
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-4xxx/4897/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ define([
}
var Foo;
(function(Foo) {
const Bar = Foo.Bar = 1234;
Foo.Bar = 1234;
})(Foo || (Foo = {}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var B;
})(B || (B = {}));
var Geometry;
(function(Geometry) {
var Points = Geometry.Points = A;
Geometry.Points = A;
var Lines = B;
Geometry.Origin = {
x: 0,
Expand Down
10 changes: 5 additions & 5 deletions crates/swc/tests/tsc-references/circularImportAlias.1.normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
var B;
(function(B) {
var a = B.a = A;
var D = /*#__PURE__*/ function(_a_C) {
B.a = A;
var D = /*#__PURE__*/ function(_B_a_C) {
"use strict";
_inherits(D, _a_C);
_inherits(D, _B_a_C);
var _super = _create_super(D);
function D() {
_class_call_check(this, D);
return _super.apply(this, arguments);
}
return D;
}(a.C);
}(B.a.C);
B.D = D;
})(B || (B = {}));
var A;
Expand All @@ -25,7 +25,7 @@ var A;
_class_call_check(this, C);
};
A.C = C;
var b = A.b = B;
A.b = B;
})(A || (A = {}));
var c;
var c = new B.a.C();
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ var B, A, B1, D, A1;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
D = function(_a_C) {
_inherits(D, _a_C);
(B1 = B || (B = {})).a = A, D = function(_B_a_C) {
_inherits(D, _B_a_C);
var _super = _create_super(D);
function D() {
return _class_call_check(this, D), _super.apply(this, arguments);
}
return D;
}(((B1 = B || (B = {})).a = A).C), B1.D = D, (A1 = A || (A = {})).C = function C() {
}(B1.a.C), B1.D = D, (A1 = A || (A = {})).C = function C() {
_class_call_check(this, C);
}, A1.b = B, new B.a.C();
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export var C = function C() {
_class_call_check(this, C);
};
(function(C) {
var x = C.x = 1;
C.x = 1;
})(C || (C = {}));
export var E;
(function(E) {
Expand All @@ -15,16 +15,16 @@ export var E;
E[E["x"] = 2] = "x";
})(E || (E = {}));
(function(E) {
var y = E.y = 1;
E.y = 1;
})(E || (E = {}));
(function(E) {
var z = E.z = 1;
E.z = 1;
})(E || (E = {}));
export var N;
(function(N) {
var x = N.x = 1;
N.x = 1;
})(N || (N = {}));
export function F() {}
(function(F) {
var x = F.x = 1;
F.x = 1;
})(F || (F = {}));
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export var C = function C() {
_class_call_check(this, C);
};
(function(C) {
var x = C.x = 1;
C.x = 1;
})(C || (C = {}));
export var E;
(function(E) {
Expand All @@ -15,16 +15,16 @@ export var E;
E[E["x"] = 2] = "x";
})(E || (E = {}));
(function(E) {
var y = E.y = 1;
E.y = 1;
})(E || (E = {}));
(function(E) {
var z = E.z = 1;
E.z = 1;
})(E || (E = {}));
export var N;
(function(N) {
var x = N.x = 1;
N.x = 1;
})(N || (N = {}));
export function F() {}
(function(F) {
var x = F.x = 1;
F.x = 1;
})(F || (F = {}));
7 changes: 4 additions & 3 deletions crates/swc/tests/tsc-references/exportImportAlias.1.normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var A;
})(A || (A = {}));
var C;
(function(C) {
var a = C.a = A;
C.a = A;
})(C || (C = {}));
var a = C.a.x;
var b = new C.a.Point(0, 0);
Expand All @@ -38,7 +38,8 @@ var X;
})(X || (X = {}));
var Z;
(function(Z) {
var y = Z.y = X.Y;
// 'y' should be a fundule here
Z.y = X.Y;
})(Z || (Z = {}));
var m = Z.y();
var n = new Z.y.Point(0, 0);
Expand All @@ -56,7 +57,7 @@ var K;
})(K || (K = {}));
var M;
(function(M) {
var D = M.D = K.L;
M.D = K.L;
})(M || (M = {}));
var o;
var o = new M.D("Hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var ns;
_class_call_check(this, Class);
};
ns.Class = Class;
var Value = ns.Value = "";
ns.Value = "";
var nested;
(function(nested) {
var NestedClass = function NestedClass() {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/tsc-references/typeOnlyMerge3.1.normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { };
//// [b.ts]
var A;
(function(A) {
var displayName = A.displayName = "A";
A.displayName = "A";
})(A || (A = {}));
export { A };
//// [c.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { A } from "./a";
//// [c.ts]
var A;
(function(A) {
var displayName = A.displayName = "A";
A.displayName = "A";
})(A || (A = {}));
A();
A.displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { };
var f1 = NonExistent;
var Foo;
(function(Foo) {
var foo = Foo.foo = 1;
Foo.foo = 1;
})(Foo || (Foo = {}));
var f2 = Foo.foo;
var f3 = Foo.T;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const I = require("./a");
"use strict";
var I;
(function(I) {
const x = I.x = 1;
I.x = 1;
})(I || (I = {}));
module.exports = I;
//// [/d.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./
const x = 1; // error
var Values;
(function(Values) {
const x = Values.x = 1;
Values.x = 1;
})(Values || (Values = {}));
// sketchy, but ok
//// [/main2.ts]
Expand All @@ -51,7 +51,7 @@ module.exports = {
"use strict";
var ns;
(function(ns) {
const x = ns.x = 1;
ns.x = 1;
})(ns || (ns = {}));
module.exports = ns;
//// [/main4.ts]
Expand Down
Loading

1 comment on commit cf96171

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.