Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/typescript): Preserve default value of an exported binding in a namespace #8029

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {}));
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 = {}));
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 };
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
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 = {}));
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
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
Loading